mirror of
https://github.com/zmkfirmware/zmk.git
synced 2026-03-20 13:05:20 -05:00
SoC: stm32c0 support (#3174)
deps: Use hal_stm32 with stm32c0 USB device fixes. Pull in ZMK fork of hal_stm32 with USB device driver fixes for stm32c0. feat: Add nBOOT_SEL bit setup for STM32 G0/C0 targets Newer STM32 C0 and G0 series SoCs do not by default allow use of the BOOT0 pin/button to enter the bootloader once something has been flash to the device, which is a change from previous series, and usually not what's wanted for keyboards running ZMK. To address this, add some optional, but default initialization code to check the nBOOT_SEL bit and override it if necessary to ensure BOOT pin/button functionality. docs: Extract bootloader config into a dedicated page. Pull the bootloader intergration options out of the system configuration page into their own dedicated one. Co-authored-by: Nicolas Munnich <98408764+nmunnich@users.noreply.github.com> --------- Co-authored-by: Nicolas Munnich <98408764+nmunnich@users.noreply.github.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
|
||||
target_sources_ifdef(CONFIG_ZMK_BOOTMODE_TO_MAGIC_VALUE_MAPPER app PRIVATE bootmode_to_magic_mapper.c)
|
||||
target_sources_ifdef(CONFIG_ZMK_DBL_TAP_BOOTLOADER app PRIVATE dbl_tap_bootloader.c)
|
||||
target_sources_ifdef(CONFIG_ZMK_DBL_TAP_BOOTLOADER app PRIVATE dbl_tap_bootloader.c)
|
||||
target_sources_ifdef(CONFIG_ZMK_BOOT_STM32_ENFORCE_NBOOT_SEL app PRIVATE stm32_enforce_nboot_sel.c)
|
||||
|
||||
@@ -41,3 +41,11 @@ config ZMK_BOOTMODE_BOOTLOADER_MAGIC_VALUE
|
||||
hex
|
||||
|
||||
endif
|
||||
|
||||
config ZMK_BOOT_STM32_ENFORCE_NBOOT_SEL
|
||||
bool
|
||||
default y
|
||||
depends on FLASH && (SOC_STM32C071XX || SOC_STM32G0B1XX)
|
||||
select FLASH_EX_OP_ENABLED
|
||||
select FLASH_STM32_OPTION_BYTES
|
||||
|
||||
|
||||
@@ -25,3 +25,4 @@ config ZMK_BOOTMODE_BOOTLOADER_MAGIC_VALUE
|
||||
default 0x57 if ZMK_BOOTMODE_MAGIC_VALUE_BOOTLOADER_TYPE_ADAFRUIT_NRF52
|
||||
|
||||
endif
|
||||
|
||||
|
||||
46
app/src/boot/stm32_enforce_nboot_sel.c
Normal file
46
app/src/boot/stm32_enforce_nboot_sel.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <soc.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/init.h>
|
||||
#include <zephyr/drivers/flash.h>
|
||||
#include <zephyr/drivers/flash/stm32_flash_api_extensions.h>
|
||||
#include <zephyr/storage/flash_map.h>
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
|
||||
const struct device *flash_dev = FIXED_PARTITION_DEVICE(storage_partition);
|
||||
|
||||
static int stm32_enforce_nboot_sel_init(void) {
|
||||
uint32_t opts = 0;
|
||||
int ret = 0;
|
||||
|
||||
if (!device_is_ready(flash_dev)) {
|
||||
LOG_ERR("flash dev not ready");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = flash_ex_op(flash_dev, FLASH_STM32_EX_OP_OPTB_READ, (uintptr_t)NULL, &opts);
|
||||
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Failed to read option bytes with flash ext op (%d)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
LOG_DBG("Current option bytes: %02X\n", opts);
|
||||
|
||||
if (opts & FLASH_OPTR_nBOOT_SEL) {
|
||||
WRITE_BIT(opts, FLASH_OPTR_nBOOT_SEL_Pos, false);
|
||||
|
||||
LOG_DBG("Writing new option bytes %02X\n", opts);
|
||||
ret = flash_ex_op(flash_dev, FLASH_STM32_EX_OP_OPTB_WRITE, opts, NULL);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Failed to write new option bytes (%d)", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SYS_INIT(stm32_enforce_nboot_sel_init, APPLICATION, 10);
|
||||
Reference in New Issue
Block a user