AnsweredAssumed Answered

STM32F4: UART not transmitting

Question asked by xie.ted on Jun 5, 2014
Latest reply on Jun 6, 2014 by xie.ted

I am currently working on an application that will send/receive time and date data through serial connection via UART. To get a prototype up and running, I modified the RTC calendar example code that comes with STM32Cube, but I'm not getting any output from the serial port. To initialize the UART I simply copied over some initialization code from the serial examples, but nothing seems to be working. Here is some relevant code...

main() function


  // LED initialization here

  UartHandle.Instance        = USARTx; // USARTx is defined as USART3 in main.h
  UartHandle.Init.BaudRate   = 9600;
  UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
  UartHandle.Init.StopBits   = UART_STOPBITS_1;
  UartHandle.Init.Parity     = UART_PARITY_NONE;
  UartHandle.Init.HwFlowCtl  = UART_HWCONTROL_NONE;
  UartHandle.Init.Mode       = UART_MODE_TX_RX;

  if (HAL_UART_Init(&UartHandle) != HAL_OK) {
      BSP_LED_On(LED3); // this LED never comes on so I presume UART init is ok
      while(1) { }

  RtcHandle.Instance = RTC;
  RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
  RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
  RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
  RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
  RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

  if  (HAL_RTC_Init(&RtcHandle) != HAL_OK)
    /* Initialization Error */

  // RTC Calendar configured here

  // Then, a function writes time and date info to a uint8_t[] with sprintf
  //  I have verified that the data stored in the array is correct w/ debugger
  HAL_UART_Transmit_IT(&UartHandle, (uint8_t *) aShowTime, timelength);
  while (HAL_UART_GetState(&UartHandle) != HAL_UART_STATE_READY)
   {     }
  HAL_UART_Transmit_IT(&UartHandle, (uint8_t *) aShowDate, datelength);

SystemClock_Config (stock code)

  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  RCC_OscInitTypeDef RCC_OscInitStruct;

  /* Enable Power Control clock */

  /* The voltage scaling allows optimizing the power consumption when the device is 
     clocked below the maximum system frequency, to update the voltage scaling value 
     regarding system frequency refer to product datasheet.  */

  /* Enable HSE Oscillator and activate PLL with HSE as source */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLM = 25;
  RCC_OscInitStruct.PLL.PLLN = 336;
  RCC_OscInitStruct.PLL.PLLQ = 7;
  if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 
     clocks dividers */
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;  
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;  
  if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)

Additionally, I have checked in stm32f4xx_hal_conf.h to ensure that everything that should be defined is defined. Is there anything obviously wrong here?

***UPDATE: I did a full chip erase and re-flashed the chip, and now it's hanging on HAL_UART_Transmit. Weird...