Resetting the Portenta X8's M4 Core from the Linux/I.MX8 side?

Is there any way anyone has found to reset the M4 core from the Linux side of this board?

I am using it for a project and occasionally the M4 core will seem to hang somewhere it shouldn't and it doesn't recover naturally. Of course, my sketch on the M4 core is to blame, but it makes me think that I should set up something like a provisional watchdog timer on the Linux side to ensure that the M4 core is indeed running, and reset it if it faults and fails to recover.

So far, I don't see anything in the Arduino docs regarding this specifically, albeit I do see a few temporarily viable, less precise options:

  • Reflash the M4 Core, manually via the tools used in the monitor-m4-elf-file.service service, or by dropping an .elf file of the compiled sketch to the /tmp/arduino directory, and causing undue stress to the flash memory if this operation becomes frequent

  • Reboot the board, incurring quite a bit of downtime waiting for the OS to come back up

I have seen some slightly more promising things in the NXP I.MX8 forums, but the OP ended up getting sent some patch for their specific board. If I get more desperate, I might try to see if there are some registers on either MCU that I can play with that will give me what I want.

I am not sure what the right way to do it would be, but if you had access to host from your container, you could touch the M4 image.

touch /tmp/arduino/m4-user-sketch.elf

Of course, this reflashes...

Using touch is at least better than what I was doing which was removing and replacing the file at that location. Thank you for that!

Ok I've spent more time with the board and I haven't tested this is the regular portenta image, but I imagine as long as openocd is in the path in some bin, this should work. [I will check eventually that openocd indeed lives somewhere that can be accessed in user space on the non-development image, but until then I will leave this comment here in case someone else stumbles upon this thread and could use a hint] Otherwise, you can probably refer to the executable by its full path.

This command uses the Open On-Chip Debugger utility to reset the m4 core then terminate the utility session:

sudo /bin/openocd -f /usr/arduino/extra/openocd_script-imx_gpio.cfg -c "reset; shutdown"

The documentation for this utility lives at https://openocd.org/doc-release/pdf/openocd.pdf.

1 Like