AnsweredAssumed Answered

HAL_UART_Transmit_IT not working as expected

Question asked by pipon.herve.001 on Nov 9, 2015
Latest reply on Nov 9, 2015 by pipon.herve.001
Hello
I try to debug my application using printf
I write some code to overwrite fputc.

My problem is with the function HAL_UART_Transmit_IT of the HAL module

It doesn't succeed to send long sentences.

My code is only sending data when a complete sentence is detected (\r\n)
I add some buffer management in case the writing will be faster than the sending but it's not the case here....

If I run the interruption step by step the full sentence is send.


query: USER gencf¦query: PASS pae
query: SYST
qury: FEAT
query: PWD
query: CWD /
query: PWD
query: TYPE A
query: PASV
query: TYPE ýÿÿÿquery: PWD

The first line is not complete.

Can you help me to understand ?

My code:
static char Idx  = 0;
static char Transmitting = 0;
static char *pBuffer;
int fputc (int aCh, FILE *stream)
{
    char Jdx ;
    char aChar ;
    char Buffer[TX_BUFFER_SIZE];
    char temp = aCh;
    char send = 0;
        UNUSED(aChar);
        UNUSED(temp);
 
    if (stream == &__stdout) {
        if (Idx == 0) {
            pBuffer = Buffer;
            send = 0;
        }
        *pBuffer++ = aCh;
        if (Idx++ >= TX_BUFFER_SIZE) {
            send = 1;
        }
        if (aCh == '\n') {
            send = 1;
        }
        if (send == 1) {
            if ( (HAL_UART_GetState (&huart3) & 0x10) || (Transmitting == 1)) {
                pBuffer = Buffer;
                RingBuffer_Put (DBG_SEND_RINGBUFFER, Idx);
                for (Jdx = 0; Jdx < Idx; Jdx++) {
                    RingBuffer_Put (DBG_SEND_RINGBUFFER, *pBuffer++);
                }
            } else {
                Transmitting = 1;
                HAL_UART_Transmit_IT (&huart3, (uint8_t *)Buffer, Idx);
            }
            Idx = 0;
        }
    }
    return (aCh);
}
 
void HAL_UART_TxCpltCallback (UART_HandleTypeDef *huart)
{
    uint8_t Jdx  = 0;
    uint8_t aChar ;
    static uint8_t Idx  = 0;
    static char *pBuffer;
    char Buffer[TX_BUFFER_SIZE];
    if (RingBuffer_Used (DBG_SEND_RINGBUFFER) > 0) {
        pBuffer = Buffer;
        RingBuffer_Get (DBG_SEND_RINGBUFFER, &Idx);
        for (Jdx = 0; Jdx < Idx; Jdx++) {
            RingBuffer_Get (DBG_SEND_RINGBUFFER, &aChar);
            *pBuffer++ = aChar;
        }
        HAL_UART_Transmit_IT (&huart3, (uint8_t *) Buffer, Idx);
    }
    Transmitting = 0;
}

Outcomes