Marvee Amasi
Marvee Amasi
DIIDevHeads IoT Integration Server
Created by Marvee Amasi on 5/26/2024 in #code-review
Modifying FreeRTOS Interrupt Priorities After Scheduler Initialization
Hey everyone @Middleware & OS , I'm neck-deep in an RTOS project using FreeRTOS. I need to read and potentially modify interrupt priorities after the FreeRTOS scheduler has been kicked off with vTaskStartScheduler(). The issue is, NVIC_GetPriority(DMA1_Channel4_IRQn) seems to behave differently depending on when I call it.
#include <FreeRTOS.h>
#include <queue.h>
#include <task.h>
#include "stm32f4xx_hal.h"

static void vTest_NVIC(void *pvParameters) {
tprintf("\r\nTask Started...");

while (1) {
taskENTER_CRITICAL();
uint32_t priority = NVIC_GetPendingIRQ(DMA1_Channel4_IRQn) ?
NVIC_GetPriority(DMA1_Channel4_IRQn) : portMAX_DELAY;
tprintf("\r\nCurrent priority (if pending): %d", (int)priority);
taskEXIT_CRITICAL();
vTaskDelay(pdMS_TO_ICKS(3000));
}
}

int main(void) {
portBASE_TYPE xReturn;
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
HAL_NVIC_SetPriority(DMA1_Channel4_IRQn, 11, 0);
tprintf("\r\nInitial priority: %d", (int)NVIC_GetPendingIRQ(DMA1_Channel4_IRQn) ?
NVIC_GetPriority(DMA1_Channel4_IRQn) : portMAX_DELAY);
vTaskStartScheduler();
}
#include <FreeRTOS.h>
#include <queue.h>
#include <task.h>
#include "stm32f4xx_hal.h"

static void vTest_NVIC(void *pvParameters) {
tprintf("\r\nTask Started...");

while (1) {
taskENTER_CRITICAL();
uint32_t priority = NVIC_GetPendingIRQ(DMA1_Channel4_IRQn) ?
NVIC_GetPriority(DMA1_Channel4_IRQn) : portMAX_DELAY;
tprintf("\r\nCurrent priority (if pending): %d", (int)priority);
taskEXIT_CRITICAL();
vTaskDelay(pdMS_TO_ICKS(3000));
}
}

int main(void) {
portBASE_TYPE xReturn;
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
HAL_NVIC_SetPriority(DMA1_Channel4_IRQn, 11, 0);
tprintf("\r\nInitial priority: %d", (int)NVIC_GetPendingIRQ(DMA1_Channel4_IRQn) ?
NVIC_GetPriority(DMA1_Channel4_IRQn) : portMAX_DELAY);
vTaskStartScheduler();
}
- Before calling vTaskStartScheduler(), NVIC_GetPriority(DMA1_Channel4_IRQn) works as expected and reflects the configured priority (11). - However, after the scheduler starts, the function consistently returns 11, regardless of any changes I try to make within the vTest_NVIC task. I've tried using taskENTER_CRITICAL() and taskEXIT_CRITICAL() to ensure thread safety, but it doesn't seem to resolve the issue. What am I missing here? Why does the behavior differ before and after the scheduler starts?
4 replies