Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training



Posted by k3nt00 on May 21, 2015


I am running FreeRTOS 8.2.1 on an STM32F103 with the newest STM32F1 Hal Driver

I had been having some issues with the interrupt UART Tx beginning a new transmission before the one before it completed. I call the interrupt transmit and then wait on a semaphore from the callback to be given.


if(HALUARTTransmitIT(&huart1, (uint8t*) outBuffer, dataSize) != HALOK) { ErrorHandler(); }

xSemaphoreTake(waitUntilSendDone, portMAX_DELAY);


The Callback:


void HALUARTTxCpltCallback (UART_HandleTypeDef *UartHandle) { xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(waitUntilSendDone, &xHigherPriorityTaskWoken); }


The problem is, the callback was being called after only 2 bytes had been transmitted, which allowed for the second transmit buffer to be sent prematurely.

The ST Examples use the following:


if(HALUARTTransmitIT(&huart1, (uint8t*) outBuffer, dataSize) != HALOK) { ErrorHandler(); }

while (UartReady != SET) { }

/* Reset transmission flag */ UartReady = RESET;


And the Callback:


void HALUARTTxCpltCallback (UART_HandleTypeDef UartHandle) { / Set transmission flag: transfer complete */ UartReady = SET; }


This solution solved the problem. The callback wasn't called until the first buffer was completely transmitted. I do not understand why this is? Why is the method of waiting effecting the callback?

Any insight would be much appreciated.


PS Posted this prematurely without proper title. Apologies.


Posted by heinbali01 on May 22, 2015


Your HAL_UART_TxCpltCallback() is calling xSemaphoreGiveFromISR() but what I miss is a call to portYIELD_FROM_ISR().

In other words: the semaphore will be set, the task waiting for the semaphore becomes runnable but it wakes up much later than expected.

It is a pity that the entire ISR handling is done within the STM32 library:

~~~~~ void HALDMAIRQHandler(DMA_HandleTypeDef hdma) { ... / Transfer complete callback */ hdma->XferCpltCallback(hdma); .... }

which calls:

static void UARTDMATransmitCplt(DMAHandleTypeDef *hdma) { HALUARTTxCpltCallback(huart); } ~~~~~

Once I made a minor change in the STM32 library. I had the same problem with the SD-card: once a transfer is ready I wanted to set a semaphore and unblock some process.

~~~~~ /* A global variable that you can set from within a TX call-back */ BaseTypet xDMAIRQ_HigherPriorityTaskWoken;

void HALDMAIRQHandler(DMAHandleTypeDef *hdma) { xDMAIRQHigherPriorityTaskWoken = pdFALSE; ... /* Transfer complete callback */ hdma->XferCpltCallback(hdma); .... if( xDMAIRQHigherPriorityTaskWoken != pdFALSE ) { portYIELDFROMISR( xDMAIRQ_HigherPriorityTaskWoken ); } } ~~~~~

PS. here was an earlier post about using 'portYIELD_FROM_ISR()' :



[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists