Skip to content

Commit

Permalink
Merge pull request #301 from ccrome/imxrt-allow-per-board-init
Browse files Browse the repository at this point in the history
Allow per-board custom init, teardown, and validate hooks
  • Loading branch information
hathach committed Mar 10, 2023
2 parents 9093ab6 + 8cd180a commit 08c47b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/board_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,17 @@
// This API does not init usb which is only init if DFU is entered
void board_init(void);

// board_init2 is the same as board_init, but allows custom boards
// to have a chance at board_init without modifying the boards.c file.
void board_init2(void) __attribute__ ((weak));

// opposite to board_init(), reset all board peripherals. Is called before jumping to application
// TODO force this API in the future
void board_teardown(void) __attribute__ ((weak));

// board_teardown2() is called immeidately after board_init()
void board_teardown2(void) __attribute__ ((weak));

// Reset board, not return
void board_reset(void);

Expand Down Expand Up @@ -112,6 +119,9 @@ extern void board_timer_handler(void);
// Check if application is valid
bool board_app_valid(void);

// Additional check if application is valid for custom board.
bool board_app_valid2(void) __attribute__ ((weak));

// Jump to Application
void board_app_jump(void);

Expand Down
3 changes: 3 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ static bool check_dfu_mode(void);
int main(void)
{
board_init();
if (board_init2) board_init2();
TU_LOG1("TinyUF2\r\n");

#if TINYUF2_PROTECT_BOOTLOADER
Expand All @@ -74,6 +75,7 @@ int main(void)
{
TU_LOG1("Jump to application\r\n");
if (board_teardown) board_teardown();
if (board_teardown2) board_teardown2();
board_app_jump();
while(1) {}
}
Expand Down Expand Up @@ -122,6 +124,7 @@ static bool check_dfu_mode(void)

// Check if app is valid
if ( !board_app_valid() ) return true;
if ( board_app_valid2 && !board_app_valid2() ) return true;

#if TINYUF2_DFU_DOUBLE_TAP
// TU_LOG1_HEX(DBL_TAP_REG);
Expand Down

0 comments on commit 08c47b9

Please sign in to comment.