cancel
Showing results for 
Search instead for 
Did you mean: 

Configuring printf on Keil

antoine
Associate II
Posted on July 01, 2016 at 14:30

Hi,

Clearly I'm not the only one who has this need, but the tutorials I followed didn't work for me .

I want to use printf() in Keil, in order to check if my ''DAC to ADC'' code works. I tried with Debug (printf) Viewer in Keil, but I guess it could work with any terminal, I'm not picky.

Apparently it has something to do with rewriting fputc() or putchar().

http://www.keil.com/support/man/docs/ulink2/ulink2_trace_itm_viewer.htm

says to implement the code in the source code, so naively I put it in the main.c, but I guess it's wrong.

If this can help, the goal here is to output a sinewave from the DAC and put it into the ADC. I want to verify the ADC reads it correctly, maybe by printing out values and compare them with the values in the sintable read by the DAC.
This discussion is locked. Please start a new topic to ask your question.
5 REPLIES 5
Nesrine M_O
Lead II
Posted on July 01, 2016 at 15:04

Hi Antoine.PM,

I recommend you to have a look to the UART example under STM32F4 cube firmware package it may be helpful.

STM32Cube_FW_F4_V1.12.0\Projects\STM32446E-Nucleo\Examples\UART\UART_Printf

This example shows how to reroute the C library printf function to the UART. It outputs a message sent by the UART on the HyperTerminal.

-Syrine-

antoine
Associate II
Posted on July 04, 2016 at 12:09

Hi,

Thanks for the links. 

It seems to work now. I'll try this in context of my real code :)
Bob Boys
Senior
Posted on June 27, 2017 at 04:22

Hello

This is an old posting but it seems many people are having problems getting the keil printf using ITM working.

This is important method as it does not use a UART or other user hardware in the processor.

I suspect the usual problem is failing to properly configure Serial Wire Viewer (SWV)

To configure SWV: See this document page 11: 

http://www.keil.com/appnotes/files/apnt_286_v1.2.pdf

 

The Core Clock: setting is important.  Enter the CMSIS global variable SystemCoreClock in a Watch window to get this value.

You can confirm a CPU clock frequency with this appnote: 

http://www.keil.com/appnotes/docs/apnt_297.asp

 

To configure printf the new and easier way:  See page 14 of appnote 286.

printf on Coretx-M0/M0+:   SWV is only available on Cortex-M3, M4 and M7 and the upcoming M23 and M33.

There is a way the implement this printf with a Cortex-M0, M0+:  in the appnote above, instead of selecting STDOUT ITM, select EVR.

Add these lines to your file containing your main() function:

#include 'EventRecorder.h'                       // Keil::ARM_Compiler  EventRecorderInitialize (EventRecordAll, 1);  // initialize and start Event Recorder

These are described here: 

http://www.keil.com/support/man/docs/uv4/uv4_db_dbg_evr_setup.htm

 

I will work these directions out later in more/less detail and update appnote 286.

Thanks

Bob Boys

ARM

Posted on July 01, 2017 at 04:21

Hello

It is possible to use the new Keil uVision Event Recorder to implement a printf that does not require a UART or Serial Wire Viewer.

You can use Event Recorder to annotate your own source code.

http://www.keil.com/pack/doc/compiler/EventRecorder/html/index.html

This will also work with other Cortex-M processors.

Attached is an updated version of the Keil ST-Link appnote. I will put this on Keil.com early next week:

Bob

________________

Attachments :

StLink_3.pdf : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HyZu&d=%2Fa%2F0X0000000b9j%2FbNp7qF3HyUYzmYHbjv.lYv9yER5rzUPgZamVtZ6vxf0&asPdf=false