You will find the sources for this "printf" project on my Github page:
If you hadn't noticed, each of my demo projects builds on the previous one. I typically copy all the files to a new directory, then get busy. In this case I copy the blink demo as a starting point.What I do here is to add a printf function, placing it in the file prf.c This begins something new, namely separating things into multiple C source files. I also split the uart driver out of the main C file and place it into uart.c I steal the prf.c from a previous project (the EBAZ4205 Bitcoin board). I stole it for that project from my STM32F411 project, and who knows where it came before that. That project was a 32 bit ARM board, but it is basically portable code and only one tweak is required to avoid compiler warnings.
This is only a few minutes work and now I have a simple printf available. I still just have a blink demo, so I am thinking of some more interesting things to do now that I have a printf function available.
In the past I have always added a bit of assembly language code to return the value of the SP register from a function. On some reflection, I realize that this is unnecessary. Simply taking the address of a local variable in an arbitrary C function will provide the desired information. So I write some code like this:
void show_stack ( int recursion ) { int dummy; show_reg ( "Stack: ", &dummy ); if ( recursion ) show_stack ( 0 ); }Running it I see the following:
Stack: F5F03B7C 00000000 Stack: F5F03B4C 00000000So the stack is at 0xf5f0xxxx, perhaps it was started at 0xf5f04000. Hardware registers start at 0xf8000000, so this is at the end of available DDR ram (which we have 4G of).
clear_bss_loop: str xzr, [x1], #8 cmp x1, x2 bls clear_bss_loop // if x1 <= x2 goto clear_bss_loop
msr SP_EL2, x0The tricky issue is knowing what EL we are running at, since each EL has its own stack. I am pretty sure we are running at EL3, but when I worked with the Fire3, it was EL2 as shown above. There are ways to find out, but for now I will just be lazy and continue to use the U-Boot stack.
Tom's electronics pages / tom@mmto.org