I am using LPC controller. I create 3 tasks. but when I tried to run the program Hard fault is coming in the bellow section.
__asm void prvStartFirstTask( void )
{
PRESERVE8
/* Use the NVIC offset register to locate the stack. */
ldr r0, =0xE000ED08
ldr r0, [r0]
ldr r0, [r0]
/* Set the msp back to the start of the stack. */
msr msp, r0
/* Clear the bit that indicates the FPU is in use in case the FPU was used
before the scheduler was started - which would otherwise result in the
unnecessary leaving of space in the SVC stack for lazy saving of FPU
registers. */
mov r0, #0
msr control, r0
/* Globally enable interrupts. */
cpsie i
cpsie f
dsb
isb
/* Call SVC to start the first task. */
svc 0
nop
nop
}
Can anyone please help how to remove this fault. inside the task I am trying to simply toggling the LED. I took the RTOS file from the KEIL library.
When users have posted similar problems in the past it has turned out that the svc instruction started the scheduler correctly, and the crash actually occurred in a task. If you step through the debugger though, the last thing you see in the svc call, and not the scv handler.
I suggest creating an application with a single task that is running at a high priority (it has to be higher than the idle and timer task priorities so you know which task will run first - the latter set by configTIMER_TASK_PRIORITY) - then put a breakpoint on the opening bracket “{” of the function that implements the task and see if the breakpoint is hit.
Those three lines do belong in FreeRTOSConfig.h, not in port.c, but that’s probably not going to fix your issue. I would make sure the scheduler is actually starting successfully as Richard describes above. Also look at the “common” issues addressed in this post.
Here I attached a smallest project. When I tried to run this project inside this function vTaskStartScheduler(); when svc call happens that time the program goes to hard fault.
I didn’t see any definition for configASSERT() in FreeRTOSConfig.h. You should define that macro so that FreeRTOS can detect configuration and other issues at runtime.
Did you define configASSERT() yet? The help page recommends this implementation during debugging:
/* Define configASSERT() to disable interrupts and sit in a loop. */
#define configASSERT ( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }