Page 1 of 1

serial UART1

Posted: Fri Mar 11, 2022 12:52 pm
by lejibxl
on a G041F8Px I can't use the UART1 (PB7, PB3)
Even if I initialize the port with

Code: Select all

HardwareSerial Serial1(PB7,PB3); // RX, TX
I can't send or receive.
What is strange is that the TX (PB3) is at idle low (and not high)??
Anyone have any idea, am I doing something wrong?

Re: serial UART1

Posted: Fri Mar 11, 2022 1:04 pm
by lejibxl
you must use PB6 instead of PB3 in the initialization! Yet the first in MX, we speak first of PB3??

Re: serial UART1

Posted: Fri Mar 11, 2022 2:38 pm
by fpiSTM
Here is the available pins vs U(S)ART instance available for G041F

Code: Select all

#ifdef HAL_UART_MODULE_ENABLED
WEAK const PinMap PinMap_UART_TX[] = {
  {PA_2,      LPUART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_LPUART1)},
  {PA_2_ALT1, USART2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART2)},
  {PA_9_R,    USART1,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART1)},
  {PA_14,     USART2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART2)},
  {PB_6,      USART1,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_USART1)},
  {NC,        NP,      0}
};
#endif

#ifdef HAL_UART_MODULE_ENABLED
WEAK const PinMap PinMap_UART_RX[] = {
  {PA_3,      LPUART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_LPUART1)},
  {PA_3_ALT1, USART2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART2)},
  {PA_10_R,   USART1,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART1)},
  {PA_15,     USART2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART2)},
  {PB_7,      USART1,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_USART1)},
  {NC,        NP,      0}
};
So PB7 is linked to USART1 and PB3 has no U(S)ART. As you stated use PB6.