Skip to content

Commit

Permalink
Add flash protect function
Browse files Browse the repository at this point in the history
  • Loading branch information
ojousima committed Apr 20, 2023
1 parent 594a00a commit 6da4bd2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/app_sensor.c
Expand Up @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions src/main.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
*
Expand All @@ -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();
Expand Down

0 comments on commit 6da4bd2

Please sign in to comment.