Вопрос

I have coded a project of mine in C on a Windows machine in the software IAR Embedded Workbench IDE. The project compiles and runs fine. I have a couple of printf functions in my code. But the thing is that the project is intended for a microcontroller AT91SAM7X256. I've successfully built my application to run on the sram of the microcontroller, and the application was loaded successfully. But the printf function is being directed to the USART port of the controller (I can only assume), and so I would like to redirect the printf to display the text on my terminal I/O. Does anyone have an idea on how I can do that?

Это было полезно?

Решение

I use the ARM, AVR32 and MSP430 processor versions of the IAR toolchain. In each of these you have to implement your own low level functionality to handle the stdin and stdout streams. The ARM compiler manual has a section on "Standard streams for input and output" which says that you need to write your own version of the __write() function, and it provides an example version where the data is written to a memory mapped LED display.

Knowing IAR I would expect they will have a similar example for your processor/toolchain combination.

Другие советы

I don't know why your printf is being redirected but to do what you want to do I did the following: First show the console window. (while running debug go to menu View-> Terminal I/O then stopping the application, go to Project->Options and in Linker-> Library check Include C-SPY debugging support

Be warned that this makes the running of the program considerably slower, than it should be. Comment out all printfs later when finishing your debugging

The standard answer is to select "Semihosted" and "Via semihosting" (Or via SWO -- but I have been using the other.) And "buffered terminal output" for speed under library options 1.

However, I am poking about here because I have a demo program from ST that won't printf to the console and I don't know why -- have many applications that work. So if anyone can remember some detail that gets left out of the standard information feel free to say something...

all you have to do is to #include <stdio.h> and use printf() in your code. For this to work with the debugger console you will have to go to Project options -> Linker -> Output (tab) and in the "Format" section where you have selected "Debug information for C-SPY" you need to have "With I/O emulation modules" checked (this requires "with runtime control modules"). This will make the linker use its special low-level I/O routines (putchar() , getchar() ) which will route it to/from the debug terminal I/O console.

When entering debug mode you get the debug console window displayed by selecting View -> Terminal I/O from the top menu. You will probably notice that if you try to printf too much text it will make the output lag a bit. But it can surely be a handy tool for debugging your application anyway.

(For the curious, you can see in the disassembler that the putchar() / getchar() functions linked into the code when using I/O emulation are just NOP instruction dummy functions. The C-SPY debugger will set a hardware breakpoint in this function, and whenever this breakpoint is reached it will read out the register to read/write the character. The communication overhead causes a small delay for each character. A side-effect of using I/O emulation is that the debugger will reserve one hardware breakpoint for each of these two functions (if you are using them), so you will get fewer hardware breakpoints available to use in your other application debugging.)

You can find some more information about "I/O emulation modules" in the IAR user manual: Help -> 8051 Embedded Workbench User Guide.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top