Skip to content

Commit

Permalink
Firmware revision 8
Browse files Browse the repository at this point in the history
+ Music format extensions to better accommodate for RTTTL
+ Fix bug when watchdog reset was delayed while playing music
+ Fix brushed mode (broken in Rev7)
+ Require power cycling for brushed mode

Support for PWM/EN bridge (PWM_ENABLE build option)
Support for two-wire serial (PA2+PA15)
Tune current sensor for AIRBOT1 and ESCAPE1 targets
Cosmetics
  • Loading branch information
neoxic committed Oct 24, 2023
1 parent 167767c commit b7e00c8
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 96 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ endfunction()
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=20 LED_MAP=0xA15B3B4)
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(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=40 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)
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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Features
+ Temperature/voltage/current protection
+ Variable PWM frequency, active freewheeling
+ Customizable startup music
+ Configuration via CLI using a USB-TTL adapter or Betaflight passthrough


Installation
Expand Down
5 changes: 3 additions & 2 deletions boot/mcu/STM32F0/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ void init(void) {
#ifdef IO_PA2
RCC_APB1ENR |= RCC_APB1ENR_USART2EN;
GPIOA_AFRL |= 0x100; // A2 (USART2_TX)
GPIOA_PUPDR |= 0x10; // A2 (pull-up)
GPIOA_MODER &= ~0x10; // 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)
#else
RCC_APB1ENR |= RCC_APB1ENR_TIM3EN;
#ifdef IO_PA6
Expand Down
5 changes: 3 additions & 2 deletions boot/mcu/STM32G0/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ void init(void) {
#ifdef IO_PA2
RCC_APBENR1 |= RCC_APBENR1_USART2EN;
GPIOA_AFRL |= 0x100; // A2 (USART2_TX)
GPIOA_PUPDR |= 0x10; // A2 (pull-up)
GPIOA_MODER &= ~0x10; // 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)
#else
RCC_APBENR1 |= RCC_APBENR1_TIM3EN;
#ifdef IO_PA6
Expand Down
2 changes: 1 addition & 1 deletion boot/src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
void initio(void) {
#ifdef IO_PA2
USART2_BRR = CLK_CNT(38400);
USART2_CR3 = USART_CR3_HDSEL;
if (!(GPIOA_IDR & 0x8000)) USART2_CR3 = USART_CR3_HDSEL; // A15 low
USART2_CR1 = USART_CR1_UE | USART_CR1_TE | USART_CR1_RE;
#else
TIM3_SMCR = TIM_SMCR_SMS_RM | TIM_SMCR_TS_TI1F_ED; // Reset on any edge on TI1
Expand Down
5 changes: 4 additions & 1 deletion mcu/AT32F421/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void init(void) {
GPIOB_MODER = 0xffffeffa; // B0 (TIM1_CH2N), B1 (TIM1_CH3N), B6 (USART1_TX)
#ifndef ANALOG
RCC_APB2ENR |= RCC_APB2ENR_TIM15EN;
GPIOA_PUPDR |= 0x10; // A2 (pull-up)
GPIOA_PUPDR |= 0x80000010; // A2 (pull-up), A15 (pull-down)
GPIOA_MODER &= ~0x10; // A2 (TIM15_CH1)
#endif

Expand Down Expand Up @@ -171,6 +171,9 @@ void io_serial(void) {
RCC_APB2ENR &= ~RCC_APB2ENR_TIM15EN;
RCC_APB1ENR |= RCC_APB1ENR_USART2EN;
GPIOA_AFRL |= 0x100; // A2 (USART2_TX)
GPIOA_AFRH |= 0x10000000; // A15 (USART2_RX)
GPIOA_MODER |= 0x80000000; // In case A15 is LED
GPIOA_MODER &= ~0x40000000; // A15 (USART2_RX)
}

void io_analog(void) {
Expand Down
5 changes: 4 additions & 1 deletion mcu/GD32E230/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void init(void) {
GPIOB_MODER = 0xffffeffa; // B0 (TIM1_CH2N), B1 (TIM1_CH3N), B6 (USART1_TX)
#ifndef ANALOG
RCC_APB2ENR |= RCC_APB2ENR_TIM15EN;
GPIOA_PUPDR |= 0x10; // A2 (pull-up)
GPIOA_PUPDR |= 0x80000010; // A2 (pull-up), A15 (pull-down)
GPIOA_MODER &= ~0x10; // A2 (TIM15_CH1)
#endif

Expand Down Expand Up @@ -130,6 +130,9 @@ void io_serial(void) {
RCC_APB2ENR &= ~RCC_APB2ENR_TIM15EN;
RCC_APB1ENR |= RCC_APB1ENR_USART2EN;
GPIOA_AFRL |= 0x100; // A2 (USART2_TX)
GPIOA_AFRH |= 0x10000000; // A15 (USART2_RX)
GPIOA_MODER |= 0x80000000; // In case A15 is LED
GPIOA_MODER &= ~0x40000000; // A15 (USART2_RX)
}

void io_analog(void) {
Expand Down
5 changes: 4 additions & 1 deletion mcu/GD32F350/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void init(void) {
#ifndef ANALOG
#ifdef IO_PA2
RCC_APB2ENR |= RCC_APB2ENR_TIM15EN;
GPIOA_PUPDR |= 0x10; // A2 (pull-up)
GPIOA_PUPDR |= 0x80000010; // A2 (pull-up), A15 (pull-down)
GPIOA_MODER &= ~0x10; // A2 (TIM15_CH1)
#else
RCC_APB1ENR |= RCC_APB1ENR_TIM3EN;
Expand Down Expand Up @@ -138,6 +138,9 @@ void io_serial(void) {
RCC_APB2ENR &= ~RCC_APB2ENR_TIM15EN;
RCC_APB1ENR |= RCC_APB1ENR_USART2EN;
GPIOA_AFRL |= 0x100; // A2 (USART2_TX)
GPIOA_AFRH |= 0x10000000; // A15 (USART2_RX)
GPIOA_MODER |= 0x80000000; // In case A15 is LED
GPIOA_MODER &= ~0x40000000; // A15 (USART2_RX)
}

void io_analog(void) {
Expand Down
5 changes: 4 additions & 1 deletion mcu/STM32F051/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void init(void) {
#ifndef ANALOG
#ifdef IO_PA2
RCC_APB2ENR |= RCC_APB2ENR_TIM15EN;
GPIOA_PUPDR |= 0x10; // A2 (pull-up)
GPIOA_PUPDR |= 0x80000010; // A2 (pull-up), A15 (pull-down)
GPIOA_MODER &= ~0x10; // A2 (TIM15_CH1)
#else
RCC_APB1ENR |= RCC_APB1ENR_TIM3EN;
Expand Down Expand Up @@ -122,6 +122,9 @@ void io_serial(void) {
RCC_APB2ENR &= ~RCC_APB2ENR_TIM15EN;
RCC_APB1ENR |= RCC_APB1ENR_USART2EN;
GPIOA_AFRL |= 0x100; // A2 (USART2_TX)
GPIOA_AFRH |= 0x10000000; // A15 (USART2_RX)
GPIOA_MODER |= 0x80000000; // In case A15 is LED
GPIOA_MODER &= ~0x40000000; // A15 (USART2_RX)
}

void io_analog(void) {
Expand Down
5 changes: 4 additions & 1 deletion mcu/STM32G071/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void init(void) {
#ifdef IO_PA2
RCC_APBENR2 |= RCC_APBENR2_TIM15EN;
GPIOA_AFRL |= 0x500; // A2 (TIM15_CH1)
GPIOA_PUPDR |= 0x10; // A2 (pull-up)
GPIOA_PUPDR |= 0x80000010; // A2 (pull-up), A15 (pull-down)
GPIOA_MODER &= ~0x10; // A2 (TIM15_CH1)
#else
RCC_APBENR1 |= RCC_APBENR1_TIM3EN;
Expand Down Expand Up @@ -242,6 +242,9 @@ void io_serial(void) {
RCC_APBENR1 |= RCC_APBENR1_USART2EN;
GPIOA_AFRL &= ~0xf00;
GPIOA_AFRL |= 0x100; // A2 (USART2_TX)
GPIOA_AFRH |= 0x10000000; // A15 (USART2_RX)
GPIOA_MODER |= 0x80000000; // In case A15 is LED
GPIOA_MODER &= ~0x40000000; // A15 (USART2_RX)
DMAMUX1_CxCR(1) = DMAMUX_CxCR_DMAREQ_ID_USART2_RX;
}

Expand Down
62 changes: 31 additions & 31 deletions src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,37 @@
XX( 0, val, arm) \
XX( 1, val, damp) \
XX( 2, val, revdir) \
XX( 3, val, timing) \
XX( 4, val, sine_range) \
XX( 5, val, sine_power) \
XX( 6, val, freq_min) \
XX( 7, val, freq_max) \
XX( 8, val, duty_min) \
XX( 9, val, duty_max) \
XX(10, val, duty_spup) \
XX(11, val, duty_ramp) \
XX(12, val, duty_rate) \
XX(13, val, duty_drag) \
XX(14, val, throt_mode) \
XX(15, val, throt_set) \
XX(16, val, throt_cal) \
XX(17, val, throt_min) \
XX(18, val, throt_mid) \
XX(19, val, throt_max) \
XX(20, val, input_mode) \
XX(21, val, input_chid) \
XX(22, val, telem_mode) \
XX(23, val, telem_phid) \
XX(24, val, telem_poles) \
XX(25, val, prot_temp) \
XX(26, val, prot_volt) \
XX(27, val, prot_cells) \
XX(28, val, prot_curr) \
XX(29, str, music) \
XX(30, val, volume) \
XX(31, val, beacon) \
XX(32, val, led) \
XX(33, val, brushed) \
XX( 3, val, brushed) \
XX( 4, val, timing) \
XX( 5, val, sine_range) \
XX( 6, val, sine_power) \
XX( 7, val, freq_min) \
XX( 8, val, freq_max) \
XX( 9, val, duty_min) \
XX(10, val, duty_max) \
XX(11, val, duty_spup) \
XX(12, val, duty_ramp) \
XX(13, val, duty_rate) \
XX(14, val, duty_drag) \
XX(15, val, throt_mode) \
XX(16, val, throt_set) \
XX(17, val, throt_cal) \
XX(18, val, throt_min) \
XX(19, val, throt_mid) \
XX(20, val, throt_max) \
XX(21, val, input_mode) \
XX(22, val, input_chid) \
XX(23, val, telem_mode) \
XX(24, val, telem_phid) \
XX(25, val, telem_poles) \
XX(26, val, prot_temp) \
XX(27, val, prot_volt) \
XX(28, val, prot_cells) \
XX(29, val, prot_curr) \
XX(30, str, music) \
XX(31, val, volume) \
XX(32, val, beacon) \
XX(33, val, led) \

static int beep = -1;

Expand Down
4 changes: 2 additions & 2 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ typedef struct {
char arm;
char damp;
char revdir;
char brushed;
char timing;
char sine_range;
char sine_power;
Expand All @@ -92,11 +93,10 @@ typedef struct {
char prot_volt;
char prot_cells;
char prot_curr;
char music[128];
char music[256];
char volume;
char beacon;
char led;
char brushed;
} Cfg;

typedef struct {
Expand Down
16 changes: 8 additions & 8 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static void entryirq(void) {
#ifdef IO_PA2
io_serial();
USART2_BRR = CLK_CNT(38400);
USART2_CR3 = USART_CR3_HDSEL;
if (!(GPIOA_IDR & 0x8000)) USART2_CR3 = USART_CR3_HDSEL; // A15 low
USART2_CR1 = USART_CR1_UE | USART_CR1_TE | USART_CR1_RE | USART_CR1_RXNEIE;
#else
TIM3_CCER = 0;
Expand Down Expand Up @@ -202,13 +202,13 @@ static void servoirq(void) {
int w = TIM_CCR2(IOTIM); // Pulse width
if (p < 2000) return; // Invalid signal
if (w >= 28 && w <= 32) { // Telemetry request
telreq = 1;
IWDG_KR = IWDG_KR_RESET;
telreq = 1;
return;
}
if (w < 800 || w > 2200) return; // Invalid signal
servoval(w);
IWDG_KR = IWDG_KR_RESET;
servoval(w);
}

static void dshotirq(void) {
Expand Down Expand Up @@ -491,10 +491,10 @@ static void throtdma(void) {
resync();
return;
}
IWDG_KR = IWDG_KR_RESET;
x &= 0xfff;
if (x & 0x800) x -= 0x1000; // Propagate sign
throt = x;
IWDG_KR = IWDG_KR_RESET;
}

static void ibusdma(void) {
Expand All @@ -520,15 +520,16 @@ static void ibusdma(void) {
u -= a + b;
if (i == n) x = v & 0xfff;
}
servoval(x);
IWDG_KR = IWDG_KR_RESET;
servoval(x);
}

static void sbusdma(void) {
if (iobuf[0] != 0x0f) { // Invalid frame
resync();
return;
}
IWDG_KR = IWDG_KR_RESET;
int n = cfg.input_chid - 1;
int i = (n * 11) >> 3;
int a = (n * 3) & 7;
Expand All @@ -540,7 +541,6 @@ static void sbusdma(void) {
x < 946 ? scale(x, 240, 946, -2000, 0):
x > 1101 ? scale(x, 1101, 1807, 0, 2000): 0:
x > 318 ? scale(x, 318, 1807, 0, 2000): 0;
IWDG_KR = IWDG_KR_RESET;
}

static void cliirq(void) {
Expand Down Expand Up @@ -569,7 +569,7 @@ static void cliirq(void) {
if (USART2_ISR & USART_ISR_FE || i == sizeof iobuf - 1) WWDG_CR = WWDG_CR_WDGA; // Data error
char b = USART2_RDR; // Clear RXNE
if (b == '\b' || b == 0x7f) { // Backspace
if (i > 0) --i;
if (i) --i;
return;
}
iobuf[i++] = b;
Expand Down Expand Up @@ -628,7 +628,7 @@ static void cliirq(void) {
TIM3_DIER = TIM_DIER_CC2IE;
n = 0;
if (b == '\b' || b == 0x7f) { // Backspace
if (i > 0) --i;
if (i) --i;
break;
}
iobuf[i++] = b;
Expand Down
Loading

0 comments on commit b7e00c8

Please sign in to comment.