diff --git a/boards/arm/mppt_2420_hc/mppt_2420_hc_0_2_0.conf b/boards/arm/mppt_2420_hc/mppt_2420_hc_0_2_0.conf index b85a808..a956d33 100644 --- a/boards/arm/mppt_2420_hc/mppt_2420_hc_0_2_0.conf +++ b/boards/arm/mppt_2420_hc/mppt_2420_hc_0_2_0.conf @@ -3,7 +3,6 @@ CONFIG_FLASH=y CONFIG_FLASH_PAGE_LAYOUT=y CONFIG_FLASH_LOG_LEVEL_WRN=y -#CONFIG_MPU_ALLOW_FLASH_WRITE=y CONFIG_SPI=y CONFIG_SPI_NOR=y diff --git a/boards/arm/mppt_2420_hc/mppt_2420_hc_defconfig b/boards/arm/mppt_2420_hc/mppt_2420_hc_defconfig index 6bb24ee..e1fdb80 100644 --- a/boards/arm/mppt_2420_hc/mppt_2420_hc_defconfig +++ b/boards/arm/mppt_2420_hc/mppt_2420_hc_defconfig @@ -55,6 +55,7 @@ CONFIG_UART_CONSOLE=y # Enable MPU CONFIG_ARM_MPU=y +CONFIG_MPU_ALLOW_FLASH_WRITE=y CONFIG_PWM=y diff --git a/src/hardware.cpp b/src/hardware.cpp index 4e07fa7..26e5d7d 100644 --- a/src/hardware.cpp +++ b/src/hardware.cpp @@ -20,7 +20,6 @@ #include #include -#include #include LOG_MODULE_REGISTER(hardware, CONFIG_HW_LOG_LEVEL); @@ -36,8 +35,12 @@ void start_stm32_bootloader() k_sleep(K_MSEC(100)); // wait for capacitor at BOOT0 pin to charge up reset_device(); #elif defined(CONFIG_SOC_SERIES_STM32G4X) - const struct device *flash = device_get_binding(DT_LABEL(DT_NODELABEL(flash0))); - flash_write_protection_set(flash, false); + if ((FLASH->CR & FLASH_CR_OPTLOCK) != 0U) { + /* Authorizes the Option Byte register programming */ + FLASH->OPTKEYR = FLASH_OPTKEY1; + FLASH->OPTKEYR = FLASH_OPTKEY2; + } + // Set proper bits for booting the embedded bootloader (see table // 5 in section 2.6.1 in document RM0440) @@ -60,7 +63,7 @@ void start_stm32_bootloader() // If OBL_LAUNCH did not reset (it should), we'll force it by // first locking back the flash registers and going for a reboot. - flash_write_protection_set(flash, true); + FLASH->CR |= FLASH_CR_OPTLOCK; reset_device(); #endif }