STM32F427ZG Custom Board Runtime Error reset does not turn off pins

Hello,

I am running into issues with my custom board using an stm32F427ZGT6 chip. I have no problems compiling code, however, I run into certain scenarios where the board seems like it gets into a runtime error (LED flashes in a specific pattern constantly). When this runtime error occurs pins hold their value and does not change until i reset the board. Are there options for the stm to run a function when a runtime error is encountered? For example, when a runtime error is encountered rather than holding pin values to set them all to 0? Or to perform a hard reset?

Any help or recommendations would be appreciated. Thank you in advance.

Best regards, Ioakeim

Hello Ioakeim,

Are there options for the stm to run a function when a runtime error is encountered? For example, when a runtime error is encountered rather than holding pin values to set them all to 0? Or to perform a hard reset?

According to the Error handling - API references and tutorials | Mbed OS 6 Documentation > Crash reporting and auto-reboot you can try to override the
void mbed_error_reboot_callback(mbed_error_ctx *error_context) function to perform a hard reset when a fatal error occured.

For example:

#include "mbed.h"
...
//Callback during reboot (on a warm reset)
void mbed_error_reboot_callback(mbed_error_ctx *error_context)
{
    NVIC_SystemReset();
}
...
int main()
{
...

However, I’d strongly recommend to debug the program rather than just to perform a hard reset. You can find relevant info at:
https://os.mbed.com/docs/mbed-os/v6.14/debug-test/index.html

Hello Zoltan,

Thank you for the reply. I have tried your suggestion and it does not seem to work. I have a way that can trigger the runtime error on my custom board and when the runtime error occurs my second LED defined as “LED2” in PinNames holds its value when the board is in the runtime error loop.

Would it be better to try the HAL_NVIC_SystemReset() function instead?

Best regards, Ioakeim

I’m afraid not. The HAL_NVIC_SystemReset() just calls the NVIC_SystemReset() function.

mbed-os/targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_hal_cortex.c:

/**
  * @brief  Initiates a system reset request to reset the MCU.
  * @retval None
  */
void HAL_NVIC_SystemReset(void)
{
  /* System Reset */
  NVIC_SystemReset();
}

Could you let us know the error message reported in the serial terminal after the runtime error occured?

I am unable to see any error messages in the serial terminal. I use a docker container that mounts to the uart serial line which communicates to the stm32 and message passing in both directions is seen in the logs of the container. When i start the container the runtime error occurs and I tried to quickly screen into the serial port via the Jetson Nano but I am unable to see any error messages. Do you know what other way there is to view error messages? I have my uart line mapped to stdout as well (message passing is done with printf())

Another way is to use the SWO (Serial Wire Output), available on pin PB_3 of the STM32 targets, as described at
https://forums.mbed.com/t/hitchhikers-guide-to-printf-in-mbed-6/12492/38

I have tried also running NVIC_SystemReset() manually. I toggle on my LED2 after 1000ms upon startup and then call NVIC_SystemReset() after 3000ms and the reset seems to stop code from running however, the led remains on. Is this the expected behaviour?

Does the LED remain on after pushing the RESET button?

Yes it remains on

Oh sorry I misread, running the NVIC_SystemReset() stops my code but keeps pins in the same state and does not seem to restart my code. Pushing the reset button toggle off all the leds and starts up my code again.

It seems to be an issue with the NVIC_SystemReset() and I have no idea what could be wrong. So I would suggest to try the Watchdog - API references and tutorials | Mbed OS 6 Documentation.

EDIT: I don’t see any Mbed enabled target using an STM32F427xx chip. The closest seems to be the STM32F429ZI. How is your custom STM32F427ZGT6 defined?

I have my custom targets defined as:

{
  "MCU_STM32F427xG": {
    "inherits": ["MCU_STM32F4"],
    "public": false,
    "extra_labels_add": ["STM32F427xG"],
    "macros_add": ["STM32F427xx"],
    "device_has_add": [
      "ANALOGIN",
      "ANALOGOUT",
      "ADC",
      "DAC",
      "CAN",
      "TRNG",
      "I2C",
      "I2CSLAVE",
      "I2C_ASYNCH",
      "INTERRUPTIN",
      "MPU",
      "PORTIN",
      "PORTINOUT",
      "PORTOUT",
      "PWMOUT",
      "RTC",
      "SERIAL",
      "SERIAL_ASYNCH",
      "SERIAL_FC",
      "SLEEP",
      "SPI",
      "SPISLAVE",
      "MPU",
      "STDIO_MESSAGES",
      "FLASH",
      "USTICKER",
      "USBDEVICE",
      "WATCHDOG"
    ]
  },
  "CUSTOM_F427ZG": {
    "inherits": ["MCU_STM32F427xG"],
    "supported_toolchains": ["ARM", "GCC_ARM", "IAR"],
    "config": {
      "usb_speed": {
        "help": "USE_USB_OTG_FS or USE_USB_OTG_HS or USE_USB_HS_IN_FS",
        "value": "USE_USB_OTG_FS"
      }
    },
    "overrides": {
      "lse_available": 0,
      "target.stdio_uart_tx": "PC_10_ALT0",
      "target.stdio_uart_rx": "PC_11_ALT0"
    },
    "is_disk_virtual": true,
    "device_name": "STM32F427ZGTx",
    "detect_code": ["0794"]
  }
}