Getting USART instance from HardwareSerial?
Posted: Fri Feb 26, 2021 10:34 am
Hi,
I am using an F303K8, and hoping to use the F3's built in USART pin inversion capabilities to avoid extra external hardware inverters.
I have found the LL functions to do this and it works (see minimal sketch below), but it requires me to explicitly define the USART instance (USART1 in this case). This required me to dig through the lower level files to figure out what the USART mapping was for the specific variant.
Is there a better way where I can somehow retrieve the USART instance from HardwareSerial?
Thanks,
George
I am using an F303K8, and hoping to use the F3's built in USART pin inversion capabilities to avoid extra external hardware inverters.
I have found the LL functions to do this and it works (see minimal sketch below), but it requires me to explicitly define the USART instance (USART1 in this case). This required me to dig through the lower level files to figure out what the USART mapping was for the specific variant.
Is there a better way where I can somehow retrieve the USART instance from HardwareSerial?
Thanks,
George
Code: Select all
#include "stm32yyxx_ll.h"
/* HardwareSerial::HardwareSerial(PinName _rx, PinName _tx) */
HardwareSerial mySerial1(PA_10, PA_9);
void setup()
{
/* Serial to display the received data */
mySerial1.begin(115200);
// Use LL functions to invert F303K8 TX and RX pins
LL_USART_Disable(USART1);
LL_USART_SetRXPinLevel(USART1, LL_USART_RXPIN_LEVEL_INVERTED);
LL_USART_SetTXPinLevel(USART1, LL_USART_TXPIN_LEVEL_INVERTED);
LL_USART_Enable(USART1);
}
void loop() {
}