Skip to content

Nucleo L432KC: LPUART low baudrate issue #2897

Closed

Description

@gicking

Describe the bug
On some STM32 boards, changing the Serial Rx or Tx pin stalls the board after ~10s. Recovery requires a HW-reset. The failure depends on which HardwareSerial or pin is used. Specifically

  • setup: Nucleo-STM32L432KC and "-DENABLE_HWSERIAL1"
  • for Serial2 setTx(PA_2) or setRx(PA3) stall the board after ~10 seconds
  • skipping SERIAL_TEST.write() in example prevents the stall
    HardwareSerial    |  setTx()  |       setRx()       |  both  | none | remarks
    ------------------------------------------------------------------------------------
    Serial1           |    ok     |         ok          |   ok   |  ok  | all Rx/Tx pin combinations
    Serial / Serial2  | PA2 stall | PA15 ok / PA3 stall |  stall |  ok  |  

To Reproduce
see attached PlatformIO project STM32_Serial_Rerouting.zip

Steps to reproduce the behavior:

  1. Compile and upload to Nucleo-STM32L432KC
  2. LED stops blinking after ~10s -> error

Expected behavior
LED should continue blinking and on Tx pin expect periodic sending of 0x55

Desktop (please complete the following information):

  • OS: Linux
  • Arduino IDE version: 2.3.7 / PlatformIO version: Core 6.1.18·Home 3.4.4
  • STM32 core version: 2.12.0
  • Upload method: STLink

Board (please complete the following information):

  • Name: [e.g. Nucleo F429ZI]
  • Hardware Revision: [e.g. Rev B]
  • Extra hardware used if any: [e.g. X-Nucleo IKS01A1]

Activity

  1. fpistm commented on Jan 22, 2026

    @fpistm
    Member

    Hi @gicking
    Could you provide the Arduino sketch as we do not support PIO here due to several misaligment. Without example code this issue will be closed.

  2. gicking commented on Jan 22, 2026

    @gicking
    ContributorAuthor

    here you go. Behavior is the same: after ~12s the LED stops blinking and sending via Tx stops

    Bug_Serial.zip

  3. added a commit that references this issue on Jan 23, 2026
    4c691f1
  4. fpistm commented on Jan 23, 2026

    @fpistm
    Member

    Hi @gicking

    Thanks for the sketch.
    First by default Serial instance is mapped on USART2 using same pin than your SERIAL_TX as by default PA2 and PA15 are connected to STLink UART to provide VCP.

    // Default pin used for 'Serial' instance (ex: ST-Link)
    // Mandatory for Firmata
    #ifndef PIN_SERIAL_RX
    #define PIN_SERIAL_RX PA15
    #endif
    #ifndef PIN_SERIAL_TX
    #define PIN_SERIAL_TX PA2_ALT1
    #endif

    But it should not be an issue as you do not init Serial.Your issue is that you think you used USART2 with your SERIAL_TEST but you used LPUART1.
    WEAK const PinMap PinMap_UART_RX[] = {
    {PA_3, LPUART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_LPUART1)},
    {PA_3_ALT1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},

    WEAK const PinMap PinMap_UART_TX[] = {
    {PA_2, LPUART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_LPUART1)},
    {PA_2_ALT1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},

    I you really want use USART2 then your code should be:

      #define SERIAL_TX     PA_2_ALT1
      #define SERIAL_RX     PA_3 _ALT1

    Now it stall because the void SystemClock_Config(void) does not change the LPUART source clock then 19200 is not reachable and due to constaint on LPUART IP. If you still want use LPUART then you have to change the clock source.

    Note that it is not a bug as if user wants higher baudrate with LPUART1 the default clock config is correct. Anyway, as low baudrate is often used by Arduino sketches (9600), I made a PR to allow it by default.
    It is up to end user to properly configure the clock depending on their needs.

    You can test by adding this on your sketch:

    extern "C" void SystemClock_Config(void)
    {
      RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
      RCC_OscInitTypeDef RCC_OscInitStruct = {};
      RCC_PeriphCLKInitTypeDef PeriphClkInit = {};
    
      /** Configure the main internal regulator output voltage
      */
      if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK) {
        Error_Handler();
      }
    
      /* Configure LSE Drive Capability */
      HAL_PWR_EnableBkUpAccess();
      __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
    
      /** Initializes the RCC Oscillators according to the specified parameters
      * in the RCC_OscInitTypeDef structure.
      */
      RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSE
                                         | RCC_OSCILLATORTYPE_MSI;
      RCC_OscInitStruct.LSEState = RCC_LSE_ON;
      RCC_OscInitStruct.HSIState = RCC_HSI_ON;
      RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
      RCC_OscInitStruct.MSIState = RCC_MSI_ON;
      RCC_OscInitStruct.MSICalibrationValue = 0;
      RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
      RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
      RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
      RCC_OscInitStruct.PLL.PLLM = 1;
      RCC_OscInitStruct.PLL.PLLN = 40;
      RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
      RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
      RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
      if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
        Error_Handler();
      }
    
      /* Initializes the CPU, AHB and APB buses clocks */
      RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
                                    | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
      RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
      RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
      RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
      RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
    
      if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) {
        Error_Handler();
      }
    
      /* Initializes the peripherals clock */
      PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_USB;
      PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_HSI;
      PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLLSAI1;
      PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_MSI;
      PeriphClkInit.PLLSAI1.PLLSAI1M = 1;
      PeriphClkInit.PLLSAI1.PLLSAI1N = 24;
      PeriphClkInit.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV7;
      PeriphClkInit.PLLSAI1.PLLSAI1Q = RCC_PLLQ_DIV2;
      PeriphClkInit.PLLSAI1.PLLSAI1R = RCC_PLLR_DIV2;
      PeriphClkInit.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_48M2CLK;
      if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
        Error_Handler();
      }
      /* Enable MSI Auto calibration */
      HAL_RCCEx_EnableMSIPLLMode();
    }
  5. changed the title [-]Serial.setTx() / Serial.setRx() stall board[/-] [+]Nucleo L432KC: LPUART low baudrate issue[/+] on Jan 23, 2026
  6. gicking commented on Jan 26, 2026

    @gicking
    ContributorAuthor

    Hi Frederic,

    you are correct, with PA_2_ALT1 and PA_3_ALT1 it now works flawlessly :-) Thanks!

    Have a great day, Georg

  7. added a commit that references this issue on Jan 26, 2026
    e531ea8
  8. added a commit that references this issue on Jan 27, 2026
    93a3148
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions