Skip to content

Commit

Permalink
Firmware revision 9 (patch 2)
Browse files Browse the repository at this point in the history
Disable AUX input by default to avoid conflict with LEDs on some boards
PWM_ENABLE fix music
Add DYS1 target
  • Loading branch information
neoxic committed Jan 26, 2024
1 parent 8ce1ca9 commit 94cf738
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 16 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ add_subdirectory(boot)
add_target(AIKON1 STM32G071 DEAD_TIME=35 COMP_MAP=213 IO_PA6)
add_target(AIRBOT1 AT32F421 DEAD_TIME=66 COMP_MAP=321 SENS_MAP=0xA3A6 VOLT_MUL=74 CURR_MUL=30 LED_MAP=0xA15B3B4)
add_target(AIRBOT2 STM32F051 DEAD_TIME=26 COMP_MAP=321 SENS_MAP=0xA3 VOLT_MUL=74 IO_PA2)
add_target(DYS1 STM32F051 DEAD_TIME=26 COMP_MAP=123 LED_MAP=0xA15B3B4 LED_INV IO_PA2)
add_target(EMAX1 STM32F051 DEAD_TIME=26 COMP_MAP=123 IO_PA2)
add_target(ESCAPE1 STM32G071 DEAD_TIME=35 COMP_MAP=123 SENS_MAP=0xA5A4 VOLT_MUL=110 CURR_MUL=30 LED_WS2812 IO_PA2)
add_target(ESCAPE1 STM32G071 DEAD_TIME=35 COMP_MAP=123 SENS_MAP=0xA5A4 VOLT_MUL=110 CURR_MUL=30 LED_WS2812 IO_PA2 IO_AUX)
add_target(FLYCOLOR1 STM32F051 DEAD_TIME=26 COMP_MAP=123 SENS_MAP=0xA6 VOLT_MUL=110 LED_MAP=0xB5B4B3 IO_PA2)
add_target(FLYCOLOR2 STM32G071 DEAD_TIME=35 COMP_MAP=123 SENS_MAP=0xA6 VOLT_MUL=110 LED_MAP=0xB8)
add_target(HAKRC1 STM32F051 DEAD_TIME=26 COMP_MAP=213 SENS_MAP=0xA3 VOLT_MUL=110 LED_MAP=0xA15B5B3 LED_INV)
Expand Down
2 changes: 1 addition & 1 deletion boot/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add_target(BOOT1_PA2 STM32F0 IO_PA2)
add_target(BOOT1_PB4 STM32F0)
add_target(BOOT2_PA2 STM32G0 IO_PA2)
add_target(BOOT2_PA2 STM32G0 IO_PA2 IO_AUX)
add_target(BOOT2_PA6 STM32G0 IO_PA6)
add_target(BOOT2_PB4 STM32G0)
add_target(BOOT3_PA2 STM32F0 IO_PA2 USARTv1)
Expand Down
4 changes: 2 additions & 2 deletions boot/mcu/STM32F0/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ void init(void) {
RCC_APB1ENR |= RCC_APB1ENR_USART2EN;
GPIOA_AFRL |= 0x100; // A2 (USART2_TX)
GPIOA_AFRH |= 0x10000000; // A15 (USART2_RX)
GPIOA_PUPDR |= 0x80000010; // A2 (pull-up), A15 (pull-down)
GPIOA_MODER &= ~0x40000010; // A2 (USART2_TX), A15 (USART2_RX)
GPIOA_PUPDR |= 0x10; // A2 (pull-up)
GPIOA_MODER &= ~0x10; // A2 (USART2_TX)
#else
RCC_APB1ENR |= RCC_APB1ENR_TIM3EN;
#ifdef IO_PA6
Expand Down
4 changes: 2 additions & 2 deletions boot/mcu/STM32G0/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ void init(void) {
RCC_APBENR1 |= RCC_APBENR1_USART2EN;
GPIOA_AFRL |= 0x100; // A2 (USART2_TX)
GPIOA_AFRH |= 0x10000000; // A15 (USART2_RX)
GPIOA_PUPDR |= 0x80000010; // A2 (pull-up), A15 (pull-down)
GPIOA_MODER &= ~0x40000010; // A2 (USART2_TX), A15 (USART2_RX)
GPIOA_PUPDR |= 0x10; // A2 (pull-up)
GPIOA_MODER &= ~0x10; // A2 (USART2_TX)
#else
RCC_APBENR1 |= RCC_APBENR1_TIM3EN;
#ifdef IO_PA6
Expand Down
6 changes: 6 additions & 0 deletions boot/src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

void initio(void) {
#ifdef IO_PA2
#ifdef IO_AUX
GPIOA_PUPDR |= 0x80000000; // A15 (pull-down)
GPIOA_MODER &= ~0x40000000; // A15 (USART2_RX)
TIM14_ARR = CLK_CNT(20000) - 1;
TIM14_EGR = TIM_EGR_UG;
TIM14_CR1 = TIM_CR1_CEN;
Expand All @@ -40,6 +43,9 @@ void initio(void) {
break;
}
}
#else
USART2_CR3 = USART_CR3_HDSEL;
#endif
USART2_BRR = CLK_CNT(38400);
USART2_CR1 = USART_CR1_UE | USART_CR1_TE | USART_CR1_RE;
#else
Expand Down
15 changes: 6 additions & 9 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,21 @@ static void entryirq(void) {
ioirq = cliirq;
#ifdef IO_PA2
io_serial();
int r1 = GPIOA_ODR;
int r2 = GPIOA_PUPDR;
int r3 = GPIOA_MODER;
GPIOA_ODR = r1 & ~0x8000; // In case A15 is output
GPIOA_PUPDR = r2 | 0x80000000; // A15 (pull-down)
GPIOA_MODER = (r3 | 0xc0000000) & ~0x40000000; // A15 (USART2_RX)
#ifdef IO_AUX
GPIOA_PUPDR |= 0x80000000; // A15 (pull-down)
GPIOA_MODER &= ~0x40000000; // A15 (USART2_RX)
TIM15_ARR = CLK_CNT(20000) - 1;
TIM15_EGR = TIM_EGR_UG;
TIM15_CR1 = TIM_CR1_CEN | TIM_CR1_OPM;
while (TIM15_CR1 & TIM_CR1_CEN) { // Wait for 50us high level on A15
if (!(GPIOA_IDR & 0x8000)) { // A15 low
GPIOA_ODR = r1;
GPIOA_PUPDR = r2;
GPIOA_MODER = r3;
USART2_CR3 = USART_CR3_HDSEL;
break;
}
}
#else
USART2_CR3 = USART_CR3_HDSEL;
#endif
USART2_BRR = CLK_CNT(38400);
USART2_CR1 = USART_CR1_UE | USART_CR1_TE | USART_CR1_RE | USART_CR1_RXNEIE;
#else
Expand Down
2 changes: 1 addition & 1 deletion src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ int playmusic(const char *str, int vol) {
#ifdef PWM_ENABLE
TIM1_CCMR1 = TIM_CCMR1_OC1M_FORCE_LOW | TIM_CCMR1_OC2PE | TIM_CCMR1_OC2M_PWM1;
TIM1_CCMR2 = TIM_CCMR2_OC3M_FORCE_LOW;
int er = TIM_CCER_CC2E;
int er = TIM_CCER_CC1NE | TIM_CCER_CC2E | TIM_CCER_CC3NE;
#else
TIM1_CCMR1 = TIM_CCMR1_OC1M_FORCE_HIGH | TIM_CCMR1_OC2PE | TIM_CCMR1_OC2M_PWM1;
TIM1_CCMR2 = TIM_CCMR2_OC3M_FORCE_HIGH;
Expand Down

0 comments on commit 94cf738

Please sign in to comment.