I'm trying Tutorial #4 (UART Communication) from CubeMX manual, but it does not work. I'm using a Discovery STM32F334C8T6.
I have followed scrupulously every step, but Tera Term (or other terminal emulators) does not show any sign of communication with my board. The board is a Discovery STM32F334C8T6: the tutorial is tailored to a Nucleo board, but the pinout of the two boards are very similar.
- Select Debug Serial Wire under SYS: done;
- Select Internal Clock as clock source under TIM2 peripheral: done;
- Select the Asynchronous mode for the USART2 peripheral: done;
- Check that the signals are properly assigned on pins: USART_RX on PA3, TCK on PA14, USART_TX on PA2, USART_RX on PA3, done. Although they have slightly different names on my board (for example, pin PA14 is assigned to SYS_JTCK-SWCLK, and pin PA13 is assigned to SYS_JTMS-SWDIO).
- Go to the Clock Configuration tab and leave the configuration untouched: done. The Nucleo-L073RZ has a default clock of 2.097 MHz: i have selected 2 MHz on mine to match as closely as possible.
- From the Configuration tab, click USART2 to open the peripheral Parameter Settings window and set the baud rate to 9600. Make sure the Data direction is set to “Receive and Transmit�?: done.
- Click TIM2 and change the pre-scaler to 16000, the Word Length to 8 bits and the Counter Period to 1000: done.
- Enable TIM2 global interrupt from the NVIC Settings tab: done.
- Add the user code as follows:
/* USER CODE BEGIN 0 */
#include "stdio.h"
#include "string.h"
/* Buffer used for transmission and number of transmissions */
char aTxBuffer[1024];
int nbtime=1;
/* USER CODE END 0 */
/* USER CODE BEGIN 2 */
/* Start Timer event generation */
HAL_TIM_Base_Start_IT(&htim2);
/* USER CODE END 2 */
/* USER CODE BEGIN 4 */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){
sprintf(aTxBuffer,"STM32CubeMX rocks %d times \t", ++nbtime);
HAL_UART_Transmit(&huart2,(uint8_t *) aTxBuffer, strlen(aTxBuffer), 5000);
}
/* USER CODE END 4 */I compile under STM32CubeIDE, no errors. Enter debug mode, code is downloaded, debug mode started. Tera Term automatically discovers the board connected to COM11 port, with the correct settings, but it does not show any message incoming.
