NUCLEO-H743ZI2 + Mbed OS problems

Hi, I am trying to build and debug basic project for NUCLEO-H743ZI2 with Mbed OS. My OS is Windows 10/11, VC and PIO are up to date. After press Start debug I got:

C:\Users\Kucza\Documents\PlatformIO\Projects\NucleoH743\src\main.cpp:1:10: fatal error: mbed.h: No such file or directory
1 | #include <mbed.h>
| ^~~~~~~~
compilation terminated.

If I press Build it it builds and generated binary but upload finished with error:

Generating LD script .pio\build\nucleo_h743zi\STM32H743xI.ld.link_script.ld
src\main.cpp: In function ‘int main()’:
src\main.cpp:11:10: warning: value computed is not used [-Wunused-value]
11 | led1 != led1;
| ~^~~
Linking .pio\build\nucleo_h743zi\firmware.elf
Checking size .pio\build\nucleo_h743zi\firmware.elf
Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
RAM: [ ] 4.1% (used 21280 bytes from 524288 bytes)
Flash: [ ] 2.8% (used 58776 bytes from 2097152 bytes)
Configuring upload protocol…
AVAILABLE: blackmagic, cmsis-dap, jlink, mbed, stlink
CURRENT: upload_protocol = stlink
Uploading .pio\build\nucleo_h743zi\firmware.elf
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-16-21:19)
Licensed under GNU GPL v2
For bug reports, read
OpenOCD: Bug Reporting
debug_level: 1

srst_only separate srst_nogate srst_open_drain connect_deassert_srst

Warn : target stm32h7x.cpu0 examination failed
embedded:startup.tcl:1070: Error: ** Unable to reset target **
in procedure ‘program’
in procedure ‘program_error’ called at file “embedded:startup.tcl”, line 1107
at file “embedded:startup.tcl”, line 1070
*** [upload] Error 1
==================================================================== [FAILED] Took 990.31 seconds ====================================================================

The terminal process “C:\Users\Kucza.platformio\penv\Scripts\platformio.exe ‘run’, ‘–target’, ‘upload’, ‘–environment’, ‘nucleo_h743zi’” terminated with exit code: 1.

So it looks like Nucleo + Mbed it doesn’t work with PIO out of the box. Anyone can give me any suggestion?

Before uploading, can you hold down the reset button on the Nucleo board, then when OpenOCD starts up, release it again? Timing might be tricky. If it works, there is a problem with the reset method.

Indeed holding/releasing reset button allow to upload firmware correctly:

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: ST STM32 (15.4.0) > ST Nucleo H743ZI
HARDWARE: STM32H743ZIT6 400MHz, 512KB RAM, 2MB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, cmsis-dap, jlink)
PACKAGES:

  • framework-mbed @ 6.60900.210318 (6.9.0)
  • tool-dfuutil @ 1.9.200310
  • tool-openocd @ 2.1100.211028 (11.0)
  • tool-stm32duino @ 1.0.2
  • toolchain-gccarmnoneeabi @ 1.90201.191206 (9.2.1)
    Collecting mbed sources…
    LDF: Library Dependency Finder
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 0 compatible libraries
    Scanning dependencies…
    No dependencies
    Building in release mode
    Checking size .pio\build\nucleo_h743zi\firmware.elf
    Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
    RAM: [ ] 0.0% (used 0 bytes from 524288 bytes)
    Flash: [ ] 0.0% (used 0 bytes from 2097152 bytes)
    Configuring upload protocol…
    AVAILABLE: blackmagic, cmsis-dap, jlink, mbed, stlink
    CURRENT: upload_protocol = stlink
    Uploading .pio\build\nucleo_h743zi\firmware.elf
    xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-16-21:19)
    Licensed under GNU GPL v2
    For bug reports, read
    OpenOCD: Bug Reporting
    debug_level: 1

srst_only separate srst_nogate srst_open_drain connect_deassert_srst

target halted due to debug-request, current mode: Thread
xPSR: 00000000 pc: 00000000 msp: 00000000
** Programming Started **
Warn : Adding extra erase range, 0x0800fe40 … 0x0801ffff
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked

