Showing results for 
Search instead for 
Did you mean: 


Associate II


I am using X-CUBE-SPN5 with F030R8 and IHM05A1 to control a stepper motor and it works well.

I would now like to use UART with provided driver (stm32f0xx_hal_uart).

Hence, I enabled UART use in stm32f0xx_hal_conf.h.

To test UART integration, I am using a piece of code generated by ST IDE in another application only dedicated to print a string in a putty terminal with HAL_UART_Transmit (this dedidated application works well).

But integration of this code no longer permits to see the string in putty, whereas the code compiles and executes well, there is nothing visible in putty.

Config. with only one USB cable between the PC and the STM32, and putty looking to the STLink Virtual COM Port.


The main is given below, with bold caracters for UART related lines :


#include "main.h"
static volatile uint16_t gLastError;
l6208_Init_t initDeviceParameters =
  1500,            //Acceleration rate in step/s^2 or (1/16)th step/s^2 for microstep modes
  20,              //Acceleration current torque in % (from 0 to 100)
  1500,            //Deceleration rate in step/s^2 or (1/16)th step/s^2 for microstep modes
  20,              //Deceleration current torque in % (from 0 to 100)
  1500,            //Running speed in step/s or (1/16)th step/s for microstep modes
  10,              //Running current torque in % (from 0 to 100)
  5,               //Holding current torque in % (from 0 to 100)
  STEP_MODE_1_16,  //Step mode via enum motorStepMode_t
  FAST_DECAY,      //Decay mode via enum motorDecayMode_t
  0,               //Dwelling time in ms
  FALSE,           //Automatic HIZ STOP
  100000           //VREFA and VREFB PWM frequency (Hz)
/* Private function prototypes -----------------------------------------------*/
static void MyFlagInterruptHandler(void);
void ButtonHandler(void);
UART_HandleTypeDef huart2;
uint8_t tx_buffer[3] = "144";
static void MX_USART2_UART_Init(void);
int main(void)
  while (1)
static void MX_USART2_UART_Init(void)
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 9600;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  if (HAL_UART_Init(&huart2) != HAL_OK)
void MyFlagInterruptHandler(void)
void MyErrorHandler(uint16_t error)
  gLastError = error;
void ButtonHandler(void)
  if (BSP_MotorControl_GetDirection(0) != BACKWARD)
    BSP_MotorControl_SetDirection(0, BACKWARD);
    BSP_MotorControl_SetDirection(0, FORWARD);
  /* Let 200 ms before clearing the IT for key debouncing */
void assert_failed(uint8_t* file, uint32_t line)
  while (1)
Lead II

Hello @user-stm 

I suggest you to verify your putty configuration. Else make sure that the gpio configuration for the USART is fine.

Best regards.


No problem about putty configuration, as the bold lines of the code are the ones used in the application only dedicated to print the string in putty, application that has been tested and works well.

ST Employee

Well, if you use an STM32F302R8, you should not edit stm32f0xx_hal_conf.h, but stm32f3xx_hal_conf.h.

By the way, you can also insert source code here as such by clicking the three dots in the text box at the top right and starting the function with </>.


In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Associate II

Mistake, I am using F030R8, that is why I have edited stm32f0xx_hal_conf.h.

Otherwise, if that can be helpful, reminds that the code compiles and executes well, while there is anything in putty ... and putty parameters are matching Tx parameters as I has been tested in the dedicated appplication.

Senior III

what is a bit strange is that you are using ButtonHandler() that contains a HAL_Delay() function but IMHO this function is not called from main(). So then it must be called from an ISR and then HAL_Delay() is not the right way to go if you are activating from an ISR based context.

In order to find the origin of your problem: combine both codes, comment out the part of the motor and then activate it step by step. Sooner or later you will find the culprit.  

Associate II

The ButtonHandler function comes from the initial main() of SPN5 dedicated to the stepper motor control.

The presented main() is indeed not calling it precisely because I am for now only trying to integrate the UART part, by getting the string in the putty terminal.