2020-08-23 08:11 AM
#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.
Solved! Go to Solution.
2020-08-23 09:04 AM
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.
2020-08-23 09:04 AM
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.
2020-08-23 10:14 AM
Hi clive1...
Thank you so much...Problem solved...