What about compiling and fatal error: mbed.h: No such file or directory #include <mbed.h> ??

How could you even the build the firmware if this error occurs o_O. Can you show a screenshot of VSCode with that error?

Of course I couldn’t. To test upload I used firmware generated in Mbed Studio.

image

You must build the firmware through the “Build” button or Project Tasks → your board → Build. This shouldn’t say "Executing task: C/C++…` but something like

> Executing task: C:\Users\Max Gerhardt\.platformio\penv\Scripts\platformio.exe run --environment ... <

If the build button (Checkmark icon in the bottom blue taskbar) does execute that task, you have conflicting VSCode extensions installed. Remove all but PlatformIO and C/C++ by Microsoft.

OK, It builds correctly when I use PROJECT TASKS → Build. Generated firmware.bin is working after upload. How to start debug? The same way? QUICK ACCESS->Debug->Start Debugging ??
I don’t have any other extensions except those you mentioned.

Yes, per docs (PlatformIO IDE for VSCode — PlatformIO latest documentation).

Then for reference, how did you trigger that C/C++ build task that fails? Ctrl+Shift+P → Something?

RUN AND DEBUG looks it proper way to start debug but in logs I got:

undefined C:\Users\Kucza.platformio\packages\toolchain-gccarmnoneeabi\bin\arm-none-eabi-gdb.exe: warning: Couldn’t determine a path for the index cache directory.

Reading symbols from c:\Users\Kucza\Documents\PlatformIO\Projects\NucleoH743.pio\build\nucleo_h743zi\firmware.elf…
PlatformIO Unified Debugger →
PlatformIO: debug_tool = stlink
PlatformIO: Initializing remote target…
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-16-21:19)
Licensed under GNU GPL v2
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
srst_only separate srst_nogate srst_open_drain connect_deassert_srst

Info : tcl server disabled
Info : telnet server disabled
Info : clock speed 1800 kHz
Info : STLINK V3J9M3 (API v3) VID:PID 0483:3754
Info : Target voltage: 3.281698
Info : stm32h7x.cpu0: Cortex-M7 r1p1 processor detected
Info : stm32h7x.cpu0: target has 71 breakpoints, 0 watchpoints
Info : starting gdb server for stm32h7x.cpu0 on pipe
Info : accepting ‘gdb’ connection from pipe
Error: timed out while waiting for target halted
Error executing event gdb-attach on target stm32h7x.cpu0:

Error: auto_probe failed
Error: Connect failed. Consider setting up a gdb-attach event for the target to prepare target for GDB connect, or use ‘gdb_memory_map disable’.
Error: attempted ‘gdb’ connection rejected
Error: error during select: Unknown error
.pioinit:13: Error in sourced command file:
Remote communication error. Target disconnected.: Success.

There absolutely is a problem with the reset method…

Let’s try a fix. Please open the file C:\Users\Kucza\.platformio\platforms\ststm32\boards\nucleo_h743zi.json and replace its content with

{
  "build": {
    "core": "stm32",
    "cpu": "cortex-m7",
    "extra_flags": "-DSTM32H7xx -DSTM32H743xx",
    "f_cpu": "400000000L",
    "mcu": "stm32h743zit6",
    "product_line": "STM32H743xx",
    "variant": "STM32H7xx/H742Z(G-I)T_H743Z(G-I)T_H747A(G-I)I_H747I(G-I)T_H750ZBT_H753ZIT_H757AII_H757IIT"
  },
  "connectivity": [
    "can",
    "ethernet"
  ],
  "debug": {
    "default_tools": [
      "stlink"
    ],
    "jlink_device": "STM32H743ZI",
    "onboard_tools": [
      "stlink"
    ],
    "openocd_board": "st_nucleo_h743zi",
    "svd_path": "STM32H743.svd"
  },
  "frameworks": [
    "arduino",
    "cmsis",
    "stm32cube",
    "mbed",
    "zephyr"
  ],
  "name": "ST Nucleo H743ZI",
  "upload": {
    "maximum_ram_size": 524288,
    "maximum_size": 2097152,
    "protocol": "stlink",
    "protocols": [
      "jlink",
      "cmsis-dap",
      "stlink",
      "blackmagic",
      "mbed"
    ]
  },
  "url": "https://www.st.com/en/evaluation-tools/nucleo-h743zi.html",
  "vendor": "ST"
}

