From 6da4bd28c6887e475c737d7022842130bf5831c9 Mon Sep 17 00:00:00 2001 From: Otso Jousimaa Date: Thu, 20 Apr 2023 20:04:51 +0300 Subject: [PATCH] Add flash protect function --- src/app_sensor.c | 1 + src/main.c | 25 +++++++++++++++++++++++++ src/ruuvi.drivers.c | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/app_sensor.c b/src/app_sensor.c index 7dc341cc..fe9b6ab3 100644 --- a/src/app_sensor.c +++ b/src/app_sensor.c @@ -394,6 +394,7 @@ rd_status_t app_sensor_init (void) m_sensors[ii]->handle = APP_SENSOR_HANDLE_UNUSED; } } + // Reinit board with fastest speed supported by board + sensors. err_code |= app_sensor_buses_uninit(); err_code |= app_sensor_buses_init (i2c_freq); diff --git a/src/main.c b/src/main.c index f4550836..0cf76a0c 100644 --- a/src/main.c +++ b/src/main.c @@ -20,6 +20,7 @@ #include "main.h" #include "run_integration_tests.h" #include "ruuvi_interface_log.h" +#include "ruuvi_interface_flash.h" #include "ruuvi_interface_power.h" #include "ruuvi_interface_scheduler.h" #include "ruuvi_interface_timer.h" @@ -56,6 +57,29 @@ void app_on_error (const rd_status_t error, } } +#ifndef CEEDLING +static +#endif +rd_status_t protect_flash (void) +{ + rd_status_t err_code = RD_SUCCESS; + #if RI_FLASH_ENABLED + // Protect softdevice + for (size_t page = 0; page < 0x26; page++) + { + err_code |= ri_flash_protect (page); + } + + // Protect bootloader + for (size_t page = 0x75; page < 0x80; page++) + { + err_code |= ri_flash_protect (page); + } + #endif + + return err_code; +} + /** * @brief setup MCU peripherals and board peripherals. * @@ -68,6 +92,7 @@ void setup (void) err_code |= ri_watchdog_init (APP_WDT_INTERVAL_MS, &on_wdt); err_code |= ri_log_init (APP_LOG_LEVEL); // Logging to terminal. # endif + err_code |= protect_flash(); err_code |= ri_yield_init(); err_code |= ri_timer_init(); err_code |= ri_scheduler_init(); diff --git a/src/ruuvi.drivers.c b/src/ruuvi.drivers.c index 6ae15be4..a7c52da2 160000 --- a/src/ruuvi.drivers.c +++ b/src/ruuvi.drivers.c @@ -1 +1 @@ -Subproject commit 6ae15be47a80a06bff006ee25c326cd77152c094 +Subproject commit a7c52da20703703d7b64273e6d935f5d107144a9