cancel
Showing results for 
Search instead for 
Did you mean: 

UART example in the STM32cube not working for me.

ckim
Associate II
Posted on November 26, 2015 at 14:58

Hello STM32 users,

I've received the STM32F401RE board and am trying to run a test program on it. I downloaded uVision5 and the STM32Cube_FW_F4_V1.9.0 and opened the UART project that came with the package. The ''DM00107720-Getting Started with STM32CubeF4 firmware package'' document says I can just run it on uVision5. I don't know much about the ARM architecture let alone S TM32. I see COM16 port is seen on my PC but when I debug run the program, a yello and bright green arrow is pointing the first line of the main() program which is HAL_init(); as in the image below.  I can press F10 to proceed but when I cross the printf statement, nothing comes up on my teraterm windows. (set to use COM16, 9600,odd,8,1 as the USART setting in the program). I guess I'm missing something very basic. What is wrong with my case? 

regards, Thanks,

Chan

 0690X000006035mQAA.jpg

3 REPLIES 3
Posted on November 26, 2015 at 15:14

It's really using ODD parity?

Keil would need retargeting code where the fputc() actually implements the output to the specific USART.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ckim
Associate II
Posted on November 27, 2015 at 01:57

Hi, clive1,

in the main.c file, it is defined as below. Isn't it correctly set already?

#ifdef __GNUC__

  /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf

     set to 'Yes') calls __io_putchar() */

  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)

#else

  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)

#endif /* __GNUC__ */

PUTCHAR_PROTOTYPE

{

  /* Place your implementation of fputc here */

  /* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */

  HAL_UART_Transmit(&UartHandle, (uint8_t *)&ch, 1, 0xFFFF); 

  return ch;

}

Also, the USART is set as below (see odd parity).

  UartHandle.Instance          = USARTx;

  

  UartHandle.Init.BaudRate     = 9600;

  UartHandle.Init.WordLength   = UART_WORDLENGTH_8B;

  UartHandle.Init.StopBits     = UART_STOPBITS_1;

  UartHandle.Init.Parity       = UART_PARITY_ODD;

  UartHandle.Init.HwFlowCtl    = UART_HWCONTROL_NONE;

  UartHandle.Init.Mode         = UART_MODE_TX_RX;

  UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;

ckim
Associate II
Posted on November 30, 2015 at 12:11

I think the fputc retargetting is correctly done to use UART port.

My question now is : for STM32F401, the printf is set to use USART pins(PA2 and PA3 on the STM32F401). Then where do we set STM32F103CBT6 chip to use USART port (PA2 and PA3) and use USB for PC connection?