2015-11-09 02:00 AM
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;
}
2015-11-09 05:07 AM
The buffer in the interrupt/callback is local, and will collapse when it exits. Consider using a static buffer if you expect it to live longer than the routine.
The static variables inside/outside the routines are not the same or visible to each other.2015-11-09 06:23 AM
Hi clive1,
Thanks a lot for your help : it was so easy.I am ashamed
not to have
seen this
faulty code.
I take this opportunity
toask another question
on this
same
code :
I had to call HAL_UART_Transmit_IT once to initiate the communication, and another time in case there is something in the ringbuffer. (that means two static buffers).. Is there a way to rise a dummy HAL_UART_TxCpltCallback so I could always write in my ringbuffer ans start the communication rising this HAL_UART_TxCpltCallback event ....looking in the RM0090 it looks like the TC bit could only be reset.. I could then have only one place calling HAL_UART_Transmit_IT...