There's a problem with using the txend2 ('Transmission Complete') callback on the current USART2 driver; it occurs as soon as you start transmission.
It occurs both with the 'official' DMA-based driver, and my interrupt-driven version.
This is because the TC flag gets set when the USART is idle, so the TC interrupt was occurring at the start of transmission, in the interval between enabling the interrupt and the first character being written to the transmit buffer.
I've generated a fix which means it's now set once the last character has been written to the transmit buffer.
The attached files include my mods to allow use of interrupt-driven routines; all the changes should be marked.
STM32 USART2 problem with transmission complete callback
Moderator: RoccoMarco
STM32 USART2 problem with transmission complete callback
- Attachments
-
- USARTv2_150415.zip
- Modifued USART2 driver with interrupt option
- (8.79 KiB) Downloaded 341 times
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: STM32 USART2 problem with transmission complete callback
Thanks,
Is it possible it is also related to this old problem? viewtopic.php?f=16&t=1375
If so it affects UARTv1 too.
Giovanni
Is it possible it is also related to this old problem? viewtopic.php?f=16&t=1375
If so it affects UARTv1 too.
Giovanni
Re: STM32 USART2 problem with transmission complete callback
Giovanni wrote:Thanks,
Is it possible it is also related to this old problem? viewtopic.php?f=16&t=1375
If so it affects UARTv1 too.
Giovanni
You've got a good memory!
Had a quick look at the USART1 driver, and it looks very similar in structure, so most likely its the same problem (with, presumably, the same fix).
I've not bothered with the setup code, but the test is quite simple:
Code: Select all
/*
* This callback is invoked when a transmission has physically completed.
*/
static void hostTxend2(UARTDriver *uartp)
{
(void)uartp;
chSysLockFromISR();
chBSemSignalI(&serialData[HOST_DATA].txSemaphore);
chSysUnlockFromISR();
}
// Main polling loop
while (1)
{
palClearPad(GPIOB, 0);
uartStartSend(&UARTD1, rxReceiveCtr, serialData[HOST_DATA].txWrappedBuffer);
chBSemWaitTimeout(&serialData[HOST_DATA].txSemaphore, MS2ST(TRANSMIT_COMPLETE_TIMEOUT));
palSetPad(GPIOB, 0);
chThdSleepMilliseconds(10);
}
If you don't get there first, I might be able to try the code once I've got room to get out some 32F407 hardware - but likely to be a week or three.
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: STM32 USART2 problem with transmission complete callback
I haven't had time for that in two years now so please go ahead if you can 
Giovanni
Giovanni
Re: STM32 USART2 problem with transmission complete callback
I decided to get it out of the way before I forgot everything (i.e. more than a few hours).
Confirmed the same problem on USARTv1; the attachment fixes it.
Confirmed the same problem on USARTv1; the attachment fixes it.
- Attachments
-
- USART1_uart_lld.zip
- ST USARTv1 transmission complete fix
- (4.49 KiB) Downloaded 353 times