cancel
Showing results for 
Search instead for 
Did you mean: 

uart printf not working, please help.. (STM32F401RE eval board, using HAL driver)

ckim
Associate II
Posted on December 04, 2015 at 13:46

Hi, all

A newcomer in this product, I've been trying to do this for several days now..

I'm using STM32F401RE evaluation board, and running the uart_printf example project that came with STM32cubeF4 package. The example project uses HAL driver, not StdPeriphLib drivers. I added a include path to avoid build error.

When I repeatedly do printf(''CGCG'') with 0.5 interval, I can see the UART signal going from the MCU(STM32F401RE) to the MCU for USB connection(STM32F103CB) correctly. But I cannot see the data on my win7 PC uart terminal (9600, 8bit, odd, 1 stop, no flow con). When I press key 'C' or 'G' or any character in my PC terminal, it appears in the UART signal in reverse direction. That is, the UART signals between F401RE and F103CB looks normal. I can see STM32F401RE chip's USART2 DR register changing according to the key I press.

My question is how can I check STM32F103CB chip's UART controller registers? Is there any way I can do that with uVision5?  Can my board be broken?

0690X00000603LfQAI.jpg

10 REPLIES 10
Posted on December 04, 2015 at 15:08

This seems like a duplicate of your other thread on materially the same topic.

Can my board be broken?

I'm doubtful, but it's why buying at least two boards always makes sense, most of the postage costs accrue for the first device, and the subsequent parts contribute fractionally.

No, the debugger cannot access the device doing the SWD/JTAG work.

Odd parity? Make sure the STM32 is configured in 9-bit mode to account for the parity bit, and 8 data bits.

Attached is an example .HEX, download it with the ST-LINK Utilities. 115200 8N1

Outputs to the USART, and echos back.

________________

Attachments :

USART2NUCLEO401.hex : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hza0&d=%2Fa%2F0X0000000bNt%2FY5mFnm8Sx9jbHm0OnWLO0gL9PUkwseAinvhTCM9tK9s&asPdf=false
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 December 04, 2015 at 16:00

I'm home now and I'll try your suggestion when I'm back at work. Thanks!

ckim
Associate II
Posted on December 06, 2015 at 05:56

clive1,

I tried 9 bit setting, but the same.

I programed your .hex file to my F401RE board, set COM to 115200,N,8,1 but I don't see any print on my PC.  LED1 keeps blinking green and red.  I used program & verify and set 'reset after program'. Than the board should run, shouldn't it? (does your sample program repeatedly print something on UART?)

I saw on youtube that we can redirect the SWD signal to PC's COM port using ITM function(only in debug mode). In this case, what should I fill in the fputc( ) redirection? My current code is HAL_UART_Transmit(..). I tried just removing it, but didn't work.

We received only one evaluation board so I cannot try another board.

I attach the code

http://pastebin.com/SHzjWm2E

 for anyone really wanting to help.(main.h, main.c, stm32f4xx_hal_msp.c, stm32f4xx_it.c )
Posted on December 06, 2015 at 15:36

It should output a brief string, and then echo back anything you type on the console, at 115200 8N1.

You could perhaps try on a different PC, and double check that we are working with the most current drivers/firmware.

For SWV (Serial Wire Viewer) you need to modify the retargeting code to use ITM_SendChar() and configure the Trace settings to exactly match the frequency you are running the part. The console data is visible in Keil in the ''Serial (printf)'' window [View -> Serial Windows -> Debug (printf) Viewer], or via the SWV window on the ST-LINK Utilities.

[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/Getting%20printf%20on%20STM32F407%20Discovery%20board&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=175]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Discovery%2FGetting%20printf%20on%20STM32F407%20Discovery%20board&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F¤tviews=175

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 December 07, 2015 at 01:16

Hi, clive1, 

Using your .hex file, I can see when I press reset, it transmits some string on the UART and when I press key in my windows7 PC, it reflects it. But I cannot see any print on my COM2 port. (sure it's COM2 because the keys are reflected on UART scope). This almost makes me believe the board is broken.. (I tried 7, 8 bit in Hercules terminal program, several parities..)

using ITM_SendChar(ch); I can see the printf on the debug window. Thanks.

But this can be done only in debug mode, I hope to be able to do it on uart. I'll check the drivers and try using another PC. 

UPDATE : I tested your USART2NUCLEO401.hex file using my another PC and it workd! Then I figured there was something different in the PCs so I made the same project on the new PC (actually an old PC) and ran it, but the printf didn't work! So I re-tested your USAR2UNCLEO401.hex with ST-LINK utility but it didn't work either!  So I have an impression that once I install uVision 5(with drivers installed), the UART print doesn't work.  I'll test this tomorrow.

ckim
Associate II
Posted on December 08, 2015 at 10:25

I've seen the USAR2UNCLEO401.hex program run ok in my PC, but after removing a driver I cannot reproduce it. I tried re-installing the programs, updated the board's firmware but cannot progress further.

Here is the driver install state of my PC.

0690X00000603MiQAI.jpg

Does my software installation look normal?

Posted on December 08, 2015 at 15:43

The is working for me

Win7 x64

V2.J24.M11 (from ST-LINK Utilities 3.7.0)

ST-LINK 12/10/2013 1.1.0.0

STLink Virtual COM Port 12/10/2013 1.0.0.0

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 December 09, 2015 at 02:08

Win7 x64

V2.J24.M11 (from ST-LINK Utilities 3.7.0)

ST-LINK 12/10/2013 1.1.0.0

the same with me, but when I add the latest VCP (latest is V1.4.0-10/20/2014, not your version is V1.0.0.0 2/10/2013) I cannot find COM port.

I wish to try VCP V1.0.0.0. Do you have the install file for it yet? (for V1.4.0 it is stsw-stm32102.zip)

ckim
Associate II
Posted on December 16, 2015 at 05:27

Hi, clive1,

I tried the same project on my colleague's win7 computer, it first worked (can see print on serial port window). With the same program programed on the board, I tested it on my win7 machine but didn't work. I connected the board on my linux machine and it works! So it's not the problem of any program on the evaluation board but the driver problem on win7 machine as I suspected. I then tested the board on my colleague's computer but it doesn't work now. Looks like something changed after the first execution..