TIVA Launchpad - Default_Handler triggered on vTaskStartScheduler()

Hi all,

I’m trying to run my first FreeRTOS project.

I’m reading all the useful guides like (the book and the FAQ and other posts).
I’m using the TIVA Launchpad (TM4C123) and the TI CCS enviroment (V10.0.0.00010) with the TI compiler (TI v20.2.1.LTS).
I’m trying to run the latest FreeRTOS (V10.3.1).
I had a look to this demo that is similar to this board, from which I get the FreeRTOSConfig.h file (see my previous post).

At the moment I’m able to create a task (it should just turn a LED on), but as soon as I start the scheduler the PC jumps to the Default_Handler.
I stepped-in the code and the exact point where this happen is at the function vPortStartFirstTask().

Looks like some exception is triggered, but I can’t understand which one. To understand which was, I tried to implement the code proposed here, but this doesn’t run with my complier (it might be for GCC, I’m not sure).

Is there someone that can help me to:

  • translate this code for the compiler that I’m using, or
  • make a GCC project build (this is not my priority)?
    • I tried to make a project using the same configuration except selecting the GCC compiler (GNU v9.2.1 Linaro), but I get a lot of errors related to the linking phase

I use the heap_4 as memory model with the following configuration:

#define configMINIMAL_STACK_SIZE            ( ( uint16_t ) 100 )
#define configTOTAL_HEAP_SIZE               ( ( size_t ) ( 10 * 1024 ) )
#define configCHECK_FOR_STACK_OVERFLOW          2

I also defined the exceptions handler in the startup code using the CMSIS style:

void PendSV_Handler        (void) __attribute__ ((weak, alias("Default_Handler")));
void SysTick_Handler       (void) __attribute__ ((weak, alias("Default_Handler")));
void SysTick_Handler       (void) __attribute__ ((weak, alias("Default_Handler")));

I updated the vector table as well:

SVC_Handler,            /* SVCall handler                  */
DebugMon_Handler,       /* Debug monitor handler           */
0,                      /* Reserved                        */
PendSV_Handler,         /* The PendSV handler              */
SysTick_Handler,        /* The SysTick handler             */

And I added these defines to the FreeRTOSConfig.h file:

#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler

I really hope that someone could help me to solve this, because all I tried failed.

Best regards,

A few notes:

  1. Sometimes it appears that a crash occurs when starting the scheduler, whereas in fact, because that function doesn’t return, the scheduler did start as expected and the crash happened in one of the tasks. Try setting up a system where you know which task is the first to run, then put a break at the top of that task to see if the break point is ever hit. The first task will always be the one that has the highest priority, but you need to take care that this is not unknowingly the timer service task. The priority of the timer service task is set by the configTIMER_TASK_PRIORITY setting in FreeRTOSConfig.h (assuming configUSE_TIMERS is 1, if configUSE_TIMERS is 0 then the timer service task is not created).

  2. vPortSVCHandler is the exception handler that executes in response to an SVC instruction, which is inside vPortStartFirstTask() function. Check this is installed as expected (it should be due to the #define in the config file as per your post) by setting a break point in it and ensure it runs. The function is implemented here: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/master/portable/CCS/ARM_CM4F/portasm.asm#L133

  3. As per our previous conversation, the default handler is installed for every interrupt that you do not explicit set a handler for yourself - in some cases that can include the hardfault handler, so the execution of the default handler might be due to a hard fault rather than an interrupt. To determine that make sure the hard fault exception has its own unique handler so you can see if you end up inside it.

  4. The code that enables you to debug a hard fault is provided in GCC syntax, you would have to translate that to the syntax required by the TI assembler. The easiest way to do that might be to add the code into the portasm.asm file linked in point (2) above so you can see the required syntax.

Hi Richard,

thanks for your time.
I tried ALL.

For me this will the last attempt.
If I couldn’t make it run I’ll unfortunately give up, since I don’t have anymore time to spend on this. :pensive: :cry: :sob: :sob:

I made a CCS project.
Is there someone with this board and with CCS that can try it?

This is the only way that I have to see if the code has some errors.
My system installation works fine because I can run all other projects that I have.

Now the code is even simpler, I even removed the LED in the task.

Environment that I used:

  • TI CCS enviroment (V10.0.0.00010)
  • TI compiler (TI v20.2.1.LTS).
  • TIVAWARE (TivaWare_C_Series-
  • FreeRTOS (V10.3.1)

In the project FreeRTOS is just a link to my local repository (so it is not part of the project’s files)
Here the project structure:

Many thanks to anyone that could run this.
FreeRTOSLaunchpadExample.zip (463.4 KB)


Going back to the other thread, where the original poster replied saying it worked if they turned on optimisation, my reply to which is here: TI Tiva TM4c1294 FreeRTOS v10.2.1

Hi chaps,

I finally solved!
The issue was related to the handlers function definition.

My vector table was defined like in the CMSIS (see my post above, here the code for your convenience):

SVC_Handler,            /* SVCall handler                  */
DebugMon_Handler,       /* Debug monitor handler           */
0,                      /* Reserved                        */
PendSV_Handler,         /* The PendSV handler              */
SysTick_Handler,        /* The SysTick handler             */

Then the handlers of the exceptions: SVC, PendSV and SysTick were redefined in the FreeRTOSConfig.h file as:

#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler

I spent some time to understand why this although looks correct to me doesn’t work.
I tried to add those definitions at the begin of the config file, I tried other ways to define them, but I always had the same issue (stunk in the Default_Handler routine).

Here my solution:
The only way I could make the code run has been to write directly into the vector table theFreeRTOS exceptions handlers:

vPortSVCHandler,            /* SVCall handler                  */
DebugMon_Handler,           /* Debug monitor handler           */
0,                          /* Reserved                        */
xPortPendSVHandler,         /* The PendSV handler              */
xPortSysTickHandler,        /* The SysTick handler             */

and of course add the external definitions into the same startup code:

extern void xPortPendSVHandler(void);
void        DebugMon_Handler      (void) __attribute__ ((weak, alias("Default_Handler")));
extern void vPortSVCHandler(void);
extern void xPortSysTickHandler(void);

Even if the project runs I don’t like consider this issue close, I’d like to understand why and how to let the original vector table work.
Can you help me?

Kind regards,

P.S. as a compare with the previous not working project, I attach a new example that lights on the red LED and increment a counter into the task. Project structure is unchanged.
fixedFreeRTOSLaunchpadExample.zip (497.3 KB)

I am so happy to see that the issue have been solved. Please keep suggesting such kind of post.

One Vanilla

Looking at the code I the normal #define method won’t work in this case because the functions are defined in a CCS specific asm file that is not #including FreeRTOS.h - therefore the asm file doesn’t see the #defines and doesn’t remap the FreeRTOS names to the CMSIS names.