arduino / arduino/ArduinoCore-mbed

HardFault when calling nicla::begin in Platformio.

Open
#372 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
411
Forks
225
PR merge metrics
No merged PRs in 30d

Description

https://github.com/arduino/ArduinoCore-mbed/blob/838c70238aaee11c7a8a32cf570de4f51ce240f7/libraries/Nicla_System/src/Nicla_System.cpp#L25-L35

Good morning.

I have tried uploading the nicla-blink code using the Platformio IDE. With the Arduino IDE, the code works fine. However, with Platformio, I get a hard fault from the mbed OS:

```
++ MbedOS Fault Handler ++

FaultType: HardFault

Context:
R 0: 00000000
R 1: 2000345C
R 2: 00000001
R 3: 20000BF5
R 4: 00002000
R 5: 00000000
R 6: 20000BEC
R 7: 00000000
R 8: 00000000
R 9: 00000000
R 10: 00000000
R 11: 00000000
R 12: 00016E79
SP : 20003408
LR : 00010753
PC : 00010764
xPSR : 41000000
PSP : 200033E8
MSP : 2000FFC0
CPUID: 410FC241
HFSR : 40000000
MMFSR: 00000000
BFSR : 00000000
UFSR : 00000001
DFSR : 00000000
AFSR : 00000000
Mode : Thread
Priv : Privileged
Stack: PSP

-- MbedOS Fault Handler --

++ MbedOS Error Info ++
Error Status: 0x80FF013D Code: 317 Module: 255
Error Message: Fault exception
Location: 0x10764
Error Value: 0x200087B4
Current Thread: main Id: 0x2000345C Entry: 0x17EE3 StackSize: 0xC00 StackMem: 0x20002838 SP: 0x20003408
For more info, visit: https://mbed.com/s/error?error=0x80FF013D&tgt=NICLA
-- MbedOS Error Info --
```
Using the debugger, the fault is triggered by the `th.start(&nicla::pingI2CThd);` call inside the `nicla::begin()` function. The code used is the following one:

```
#include "Nicla_System.h"

void setup() {
Serial.begin(115200);
while(!Serial);

nicla::begin();
nicla::leds.begin();
}

void loop() {
nicla::leds.setColor(green);
delay(1000);
nicla::leds.setColor(off);
delay(1000);
}
```
The platformio.ini file is the following one:
```
[env:nicla_sense_me]
platform = nordicnrf52
board = nicla_sense_me
framework = arduino
monitor_speed=115200
debug_tool = cmsis-dap
upload_protocol = cmsis-dap
```
I have previously posted the issue in the Platformio community and they have told me that I should post it here(https://community.platformio.org/t/arduino-mbed-thread-issue-on-arduino-nicla/24915).

Thank you for your attention.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by comparing the Arduino IDE and PlatformIO builds using the supplied platformio.ini, then inspect Nicla_System.cpp lines 25-35 around nicla::begin() and the th.start call. Reproduce the fault with the provided sketch and debugger; done means nicla::begin() no longer hard-faults under PlatformIO and the blink example runs.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.