sd card functions throwing Hardfaults() inside tasks but not in main (FREERTOS+SDcard(spi))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-08-11 7:22 AM
I am following this Controlerstech tutorial , learning how to FREERTOS+SD card.
I found out some functions that work fine outside any os task , throw a Hardfault when executerd inside any FREERTOS task.....
Functions that seem to be working from him.
I feel like these functions are trying to access a forbidden area of memory.... but i dont know why is it forbidden, are there any memory boundaries we should respect when working inside tasks?
I am new with FREERTOS and their QA didnt helped me yet.
- This felow had the same issue but using an esp32
- similar issue here in the commiunity https://community.st.com/s/question/0D53W00000MA9VRSA1/free-rtos-sdcard-sdio-fatfs-fopen-problem
Solved! Go to Solution.
- Labels:
-
FreeRTOS
-
SDIO-SDMMC
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-08-11 9:08 AM
I fixed it, my Task priority needed to be raised to osPriorityRealTime
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-08-11 7:29 AM
Im going to follow the freertos oficial hardfault debugging advices
https://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html
PRiority grouping is already set to 4 in HAL_init() so thats not the issue
/* Set Interrupt Group Priority */
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-08-11 7:57 AM
I did something and isntead of triggering the HARD_FAULT now the programm gets stuck in this configAssert inside the xQueueSemaphoreTake()
/* Cannot block if the scheduler is suspended. */
#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
{
configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
}
#endif
A note for users of ARM Cortex-M MCUs
Most support requests on ARM Cortex-M microcontrollers result from issues attributed
to incorrect interrupt priority assignment. FreeRTOS V7.5.0 and on-wards includes
configASSERT() calls to trap this common source of user error. Please ensure
configASSERT() is defined during development.
If the configASSERT is met we deactivate the interrupts and we fall into an endelss loop :
/* 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( ;; );}
The conditions we are meeting are:
- xTaskGetSchedulerState() returns taskSCHEDULER_SUSPENDED
/* Definitions returned by xTaskGetSchedulerState(). taskSCHEDULER_SUSPENDED is
0 to generate more optimal code when configASSERT() is defined as the constant
is used in assert() statements. */
#define taskSCHEDULER_SUSPENDED ( ( BaseType_t ) 0 )
#define taskSCHEDULER_NOT_STARTED ( ( BaseType_t ) 1 )
#define taskSCHEDULER_RUNNING ( ( BaseType_t ) 2 )
- xTicksToWait has a value of 1000
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-08-11 8:32 AM
Found this post https://community.st.com/s/question/0D53W00000Ip7vMSAR/fatfs-on-sd-card-with-freertos-does-it-insist-on-using-dma
I tought i was using a very high non preentive interruption number but who knows.
TeslaDelorean implies the data transfer is not tolerating intetuprions, so im wrapping my code in between:
vPortEnterCritical();
//my code
vPortExitCritical();
...same outcome, and it breaks other SD functions like mount and unmount
LEts try :https://stackoverflow.com/questions/68343923/cmsis-api-for-taskenter-critical-in-freertos
osKernelLock();
//my code
osKernelUnlock();
that breaks things even further i think im stopping the kernel? no description in those functions...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-08-11 9:08 AM
I fixed it, my Task priority needed to be raised to osPriorityRealTime
