Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.5 stm32 bootloader support #39

Open
wants to merge 2 commits into
base: v3.5.0+zmk-fixes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dts/arm/st/f0/stm32f072.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
soc {
compatible = "st,stm32f072", "st,stm32f0", "simple-bus";

rom_bootloader: rom_bootloader@0x1FFFC800 {
compatible = "st,stm32-bootloader";
reg = <0x1FFFC800 DT_SIZE_K(12)>;
status = "reserved";
};

can1: can@40006400 {
compatible = "st,stm32-bxcan";
reg = <0x40006400 0x400>;
Expand Down
6 changes: 6 additions & 0 deletions dts/arm/st/f4/stm32f401.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
soc {
compatible = "st,stm32f401", "st,stm32f4", "simple-bus";

rom_bootloader: rom_bootloader@0x1FFF0000 {
compatible = "st,stm32-bootloader";
reg = <0x1FFF0000 DT_SIZE_K(29)>;
status = "reserved";
};

spi2: spi@40003800 {
compatible = "st,stm32-spi";
#address-cells = <1>;
Expand Down
7 changes: 7 additions & 0 deletions dts/arm/st/f4/stm32f411.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
soc {
compatible = "st,stm32f411", "st,stm32f4", "simple-bus";


rom_bootloader: rom_bootloader@0x1FFF0000 {
compatible = "st,stm32-bootloader";
reg = <0x1FFF0000 DT_SIZE_K(29)>;
status = "reserved";
};

spi5: spi@40015000 {
compatible = "st,stm32-spi";
#address-cells = <1>;
Expand Down
1 change: 1 addition & 0 deletions soc/arm/st_stm32/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ zephyr_sources(stm32cube_hal.c)
zephyr_linker_sources_ifdef(CONFIG_STM32_CCM SECTIONS ccm.ld)

zephyr_sources_ifdef(CONFIG_STM32_BACKUP_SRAM stm32_backup_sram.c)
zephyr_sources_ifdef(CONFIG_STM32_BOOTLOADER stm32_bootloader.c)
zephyr_linker_sources_ifdef(CONFIG_STM32_BACKUP_SRAM SECTIONS stm32_backup_sram.ld)

zephyr_sources(soc_config.c)
11 changes: 11 additions & 0 deletions soc/arm/st_stm32/common/Kconfig.soc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ config STM32_BACKUP_SRAM
help
Enable support for STM32 backup SRAM.


config HAS_STM32_BOOTLOADER
def_bool $(dt_compat_enabled,$(DT_COMPAT_ST_STM32_BOOTLOADER))

config STM32_BOOTLOADER
bool "STM32 Bootloader Support"
default HAS_STM32_BOOTLOADER
depends on RETENTION_BOOT_MODE
help
Enable support for jumping into the STM32 when the bootmode is set.

config USE_STM32_ASSERT
depends on ASSERT
bool "STM32Cube HAL and LL drivers asserts"
Expand Down
55 changes: 55 additions & 0 deletions soc/arm/st_stm32/common/stm32_bootloader.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2020 Google LLC.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <soc.h>
#include <zephyr/init.h>
#include <zephyr/retention/retention.h>
#include <zephyr/retention/bootmode.h>
#include <stm32_ll_system.h>

static const uint32_t bootloader = DT_REG_ADDR(DT_INST(0, st_stm32_bootloader));
static FUNC_NORETURN void jump_to_bootloader(void)
{
uint32_t i = 0;
void (*jmp)(void);

__disable_irq();

SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;

for (i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); i++)

Check failure on line 25 in soc/arm/st_stm32/common/stm32_bootloader.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

OPEN_BRACE

soc/arm/st_stm32/common/stm32_bootloader.c:25 that open brace { should be on the previous line

Check warning on line 25 in soc/arm/st_stm32/common/stm32_bootloader.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

ARRAY_SIZE

soc/arm/st_stm32/common/stm32_bootloader.c:25 Prefer ARRAY_SIZE(NVIC->ICER)
{
NVIC->ICER[i] = 0xFFFFFFFF;
NVIC->ICPR[i] = 0xFFFFFFFF;
}

LL_SYSCFG_SetRemapMemory(LL_SYSCFG_REMAP_SYSTEMFLASH);

jmp = (void (*)(void)) (void (*)(void)) (*((uint32_t *) ((bootloader + 4))));

__set_CONTROL(0);
__set_MSP(*(uint32_t *)bootloader);

__enable_irq();

jmp();

while (1) { }

Check failure on line 42 in soc/arm/st_stm32/common/stm32_bootloader.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TRAILING_STATEMENTS

soc/arm/st_stm32/common/stm32_bootloader.c:42 trailing statements should be on next line
}

static int bootloader_check_boot_init(void)
{
if (bootmode_check(BOOT_MODE_TYPE_BOOTLOADER) > 0) {
bootmode_clear();
jump_to_bootloader();
}

return 0;
}

SYS_INIT(bootloader_check_boot_init, EARLY, 0);
Loading