The __earlyInit() hook was not early enough Topic is solved

Use this forum for requesting small changes in ChibiOS. Large changes should be discussed in the development forum. This forum is NOT for support.
Post Reply
genosensor
Posts: 65
Joined: Thu Oct 03, 2013 1:06 am
Has thanked: 1 time
Been thanked: 1 time

The __earlyInit() hook was not early enough

Post by genosensor »

Hi,

I just spent a few days fighting to get a new board to reset reliably.
One of the problems encountered was due to the board's having a 1kOhm resistor in series with its 3.3V power input until bypassed by a FET under software control. This was done to limit inrush, as up to sixty of these boards may be mounted on a single I2C bus.

Unfortunately, the STM32L1xx does not startup in a low-power run state. Directly after reset, it is running on the MSI clock at approximately 2Mhz drawing about 2ma. Even after putting code in __early_init() to get the CPU into a low-power run mode, where it should have been drawing <100microamps, I observed high current consumption for 50ms before the board *eventually* finished resetting itself.

My fix was to move the __early_init() call before the stack is filled with a canary pattern.
I could have simply turned the stack fill config option off, but I really do like it.

Stack fill is a great feature, but it conflicts with this scenario. Before stack fill could complete, the CPU voltage would sag to the point to resetting again (many times).

Is there some scenario that requires the stack to be filled before __early_init() is invoked?
I suppose __early_init() would not get the benefit of the canary pattern to detect a stack overflow...
However, detecting a stack overflow in __early_init() should be obvious just by looking at the Stack Pointer.
There is only one context that early in the system initialization. Right?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: The __earlyInit() hook was not early enough

Post by Giovanni »

Hi,

I will consider this change, moving this topic in "change request".

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: The __earlyInit() hook was not early enough

Post by Giovanni »

Hi,

Which version are you using? __early_init() is called before stack already in 17.6.x.

Giovanni
Post Reply