diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ba3e51..ff32e33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/boot/CMakeLists.txt b/boot/CMakeLists.txt index 2677465..4d84585 100644 --- a/boot/CMakeLists.txt +++ b/boot/CMakeLists.txt @@ -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) diff --git a/boot/mcu/STM32F0/config.c b/boot/mcu/STM32F0/config.c index 95e2132..120dbba 100644 --- a/boot/mcu/STM32F0/config.c +++ b/boot/mcu/STM32F0/config.c @@ -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 diff --git a/boot/mcu/STM32G0/config.c b/boot/mcu/STM32G0/config.c index a58020a..d2bed2b 100644 --- a/boot/mcu/STM32G0/config.c +++ b/boot/mcu/STM32G0/config.c @@ -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 diff --git a/boot/src/io.c b/boot/src/io.c index f0a317c..01b20c4 100644 --- a/boot/src/io.c +++ b/boot/src/io.c @@ -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; @@ -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 diff --git a/src/io.c b/src/io.c index ac95063..d44c1b2 100644 --- a/src/io.c +++ b/src/io.c @@ -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 diff --git a/src/util.c b/src/util.c index 483d2a9..8f3c49f 100644 --- a/src/util.c +++ b/src/util.c @@ -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;