cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo STM32H755 problems with UART using LL drivers

zan
Associate

Hello,

I am using the nucleo h755zi-q board on my project. I am having issues with getting the uart driver to work with the LL library. For starters I have the CM4 core disabled via the option bytes and am just working with the CM7. 

Code for clockConfig:

void SystemClock_Config()
{
  LL_PWR_ConfigSupply(LL_PWR_DIRECT_SMPS_SUPPLY);
  LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE3);
  LL_RCC_HSI_Enable();

   /* Wait till HSI is ready */
  while(LL_RCC_HSI_IsReady() != 1)
  {

  }
  LL_RCC_HSI_SetCalibTrimming(32);
  LL_RCC_HSI_SetDivider(LL_RCC_HSI_DIV1);
  LL_RCC_PLL_SetSource(LL_RCC_PLLSOURCE_HSI);
  LL_RCC_PLL1Q_Enable();
  LL_RCC_PLL1_SetVCOInputRange(LL_RCC_PLLINPUTRANGE_8_16);
  LL_RCC_PLL1_SetVCOOutputRange(LL_RCC_PLLVCORANGE_MEDIUM);
  LL_RCC_PLL1_SetM(4);
  LL_RCC_PLL1_SetN(9);
  LL_RCC_PLL1_SetP(2);
  LL_RCC_PLL1_SetQ(2);
  LL_RCC_PLL1_SetR(2);
  LL_RCC_PLL1_SetFRACN(3072);
  LL_RCC_PLL1FRACN_Enable();
  LL_RCC_PLL1_Enable();

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

  LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSI);
  LL_RCC_SetSysPrescaler(LL_RCC_SYSCLK_DIV_1);
  LL_RCC_SetAHBPrescaler(LL_RCC_AHB_DIV_1);
  LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2);
  LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
  LL_RCC_SetAPB3Prescaler(LL_RCC_APB3_DIV_1);
  LL_RCC_SetAPB4Prescaler(LL_RCC_APB4_DIV_1);
  LL_SetSystemCoreClock(64000000);
}
UART driver:
void USART3_Init()
{
    /**
     * UART3 TX -> PD8
     * UART3 RX -> PD9
     * Used for ST-link and virtual COM port
    */
    LL_USART_InitTypeDef USART_InitStruct = {0};
    LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
   
    LL_RCC_SetUSARTClockSource(LL_RCC_USART234578_CLKSOURCE_PCLK1);

    // enable clocks for usart and gpio
    LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART3);
    LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOD);

    // GPIO init
    GPIO_InitStruct.Pin = LL_GPIO_PIN_8 | LL_GPIO_PIN_9;
    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_7;

    LL_GPIO_Init(GPIOD, &GPIO_InitStruct);

    // UART init
    USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
    USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV4;
    USART_InitStruct.BaudRate = 115200;
    USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
    USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
    USART_InitStruct.Parity = LL_USART_PARITY_NONE;
    USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
    USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;

    LL_USART_Init(USART3, &USART_InitStruct);
    LL_USART_SetTXFIFOThreshold(USART3, LL_USART_FIFOTHRESHOLD_1_8);
    LL_USART_SetRXFIFOThreshold(USART3, LL_USART_FIFOTHRESHOLD_1_8);
    LL_USART_ConfigAsyncMode(USART3);

    LL_USART_Enable(USART3);

    LL_RCC_GetUSARTClockFreq(LL_RCC_USART234578_CLKSOURCE);
}

/**
 * @brief Transmit function with polling
*/
void UsartTransmitPoll(USART_TypeDef *USARTx, uint8_t *txBuffer, uint8_t size)
{
    uint8_t byteIndex = 0;
    //LL_USART_Enable(USARTx);

    while(byteIndex < size)
    {
        while(!(LL_USART_IsActiveFlag_TXE_TXFNF(USARTx))); //wait for TX empty flag
        LL_USART_TransmitData8(USARTx, txBuffer[byteIndex]); // write to TDR
        byteIndex++;    
    }

    while (!(LL_USART_IsActiveFlag_TC(USARTx))); // wait for transmision complete (TC) flag
    //LL_USART_Disable(USARTx);
}
 
So this is pretty straight fowrard, but the transmittion is not working even though the data is being written into the TDR and the receiving part is also working (I can see the data inside RDR). So I created a new project with CubeIDE and HAL  and here the UART obiously worked. Than I went comparing the SFRs and basically the UART and GPIO registers are set identically as well as the RCC registers look pretty similar as well.
 
At this point I have invested like 10+ hours into solving this and I am kind of running out of ideas what to even investigate anymore. I would appreciate if any one could give me some pointers what to look for.
0 REPLIES 0