A Raspberry Pi 3B+ is talking to an STM32 chip via UART over pins 8 (TXD) & 10 (RXD). When I take control of those pins using GPIO.setup(8, GPIO.OUTPUT); GPIO.output(8, GPIO.LOW);
and later release them by calling GPIO.cleanup()
, UART no longer works. To restore UART, I have to reboot the Pi. /boot/config.txt
contains enable_uart=1
.
How do I restore UART pins to the way the kernel sets them without rebooting the Pi?
The reason why I need to pull down the UART pins, is because the Pi and a the STM32 have a common ground, but the STM32's board has a safety diode that seems to be turned on by the Pi's UART pins when it's power source is off. Pulling down the pins to zero when the STM32 is off seems to prevent this current from flowing. This is obviously not ideal, but due to time constraints, I can't add an opto-coupler yet.
GPIO.cleanup()
does not restore previous modes, but instead places pins in INPUT mode. I've added a detailed answer below. Boot mode on the STM32 controller is controlled via its BOOT and RESET pins, which I am also doing, but those are connected to different GPIO pins on the RPi. – Petrus Theron Nov 12 '18 at 10:42