Skip to content

Commit

Permalink
sys/riotboot: serial: add bootloader LED
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Nov 21, 2021
1 parent f53a398 commit e6a0650
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bootloaders/riotboot_serial/Makefile.ci
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
BOARD_INSUFFICIENT_MEMORY := \
frdm-kw41z \
pba-d-01-kw2x \
phynode-kw41z \
usb-kw41z \
#
12 changes: 12 additions & 0 deletions sys/include/riotboot/bootloader_selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ extern "C" {
#define BTN_BOOTLOADER_INVERTED true
#endif

/** @brief LED pin for bootloader indication
*
* This pin (typically connected to a LED) will be toggled while the bootloader is active.
* It can be used to communicate the current bootloader state to the user.
*/
#if !defined(LED_BOOTLOADER_PIN) && defined(LED0_PIN) && !defined(LED_BOOTLOADER_NONE) || DOXYGEN
#define LED_BOOTLOADER_PIN LED0_PIN
#define LED_BOOTLOADER_ON LED0_ON /**< Turn the bootloader LED on */
#define LED_BOOTLOADER_OFF LED0_OFF /**< Turn the bootloader LED off */
#define LED_BOOTLOADER_TOGGLE LED0_TOGGLE /**< Toggle the bootloader LED */
#endif

#ifdef __cplusplus
}
#endif
Expand Down
21 changes: 21 additions & 0 deletions sys/riotboot/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ static inline bool _boot_pin(void)
#endif
}

static inline void _boot_led_toggle(void)
{
#ifdef LED_BOOTLOADER_PIN
static unsigned count = RIOTBOOT_DELAY / 10;

if (--count == 0) {
count = RIOTBOOT_DELAY / 10;
LED_BOOTLOADER_TOGGLE;
}
#endif
}

/* send 'hello' byte until we get enter bootloader byte or timeout */
static bool _bootdelay(unsigned tries, volatile bool *boot_default)
{
Expand All @@ -88,6 +100,7 @@ static bool _bootdelay(unsigned tries, volatile bool *boot_default)
if (_boot_pin()) {
return false;
}
_boot_led_toggle();
}

return *boot_default;
Expand Down Expand Up @@ -238,6 +251,10 @@ int riotboot_serial_loader(void)
#ifdef BTN_BOOTLOADER_PIN
gpio_init(BTN_BOOTLOADER_PIN, BTN_BOOTLOADER_MODE);
#endif
#ifdef LED_BOOTLOADER_PIN
gpio_init(LED_BOOTLOADER_PIN, GPIO_OUT);
LED_BOOTLOADER_OFF;
#endif

uart_init(RIOTBOOT_UART_DEV, RIOTBOOT_UART_BAUDRATE,
_uart_rx_cmd, (void *)&reading);
Expand All @@ -247,6 +264,10 @@ int riotboot_serial_loader(void)
return -1;
}

#ifdef LED_BOOTLOADER_ON
LED_BOOTLOADER_ON;
#endif

while (1) {

/* we can't use mutex in riotboot */
Expand Down

0 comments on commit e6a0650

Please sign in to comment.