Tasks stop when USART ISR priority is defined


I recently made a post about a crash in stream buffer when using ISR. The solution to that crash was defining ISR priority. This worked fine for a while(up to two hours), but later something really strange happens, the app stops running, there is no crash, it just stops.

For debugging purposes I simplified my code not to rely on ISR at all. The ISR is there just for tests, it does nothing. Here it is:

extern "C" void USART3_IRQHandler() {

I have also modified my read method not to read data register:

uint8_t Uart3::readByte(char *output, uint32_t timeoutMs) {
    *output = 's';
    return UART_OK;

And here is how I enable ISR:

    NVIC_InitTypeDef NVIC_InitStructure;
    NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_SetPriority(USART3_IRQn, 254);

Now when I comment out NVIC_SetPriority everything works fine, but than I cannot use StreamBuffers. I tried setting various priority numbers, but without luck. Here is how priority is set in FreeRTOSConfig.h:


I am using FreeRTOS V10.4.3, latest as of this writing.
Do you guys have any idea what could be happening?

Thanks in advance.

Double check how you are using this function. You are passing in the priority shifted into the top most bits (which is what the hardware expects), but I think this function expects the priority to be in the least significant bits - which the shift being performed inside the function itself. RTOS for ARM Cortex-M

Also on the same page note if you are using an STM32 you also have to call NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 ).

This looks like a STM32. AFAIK, most of them have 4 priority bits implemented (F0 series have 2 bits). This means that the parameter you can pass to NVIC_SetPriority() must be in [0-15] interval, 15 being the lowest priority.

A call to NVIC_PriorityGroupConfig() is probably not needed because by default (after reset) all bits are main-priority bits (0 bits for sub-priority).