Skip to content

Commit

Permalink
fix: Fix BluePill board PWM outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
lcgamboa committed Nov 16, 2024
1 parent f732d22 commit 6858b19
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 61 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ PACKAGE=picsimlab
MAINVER=0
MINORVER=9
VERSION=0.9.2
DATE=241005
DATE=241116
VERSION_STABLE=0.9.2
46 changes: 16 additions & 30 deletions src/boards/board_Blue_Pill.cc
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,6 @@ void cboard_Blue_Pill::PinsExtraConfig(int cfg) {
master_uart[1].tx_pin = iopin(A, 2);
master_uart[1].rx_pin = iopin(A, 3);
master_uart[1].ctrl_on = 1;
break;
}
// tim2 ch3
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM2);
Expand All @@ -959,7 +958,6 @@ void cboard_Blue_Pill::PinsExtraConfig(int cfg) {
master_uart[1].tx_pin = iopin(A, 2);
master_uart[1].rx_pin = iopin(A, 3);
master_uart[1].ctrl_on = 1;
break;
}
// tim2 ch4
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM2);
Expand Down Expand Up @@ -987,7 +985,6 @@ void cboard_Blue_Pill::PinsExtraConfig(int cfg) {
master_spi[0].copi_pin = iopin(A, 7);
master_spi[0].cipo_pin = iopin(A, 6);
master_spi[0].ctrl_on = 1;
break;
}
// tim3 ch1
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM3);
Expand All @@ -1003,13 +1000,11 @@ void cboard_Blue_Pill::PinsExtraConfig(int cfg) {
master_spi[0].copi_pin = iopin(A, 7);
master_spi[0].cipo_pin = iopin(A, 6);
master_spi[0].ctrl_on = 1;
break;
}
// tim1_ch1n (alt)
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM1);
if (*afio == 1) {
bitbang_pwm_set_pin(&pwm_out, (0 << 2) + 0, iopin(A, 7));
break;
}
// tim3 ch2
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM3);
Expand All @@ -1031,7 +1026,6 @@ void cboard_Blue_Pill::PinsExtraConfig(int cfg) {
master_uart[0].tx_pin = iopin(A, 9);
master_uart[0].rx_pin = iopin(A, 10);
master_uart[0].ctrl_on = 1;
break;
}
// tim1 ch2
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM1);
Expand All @@ -1046,7 +1040,6 @@ void cboard_Blue_Pill::PinsExtraConfig(int cfg) {
master_uart[0].tx_pin = iopin(A, 9);
master_uart[0].rx_pin = iopin(A, 10);
master_uart[0].ctrl_on = 1;
break;
}
// tim1 ch3
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM1);
Expand Down Expand Up @@ -1078,7 +1071,6 @@ void cboard_Blue_Pill::PinsExtraConfig(int cfg) {
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM1);
if (*afio == 1) {
bitbang_pwm_set_pin(&pwm_out, (0 << 2) + 1, iopin(B, 0));
break;
}
// tim3_ch3
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM3);
Expand All @@ -1091,14 +1083,12 @@ void cboard_Blue_Pill::PinsExtraConfig(int cfg) {
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM1);
if (*afio == 1) {
bitbang_pwm_set_pin(&pwm_out, (0 << 2) + 2, iopin(B, 1));
break;
}
// tim3_ch4
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM3);
if (*afio == 0) {
bitbang_pwm_set_pin(&pwm_out, (2 << 2) + 3, iopin(B, 1));
}

break;
case 2:
break;
Expand All @@ -1107,15 +1097,15 @@ void cboard_Blue_Pill::PinsExtraConfig(int cfg) {
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM2);
if (*afio == 1) {
bitbang_pwm_set_pin(&pwm_out, (1 << 2) + 1, iopin(B, 3));
break;
}
break;
case 4:
// tim3_ch1n (alt)
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM3);
if (*afio == 2) {
bitbang_pwm_set_pin(&pwm_out, (2 << 2) + 0, iopin(B, 4));
break;
}
break;
case 5:
// spi1 (alt)
afio = qemu_picsimlab_get_internals(0x1000 | STM32_SPI1);
Expand All @@ -1124,13 +1114,11 @@ void cboard_Blue_Pill::PinsExtraConfig(int cfg) {
master_spi[0].copi_pin = iopin(B, 5);
master_spi[0].cipo_pin = iopin(B, 4);
master_spi[0].ctrl_on = 1;
break;
}
// tim3_ch2n (alt)
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM3);
if (*afio == 2) {
bitbang_pwm_set_pin(&pwm_out, (2 << 2) + 1, iopin(B, 5));
break;
}
break;
case 6:
Expand All @@ -1140,15 +1128,13 @@ void cboard_Blue_Pill::PinsExtraConfig(int cfg) {
master_uart[0].tx_pin = iopin(B, 6);
master_uart[0].rx_pin = iopin(B, 7);
master_uart[0].ctrl_on = 1;
break;
}
// i2c
afio = qemu_picsimlab_get_internals(0x1000 | STM32_I2C1);
if (!(*afio)) {
master_i2c[0].scl_pin = iopin(B, 6);
master_i2c[0].sda_pin = iopin(B, 7);
master_i2c[0].ctrl_on = 1;
break;
}
// tim4 ch1
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM4);
Expand All @@ -1163,15 +1149,13 @@ void cboard_Blue_Pill::PinsExtraConfig(int cfg) {
master_uart[0].tx_pin = iopin(B, 6);
master_uart[0].rx_pin = iopin(B, 7);
master_uart[0].ctrl_on = 1;
break;
}
// i2c0
afio = qemu_picsimlab_get_internals(0x1000 | STM32_I2C1);
if (!(*afio)) {
master_i2c[0].scl_pin = iopin(B, 6);
master_i2c[0].sda_pin = iopin(B, 7);
master_i2c[0].ctrl_on = 1;
break;
}
// tim4 ch2
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM4);
Expand All @@ -1186,21 +1170,20 @@ void cboard_Blue_Pill::PinsExtraConfig(int cfg) {
master_i2c[0].scl_pin = iopin(B, 8);
master_i2c[0].sda_pin = iopin(B, 9);
master_i2c[0].ctrl_on = 1;
break;
}
// tim4 ch3
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM4);
if (*afio == 0) {
bitbang_pwm_set_pin(&pwm_out, (3 << 2) + 2, iopin(B, 8));
}
break;
case 9:
// i2c0 (alt)
afio = qemu_picsimlab_get_internals(0x1000 | STM32_I2C1);
if ((*afio)) {
master_i2c[0].scl_pin = iopin(B, 8);
master_i2c[0].sda_pin = iopin(B, 9);
master_i2c[0].ctrl_on = 1;
break;
}
// tim4 ch4
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM4);
Expand All @@ -1213,7 +1196,6 @@ void cboard_Blue_Pill::PinsExtraConfig(int cfg) {
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM2);
if (*afio == 1) {
bitbang_pwm_set_pin(&pwm_out, (1 << 2) + 2, iopin(B, 10));
break;
}
/*
// uart3
Expand All @@ -1232,15 +1214,13 @@ void cboard_Blue_Pill::PinsExtraConfig(int cfg) {
master_i2c[1].scl_pin = iopin(B, 10);
master_i2c[1].sda_pin = iopin(B, 11);
master_i2c[1].ctrl_on = 1;
break;
}
break;
case 11:
// tim2_ch4n (alt)
afio = qemu_picsimlab_get_internals(0x1000 | STM32_TIM2);
if (*afio == 1) {
bitbang_pwm_set_pin(&pwm_out, (1 << 2) + 3, iopin(B, 10));
break;
}
/*
// uart3
Expand All @@ -1259,7 +1239,6 @@ void cboard_Blue_Pill::PinsExtraConfig(int cfg) {
master_i2c[1].scl_pin = iopin(B, 10);
master_i2c[1].sda_pin = iopin(B, 11);
master_i2c[1].ctrl_on = 1;
break;
}
break;
case 12:
Expand Down Expand Up @@ -1303,17 +1282,24 @@ void cboard_Blue_Pill::PinsExtraConfig(int cfg) {
int duty = (cfg & 0xFFFF0) >> 4;
int chn = (cfg & 0x000C) >> 2;
int timer = cfg & 0x0003;
// printf("TIM %i chn %i dut set to %i\n", timer +
// 1, chn + 1, duty);
// printf("TIM %i chn %i dut set to %i\n", timer + 1, chn + 1, duty);
bitbang_pwm_set_duty(&pwm_out, (timer << 2) + chn, duty);
} else if ((cfg & 0xF00000) == 0xD00000) { // timer frequency
int freq = (cfg & 0xFFFFC) >> 2;
int timer = cfg & 0x0003;
// printf("TIM %i freq set to %i\n", timer + 1, freq);
bitbang_pwm_set_freq(&pwm_out, timer + 0, freq);
bitbang_pwm_set_freq(&pwm_out, timer + 1, freq);
bitbang_pwm_set_freq(&pwm_out, timer + 2, freq);
bitbang_pwm_set_freq(&pwm_out, timer + 3, freq);
bitbang_pwm_set_freq(&pwm_out, (timer << 2) + 0, freq);
bitbang_pwm_set_freq(&pwm_out, (timer << 2) + 1, freq);
bitbang_pwm_set_freq(&pwm_out, (timer << 2) + 2, freq);
bitbang_pwm_set_freq(&pwm_out, (timer << 2) + 3, freq);
} else if ((cfg & 0xF00000) == 0xE00000) { // timer enable output
int ccer = (cfg & 0xFFFFC) >> 2;
int timer = cfg & 0x0003;
// printf("TIM %i ccer 0x%04X\n", timer + 1, ccer);
bitbang_pwm_set_enable(&pwm_out, (timer << 2) + 0, (ccer & 0x0005) > 0);
bitbang_pwm_set_enable(&pwm_out, (timer << 2) + 1, (ccer & 0x0050) > 0);
bitbang_pwm_set_enable(&pwm_out, (timer << 2) + 2, (ccer & 0x0500) > 0);
bitbang_pwm_set_enable(&pwm_out, (timer << 2) + 3, (ccer & 0x5000) > 0);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/boards/board_C3_DevKitC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ void cboard_C3_DevKitC::PinsExtraConfig(int cfg) {
case 50: // ledc_ls_sig_out5
// printf("LEDC channel %i in GPIO %i\n", function - 45, gpio);
bitbang_pwm_set_pin(&pwm_out, function - 45, io2pin(gpio));
bitbang_pwm_set_enable(&pwm_out, function - 45, 1);
break;
case 51: // rmt_sig_out0
case 52: // rmt_sig_out1
Expand Down
1 change: 1 addition & 0 deletions src/boards/board_DevKitC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,7 @@ void cboard_DevKitC::PinsExtraConfig(int cfg) {
case 86: // ledc_ls_sig_out7
// printf("LEDC channel %i in GPIO %i\n",function - 71, gpio);
bitbang_pwm_set_pin(&pwm_out, function - 71, io2pin(gpio));
bitbang_pwm_set_enable(&pwm_out, function - 71, 1);
break;
case 87: // rmt_sig_out0
// case 88: // rmt_sig_out1 //FIXME only channel 0 enabled
Expand Down
Loading

0 comments on commit 6858b19

Please sign in to comment.