Arduino GIGA R1 WiFi + Zephyr 0.90.0: runtime USB missing due to stale STM32H7 PGSERR / flash read -EIO

I ran into an issue with Arduino GIGA R1 WiFi using Arduino Zephyr Boards 0.90.0 where sketches uploaded successfully, but after reset the Zephyr runtime USB device never appeared.

Arduino Mbed OS GIGA Boards 4.6.0 worked correctly on the same hardware, USB cable and board.

After instrumenting the Zephyr loader over USART1 (PA9/PB7), the exact failure was identified.

flash_area_open(user_sketch) succeeds, but the first flash_area_read() of the sketch header returns -EIO.

The failure is in:

zephyr/drivers/flash/flash_stm32h7x.c

flash_stm32h7_read() performs the memory read and afterwards calls flash_stm32_check_status().

Before the read, STM32H747 Bank 2 FLASH_SR2 already contains:

0x00040000 = PGSERR

This is a stale program-sequence error flag left from an earlier programming/boot stage. The read itself does not cause the error, but the driver sees the old flag after the memcpy and returns -EIO.

Because of this, the Arduino Zephyr loader exits before reading the sketch header, before usb_enable(), and before loading the LLEXT sketch.

A minimal diagnostic fix was to clear the pre-existing flash status before starting the read:

(void)flash_stm32_check_status(dev);

With this change:

flash_area_read() = 0

the sketch header is read correctly,

usb_enable() = 0,

and the board enumerates normally as:

VID:PID 2341:0666

Arduino GIGA R1

/dev/cu.usbmodem211101

arduino-cli also recognizes it correctly as:

arduino:zephyr_main:giga

The result was reproduced after a physical power cycle.

So this was not a WLAN, USB hardware, LLEXT or sketch issue. The loader was being stopped by a stale STM32H7 flash status flag.

I have full UART before/after logs, instrumented ELF/BIN files and a minimal patch available if useful to the maintainers.

Hi @arnaskav.

I'm sure they would be interested.

You can submit a formal report via an issue in the GitHub repository:

https://github.com/arduino/ArduinoCore-zephyr/issues/new/choose

Or if you want to propose a change to the code directly, you can submit it as a pull request (PR) to that repository.

Take a look at my issue:

0.90 and current sources: One GIGA boots the other does not · Issue #591 · arduino/ArduinoCore-zephyr

I fixed it by Under MBED ran:
Updated wifi firmware on MBED (WiFiFirmwareUpdater.ino)

You might also be able to fix it, by downgrading to previous release of Zephyr
0.56.0 which boots.

Also suggested later in the issue by @pennam (I would try under 0.56.0)

Would you mind also testing this sketch to flash the Wi-Fi firmware?

You just need to upload it and go through the prompts. The most important one is:

Do you want to restore the WiFi firmware?

Answer yes, wait for it to complete, and then check if the board still works by uploading your test sketch.

@KurtE's issue report (arduino/ArduinoCore-zephyr#591) actually came to my mind when I was reading this topic. Definitely worth a close look to see if it is the same as the problem you encountered.

If so, there is no need to open an additional issue in the GitHub repository. You are welcome to comment on the thread in arduino/ArduinoCore-zephyr#591 if you have additional technical information that may be useful to the developers in addressing the issue.