Skip to content

Commit

Permalink
Bootloader updated to v0.5.3 (ExpressLRS#260)
Browse files Browse the repository at this point in the history
Bootloader updated to v0.5.3

* GPIO handling enhanced
* UART pinout config per pio env
* 2 different UART configs can be used for R9M
* Xmodem + STK500 dual boot option
* Fixes ELRS FW bootup time crash
  • Loading branch information
cruwaller authored Dec 26, 2020
1 parent 4d2e565 commit 4033e29
Show file tree
Hide file tree
Showing 32 changed files with 827 additions and 448 deletions.
Binary file modified src/bootloader/bootloader_sx1280_rx_ccg_nano_v05.bin
Binary file not shown.
Binary file not shown.
Binary file modified src/bootloader/jumper_r900_bootloader.bin
Binary file not shown.
Binary file modified src/bootloader/jumper_r900_bootloader_no_btn.bin
Binary file not shown.
Binary file modified src/bootloader/r9m_bootloader.bin
Binary file not shown.
Binary file modified src/bootloader/r9m_elrs_bl.frk
Binary file not shown.
Binary file modified src/bootloader/r9mm_bootloader.bin
Binary file not shown.
Binary file modified src/bootloader/r9mm_elrs_bl.frk
Binary file not shown.
Binary file modified src/bootloader/r9mm_no_btn_bootloader.bin
Binary file not shown.
Binary file modified src/bootloader/r9mm_no_btn_elrs_bl.frk
Binary file not shown.
Binary file modified src/bootloader/r9mx_bootloader.bin
Binary file not shown.
Binary file modified src/bootloader/r9mx_elrs_bl.frk
Binary file not shown.
Binary file modified src/bootloader/r9mx_no_btn_bootloader.bin
Binary file not shown.
Binary file modified src/bootloader/r9mx_no_btn_elrs_bl.frk
Binary file not shown.
Binary file modified src/bootloader/r9slim_plus_bootloader.bin
Binary file not shown.
Binary file modified src/bootloader/r9slim_plus_elrs_bl.frk
Binary file not shown.
Binary file modified src/bootloader/r9slim_plus_ota_bootloader.bin
Binary file not shown.
Binary file modified src/bootloader/r9slim_plus_ota_elrs_bl.frk
Binary file not shown.
27 changes: 27 additions & 0 deletions src/bootloader/src/Src/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

#include "flash.h"
#include "main.h"
#include "uart.h"

#ifndef DUMPING
#define DUMPING 0
#endif

#ifndef FLASH_TYPEPROGRAM_HALFWORD
#define FLASH_TYPEPROGRAM_HALFWORD 0 // should fail
Expand Down Expand Up @@ -44,6 +49,24 @@ uint32_t get_flash_end(void) {
/* Function pointer for jumping to user application. */
typedef void (*fnc_ptr)(void);

#if DUMPING
flash_status flash_dump(void)
{
//__IO uint8_t* address = (uint8_t*)FLASH_BASE;
uint32_t len = 0x2000;
uart_transmit_str("Memory dump start >>>>\r\n");
uart_transmit_bytes((uint8_t*)FLASH_BASE, len);
uart_transmit_str("<<<< Memory dump end\r\n");
return FLASH_OK;
}
#else
flash_status flash_dump(void)
{
return FLASH_OK;
}
#endif


/**
* @brief This function erases the memory.
* @param address: First address to be erased (the last is the end of the
Expand Down Expand Up @@ -256,10 +279,14 @@ void flash_jump_to_app(void)
NVIC_SystemReset();
}

/* Small delay to allow UART TX send out everything */
HAL_Delay(100);

/* Function pointer to the address of the user application. */
fnc_ptr jump_to_app;
jump_to_app = (fnc_ptr)(*(volatile uint32_t *)(FLASH_APP_START_ADDRESS + 4u));
/* Remove configs before jump. */
uart_deinit();
HAL_DeInit();
/* Change the main stack pointer. */
asm volatile("msr msp, %0" ::"g"(*(volatile uint32_t *)FLASH_APP_START_ADDRESS));
Expand Down
1 change: 1 addition & 0 deletions src/bootloader/src/Src/flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ uint32_t get_flash_end(void);

typedef uint8_t flash_status;

flash_status flash_dump(void);
flash_status flash_erase(uint32_t address);
flash_status flash_erase_page(uint32_t address);
flash_status flash_write(uint32_t address, uint32_t *data, uint32_t length);
Expand Down
71 changes: 71 additions & 0 deletions src/bootloader/src/Src/irq.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Definitions for irq enable/disable on ARM Cortex-M processors
//
// Copyright (C) 2017-2018 Kevin O'Connor <kevin@koconnor.net>
// https://github.com/KevinOConnor/klipper
//
// This file may be distributed under the terms of the GNU GPLv3 license.

#include "irq.h" // irqstatus_t

void irq_disable(void)
{
asm volatile("cpsid i" ::
: "memory");
}

void irq_enable(void)
{
asm volatile("cpsie i" ::
: "memory");
}

irqstatus_t
irq_save(void)
{
irqstatus_t flag;
asm volatile("mrs %0, primask"
: "=r"(flag)::"memory");
irq_disable();
return flag;
}

void irq_restore(irqstatus_t flag)
{
asm volatile("msr primask, %0" ::"r"(flag)
: "memory");
}

void irq_wait(void)
{
asm volatile("cpsie i\n wfi\n cpsid i\n" ::
: "memory");
}

void irq_poll(void)
{
}

// Clear the active irq if a shutdown happened in an irq handler
void clear_active_irq(void)
{
uint32_t psr;
asm volatile("mrs %0, psr"
: "=r"(psr));
if (!(psr & 0x1ff))
// Shutdown did not occur in an irq - nothing to do.
return;
// Clear active irq status
psr = 1 << 24; // T-bit
uint32_t temp;
asm volatile(
" push { %1 }\n"
" adr %0, 1f\n"
" push { %0 }\n"
" push { r0, r1, r2, r3, r4, lr }\n"
" bx %2\n"
".balign 4\n"
"1:\n"
: "=&r"(temp)
: "r"(psr), "r"(0xfffffff9)
: "r12", "cc");
}
30 changes: 30 additions & 0 deletions src/bootloader/src/Src/irq.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Definitions for irq enable/disable on ARM Cortex-M processors
//
// Copyright (C) 2019 Kevin O'Connor <kevin@koconnor.net>
// https://github.com/KevinOConnor/klipper
//
// This file may be distributed under the terms of the GNU GPLv3 license.

#ifndef __GENERIC_IRQ_H
#define __GENERIC_IRQ_H

#include <stdint.h>

#ifdef __cplusplus
extern "C"
{
#endif

typedef unsigned long irqstatus_t;

void irq_disable(void);
void irq_enable(void);
irqstatus_t irq_save(void);
void irq_restore(irqstatus_t flag);
void irq_wait(void);
void irq_poll(void);
#ifdef __cplusplus
}
#endif

#endif // irq.h
36 changes: 16 additions & 20 deletions src/bootloader/src/Src/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#include "main.h"

#if defined(WS2812_LED_PIN)
static void *ws2812_port;
static uint32_t ws2812_pin;
struct gpio_pin led_pin;

#ifndef BRIGHTNESS
#define BRIGHTNESS 30 // 1...256
#endif

#define WS2812_DELAY_LONG() \
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); \
Expand All @@ -25,26 +27,27 @@ static uint32_t ws2812_pin;


static inline void
ws2812_send_1(void * const port, uint32_t const pin)
ws2812_send_1(struct gpio_pin pin)
{
GPIO_WritePin(port, pin, 1);
GPIO_Write(pin, 1);
WS2812_DELAY_LONG();
GPIO_WritePin(port, pin, 0);
GPIO_Write(pin, 0);
WS2812_DELAY_SHORT();
}

static inline void
ws2812_send_0(void * const port, uint32_t const pin)
ws2812_send_0(struct gpio_pin pin)
{
GPIO_WritePin(port, pin, 1);
GPIO_Write(pin, 1);
WS2812_DELAY_SHORT();
GPIO_WritePin(port, pin, 0);
GPIO_Write(pin, 0);
WS2812_DELAY_LONG();
}

static uint32_t bitReverse(uint8_t input)
static uint32_t bitReverse(uint32_t input)
{
uint8_t r = input; // r will be reversed bits of v; first get LSB of v
// r will be reversed bits of v; first get LSB of v
uint8_t r = (uint8_t)((input * BRIGHTNESS) >> 8);
uint8_t s = 8 - 1; // extra shift needed at end

for (input >>= 1; input; input >>= 1) {
Expand All @@ -58,28 +61,21 @@ static uint32_t bitReverse(uint8_t input)

static void ws2812_send_color(uint8_t const *const RGB) // takes RGB data
{
void * const port = ws2812_port;
uint32_t const pin = ws2812_pin;
struct gpio_pin pin = led_pin;
uint32_t LedColourData =
bitReverse(RGB[1]) + // Green
(bitReverse(RGB[0]) << 8) + // Red
(bitReverse(RGB[2]) << 16); // Blue
uint8_t bits = 24;
while (bits--) {
(LedColourData & 0x1) ? ws2812_send_1(port, pin) : ws2812_send_0(port, pin);
(LedColourData & 0x1) ? ws2812_send_1(pin) : ws2812_send_0(pin);
LedColourData >>= 1;
}
}

void ws2812_init(void)
{
gpio_port_pin_get(IO_CREATE(WS2812_LED_PIN), &ws2812_port, &ws2812_pin);
gpio_port_clock((uint32_t)ws2812_port);
LL_GPIO_SetPinMode(ws2812_port, ws2812_pin, LL_GPIO_MODE_OUTPUT);
LL_GPIO_SetPinOutputType(ws2812_port, ws2812_pin, LL_GPIO_OUTPUT_PUSHPULL);
LL_GPIO_SetPinSpeed(ws2812_port, ws2812_pin, LL_GPIO_SPEED_FREQ_HIGH);
//LL_GPIO_SetPinPull(ws2812_port, ws2812_pin, LL_GPIO_PULL_NO);
LL_GPIO_ResetOutputPin(ws2812_port, ws2812_pin);
led_pin = GPIO_Setup(IO_CREATE(WS2812_LED_PIN), GPIO_OUTPUT, -1);
}

void ws2812_set_color(uint8_t const r, uint8_t const g, uint8_t const b)
Expand Down
Loading

0 comments on commit 4033e29

Please sign in to comment.