How to debug the blinking lights of death / mbed_die()?

Hi,
I recently ported an old FreeScale system to a Nucleo H753ZI dev board (one of the few Ethernet boards available back then). Software port to Mbed is reasonably easy, hardware consists of quite a bunch of wires over to a headless donor board. This was then consolidated into a custom board using the STM32F437VIT6 (TQFP100 is plenty and there’s space restrictions, plus availability considerations again). I made two of them and both do work at least on a basic level, e.g. blinky examples and printf responses via STM32CubeIDE work fine. The board is programmed via a smaller Nucleo F103RB STLinkv2 that is known good by also running the H753 in that configuration, circumventing the STlink v3e of the H753.

Mbed however does not work at all. There’s little support of the exact chip in the first place, the Keil STM32F4 package is outdated, the STM32Cube_FW files are outdated, and basically the only thing I get back from the board is the blinking lights of death. I can move around the LED by changing PinNames.h definition (#define LED1 PE_15 // act1), but that’s about it. Debugging sessions yield nothing, as I cannot run code or even stop before code execution. There’s one warning when starting the debug, “Loadable section “RW_IRAM1” outside of ELF segments”, on which I dug deeper over the last two days into all the weird and wonderful config files, but I cannot make that go away and I don’t even know if that is a fatal error or just a warning.
So - how do I make Mbed stop right at the beginning of code execution so that I can actually watch something crash and make the thing enter mbed_die()? Any input is highly appreciated.

Debug output:
0018843:INFO:loader:Erased chip, programmed 62464 bytes (61 pages), skipped 3072 bytes (3 pages) at 3.64 kB/s
Resetting target with halt
Successfully halted device on reset
Image loaded: c:/Users/Buchwald.M/Mbed Programs/753blinky/BUILD/EL112-3/ARMC6/753blinky.elf
Note: automatically using hardware breakpoints for read-only addresses.

Pressing Pause on the Debugger adds these lines:

 received signal SIGINT, Interrupt.
0x080076ca in _wait_us_ticks (ticks=400000) at .\mbed-os\platform\source/mbed_wait_api_no_rtos.c:44
44	    while (((us_ticker_read() - start) & US_TICKER_MASK) < ticks);

custom_targets.json
{
    "MCU_STM32F437xI": {
        "inherits": [
            "MCU_STM32F4"
        ],
        "extra_labels_add": [
            "STM32F437xI"
        ],
        "macros_add": [
            "STM32F437xx",
            "STM32F437VITx",
            "STM32F437",
            "MBEDTLS_CONFIG_HW_SUPPORT"
        ],
        "device_has_add": [
            "ANALOGOUT",
            "CAN",
            "TRNG"
        ],
        "device_name": "STM32F437VITx"
        },
        

    "EL112-3": { 
         "detect_code": [
            "0799"
        ],
        "inherits": ["MCU_STM32F437xI"],
        "bootloader_supported": true
    }
}
mbed_app.json:
{        "config": {
                    "clock_source": "USE_PLL_HSI"
    }
,
    "target_overrides": {
        "*": {
            "target.stdio_uart_tx": "PD_8",
            "target.stdio_uart_rx": "PD_9",
            "target.printf_lib": "std",
            "target.c_lib": "std",
            "platform.stdio-baud-rate": 9600,
            "platform.stdio-buffered-serial": true,
            "platform.default-serial-baud-rate": 9600,
            "platform.error-filename-capture-enabled": true,
            "platform.error-all-threads-info": true,
            "platform.crash-capture-enabled": false,
            "platform.stack-dump-enabled": false,
            "clock_source": "USE_PLL_HSI",
            "platform.use-mpu": false
            }
    }
}

enabling platform.crash-capture-enabled in the above field yields compile errors, which seems to be a known bug

[Error] @0,0: L6218E: Undefined symbol Image$$RW_m_crash_data$$ZI$$Base (referred from BUILD/EL112-3/ARMC6/mbed-os/platform/source/TARGET_CORTEX_M/TOOLCHAIN_ARM/except.o).
Error: L6218E: Undefined symbol Image$$RW_m_crash_data$$ZI$$Base (referred from BUILD/EL112-3/ARMC6/mbed-os/platform/source/TARGET_CORTEX_M/TOOLCHAIN_ARM/except.o).
Finished: 0 information, 0 warning and 1 error messages.
[ERROR] Error: L6218E: Undefined symbol Image$$RW_m_crash_data$$ZI$$Base (referred from BUILD/EL112-3/ARMC6/mbed-os/platform/source/TARGET_CORTEX_M/TOOLCHAIN_ARM/except.o).
Finished: 0 information, 0 warning and 1 error messages.

Similar things happen on platform.stack-dump-enabled

[Error] @0,0: L6218E: Undefined symbol __INITIAL_SP (referred from BUILD/EL112-3/ARMC6/mbed-os/platform/source/mbed_error.o).
Error: L6218E: Undefined symbol __INITIAL_SP (referred from BUILD/EL112-3/ARMC6/mbed-os/platform/source/mbed_error.o).
Finished: 0 information, 0 warning and 1 error messages.
[ERROR] Error: L6218E: Undefined symbol __INITIAL_SP (referred from BUILD/EL112-3/ARMC6/mbed-os/platform/source/mbed_error.o).
Finished: 0 information, 0 warning and 1 error messages.

Code crashing instantly includes the standard blinky or something trivial like

#include "mbed.h"
int main()
{
int i = 1;
    while (true) {
        
        wait_us(i * 1000);
        i++;
    }
}

(Mbed ignoring all breakpoints possible on those few lines of code)

And so on, and so forth…porting 15 year old code from a different manufacturer and architecture plus adding Ethernet connectivity for the first time ever was easy peasy compared to making code from a STM32 H753 run on a F437 as well?!

Hello,

when Mbed already blinking the dead sequence (= MbedOS crash), then the system is already restarted and and a crash report was already sended to the console via printf from ram.
When you have an error in settings of board initialization then of course can not set any break point in main.cpp because the main was never reached.

BR, Jan

Hi Jan,

Well, I didn’t make it up if you suggest that. The F439 https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/system_clock.c also has this setting, and for now, I’d like to use the internal clock, as I do have an oscillator present on the board (50 MHz required for Ethernet), and ideally, I’d like to keep it simple during troubleshooting. It doesn’t change anything, though, I can remove the entry and it crashes just like before.

Memory settings are correct https://www.st.com/resource/en/datasheet/stm32f437vg.pdf (page 86/chapter 5 “Memory mapping” and not too dissimilar to the F439 again. Linker - well, could be anything, right?

  • The best option for clock is make settings in STM32CubeIDE and copy generated code for Clock init. But how you wrote F439 seems to be similar/same.
  • CCM data RAM aka MBED_RAM1_START is not used in linker, but probably not related to this.
  • You can try to commented out the line with error("SetSysClock failed\n"); and when clock settings is reason of Mbed OS crash then board will just freeze and not blinking.
  • For simplest settings is also good disable everyting around LSE.
        "device_has_remove": [
            "LPTICKER"
        ],

and

        "overrides": {
            "lse_available":  0
        },

BR, Jan

Clock doesn’t really need any settings in STM32CubeIDE, it works out of the box. I would use the settings generated there once I’m in and needed that reference clock for networking, but a new projects compiles and runs just fine in the STM tool…

The two settings you suggested do nothing, unfortunately (except for the override if placed in the mbed_app.json, then it complains about not being set in the first place).

CCM RAM is declared in cmsis_nvic.h and the file is identical to the F439.

Uncommenting that error() line in system_clock.c does bring me back to a functional debugger where I can step through code. Some random blinking stuff is now working…Jan, how did you know!?
Okay, gonna dig up some documentation for clock settings now :partying_face:

Hmm, so HAL clock init failed how as I assumed.

I am just a self learner, so it was tip from my experiences what I collected here and especially during some small contribution to MbedCE, plus the ST is my favorite brand.

BTW if you missed this helpful page - mbed-os/targets/TARGET_STM/README.md at master · ARMmbed/mbed-os (github.com)

BR, Jan