cancel
Showing results for 
Search instead for 
Did you mean: 

sd card functions throwing Hardfaults() inside tasks but not in main (FREERTOS+SDcard(spi))

Javier1
Principal

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.

we dont need to firmware by ourselves, lets talk
1 ACCEPTED SOLUTION

Accepted Solutions

I fixed it, my Task priority needed to be raised to osPriorityRealTime

0693W00000QNVSWQA5.png

we dont need to firmware by ourselves, lets talk

View solution in original post

4 REPLIES 4
Javier1
Principal

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);

we dont need to firmware by ourselves, lets talk

0693W00000QNVFvQAP.jpgI 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

 and the freertos page says:

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
we dont need to firmware by ourselves, lets talk
Javier1
Principal

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...

we dont need to firmware by ourselves, lets talk

I fixed it, my Task priority needed to be raised to osPriorityRealTime

0693W00000QNVSWQA5.png

we dont need to firmware by ourselves, lets talk