We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I recently found out that in Keil 5 I can select different IO retarget modes. So I went and gave it a try.
I go to "Manage Run-Time Enviroment" -> Compiler -> I/O and select STDIN equal ITM. After that, retarget_io.c appears in the project window.
I briefly read it and found out several interesting things:
- It compiles (which is good).
- There is a definition of ITM_SendChar function, which is already defined in core_cm4.h.
- If I add printf call in my program, code size bloates from 436 bytes (empty main) to 3538 bytes (one printf call in main).
- That printf call doesn't do anything in simulation, debug (printf) window is empty.
I used to implement I/O retargeting roughly like this:
int fputc(int c, FILE *f) { return ITM_SendChar(c); } void _ttywrch(int ch) { ITM_SendChar(ch); }
- If I implement retarget like this, printf call makes code size just 704 bytes. - It actually works in simulator.
So my question is: am I doing something wrong here?
I'm using Keil 5.23 with ARMCC compiler 5.06 update 4 (build 422).
Have you configured SWO (ITM) trace correctly?
Chen Tang, no, I don't know how ITM should be configured for simulator and I believe that it couldn't be. But with my old code it works 'as is'.
By pure luck I figured out that I need to include #include "RTE_Components.h" in main.c (where I use printf). Then printf starts to work.
I must emphasize that it's not mentioned anywhere around this help page www.keil.com/.../_retarget__examples__i_t_m.html.
And of course it doesn't solve the issue with bloated code size or multiple definition of ITM_SendChar function.