cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103RBT6 UART using LL drivers

Hi everyone,

I'm trying to use LL drivers for STM32F103 series using CubeMX and my problem is that when i try to send a byte LL_USART_TransmitData8(USART1, data) the USART Transmission Complete Flag is never set and no data is transmitted through .

I should say that when i switch to HAL everything works perfectly fine and both sending and receiving data is working fine.

any help is greatly appreciated

4 REPLIES 4

If CubeMX generates junk when you hit the button, it will keep doing it the same with each press.

If you want to debug what is happening with the generated code you're going to have to look at the registers being set, and inspect the clocks, pin configurations/mappings, and USART settings.

Test the library code using the examples where available rather than the machine generated code.

If you want to get ST engineers to look at your issue you're going to have to furnish .IOC files, source, and board details.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

as you can see the board set up and the .IOC file are both simple, i also tested the board using the given examples in stm32cube folder and still no data is transmitted .0690X000006CLpQQAW.png

static void MX_USART1_UART_Init(void)
{
 
  LL_USART_InitTypeDef USART_InitStruct;
 
  LL_GPIO_InitTypeDef GPIO_InitStruct;
 
  /* Peripheral clock enable */
  LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
  
  /**USART1 GPIO Configuration  
  PA9   ------> USART1_TX
  PA10   ------> USART1_RX 
  */
  GPIO_InitStruct.Pin = LL_GPIO_PIN_9;
  GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
  GPIO_InitStruct.Pin = LL_GPIO_PIN_10;
  GPIO_InitStruct.Mode = LL_GPIO_MODE_FLOATING;
  LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
  /* USART1 DMA Init */
  
  /* USART1_RX Init */
  LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_5, LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
 
  LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_5, LL_DMA_PRIORITY_LOW);
 
  LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_5, LL_DMA_MODE_CIRCULAR);
 
  LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_5, LL_DMA_PERIPH_NOINCREMENT);
 
  LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_5, LL_DMA_MEMORY_INCREMENT);
 
  LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_5, LL_DMA_PDATAALIGN_BYTE);
 
  LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_5, LL_DMA_MDATAALIGN_BYTE);
 
  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;
  LL_USART_Init(USART1, &USART_InitStruct);
 
  LL_USART_ConfigAsyncMode(USART1);
 
  LL_USART_Enable(USART1);
 
}

the code generated by CubeMX is included as well as the function that is supposed to send the data,

thanks in advance for the help

void usart_transmit_data(const void* data, uint16_t len) {
    const uint8_t* b = data;
    while (len--) {
        LL_USART_TransmitData8(USART1, *b++);
        
        while (!LL_USART_IsActiveFlag_TXE(USART1)){
          transmit_empty_register=LL_USART_IsActiveFlag_TXE(USART1);
          transfer_complete=LL_USART_IsActiveFlag_TC(USART1);
          //LL_USART_ClearFlag_PE(USART1);
        }
        }
 
}