This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Task switching HardFault on Cortex-M0+ (arduino)

Hi All,

I am using an Arduino SAMD21 Cortex-M0+ board, and I am working on a preemptive task switcher which almost works except for one thing. If I trigger PendSV from SysTick it works, if I trigger PendSV from main program via yield() it works, but if I do both (use yield and also have an interrupt) then there is a hard fault. This is my Arduino sketch that rerpos the issue.. Inside the HardFault handler the stacked PC is 0xFFFFFFF8 and LR is pointing to the instruction in the Arduino's SysTick_Handler after it calls the sysTickHook(). Any idea how to debug this issue or what could be the cause? Thank you!

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#define SSIZE 1024
void task() {
while (1) {
SerialUSB.println("task");
yield();
//delay(1000);
}
}
struct Ctx {
uint32_t r8;
uint32_t r9;
uint32_t r10;
uint32_t r11;
uint32_t r4;
uint32_t r5;
uint32_t r6;
uint32_t r7;
uint32_t r0;
uint32_t r1;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

0