2020-03-02 09:04 AM
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.
/* 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.
Solved! Go to Solution.
2020-03-02 11:17 AM
User Manual UM1735 says:
"The USART2 interface available on PB3 and PB4 of the STM32F334C8T6 can be connected to ST-LINK/V2-1 MCU to use the virtual COM port function.
By default the USART2 communication between the target STM32F334C8T6 and ST-LINK/V2-1 MCU is not enabled.
To use the virtual COM port function with:
•The on-board STM32F334C8T6, then set SB14 and SB16 ON.
2020-03-02 09:36 AM
I would try to use regular USART instead of the SWO debug line.
There should be a UART to USB conversion through the STLink on board the discovery. Use it.
Don't put things taking time in any callback function. Callbacks should be snappy.
sprintf() may not work directly, just send a single character to see if it works.
When setting the virtual com port, use the same baudrate as you programmed on STM32.
2020-03-02 10:37 AM
Thank you for your kind reply. Unfortunately I'm still a learner, so please bear with me: I am unsure about what you mean when you say that there should be a UART to USB conversion through the STLink on board the Discovery. I have read on the manual that USART2 is physically connected to the Discovery's USB port, and I have activated USART2 on the peripheral list, in Asynchronous mode and with the suggested settings (which, by the way, are the same as Tera Term: Baud Rate 9600, Word Length 8 bits, no parity, 1 Stop Bits, Receive and Transmit):
This is the pinout, as suggested by the manual:
I have activated the green LED as well, to verify the Callback function. I have followed your suggestion, and tried to send a single character instead of a string:
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_9);
char c = 'A';
HAL_UART_Transmit_IT(&huart2, (uint8_t*)&c, 1);
}
Whenever the timer2 sends an interrupt, the green LED toggles, so this proves that the Callback function works. But, again, the terminal windows stays silent:
Thank you for your patience.
2020-03-02 11:17 AM
Did you check for sure that the UART2 is on the COM11 on your PC? Did you check on the scheme in the PDF file that the UART2 is indeed on PA2 and PA3 on this board?
Could you try to send this:
while(1) {
HAL_UART_Transmit(&huart2, (uint8_t*) "#", 1, 1000);
HAL_Delay(500);
}
I use CoolTerm soft for monitoring UART.
2020-03-02 11:17 AM
User Manual UM1735 says:
"The USART2 interface available on PB3 and PB4 of the STM32F334C8T6 can be connected to ST-LINK/V2-1 MCU to use the virtual COM port function.
By default the USART2 communication between the target STM32F334C8T6 and ST-LINK/V2-1 MCU is not enabled.
To use the virtual COM port function with:
•The on-board STM32F334C8T6, then set SB14 and SB16 ON.
2020-03-02 11:36 AM
Thank you for your reply. Yes, the correct COM port number is 11: I had simply selected the wrong pins, PA2 and PA3 instead of PB3 and PB4. Now everything works fine.
Thank you again!
2020-03-02 11:37 AM
Thank you very much! I was absolutely adamant that the correct pins were PA2 and PA3 (they weren't): I don't know how I could miss that passage on the UM1735. Now everything works perfectly.
Thanks again!