Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various soft serial fixes #3382

Merged
merged 4 commits into from
Mar 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions radio/src/io/multi_firmware_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ const char * MultiFirmwareUpdateDriver::waitForInitialSync()

const char * MultiFirmwareUpdateDriver::getDeviceSignature(uint8_t * signature) const
{
clear();

// Read signature
sendByte(STK_READ_SIGN);
sendByte(CRC_EOP);
Expand Down
6 changes: 5 additions & 1 deletion radio/src/targets/common/arm/stm32/stm32_pulse_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ void stm32_pulse_init(const stm32_pulse_timer_t* tim, uint32_t freq)
}

timInit.Prescaler = __LL_TIM_CALC_PSC(tim->TIM_Freq, freq);
timInit.Autoreload = STM32_DEFAULT_TIMER_AUTORELOAD;
if (IS_TIM_32B_COUNTER_INSTANCE(tim->TIMx)) {
timInit.Autoreload = 0xFFFFFFFFUL;
} else {
timInit.Autoreload = STM32_DEFAULT_TIMER_AUTORELOAD;
}

enable_tim_clock(tim->TIMx);
LL_TIM_Init(tim->TIMx, &timInit);
Expand Down
11 changes: 9 additions & 2 deletions radio/src/targets/common/arm/stm32/stm32_softserial_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,21 @@ static const stm32_softserial_rx_port* _softserialPort;
static void _softserial_exti()
{
if (rxBitCount == 0) {
auto port = _softserialPort;

// cheap debouncing...
for (uint8_t i = 0; i < 16; ++i) {
if (LL_GPIO_IsInputPinSet(port->GPIOx, port->GPIO_Pin) == 0)
return;
}

// enable timer counter
auto TIMx = _softserialPort->TIMx;
auto TIMx = port->TIMx;
LL_TIM_SetAutoReload(TIMx, (BITLEN + BITLEN/2) - 1);
LL_TIM_EnableCounter(TIMx);

// disable start bit interrupt
LL_EXTI_DisableIT_0_31(_softserialPort->EXTI_Line);
LL_EXTI_DisableIT_0_31(port->EXTI_Line);
}
}

Expand Down
9 changes: 5 additions & 4 deletions radio/src/targets/common/arm/stm32/stm32_usart_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,14 +557,15 @@ void stm32_usart_isr(const stm32_usart_t* usart, etx_serial_callbacks_t* cb)
// Drain RX
while (status & (LL_USART_SR_RXNE | USART_FLAG_ERRORS)) {

// This will clear the RXNE bit in USART_DR register
uint8_t data = LL_USART_ReadReg(usart->USARTx, DR);

if (status & USART_FLAG_ERRORS) {
if (cb->on_error)
cb->on_error();
}
else {

if (status & LL_USART_SR_RXNE) {
// This will clear the RXNE bit in USART_DR register
uint8_t data = LL_USART_ReadReg(usart->USARTx, DR);

if (cb->on_receive)
cb->on_receive(data);
}
Expand Down