MaJerle / stm32-usart-uart-dma-rx-tx

STM32 examples for USART using DMA for efficient RX and TX transmission
MIT License
1.3k stars 322 forks source link

Return variable "started" has almost no useful purpose #24

Closed jnz86 closed 1 year ago

jnz86 commented 2 years ago

At https://github.com/MaJerle/stm32-usart-uart-dma-rx-tx/blob/main/projects/usart_rx_idle_line_irq_ringbuff_tx_H7/Src/main.c

/**
 * \brief           Check if DMA is active and if not try to send data
 *
 * This function can be called either by application to start data transfer
 * or from DMA TX interrupt after previous transfer just finished
 *
 * \return          `1` if transfer just started, `0` if on-going or no data to transmit
 */
uint8_t
usart_start_tx_dma_transfer(void) {
    uint32_t primask;
    uint8_t started = 0;

The function usart_rx_check(void) returns 1 for started, or 0 for "transmission already in progress".

I'm really not sure I can see reason the result of started / not started would matter to the user.

Either you're already transmitting, in which case the DMA will get to your new ring buffer data soon. Or, congrats, you're sending your data now. Same effect either way your data will be sent.

I suppose the user could implement an abort and then priority send, but not really because you probably aren't certain if there is data in the ring buffer ahead of yours.

Am I missing something on this? Did this just exist for testing?

MaJerle commented 2 years ago

User may or may not use the status. It is not wrong having it tho.