cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H573 UART9 initialization not working

xkl
Associate II

use STM32CubeMX to get the initialization code,but UART9 not work,use the LL Library

UART9 initialization

void MX_UART9_Init(void)
{
    LL_USART_InitTypeDef USART_InitStruct = {0};
    LL_GPIO_InitTypeDef GPIO_InitStruct = {0};

    LL_RCC_SetUARTClockSource(LL_RCC_UART9_CLKSOURCE_PCLK1);
    // __HAL_RCC_UART9_CONFIG(RCC_UART9CLKSOURCE_PCLK1);
    // __HAL_RCC_UART9_CLK_ENABLE();
    /* Peripheral clock enable */
    LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_UART9);
    LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD);
    /**UART9 GPIO Configuration
    PD14   ------> UART9_RX
    PD15   ------> UART9_TX
    */
    GPIO_InitStruct.Pin = LL_GPIO_PIN_14 | LL_GPIO_PIN_15;
    GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
    GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
    GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
    GPIO_InitStruct.Alternate = LL_GPIO_AF_11;
    LL_GPIO_Init(GPIOD, &GPIO_InitStruct);

    USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1;
    USART_InitStruct.BaudRate = 9600;
    USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
    USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
    USART_InitStruct.Parity = LL_USART_PARITY_NONE;
    USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
    USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
    USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
    LL_USART_Init(UART9, &USART_InitStruct);

    LL_USART_SetTXFIFOThreshold(UART9, LL_USART_FIFOTHRESHOLD_1_8);
    LL_USART_SetRXFIFOThreshold(UART9, LL_USART_FIFOTHRESHOLD_1_8);
    LL_USART_DisableFIFO(UART9);
    LL_USART_ConfigAsyncMode(UART9);

    LL_USART_Enable(UART9);

    NVIC_SetPriority(UART9_IRQn, 0);
    NVIC_EnableIRQ(UART9_IRQn);

    LL_USART_EnableIT_RXNE(UART9);
}

and the system clock initialization

void SystemClock_Config(void)
{
    LL_FLASH_SetLatency(LL_FLASH_LATENCY_5);
    while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_5)
    {
    }

    LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE0);
    while (LL_PWR_IsActiveFlag_VOS() == 0)
    {
    }
    LL_RCC_HSE_EnableBypass();
    LL_RCC_HSE_SetExternalClockType(LL_RCC_HSE_ANALOG_TYPE);
    LL_RCC_HSE_Enable();

    /* Wait till HSE is ready */
    while (LL_RCC_HSE_IsReady() != 1)
    {
    }

    LL_RCC_PLL1_SetSource(LL_RCC_PLL1SOURCE_HSE);
    LL_RCC_PLL1_SetVCOInputRange(LL_RCC_PLLINPUTRANGE_4_8);
    LL_RCC_PLL1_SetVCOOutputRange(LL_RCC_PLLVCORANGE_WIDE);
    LL_RCC_PLL1_SetM(8);
    LL_RCC_PLL1_SetN(125);
    LL_RCC_PLL1_SetP(2);
    LL_RCC_PLL1_SetQ(2);
    LL_RCC_PLL1_SetR(2);
    LL_RCC_PLL1Q_Enable();
    LL_RCC_PLL1P_Enable();
    LL_RCC_PLL1_Enable();

    /* Wait till PLL is ready */
    while (LL_RCC_PLL1_IsReady() != 1)
    {
    }

    LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL1);

    /* Wait till System clock is ready */
    while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL1)
    {
    }

    LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
    LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
    LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
    LL_RCC_SetAPB3Prescaler(LL_RCC_APB3_DIV_1);
    LL_SetSystemCoreClock(250000000);

    /* Update the time base */
    if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK)
    {
        Error_Handler();
    }
}

when I try to call the transmit function,it is waiting for transmit to complete

while(!LL_USART_IsActiveFlag_TC(UART9));
LL_USART_TransmitData8(UART9, 0xFF);

and UART4 can work normally with this similar configuration.Can you tell me where else I need to configure?

1 ACCEPTED SOLUTION

Accepted Solutions

Thanks for coming back with the solution.

This indeed has been recently fixed in Cube.

Please click on "Accept as solution" in that post so that the thread is marked as solved.

JW

View solution in original post

4 REPLIES 4

Read out and check/post content of UART and relevant RCC registers.

JW

I have read content of UART and RCC,the only difference of UART4 and UART9 is the uart clk enable,

UART4 use RCC->APB1LENR  and UART9 use RCC->APB1HENR,is there any other differences?

xkl
Associate II

I've found the problem.

There is a problem when use LL library to initialize UART9.

In the LL_USART_Init function,

xkl_0-1716368488166.png

This function is used incorrectly,LL_RCC_GetUARTClockFreq should be used

 

Thanks for coming back with the solution.

This indeed has been recently fixed in Cube.

Please click on "Accept as solution" in that post so that the thread is marked as solved.

JW