Thanks for the insightfil reply.
So, from your reply I understand that I have to do the following
monitor one rpi gpio for shutdown signal with a script like in the tutorial. The rpi shutdown signal can come from stm32 or the external microcontroller.
Shutdown stm32 by cutting the power with an external switch controller also by the micro controller. In this case, I can use a relay to cut the main supply for core2-ROS.
Is there any easy way to determine rpi actually properly shutdown after step 1 ? Do we have something in hframework that can check if the rpi is on or off ?