Closed adri326 closed 5 months ago
alternatively, we could add a flag in the config for embassy_stm32::init, since the GPIO API currently doesn't have any configuration, that would turn on this power supply.
yes, this is what I'd do (and turn it on by default).
it looks like the USB peripheral also runs on a different power supply, so I wonder if it isn't also suffering from the same issue.
yes, this is handled automatically when you turn on USB: https://github.com/embassy-rs/embassy/blob/ea25112f7d1ce27a7216ce6c3aab983dc3a0d7c0/embassy-stm32/src/usb_otg/usb.rs#L565
I don't think we can do that for IOSV though. It'll be annoying to implement in the HAL since many peripherals can use the affected pins, and could be bad for perf/codesize too. a setting in init
seems beter to me.
And the Peripherals
struct should then keep track of it to unset it on Drop
?
no, just enable it on init
if requested, and leave it enabled forever.
On some STM32 MCUs (which includes the STM32L4xx family), the GPIOG ports are powered by an alternative power supply, which is only available when the
IOSV
bit is set by the user inPWR->CR2
, butembassy-stm32
doesn't provide a way to turn it on, nor does it turn it on automatically when trying to use GPIOG.How I encountered the bug
According to the manual for my testing board, I should be able to use the serial I/O of the ST-Link by sending data over the LPUSART1 peripheral with the PG7 and PG8 pins.
However, when changing the chip name and the pings accordingly, I don't seem to be able to get any output, and the
stm32l4/usart
example then panics over aFraming
error.Flashing and running the board with an equivalent program using STM32's HAL library does print an output, in contrast.
Changes made
Output
What the issue (and fix) is
Looking at my C code, the following seems to be the strict minimum to get UART working with STMicro's HAL library:
The
HAL_PWREx_EnabledVddIO2()
line stands out: looking into its source code, it sets theIOSV
bit of thePWR->CR2
register to 1, and according to the MCU datasheet, this register toggles the separate power supply for the GPIOG pins, which is by default turned off. Normally, you would use the PVM API to gracefully turn on the separate power supply first (see page 164), but skipping that step seems to not cause any issues on my end.Once I manually set this bit using
stm32-metapac
, the code then works:I would happily contribute a fix to this, although I would need guidance, namely:
embassy_stm32::init
, since the GPIO API currently doesn't have any configuration, that would turn on this power supply.