Time source in bootloader

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
mialc_1106291
Level 4
Level 4
10 questions asked 50 sign-ins 50 replies posted

Hi,

I'm adding support for SPI flash to our bootloader firmware. This firmware must be compatible with existing host software, which expects to be able to set certain non-volatile fields using vendor commands. Some host applications may very quickly set multiple fields. In order to write SPI flash the sector that stores this data must first be erased. A sector erase may take up to 250 ms to complete. It's inefficient to read the contents of the sector into RAM, erase the sector, and then re-write the entire sector each time one of the host sets these fields. Instead, it would be better to read all non-volatile fields into RAM and maintain them in a RAM buffer, then when one of the fields is set by the host set a flag indicating that RAM is dirty and start a timer. Once the timer expires the appropriate sector of SPI flash will be erased and the RAM contents will be written to the SPI flash. In order for this to work I need a time source. However, I can't find anything in the API documentation about timers in the bootloader.

What are the available time sources for bootloader firmware?

Thanks,
Michael

0 Likes
1 Solution
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello Michael,

Unfortunately, we do not have timer APIs in the boot library.

To implement a timer you can use a loop or use a simple GPIO. To use simple GPIO you would need to feed the clock to the GPIO and register for the interrupt based on the period you need.

Regards,
Rashi

View solution in original post

0 Likes
2 Replies
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello Michael,

Unfortunately, we do not have timer APIs in the boot library.

To implement a timer you can use a loop or use a simple GPIO. To use simple GPIO you would need to feed the clock to the GPIO and register for the interrupt based on the period you need.

Regards,
Rashi
0 Likes
zzz_3221081
Level 5
Level 5
25 solutions authored 100 sign-ins 10 likes received

> However, I can't find anything in the API documentation about timers in the bootloader.

If I understood that problem correctly (and the answer by Rashi_Vatsa), the only issue is there is no pre-initialized timer in the bootloader, or in a ROM API.

But what keeps you from using the same timer as in your main application ? You could share the respective code, or perhaps modify it to work in both environments. 

My company has a set of different platforms and similar bootloaders, and we share such code routinely.

> Instead, it would be better to read all non-volatile fields into RAM and maintain them in a RAM buffer, then when one of the fields is set by the host set a flag indicating that RAM is dirty and start a timer. Once the timer expires the appropriate sector of SPI flash will be erased and the RAM contents will be written to the SPI flash.

Flash erase/program timing is often an issue.

Your approach might get into trouble if a sudden power-off is possible, and the sector gets corrupted.

In this case, a setup with multiple sectors, used in a "ringbuffer" fashion, might be helpful. Incrementally use the next buffer/sector with each operation, and add a validation marker (e.g. checksum). In case of corruption, you can fall back to the last proper set of values.

0 Likes