Hi,
I'm trying to run an STM32F103 on as little power as possible. Most of the time, the processor is in Standby, waking up occasionally on a RTC alarm interrupt.
When the processor wakes, from the current consumption, it appears that it takes approximately 2ms before I get to the start of my c main() function - which seems like a long time to me.
The processor is fitted with an 8MHz external xtal, but I'm hoping to start up on the HSI clock (which appears to be the case if I check with the debugger).
I'm using the Keil microlib; I know it will take some time to initialise memory etc. - but 2ms seems rather long. According to the hardware manual, the HCI startup time is 2us.
Can anyone give me an idea about what I'm missing? What is the processor doing for 2ms before it gets to main()?
Thanks in advance,
Jon.
Per,
That sounds like the kind of solution I need - it hadn't occurred to me. Your description makes sense - apart from the piece about the stack frame. Can you point me towards an explanation or so example code ensure that I've got a stack frame? Does that just mean that I need to ensure that the SP is set to a sensible stack address before calling my function (as long as my function prototype is void func(void))?
Regards, Jon.
You need an initialized stack, so your initial C function can be allowed to call secondary C functions.
And you should call your C function the same way the compiler would implement a call. You can look at disassembly to see what is required.
The stack size is usually defined in startup_stm32f10x.s, usually pretty small by default, 512 bytes?
The initialization code is pretty efficient, a tight assembler loop, but I'd still expect it to take 3-4 cycles per 32-bit word to zero, and a few more to copy.
Try not to have 8.5 KB of space to zero