chore: New module/serial API (#3055)
* WiP: new module interface * WiP: softserial timer DMA * WiP: setup() and send() in one step and remove methods specific to internal or external module * fixes and extra port config * horus targets * module ports have moved * T8 support (only internal module) * fix nv14 * stupid GCC.... * disable BT * remove nv14 telem driver * remove old aux serial driver * Move module buffers out of pulses.h * Soft serial fixes and PXX1 support * Fixed PPM module output * Fixed CLI * compilation fixes * Ported bluetooth and flysky gimbal to new serial driver * Re-enable soft-serial RX * fixes and cleanup * nv14 fixes * Fix flysky gimbals * Ghost module * 16 bytes of RAM * Remove getByte from module API * Ghost cleanup * fix: _half_duplex_input() must be called after usart init * WiP * more cleanup * Remove board specific settings from PXX1 / PXX2 drivers * A bit of PXX2 header cleanup * Add support for OVER8 and ONEBIT * Add some support for inverters (NV14 / EL18) * Support NV14 power fixes in generic board * Fix polarity handling * Fix RX DMA * Fix mixer not running * Add soft-serial polarity control * Quick fix for telemetry polling while module port is changed * Fix bootloader DEBUG * Fix MPM telemetry * Fix pulse start * DSM2 soft-serial fallback * DSMP async module restart * Fix CRSF LUA upstream * Remove global variable telemetryProtocol * Use HAL/LL constants * Fix various issue with AFHDS3 and NV14/EL18 internal module * Fixed S.PORT unit tests * fix: update widx after writing at current index * fix: init error condition * Fix: possible infinite loop in _find_port() * Add support for bidir S.PORT init * Add support for "getLastByte" in HW serial driver * PXX1: Add support for S.PORT based on IDLE callback * Fix rebase error * Fix softserial _rx_fifo_push() * Add softserial support for waitForTxCompleted() * Fix MPM flashing (internal / external) * Fixed external MPM * Activate RX DMA on internal module Seems to work with serial passthrough without issues, at least on the L3R PRO. * Fix softserial DMA on stdlcd F4 targets * Add softserial support for 32bit timers (mostly TIM2) * More precise soft-serial * Fix MPM update using inverters & HW uart * Raise S.PORT DMA/USART IRQ prio to achieve faster switching to input * Remove useless delays * Fix flashing external ELRS module * Added a retry mechanism for FrSky S.PORT update * Remove useless enableRx() * External FrSky modules are all flashed via S.PORT * Remove power management unit update This was only used on the first batch of X-lite.
This commit is contained in:
@@ -19,8 +19,9 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_usart_driver.h"
|
||||
#include "stm32_dma.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
// WARNING:
|
||||
@@ -51,6 +52,28 @@ static void _enable_usart_irq(const stm32_usart_t* usart)
|
||||
NVIC_EnableIRQ(usart->IRQn);
|
||||
}
|
||||
|
||||
static void _enable_tx_dma_irq(const stm32_usart_t* usart)
|
||||
{
|
||||
NVIC_SetPriority(usart->txDMA_IRQn, usart->txDMA_IRQ_Prio);
|
||||
NVIC_EnableIRQ(usart->txDMA_IRQn);
|
||||
}
|
||||
|
||||
static inline void _half_duplex_input(const stm32_usart_t* usart)
|
||||
{
|
||||
if (usart->set_input) {
|
||||
usart->set_input(true);
|
||||
LL_USART_EnableDirectionRx(usart->USARTx);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void _half_duplex_output(const stm32_usart_t* usart)
|
||||
{
|
||||
if (usart->set_input) {
|
||||
usart->set_input(false);
|
||||
LL_USART_DisableDirectionRx(usart->USARTx);
|
||||
}
|
||||
}
|
||||
|
||||
void stm32_usart_enable_tx_irq(const stm32_usart_t* usart)
|
||||
{
|
||||
if (LL_USART_IsEnabledDMAReq_TX(usart->USARTx)) {
|
||||
@@ -65,6 +88,19 @@ void stm32_usart_enable_tx_irq(const stm32_usart_t* usart)
|
||||
LL_USART_EnableIT_TXE(usart->USARTx);
|
||||
}
|
||||
|
||||
void stm32_usart_set_idle_irq(const stm32_usart_t* usart, uint32_t enabled)
|
||||
{
|
||||
if (enabled) {
|
||||
LL_USART_EnableIT_IDLE(usart->USARTx);
|
||||
_enable_usart_irq(usart);
|
||||
} else {
|
||||
LL_USART_DisableIT_IDLE(usart->USARTx);
|
||||
// Let's assume the port will be disabled soon
|
||||
// and we don't need to figure out whether or
|
||||
// not the IRQ needs to be disabled
|
||||
}
|
||||
}
|
||||
|
||||
static void enable_usart_clock(USART_TypeDef* USARTx)
|
||||
{
|
||||
if (USARTx == USART1) {
|
||||
@@ -106,15 +142,39 @@ static void disable_usart_clock(USART_TypeDef* USARTx)
|
||||
|
||||
}
|
||||
|
||||
void stm32_usart_init_rx_dma(const stm32_usart_t* usart, void* buffer, uint32_t length)
|
||||
static uint32_t _get_pin_speed(uint32_t baudrate)
|
||||
{
|
||||
// 1 Mbps and above
|
||||
if (baudrate >= 1000000) {
|
||||
return LL_GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
}
|
||||
// 400kbps and above
|
||||
else if (baudrate >= 400000) {
|
||||
return LL_GPIO_SPEED_FREQ_HIGH;
|
||||
}
|
||||
|
||||
// under 400kbps
|
||||
return LL_GPIO_SPEED_FREQ_LOW;
|
||||
}
|
||||
|
||||
static uint32_t _get_usart_af(USART_TypeDef* USARTx)
|
||||
{
|
||||
if (USARTx == USART1 || USARTx == USART2 || USARTx == USART3) {
|
||||
return LL_GPIO_AF_7;
|
||||
} else {
|
||||
return LL_GPIO_AF_8;
|
||||
}
|
||||
}
|
||||
|
||||
void stm32_usart_init_rx_dma(const stm32_usart_t* usart, const void* buffer, uint32_t length)
|
||||
{
|
||||
if (!usart->rxDMA) return;
|
||||
|
||||
// Disable IRQ based RX
|
||||
LL_USART_DisableIT_RXNE(usart->USARTx);
|
||||
|
||||
// In case TX DMA is used, disable the ISR completely
|
||||
if (usart->txDMA) {
|
||||
// In case TX DMA is used and IDLE IRQ is not, disable the ISR completely
|
||||
if (usart->txDMA && !LL_USART_IsEnabledIT_IDLE(usart->USARTx)) {
|
||||
NVIC_DisableIRQ(usart->IRQn);
|
||||
}
|
||||
|
||||
@@ -151,69 +211,90 @@ void stm32_usart_deinit_rx_dma(const stm32_usart_t* usart)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: probably needs to be a separate API on the serial driver
|
||||
//
|
||||
// - USART_OneBitMethodCmd(TELEMETRY_USART, ENABLE);
|
||||
|
||||
// OBSOLETE:
|
||||
// - asymmetric bitrates for half-duplex (GHOST)
|
||||
// - ??? ability to switch RX DMA OFF ??? (-> X12S)
|
||||
//
|
||||
void stm32_usart_init(const stm32_usart_t* usart, const etx_serial_init* params)
|
||||
{
|
||||
enable_usart_clock(usart->USARTx);
|
||||
LL_USART_DeInit(usart->USARTx);
|
||||
LL_GPIO_Init(usart->GPIOx, (LL_GPIO_InitTypeDef*)usart->pinInit);
|
||||
|
||||
// TODO: enable GPIO clock
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
|
||||
pinInit.Pin = usart->GPIO_Pin;
|
||||
pinInit.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||
pinInit.Speed = _get_pin_speed(params->baudrate);
|
||||
pinInit.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
pinInit.Pull = LL_GPIO_PULL_UP;
|
||||
pinInit.Alternate = _get_usart_af(usart->USARTx);
|
||||
LL_GPIO_Init(usart->GPIOx, &pinInit);
|
||||
|
||||
LL_USART_InitTypeDef usartInit;
|
||||
LL_USART_StructInit(&usartInit);
|
||||
|
||||
usartInit.BaudRate = params->baudrate;
|
||||
usartInit.Parity = LL_USART_PARITY_NONE;
|
||||
usartInit.DataWidth = LL_USART_DATAWIDTH_8B;
|
||||
|
||||
uint32_t parity = LL_USART_PARITY_NONE;
|
||||
switch(params->parity){
|
||||
case ETX_Parity_None:
|
||||
parity = LL_USART_PARITY_NONE;
|
||||
break;
|
||||
case ETX_Parity_Even:
|
||||
parity = LL_USART_PARITY_EVEN;
|
||||
break;
|
||||
case ETX_Parity_Odd:
|
||||
parity = LL_USART_PARITY_ODD;
|
||||
break;
|
||||
}
|
||||
usartInit.Parity = parity;
|
||||
switch(params->encoding){
|
||||
|
||||
uint16_t stop_bits = LL_USART_STOPBITS_1;
|
||||
switch(params->stop_bits) {
|
||||
case ETX_StopBits_One:
|
||||
stop_bits = LL_USART_STOPBITS_1;
|
||||
break;
|
||||
case ETX_StopBits_OneAndHalf:
|
||||
stop_bits = LL_USART_STOPBITS_1_5;
|
||||
break;
|
||||
case ETX_StopBits_Two:
|
||||
stop_bits = LL_USART_STOPBITS_2;
|
||||
break;
|
||||
}
|
||||
usartInit.StopBits = stop_bits;
|
||||
case ETX_Encoding_8E2:
|
||||
usartInit.Parity = LL_USART_PARITY_EVEN;
|
||||
usartInit.StopBits = LL_USART_STOPBITS_2;
|
||||
usartInit.DataWidth = LL_USART_DATAWIDTH_9B;
|
||||
break;
|
||||
|
||||
if (params->word_length == ETX_WordLength_9) {
|
||||
usartInit.DataWidth = LL_USART_DATAWIDTH_9B;
|
||||
} else {
|
||||
usartInit.DataWidth = LL_USART_DATAWIDTH_8B;
|
||||
case ETX_Encoding_8N1:
|
||||
break;
|
||||
|
||||
default:
|
||||
// TODO: return some error
|
||||
return;
|
||||
}
|
||||
|
||||
usartInit.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
|
||||
usartInit.TransferDirection = LL_USART_DIRECTION_TX_RX;
|
||||
|
||||
usartInit.TransferDirection = LL_USART_DIRECTION_NONE;
|
||||
|
||||
if (params->direction & ETX_Dir_RX)
|
||||
usartInit.TransferDirection |= LL_USART_DIRECTION_RX;
|
||||
|
||||
if (params->direction & ETX_Dir_TX)
|
||||
usartInit.TransferDirection |= LL_USART_DIRECTION_TX;
|
||||
|
||||
LL_USART_Init(usart->USARTx, &usartInit);
|
||||
LL_USART_Enable(usart->USARTx);
|
||||
|
||||
// Enable TX DMA request
|
||||
if (usart->txDMA) {
|
||||
LL_USART_EnableDMAReq_TX(usart->USARTx);
|
||||
if (params->direction & ETX_Dir_TX) {
|
||||
// Enable TX DMA request
|
||||
if (usart->txDMA) {
|
||||
LL_USART_EnableDMAReq_TX(usart->USARTx);
|
||||
|
||||
// 2-wire half-duplex: setup TX DMA IRQ
|
||||
if (usart->set_input && (int32_t)(usart->txDMA_IRQn) >= 0) {
|
||||
_enable_tx_dma_irq(usart);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Enable RX IRQ
|
||||
if (params->rx_enable) {
|
||||
if (params->direction & ETX_Dir_RX) {
|
||||
// IRQ based RX
|
||||
LL_USART_EnableIT_RXNE(usart->USARTx);
|
||||
|
||||
// half-duplex: start in input mode
|
||||
if (usart->set_input)
|
||||
_half_duplex_input(usart);
|
||||
}
|
||||
|
||||
if (!usart->txDMA || (params->rx_enable && !usart->rxDMA)) {
|
||||
if (((params->direction & ETX_Dir_TX) && !usart->txDMA) ||
|
||||
LL_USART_IsEnabledIT_RXNE(usart->USARTx)) {
|
||||
_enable_usart_irq(usart);
|
||||
}
|
||||
}
|
||||
@@ -235,7 +316,8 @@ void stm32_usart_deinit(const stm32_usart_t* usart)
|
||||
|
||||
// Reconfigure pin as output
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
memcpy(&pinInit, usart->pinInit, sizeof(LL_GPIO_InitTypeDef));
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
pinInit.Pin = usart->GPIO_Pin;
|
||||
pinInit.Mode = LL_GPIO_MODE_OUTPUT;
|
||||
pinInit.Pull = LL_GPIO_PULL_NO;
|
||||
pinInit.Alternate = LL_GPIO_AF_0;
|
||||
@@ -247,11 +329,22 @@ void stm32_usart_send_byte(const stm32_usart_t* usart, uint8_t byte)
|
||||
{
|
||||
// TODO: split into 2 steps to avoid blocking on send
|
||||
while (!LL_USART_IsActiveFlag_TXE(usart->USARTx));
|
||||
|
||||
if (usart->set_input) {
|
||||
_half_duplex_output(usart);
|
||||
|
||||
// switch back to input after TC
|
||||
LL_USART_ClearFlag_TC(usart->USARTx);
|
||||
LL_USART_EnableIT_TC(usart->USARTx);
|
||||
}
|
||||
|
||||
LL_USART_TransmitData8(usart->USARTx, byte);
|
||||
}
|
||||
|
||||
void stm32_usart_send_buffer(const stm32_usart_t* usart, const uint8_t * data, uint32_t size)
|
||||
{
|
||||
_half_duplex_output(usart);
|
||||
|
||||
if (usart->txDMA) {
|
||||
LL_DMA_DeInit(usart->txDMA, usart->txDMA_Stream);
|
||||
|
||||
@@ -267,6 +360,10 @@ void stm32_usart_send_buffer(const stm32_usart_t* usart, const uint8_t * data, u
|
||||
dmaInit.Priority = LL_DMA_PRIORITY_VERYHIGH; // TODO: make it configurable
|
||||
|
||||
LL_DMA_Init(usart->txDMA, usart->txDMA_Stream, &dmaInit);
|
||||
|
||||
if (usart->set_input && (int32_t)(usart->txDMA_IRQn) >= 0) {
|
||||
LL_DMA_EnableIT_TC(usart->txDMA, usart->txDMA_Stream);
|
||||
}
|
||||
LL_DMA_EnableStream(usart->txDMA, usart->txDMA_Stream);
|
||||
|
||||
return;
|
||||
@@ -278,6 +375,20 @@ void stm32_usart_send_buffer(const stm32_usart_t* usart, const uint8_t * data, u
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t stm32_usart_tx_completed(const stm32_usart_t* usart)
|
||||
{
|
||||
if (LL_USART_IsEnabledDMAReq_TX(usart->USARTx)) {
|
||||
// TX DMA is configured, let's check if the stream is currently enabled
|
||||
if (LL_DMA_IsEnabledStream(usart->txDMA, usart->txDMA_Stream) ||
|
||||
!LL_USART_IsActiveFlag_TXE(usart->USARTx))
|
||||
return 0;
|
||||
} else if (LL_USART_IsEnabledIT_TXE(usart->USARTx)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return LL_USART_IsActiveFlag_TXE(usart->USARTx);
|
||||
}
|
||||
|
||||
void stm32_usart_wait_for_tx_dma(const stm32_usart_t* usart)
|
||||
{
|
||||
// TODO: check if everything is properly initialised, this seems to block when
|
||||
@@ -286,29 +397,133 @@ void stm32_usart_wait_for_tx_dma(const stm32_usart_t* usart)
|
||||
|
||||
switch(usart->txDMA_Stream) {
|
||||
case LL_DMA_STREAM_1:
|
||||
while (LL_DMA_IsActiveFlag_TC1(usart->txDMA));
|
||||
while (!LL_DMA_IsActiveFlag_TC1(usart->txDMA));
|
||||
LL_DMA_ClearFlag_TC1(usart->txDMA);
|
||||
break;
|
||||
case LL_DMA_STREAM_3:
|
||||
while (LL_DMA_IsActiveFlag_TC3(usart->txDMA));
|
||||
while (!LL_DMA_IsActiveFlag_TC3(usart->txDMA));
|
||||
LL_DMA_ClearFlag_TC3(usart->txDMA);
|
||||
break;
|
||||
case LL_DMA_STREAM_5:
|
||||
while (LL_DMA_IsActiveFlag_TC5(usart->txDMA));
|
||||
while (!LL_DMA_IsActiveFlag_TC5(usart->txDMA));
|
||||
LL_DMA_ClearFlag_TC5(usart->txDMA);
|
||||
break;
|
||||
case LL_DMA_STREAM_6:
|
||||
while (LL_DMA_IsActiveFlag_TC6(usart->txDMA));
|
||||
while (!LL_DMA_IsActiveFlag_TC6(usart->txDMA));
|
||||
LL_DMA_ClearFlag_TC6(usart->txDMA);
|
||||
break;
|
||||
case LL_DMA_STREAM_7:
|
||||
while (LL_DMA_IsActiveFlag_TC7(usart->txDMA));
|
||||
while (!LL_DMA_IsActiveFlag_TC7(usart->txDMA));
|
||||
LL_DMA_ClearFlag_TC7(usart->txDMA);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void stm32_usart_enable_rx(const stm32_usart_t* usart)
|
||||
{
|
||||
_half_duplex_input(usart);
|
||||
}
|
||||
|
||||
// from stm32f4xx_ll_usart.c
|
||||
static uint32_t _get_usart_periph_clock(USART_TypeDef* USARTx)
|
||||
{
|
||||
uint32_t periphclk = LL_RCC_PERIPH_FREQUENCY_NO;
|
||||
LL_RCC_ClocksTypeDef rcc_clocks;
|
||||
|
||||
LL_RCC_GetSystemClocksFreq(&rcc_clocks);
|
||||
if (USARTx == USART1) {
|
||||
periphclk = rcc_clocks.PCLK2_Frequency;
|
||||
} else if (USARTx == USART2) {
|
||||
periphclk = rcc_clocks.PCLK1_Frequency;
|
||||
}
|
||||
#if defined(USART3)
|
||||
else if (USARTx == USART3) {
|
||||
periphclk = rcc_clocks.PCLK1_Frequency;
|
||||
}
|
||||
#endif /* USART3 */
|
||||
#if defined(USART6)
|
||||
else if (USARTx == USART6) {
|
||||
periphclk = rcc_clocks.PCLK2_Frequency;
|
||||
}
|
||||
#endif /* USART6 */
|
||||
#if defined(UART4)
|
||||
else if (USARTx == UART4) {
|
||||
periphclk = rcc_clocks.PCLK1_Frequency;
|
||||
}
|
||||
#endif /* UART4 */
|
||||
#if defined(UART5)
|
||||
else if (USARTx == UART5) {
|
||||
periphclk = rcc_clocks.PCLK1_Frequency;
|
||||
}
|
||||
#endif /* UART5 */
|
||||
#if defined(UART7)
|
||||
else if (USARTx == UART7) {
|
||||
periphclk = rcc_clocks.PCLK1_Frequency;
|
||||
}
|
||||
#endif /* UART7 */
|
||||
#if defined(UART8)
|
||||
else if (USARTx == UART8) {
|
||||
periphclk = rcc_clocks.PCLK1_Frequency;
|
||||
}
|
||||
#endif /* UART8 */
|
||||
#if defined(UART9)
|
||||
else if (USARTx == UART9) {
|
||||
periphclk = rcc_clocks.PCLK2_Frequency;
|
||||
}
|
||||
#endif /* UART9 */
|
||||
#if defined(UART10)
|
||||
else if (USARTx == UART10) {
|
||||
periphclk = rcc_clocks.PCLK2_Frequency;
|
||||
}
|
||||
#endif /* UART10 */
|
||||
|
||||
return periphclk;
|
||||
}
|
||||
|
||||
uint32_t stm32_usart_get_baudrate(const stm32_usart_t* usart)
|
||||
{
|
||||
auto periphclk = _get_usart_periph_clock(usart->USARTx);
|
||||
auto oversampling = LL_USART_GetOverSampling(usart->USARTx);
|
||||
return LL_USART_GetBaudRate(usart->USARTx, periphclk, oversampling);
|
||||
}
|
||||
|
||||
void stm32_usart_set_baudrate(const stm32_usart_t* usart, uint32_t baudrate)
|
||||
{
|
||||
auto periphclk = _get_usart_periph_clock(usart->USARTx);
|
||||
auto oversampling = LL_USART_GetOverSampling(usart->USARTx);
|
||||
LL_USART_SetBaudRate(usart->USARTx, periphclk, oversampling, baudrate);
|
||||
|
||||
// update pin speed accordingly (must be done one-by-one)
|
||||
uint32_t pin_speed = _get_pin_speed(baudrate);
|
||||
uint32_t pindef = usart->GPIO_Pin;
|
||||
|
||||
// loop borrowed from LL_GPIO_init()
|
||||
uint32_t pinpos = POSITION_VAL(pindef);
|
||||
uint32_t currentpin = 0;
|
||||
while ((pindef >> pinpos) != 0) {
|
||||
currentpin = pindef & (1 << pinpos);
|
||||
if (currentpin) LL_GPIO_SetPinSpeed(usart->GPIOx, currentpin, pin_speed);
|
||||
pinpos++;
|
||||
}
|
||||
}
|
||||
|
||||
void stm32_usart_set_hw_option(const stm32_usart_t* usart, uint32_t option)
|
||||
{
|
||||
switch(option) {
|
||||
case ETX_HWOption_OVER8: {
|
||||
// BRR depends on oversampling as well, so we must
|
||||
// re-compute the baudrate as well.
|
||||
auto baudrate = stm32_usart_get_baudrate(usart);
|
||||
LL_USART_SetOverSampling(usart->USARTx, LL_USART_OVERSAMPLING_8);
|
||||
stm32_usart_set_baudrate(usart, baudrate);
|
||||
} break;
|
||||
case ETX_HWOption_ONEBIT:
|
||||
LL_USART_EnableOneBitSamp(usart->USARTx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#define USART_FLAG_ERRORS \
|
||||
(LL_USART_SR_ORE | LL_USART_SR_NE | LL_USART_SR_FE | LL_USART_SR_PE)
|
||||
|
||||
@@ -316,6 +531,26 @@ void stm32_usart_isr(const stm32_usart_t* usart, etx_serial_callbacks_t* cb)
|
||||
{
|
||||
uint32_t status = LL_USART_ReadReg(usart->USARTx, SR);
|
||||
|
||||
// cache these first, as RXNE might clear SR
|
||||
uint32_t idle = (status & LL_USART_SR_IDLE);
|
||||
uint32_t txe = (status & LL_USART_SR_TXE);
|
||||
|
||||
// TC is only enabled with 2-wire half-duplex when TX DMA was in use
|
||||
if (LL_USART_IsEnabledIT_TC(usart->USARTx) && (status & LL_USART_SR_TC)) {
|
||||
|
||||
// disable TC IRQ
|
||||
LL_USART_DisableIT_TC(usart->USARTx);
|
||||
|
||||
// switch to input
|
||||
_half_duplex_input(usart);
|
||||
|
||||
// and drain RX side first
|
||||
while (status & LL_USART_SR_RXNE) {
|
||||
status = LL_USART_ReadReg(usart->USARTx, DR);
|
||||
status = LL_USART_ReadReg(usart->USARTx, SR);
|
||||
}
|
||||
}
|
||||
|
||||
// Receive: do it first as it is more time critical
|
||||
if (LL_USART_IsEnabledIT_RXNE(usart->USARTx)) {
|
||||
|
||||
@@ -339,7 +574,7 @@ void stm32_usart_isr(const stm32_usart_t* usart, etx_serial_callbacks_t* cb)
|
||||
}
|
||||
|
||||
// IRQ based send: TXE IRQ is enabled only during transfer
|
||||
if (LL_USART_IsEnabledIT_TXE(usart->USARTx) && (status & LL_USART_SR_TXE)) {
|
||||
if (LL_USART_IsEnabledIT_TXE(usart->USARTx) && txe) {
|
||||
|
||||
uint8_t data;
|
||||
if (cb->on_send && cb->on_send(&data)) {
|
||||
@@ -348,4 +583,27 @@ void stm32_usart_isr(const stm32_usart_t* usart, etx_serial_callbacks_t* cb)
|
||||
LL_USART_DisableIT_TXE(usart->USARTx);
|
||||
}
|
||||
}
|
||||
|
||||
if (LL_USART_IsEnabledIT_IDLE(usart->USARTx) && idle) {
|
||||
// SR clear sequence
|
||||
status = LL_USART_ReadReg(usart->USARTx, DR);
|
||||
if (cb->on_idle) cb->on_idle();
|
||||
}
|
||||
}
|
||||
|
||||
void stm32_usart_tx_dma_isr(const stm32_usart_t* usart)
|
||||
{
|
||||
if (!stm32_dma_check_tc_flag(usart->txDMA, usart->txDMA_Stream))
|
||||
return;
|
||||
|
||||
auto USARTx = usart->USARTx;
|
||||
|
||||
// clear TC flag before enabling USART TC interrupt:
|
||||
// -> TC flag will be re-triggered once the last byte which has
|
||||
// just been transfered from DMA to USART will be transmitted,
|
||||
// thus triggering TELEMETRY_USART_IRQHandler(), which will
|
||||
// switch from output to input mode.
|
||||
//
|
||||
LL_USART_ClearFlag_TC(USARTx);
|
||||
LL_USART_EnableIT_TC(USARTx);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user