mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #17248 from benpicco/riotboot_serial-btn
riotboot_serial: enter bootloader mode by pin
This commit is contained in:
commit
8d3d012acd
@ -28,7 +28,7 @@
|
||||
#include "riotboot/usb_dfu.h"
|
||||
#include "ztimer.h"
|
||||
|
||||
#include "bootloader_selection.h"
|
||||
#include "riotboot/bootloader_selection.h"
|
||||
|
||||
#ifdef BTN_BOOTLOADER_PIN
|
||||
#include "periph/gpio.h"
|
||||
|
@ -1,3 +1,6 @@
|
||||
BOARD_INSUFFICIENT_MEMORY := \
|
||||
frdm-kw41z \
|
||||
pba-d-01-kw2x \
|
||||
phynode-kw41z \
|
||||
usb-kw41z \
|
||||
#
|
||||
|
@ -2,7 +2,7 @@ RIOTBOOT_SERIAL := $(RIOTTOOLS)/riotboot_serial/riotboot_serial
|
||||
|
||||
FLASHER ?= $(RIOTBOOT_SERIAL)
|
||||
FLASHFILE ?= $(HEXFILE)
|
||||
PROG_BAUD ?= 115200
|
||||
PROG_BAUD ?= $(BAUD)
|
||||
FFLAGS ?= $(FLASHFILE) $(PORT) $(PROG_BAUD)
|
||||
|
||||
ROM_OFFSET ?= $(RIOTBOOT_LEN)
|
||||
|
@ -19,8 +19,8 @@
|
||||
* to the riotboot_dfu application that isn't written in C++ and not included
|
||||
* from anywhere else either, but still here for consistency (and because
|
||||
* otherwise the checks complain) */
|
||||
#ifndef BOOTLOADER_SELECTION_H
|
||||
#define BOOTLOADER_SELECTION_H
|
||||
#ifndef RIOTBOOT_BOOTLOADER_SELECTION_H
|
||||
#define RIOTBOOT_BOOTLOADER_SELECTION_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -68,10 +68,22 @@ 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
|
||||
|
||||
#endif /* BOOTLOADER_SELECTION_H */
|
||||
#endif /* RIOTBOOT_BOOTLOADER_SELECTION_H */
|
||||
|
||||
/** @} */
|
@ -23,11 +23,13 @@
|
||||
|
||||
#include "stdio_uart.h"
|
||||
#include "periph/uart.h"
|
||||
#include "periph/gpio.h"
|
||||
#include "periph/flashpage.h"
|
||||
#include "unaligned.h"
|
||||
#include "checksum/crc8.h"
|
||||
#include "riotboot/serial.h"
|
||||
#include "riotboot/magic.h"
|
||||
#include "riotboot/bootloader_selection.h"
|
||||
|
||||
#include "board.h"
|
||||
|
||||
@ -53,6 +55,32 @@ static inline void uart_write_byte(uart_t uart, uint8_t data)
|
||||
uart_write(uart, &data, 1);
|
||||
}
|
||||
|
||||
static inline bool _boot_pin(void)
|
||||
{
|
||||
#ifdef BTN_BOOTLOADER_PIN
|
||||
if (BTN_BOOTLOADER_INVERTED) {
|
||||
return !gpio_read(BTN_BOOTLOADER_PIN);
|
||||
}
|
||||
else {
|
||||
return gpio_read(BTN_BOOTLOADER_PIN);
|
||||
}
|
||||
#else
|
||||
return false;
|
||||
#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)
|
||||
{
|
||||
@ -69,6 +97,10 @@ static bool _bootdelay(unsigned tries, volatile bool *boot_default)
|
||||
|
||||
while (--tries && *boot_default) {
|
||||
uart_write_byte(RIOTBOOT_UART_DEV, 0);
|
||||
if (_boot_pin()) {
|
||||
return false;
|
||||
}
|
||||
_boot_led_toggle();
|
||||
}
|
||||
|
||||
return *boot_default;
|
||||
@ -180,9 +212,9 @@ error:
|
||||
|
||||
static void _get_page(uintptr_t addr)
|
||||
{
|
||||
uart_write_byte(RIOTBOOT_UART_DEV, RIOTBOOT_STAT_OK);
|
||||
uint32_t page = flashpage_page((void *)addr);
|
||||
|
||||
uart_write_byte(RIOTBOOT_UART_DEV, RIOTBOOT_STAT_OK);
|
||||
uart_write(RIOTBOOT_UART_DEV, (void *)&page, sizeof(page));
|
||||
}
|
||||
|
||||
@ -216,6 +248,14 @@ int riotboot_serial_loader(void)
|
||||
{
|
||||
volatile bool reading = true;
|
||||
|
||||
#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);
|
||||
|
||||
@ -224,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 */
|
||||
|
Loading…
Reference in New Issue
Block a user