Sharing one ESP8266 between multiple STM32s
Posted: Thu Nov 05, 2020 9:46 am
Now I got a dual motor Prius Gen3 board from Damien that I finally put together and it looks working well.
Because I'm a cheapshit I would like to deploy only one ESP module instead of 2 (or maybe 3 on boards to come). then change the STM that you want to talk to on the fly with a button/custom command. This would also be easier then changing between wifi networks.
So, first thing I did was some recognition code. The MG1 MCU on the dual motor board can be spotted because its throttle input is floating. So it shows up as "PriusMG1" in hwver. (If this is to be applied to a 3-inverter board, all 3 MCUs must somehow be distinguished)
Next, all STMs uart outputs would have to be tied together, maybe with some series resistors on TX to avoid them fighting each other in the boot loader phase.
Now, when a board starts up and detects as MG1 (MG2 is considered primary, MG1 secondary) it disabled its UART TX line by simply configuring the pin as floating. The RX line still listens!
All commands that change something (e.g. set, start, reset) are ignored by the disabled MCU, all others can be executed, just that their output never shows up on the TX pin.
Then there is a special command like "enableuart 1/2/x". When MG2 receives "enableuart 1" it DISABLES its UART in the same way as above, and MG1 ENABLES its UART by configuring the TX pin as UART_TX.
This should even work for a firmware update on the selected MCU, the inactive one just sees the reset command come by and also the binary pages and doesn't react, while the active one actually receives the update.
The reason why I write about it is because it is a breaking change. The board with two ESP modules would always start into an inactive MG1 MCU.
Any comments?
Because I'm a cheapshit I would like to deploy only one ESP module instead of 2 (or maybe 3 on boards to come). then change the STM that you want to talk to on the fly with a button/custom command. This would also be easier then changing between wifi networks.
So, first thing I did was some recognition code. The MG1 MCU on the dual motor board can be spotted because its throttle input is floating. So it shows up as "PriusMG1" in hwver. (If this is to be applied to a 3-inverter board, all 3 MCUs must somehow be distinguished)
Next, all STMs uart outputs would have to be tied together, maybe with some series resistors on TX to avoid them fighting each other in the boot loader phase.
Now, when a board starts up and detects as MG1 (MG2 is considered primary, MG1 secondary) it disabled its UART TX line by simply configuring the pin as floating. The RX line still listens!
All commands that change something (e.g. set, start, reset) are ignored by the disabled MCU, all others can be executed, just that their output never shows up on the TX pin.
Then there is a special command like "enableuart 1/2/x". When MG2 receives "enableuart 1" it DISABLES its UART in the same way as above, and MG1 ENABLES its UART by configuring the TX pin as UART_TX.
This should even work for a firmware update on the selected MCU, the inactive one just sees the reset command come by and also the binary pages and doesn't react, while the active one actually receives the update.
The reason why I write about it is because it is a breaking change. The board with two ESP modules would always start into an inactive MG1 MCU.
Any comments?