Solved
Bus fault in the below program
#include<stdio.h>
#include<stdint.h>
#define SCHED_STACK_START 20126976U
void init_tasks_stack(void);
void task1handler(void);
void enable_processor_faults(void);
__attribute__((naked)) void init_scheduler_stack(uint32_t sched_top_of_stack);
int main(void)
{
enable_processor_faults();
init_scheduler_stack(SCHED_STACK_START);
task1handler();
for(;;);
}
__attribute__((naked)) void init_scheduler_stack(uint32_t sched_top_of_stack)
{
__asm volatile("MSR MSP,%0": : "r" (sched_top_of_stack) : );
__asm volatile("BX LR");
}
void task1handler(void)
{
while(1)
{
printf("In task1 handler\n");
}
}
void enable_processor_faults(void)
{
uint32_t *pSHCSR = (uint32_t*)0xE000ED24;
*pSHCSR |= ( 1 << 16); //mem manage
*pSHCSR |= ( 1 << 17); //bus fault
*pSHCSR |= ( 1 << 18); //usage fault
}
void HardFault_Handler(void)
{
printf("Exception : Hardfault\n");
while(1);
}
void MemManage_Handler(void)
{
printf("Exception : MemManage\n");
while(1);
}
void BusFault_Handler(void)
{
printf("Exception : BusFault\n");
while(1);
}
I am trying to execute above code
if
init_scheduler_stack(SCHED_STACK_START);is commented out then, no problem in the code else there is bus fault
The fault analyser window throws error:
* Precise Data Access Violation
* Stacking error.
