Skip to content

Commit 08c47b9

Browse files
authored
Merge pull request #301 from ccrome/imxrt-allow-per-board-init
Allow per-board custom init, teardown, and validate hooks
2 parents 9093ab6 + 8cd180a commit 08c47b9

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/board_api.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,17 @@
8181
// This API does not init usb which is only init if DFU is entered
8282
void board_init(void);
8383

84+
// board_init2 is the same as board_init, but allows custom boards
85+
// to have a chance at board_init without modifying the boards.c file.
86+
void board_init2(void) __attribute__ ((weak));
87+
8488
// opposite to board_init(), reset all board peripherals. Is called before jumping to application
8589
// TODO force this API in the future
8690
void board_teardown(void) __attribute__ ((weak));
8791

92+
// board_teardown2() is called immeidately after board_init()
93+
void board_teardown2(void) __attribute__ ((weak));
94+
8895
// Reset board, not return
8996
void board_reset(void);
9097

@@ -112,6 +119,9 @@ extern void board_timer_handler(void);
112119
// Check if application is valid
113120
bool board_app_valid(void);
114121

122+
// Additional check if application is valid for custom board.
123+
bool board_app_valid2(void) __attribute__ ((weak));
124+
115125
// Jump to Application
116126
void board_app_jump(void);
117127

src/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static bool check_dfu_mode(void);
6363
int main(void)
6464
{
6565
board_init();
66+
if (board_init2) board_init2();
6667
TU_LOG1("TinyUF2\r\n");
6768

6869
#if TINYUF2_PROTECT_BOOTLOADER
@@ -74,6 +75,7 @@ int main(void)
7475
{
7576
TU_LOG1("Jump to application\r\n");
7677
if (board_teardown) board_teardown();
78+
if (board_teardown2) board_teardown2();
7779
board_app_jump();
7880
while(1) {}
7981
}
@@ -122,6 +124,7 @@ static bool check_dfu_mode(void)
122124

123125
// Check if app is valid
124126
if ( !board_app_valid() ) return true;
127+
if ( board_app_valid2 && !board_app_valid2() ) return true;
125128

126129
#if TINYUF2_DFU_DOUBLE_TAP
127130
// TU_LOG1_HEX(DBL_TAP_REG);

0 commit comments

Comments
 (0)