Does it make a difference?

Stil the same. It can not upload firmware:

Generating LD script .pio\build\nucleo_h743zi\STM32H743xI.ld.link_script.ld
Linking .pio\build\nucleo_h743zi\firmware.elf
Checking size .pio\build\nucleo_h743zi\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   4.1% (used 21304 bytes from 524288 bytes)
Flash: [          ]   2.8% (used 58796 bytes from 2097152 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, jlink, mbed, stlink
CURRENT: upload_protocol = stlink
Uploading .pio\build\nucleo_h743zi\firmware.elf
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-16-21:19)
Licensed under GNU GPL v2
debug_level: 1

srst_only separate srst_nogate srst_open_drain connect_deassert_srst

Error: Cortex-M PARTNO 0x0 is unrecognized
Warn : target stm32h7x.cpu0 examination failed
Error: Cortex-M PARTNO 0x0 is unrecognized
embedded:startup.tcl:1070: Error: ** Unable to reset target **
in procedure 'program' 
in procedure 'program_error' called at file "embedded:startup.tcl", line 1107
at file "embedded:startup.tcl", line 1070
*** [upload] Error 1
====================================================================================================================================== [FAILED] Took 305.88 seconds ======================================================================================================================================
The terminal process "C:\Users\info\.platformio\penv\Scripts\platformio.exe 'run', '--target', 'upload', '--environment', 'nucleo_h743zi'" terminated with exit code: 1.

Is it dificult to try integrate OpenOCD ST fork? I’am asking becouse all development enviroments that use OpenOCD can not connect to this Nucleo board. I have try debuging it in STM32CubeIDE and uploading and debuging work as it should.

Where’s ST’s OpenOCD fork? Or do you mean GitHub - stlink-org/stlink: Open source STM32 MCU programming toolset?

@maxgerhardt Hi max, I got the same error like the host.

but I make the board on my own, and there is no way to press the reset button.

Archiving .pio\build\nucleo_h743zi\libFrameworkCMSISDevice.a
Indexing .pio\build\nucleo_h743zi\libFrameworkCMSISDevice.a
Linking .pio\build\nucleo_h743zi\firmware.elf
Checking size .pio\build\nucleo_h743zi\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.0% (used 48 bytes from 524288 bytes)
Flash: [          ]   0.2% (used 4720 bytes from 2097152 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, jlink, mbed, stlink
CURRENT: upload_protocol = stlink
Uploading .pio\build\nucleo_h743zi\firmware.elf
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-16-21:19)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

srst_only separate srst_nogate srst_open_drain connect_deassert_srst

Error: timed out while waiting for target halted
embedded:startup.tcl:1070: Error: ** Unable to reset target **
in procedure 'program'
in procedure 'program_error' called at file "embedded:startup.tcl", line 1107
at file "embedded:startup.tcl", line 1070
*** [upload] Error 1

I can upload my code with keil successfully with this same stlinkv2(4 lines connected only).
I guess it’s mybe the credit of this setting “Autodetect” or something in keil but i can’t find it in platformio.

And i also try like append reset_config trst_only or reset_config none but none of them works.
Could you give some advice for me, thanks a lot.

If you’ve tried all possible OpenOCD reset_config options but it still won’t correctly reset your board, better open a ticket in OpenOCD - Open On-Chip Debugger / Tickets.

Thanks max!! I’ve realize that the problem is the settings position of openocd wrong.

I find some config file in "C:\Users\xxx\.platformio\packages\tool-openocd\scripts\board\st_nucleo_h743zi.cfg"

and I change the reset_config to none, and it sove my problem!!

I thought it’s the setting position in platform.ini that cause my previous setting not effect.