Hi
I have a lower priority task whose job is to write to external flash memory on both a regular and ad-hoc basis. Viz:
#define NORFLASH_TASK_STACK_SIZE 512
#define HAL_TIME_OUT 10
TaskHandle_t USE_DTCM norFlashTskHandle;
StaticTask_t USE_DTCM norFlashTskBuffer;
StackType_t USE_DTCM norFlashTskStack[NORFLASH_TASK_STACK_SIZE];
SemaphoreHandle_t USE_DTCM flashMemRdySemHandle = {NULL};
#define QUEUE_LENGTH 5
#define ITEM_SIZE OSPI_BLOCK_SIZE /* (4096) */
StaticQueue_t USE_DTCM xStaticQueue;
QueueHandle_t USE_DTCM xQueueFlashMem;
uint8_t ucQueueStorageArea[QUEUE_LENGTH * ITEM_SIZE];
/*****************************************************************************/
static void createNorFlashTask(void)
{
/* Create a queue capable of containing 5 flash memory blocks. */
xQueueFlashMem = xQueueCreateStatic( QUEUE_LENGTH,
ITEM_SIZE,
ucQueueStorageArea,
&xStaticQueue );
configASSERT(xQueueFlashMem);
vQueueAddToRegistry(xQueueFlashMem, "xQueueFlashMem");
norFlashTskHandle = xTaskCreateStatic(norFlashTask,
"norFlashTask",
NORFLASH_TASK_STACK_SIZE,
NULL,
PRIO_NOR_FLASH_TASK,
norFlashTskStack,
&norFlashTskBuffer);
configASSERT(norFlashTskHandle);
rtosTaskStates.norFlashTsk = eRunning;
#if(DEBUG_FLASH_DRVR == 1)
printfdma("Create NOR Flash Task\r\n\r\n");
#endif
}
/*****************************************************************************/
USE_ITCM flashError_t writeFlashData(const uint8_t* parData, const uint32_t writeDataLen)
{
flashInit.writeDataLen = writeDataLen;
flashInit.disableMemoryMappedMode = false;
flashInit.norFlashBusy = true;
if(xQueueSend(xQueueFlashMem, parData, 10) != pdPASS)
{
flashInit.writeDataLen = writeDataLen; /* Debug only */
}
#if(DEBUG_FLASH_DRVR == 1)
printfdma("writeFlashData Fcn\r\n");
#endif
return FLASH_MEM_OK;
}
/*****************************************************************************/
USE_ITCM void norFlashTask(void *argument)
{
while(1)
{
if(xQueueReceive(xQueueFlashMem, &flashInit.parData, portMAX_DELAY) != pdPASS)
{
flashInit.norFlashBusy = false; /* TODO */
}
else
{
flashInit.flashError = writeDataToNorFlash();
flashInit.norFlashBusy = false; /* TODO */
}
HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_11);
// vTaskDelay(100);
}
}
I start the norFlashTskHandle task in the default startup task i call the monitor:
#if(FLASH_MEM_ON == 1)
/* Initialise nor flash task */
initialiseNorFlash(TOUCHGFX_ENABLE,
OCTISPI_IRQP,
OCTISPI_IRQP); /* TODO */
/* Make time for the flash task to run through its initialisation */
vTaskDelay(10);
#endif
You can see I put a small delay in to make time for the lower priority flash task to startup.
After this I call a function setSystemSpecificConstants(); that calls the writeFlashData() function that puts data to be stored in the queue.
The problem I have is that if I include the xQueueReceive code in the flash task the system hangs. If I comment it out and put in a delay the task runs normally. I seems like the nor flash task is not being unblocked when the items are sent to the queue. The monitor task runs every 250 ms and the system idle time is 65%. If I put a breakpoint after the queueReceive it never gets hit.
The task priorities for all the tasks are:
/*********************************************************************
* TASK PRIORITIES *
*********************************************************************
*/
#define PRIO_PROX_TASK osPriorityRealtime7
#define PRIO_CLOCK_CONTROL osPriorityRealtime6
#define PRIO_TMR_SRVC osPriorityNormal3 /* Set manually in FreeRTOSConfig.h */
#define PRIO_MONITOR_TASK osPriorityNormal2
#define PRIO_GUI_TASK osPriorityNormal
#define PRIO_NOR_FLASH_TASK osPriorityBelowNormal7
#define PRIO_WI_FI_TASK osPriorityBelowNormal6
#define PRIO_DIG_TEMP_TASK osPriorityLow5
#define PRIO_PRINTF_DMA osPriorityLow4
#define PRIO_FLASH_BACKUP osPriorityLow3
My FreeRTOS Config File is:
/* USER CODE BEGIN Header */
/*
* FreeRTOS Kernel V10.2.1
/* USER CODE END Header */
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
/* USER CODE BEGIN Includes */
#include "cmsis_os2.h"
#include "RTOSParameters.h"
/* USER CODE END Includes */
/* Ensure definitions are only used by the compiler, and not by the assembler. */
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
#include <stdint.h>
extern uint32_t SystemCoreClock;
extern void configureTimerForRunTimeStats(void);
extern unsigned long getRunTimeCounterValue(void);
#endif
#ifndef CMSIS_device_header
#define CMSIS_device_header "stm32h7xx.h"
#endif /* CMSIS_device_header */
#define configENABLE_FPU 0
#define configENABLE_MPU 0
#define configUSE_PREEMPTION 1
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 1
#define configCPU_CLOCK_HZ ( SystemCoreClock )
#define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES ( 56 )
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
#define configTOTAL_HEAP_SIZE ((size_t)32768)
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_TRACE_FACILITY 1
#define configGENERATE_RUN_TIME_STATS 1
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
#define configRECORD_STACK_HIGH_ADDRESS 1
#define configUSE_16_BIT_TICKS 0
#define configUSE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 16
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_TASK_NOTIFICATIONS 1
#define configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H 1
/* USER CODE BEGIN MESSAGE_BUFFER_LENGTH_TYPE */
/* Defaults to size_t for backward compatibility, but can be changed
if lengths will always be less than the number of bytes in a size_t. */
#define configMESSAGE_BUFFER_LENGTH_TYPE size_t
/* USER CODE END MESSAGE_BUFFER_LENGTH_TYPE */
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Software timer definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY PRIO_TMR_SRVC
#define configTIMER_QUEUE_LENGTH 30
#define configTIMER_TASK_STACK_DEPTH 512
/* CMSIS-RTOS V2 flags */
#define configUSE_OS2_THREAD_SUSPEND_RESUME 1
#define configUSE_OS2_THREAD_ENUMERATE 1
#define configUSE_OS2_EVENTFLAGS_FROM_ISR 1
#define configUSE_OS2_THREAD_FLAGS 1
#define configUSE_OS2_TIMER 1
#define configUSE_OS2_MUTEX 1
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xQueueGetMutexHolder 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
/*
* The CMSIS-RTOS V2 FreeRTOS wrapper is dependent on the heap implementation used
* by the application thus the correct define need to be enabled below
*/
#define USE_FreeRTOS_HEAP_4
/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS
/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
#define configPRIO_BITS __NVIC_PRIO_BITS
#else
#define configPRIO_BITS 4
#endif
/* The lowest interrupt priority that can be used in a call to a "set priority"
function. */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15
/* The highest interrupt priority that can be used by any interrupt service
routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
/* Interrupt priorities used by the kernel port layer itself. These are generic
to all Cortex-M ports, and do not rely on any particular library functions. */
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
/* USER CODE BEGIN 1 */
#define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}
/* USER CODE END 1 */
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
/* IMPORTANT: After 10.3.1 update, Systick_Handler comes from NVIC (if SYS timebase = systick), otherwise from cmsis_os2.c */
#define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 0
/* USER CODE BEGIN Defines */
/* Definitions needed when configGENERATE_RUN_TIME_STATS is on */
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS configureTimerForRunTimeStats
#define portGET_RUN_TIME_COUNTER_VALUE getRunTimeCounterValue
/* IMPORTANT: This define is commented when used with STM32Cube firmware, when the timebase source is SysTick,
to prevent overwriting SysTick_Handler defined within STM32Cube HAL */
// #define xPortSysTickHandler SysTick_Handler
/* Integrates the Tracealyzer recorder with FreeRTOS */
#if ( configUSE_TRACE_FACILITY == 1 )
//#include "trcRecorder.h"
#endif
/* USER CODE END Defines */
#endif /* FREERTOS_CONFIG_H */
When I run the program in debug when I halt it with the pause button the progam invariably stops in portmacr.h at:
portFORCE_INLINE static void vPortRaiseBASEPRI( void )
{
uint32_t ulNewBASEPRI; /* <== Stops here */
__asm volatile
(
" mov %0, %1 \n" \
" msr basepri, %0 \n" \
" isb \n" \
" dsb \n" \
:"=r" (ulNewBASEPRI) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) : "memory"
);
}
When I run the profiler I get:
I have checked all my interrupt to ensure they are above the minimum set by FreeRTOS Config.
I have checked that the data is being copied to the queue buffer correctly in the xQueueSend function and it is.
Has anyone any idea what I might be doing wrong? Am I using the queue correctly?
Best regards
Rob