Hello,
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)
{
HAL_Init();
SystemClock_Config();
MX_USART2_UART_Init();
while (1)
{
HAL_UART_Transmit(&huart2,tx_buffer,sizeof(tx_buffer),HAL_MAX_DELAY);
HAL_Delay(1000);
}
}
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)
{
while(1){
}
}
}
void MyFlagInterruptHandler(void)
{
BSP_MotorControl_CmdDisable(0);
}
void MyErrorHandler(uint16_t error)
{
gLastError = error;
while(1)
{
}
}
void ButtonHandler(void)
{
if (BSP_MotorControl_GetDirection(0) != BACKWARD)
{
BSP_MotorControl_SetDirection(0, BACKWARD);
}
else
{
BSP_MotorControl_SetDirection(0, FORWARD);
}
/* Let 200 ms before clearing the IT for key debouncing */
HAL_Delay(200);
__HAL_GPIO_EXTI_CLEAR_IT(KEY_BUTTON_PIN);
HAL_NVIC_ClearPendingIRQ(KEY_BUTTON_EXTI_IRQn);
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
while (1)
{
}
}
#endif