adafruit / tinyuf2

UF2 bootloader based on TinyUSB for embedded devices such as ESP32S2, STM32F4 and iMX RT10xx
MIT License
310 stars 170 forks source link

Allow per-board custom init, teardown, and validate hooks #301

Closed ccrome closed 1 year ago

ccrome commented 1 year ago

Checklist


Description of Change

Some custom i.MX boards require per board setup. Currently, I don't see a mechanism for a specific board to have a setup call.

As a specific example, For example, on the i.MX RT 1011, if you happen to have the boot LED on GPIO_AD_02, you might need to custom configure GPR26 in order for it to work with the GPIO configuration you want to use.

Additionally, there are lots of other potential reasons you might want to do some setup in boards/<board_name>.

This patch adds #ifdef BOARD_INIT_POST_HOOK, and if it's defined, then board_init_post_hook() will be called at the end of board_init().

ccrome commented 1 year ago

It does beg the question, are there other places where there should be custom hooks on a per-board basis?

hathach commented 1 year ago

we add an optional API (weak function) to board_api.h e.g board_init_post() in conjunction with board_teardown_post()

ccrome commented 1 year ago

I updated the hooks to be in main now, rather than in the port directory. Now it's easy for any board anywhere to define the functions to do per board custom stuff.

void board_init_post(void) __attribute__ ((weak));
void board_teardown_post(void) __attribute__ ((weak));
bool board_app_valid_post() __attribute__ ((weak));
ccrome commented 1 year ago

I think I've got it all. Thanks!