Skip to main content
Disha
Associate II
August 23, 2020
Solved

Bus fault in the below program

  • August 23, 2020
  • 2 replies
  • 915 views
#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.

This topic has been closed for replies.
Best answer by Tesla DeLorean

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.

2 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
August 23, 2020

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Disha
DishaAuthor
Associate II
August 23, 2020

Hi clive1...

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