cancel
Showing results for 
Search instead for 
Did you mean: 

Bus fault in the below program

Disha
Associate II
#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.

1 ACCEPTED SOLUTION

Accepted Solutions

Well the address you're supplying for the stack looks entirely bogus, should this be in hex?

If you change the stack, hopefully the calling procedure doesn't break if it tries to pop context off it.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

2 REPLIES 2

Well the address you're supplying for the stack looks entirely bogus, should this be in hex?

If you change the stack, hopefully the calling procedure doesn't break if it tries to pop context off it.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hi clive1...

Thank you so much...Problem solved...