Code works via Arduino IDE, but not via PlatformIO, tried two different boards, no errors are seen in verbose

Hi,

I have Nicla Sense ME and Portenta H7 Lite Connected. I am trying to upload simple blink example. Blink example for Portenta H7:

void setup() {
    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, HIGH); // turn the LED off after being turned on by pinMode()
}

void loop() {
    digitalWrite(LED_BUILTIN, LOW); // turn the LED on (LOW is the voltage level)
    delay(1000); // wait for a second
    digitalWrite(LED_BUILTIN, HIGH); // turn the LED off by making the voltage HIGH
    delay(1000); // wait for a second
}

Verbose of Portenta upload:

CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/portenta_h7_m4.html
PLATFORM: ST STM32 (16.0.0) > Arduino Portenta H7 (M4 core)
HARDWARE: STM32H747XIH6 480MHz, 287.35KB RAM, 1MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, jlink, stlink)
PACKAGES: 
 - framework-arduino-mbed @ 4.0.2 
 - tool-dfuutil @ 1.11.0 
 - tool-openocd @ 3.1200.0 (12.0) 
 - tool-stm32duino @ 1.0.1 
 - toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 42 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
MethodWrapper(["checkprogsize"], [".pio/build/portenta_h7_m4/firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  14.5% (used 42808 bytes from 294248 bytes)
Flash: [=         ]   6.7% (used 69752 bytes from 1048576 bytes)
.pio/build/portenta_h7_m4/firmware.elf  :
section              size        addr
.text               65304   135266304
.ARM.extab            160   135331608
.ARM.exidx            376   135331768
.data                4072   268436120
.uninitialized          0   268440192
.bss                38736   268440192
.openamp_section        0   939524096
.pdm_section        64512   939524096
.heap              250416   268478928
.ARM.attributes        46           0
.comment              247           0
.debug_frame         6460           0
.stab                  60           0
.stabstr              118           0
Total              430507
<lambda>(["upload"], [".pio/build/portenta_h7_m4/firmware.bin"])
AVAILABLE: cmsis-dap, dfu, jlink, mbed, stlink
CURRENT: upload_protocol = dfu
BeforeUpload(["upload"], [".pio/build/portenta_h7_m4/firmware.bin"])
Using manually specified: /dev/ttyACM1
Forcing reset using 1200bps open/close on port /dev/ttyACM1
Waiting for the new upload port...
"/home/hako/.platformio/packages/tool-dfuutil/bin/dfu-util" -d 0x2341:0x035b -a 0 -s 0x08100000:leave -D "/home/hako/Documents/PlatformIO/Projects/portenta_v1/.pio/build/portenta_h7_m4/firmware.bin"
dfu-util 0.11

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2021 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Opening DFU capable USB device...
Device ID 2341:035b
Device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Interface #0 ...
Determining device status...
DFU state(2) = dfuIDLE, status(0) = No error condition is present
DFU mode device DFU version 011a
Device returned transfer size 4096
DfuSe interface name: "Internal Flash   "
Downloading element to address = 0x08100000, size = 69912

Erase           [                         ]   0%            0 bytes
Erase           [                         ]   0%            0 bytes
Erase           [=                        ]   5%         4096 bytes
Erase           [==                       ]  11%         8192 bytes
Erase           [====                     ]  17%        12288 bytes
Erase           [=====                    ]  23%        16384 bytes
Erase           [=======                  ]  29%        20480 bytes
Erase           [========                 ]  35%        24576 bytes
Erase           [==========               ]  41%        28672 bytes
Erase           [===========              ]  46%        32768 bytes
Erase           [=============            ]  52%        36864 bytes
Erase           [==============           ]  58%        40960 bytes
Erase           [================         ]  64%        45056 bytes
Erase           [=================        ]  70%        49152 bytes
Erase           [===================      ]  76%        53248 bytes
Erase           [====================     ]  82%        57344 bytes
Erase           [=====================    ]  87%        61440 bytes
Erase           [=======================  ]  93%        65536 bytes
Erase           [======================== ]  99%        69632 bytes
Erase           [=========================] 100%        69912 bytes
Erase    done.

Download        [                         ]   0%            0 bytes
Download        [=                        ]   5%         4096 bytes
Download        [==                       ]  11%         8192 bytes
Download        [====                     ]  17%        12288 bytes
Download        [=====                    ]  23%        16384 bytes
Download        [=======                  ]  29%        20480 bytes
Download        [========                 ]  35%        24576 bytes
Download        [==========               ]  41%        28672 bytes
Download        [===========              ]  46%        32768 bytes
Download        [=============            ]  52%        36864 bytes
Download        [==============           ]  58%        40960 bytes
Download        [================         ]  64%        45056 bytes
Download        [=================        ]  70%        49152 bytes
Download        [===================      ]  76%        53248 bytes
Download        [====================     ]  82%        57344 bytes
Download        [=====================    ]  87%        61440 bytes
Download        [=======================  ]  93%        65536 bytes
Download        [======================== ]  99%        69632 bytes
Download        [=========================] 100%        69912 bytes
Download done.
File downloaded successfully
Submitting leave request...
Transitioning to dfuMANIFEST state

Platform.ini:

[env:portenta_h7_m4]
platform = ststm32
board = portenta_h7_m4
framework = arduino

If I use Arduino IDE all works fine. Same issue happens for Nicla Sense ME as well. How can i debug this further? Many thanks.

Are you sure you don’t need to use portenta_h7_m7 as that’s the main core?

Hi @maxgerhardt,

I have changed to that one. I cannot still upload anything.

Here is how .ini looks:

[env:portenta_h7_m7]
platform = ststm32
board = portenta_h7_m7
framework = arduino

I think the issue is independent from the core. I cannot upload anything to Nicla Sense ME as well.

My OS is Ubuntu 20.04.

When I try to upload my code again, I get this error.

Error: [nrf52.cpu] clearing lockup after double fault

Maybe this can lead to anything, hopefully.

I am also adding Arduino IDE verbose, which works fine:

FQBN: arduino:mbed_nicla:nicla_sense
Using board 'nicla_sense' from platform in folder: /home/hako/.arduino15/packages/arduino/hardware/mbed_nicla/4.0.2
Using core 'arduino' from platform in folder: /home/hako/.arduino15/packages/arduino/hardware/mbed_nicla/4.0.2
...
...
Using library Nicla_Sense_System at version 1.0 in folder: /home/hako/.arduino15/packages/arduino/hardware/mbed_nicla/4.0.2/libraries/Nicla_System 
Using library Wire in folder: /home/hako/.arduino15/packages/arduino/hardware/mbed_nicla/4.0.2/libraries/Wire (legacy)
/home/hako/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-size -A /tmp/arduino/sketches/F6E3EA505FB42A798AFE11DF558DBED6/nicla_blink.ino.elf
Sketch uses 55536 bytes (10%) of program storage space. Maximum is 527616 bytes.
Global variables use 12256 bytes (19%) of dynamic memory, leaving 52032 bytes for local variables. Maximum is 64288 bytes.
"/home/hako/Documents/xpack-openocd-0.12.0-1/bin/openocd" -d2 -s "/home/hako/Documents/xpack-openocd-0.12.0-1/share/openocd/scripts/" -f interface/cmsis-dap.cfg -c "transport select swd; adapter speed 1000" -f target/nrf52.cfg -c "telnet_port disabled; init; reset init; halt; adapter speed 10000; program {/tmp/arduino/sketches/F6E3EA505FB42A798AFE11DF558DBED6/nicla_blink.ino.elf}; reset run; shutdown"
xPack Open On-Chip Debugger 0.12.0-01004-g9ea7f3d64-dirty (2023-01-30-15:03)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
debug_level: 2

adapter speed: 1000 kHz

Info : CMSIS-DAP: SWD supported
Info : CMSIS-DAP: FW Version = v1.0
Info : CMSIS-DAP: Serial# = AA7EAA93
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : [nrf52.cpu] Cortex-M4 r0p1 processor detected
Info : [nrf52.cpu] target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for nrf52.cpu on 3333
Info : Listening on port 3333 for gdb connections
[nrf52.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00006e0c msp: 0x20010000
[nrf52.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00006e0c msp: 0x20010000
** Programming Started **
Info : nRF52832-CIAA(build code: E0) 512kB Flash, 64kB RAM
Warn : Adding extra erase range, 0x0001d8f8 .. 0x0001dfff
** Programming Finished **
shutdown command invoked

PACKAGES: 
 - framework-arduino-mbed @ 4.0.2 
 - tool-bossac-nordicnrf52 @ 1.10901.201022 (1.9.1) 
 - tool-openocd @ 3.1200.0 (12.0) 
 - tool-sreccat @ 1.164.0 (1.64) 
 - toolchain-gccarmnoneeabi @ 1.100301.220327 (10.3.1)

One by one, I updated/played with these tools etc, it did not help.

I am still hopeful while trying to swim in this vast ocean alone.

Best Regards,

Hako

Is it maybe the latest 10.0.0 release that’s broken? Pick an older version per Releases · platformio/platform-nordicnrf52 · GitHub and reference it in the platformio.ini

platform = nordicnrf52@9.6.0

etc.

In case it still doesn’t work, please file an issue at Issues · platformio/platform-nordicnrf52 · GitHub.

I have found the fix. My struggles were not in vain. I changed the bloody

- toolchain-gccarmnoneeabi @ 1.100301.220327 (10.3.1)

with the one that Arduino IDE uses. Now, I can upload my code.

Thanks for the help @maxgerhardt.

CC @valeros possible toolchain or flags broken, might already be Upload issue with 9.6.0 for Arduino Nano 33 BLE · Issue #175 · platformio/platform-nordicnrf52 · GitHub