mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Pull out settings flash calls
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "UnitSettings.h"
|
#include "UnitSettings.h"
|
||||||
#include "BSP_QC.h"
|
#include "BSP_QC.h"
|
||||||
|
#include "BSP_Flash.h"
|
||||||
/*
|
/*
|
||||||
* BSP.h -- Board Support
|
* BSP.h -- Board Support
|
||||||
*
|
*
|
||||||
|
|||||||
26
workspace/TS100/Core/BSP/BSP_Flash.h
Normal file
26
workspace/TS100/Core/BSP/BSP_Flash.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* BSP_Flash.h
|
||||||
|
*
|
||||||
|
* Created on: 29 May 2020
|
||||||
|
* Author: Ralim
|
||||||
|
*/
|
||||||
|
#include "stdint.h"
|
||||||
|
#ifndef BSP_BSP_FLASH_H_
|
||||||
|
#define BSP_BSP_FLASH_H_
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
* Wrappers to allow read/writing to a sector of flash that we use to store all of the user settings
|
||||||
|
*
|
||||||
|
* Should allow reading and writing to the flash
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Erase the flash, then save the buffer. Returns 1 if worked
|
||||||
|
uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length);
|
||||||
|
|
||||||
|
void flash_read_buffer(uint8_t *buffer, const uint16_t length);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif /* BSP_BSP_FLASH_H_ */
|
||||||
49
workspace/TS100/Core/BSP/Miniware/flash.c
Normal file
49
workspace/TS100/Core/BSP/Miniware/flash.c
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* flash.c
|
||||||
|
*
|
||||||
|
* Created on: 29 May 2020
|
||||||
|
* Author: Ralim
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "BSP_Flash.h"
|
||||||
|
#include "BSP.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "stm32f1xx_hal.h"
|
||||||
|
/*Flash start OR'ed with the maximum amount of flash - 1024 bytes*/
|
||||||
|
/*We use the last 1024 byte page*/
|
||||||
|
#define FLASH_ADDR (0x8000000 |0xFC00)
|
||||||
|
uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length) {
|
||||||
|
FLASH_EraseInitTypeDef pEraseInit;
|
||||||
|
pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||||
|
pEraseInit.Banks = FLASH_BANK_1;
|
||||||
|
pEraseInit.NbPages = 1;
|
||||||
|
pEraseInit.PageAddress = FLASH_ADDR;
|
||||||
|
uint32_t failingAddress = 0;
|
||||||
|
resetWatchdog();
|
||||||
|
__HAL_FLASH_CLEAR_FLAG(
|
||||||
|
FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | FLASH_FLAG_BSY);
|
||||||
|
HAL_FLASH_Unlock();
|
||||||
|
HAL_Delay(10);
|
||||||
|
resetWatchdog();
|
||||||
|
HAL_FLASHEx_Erase(&pEraseInit, &failingAddress);
|
||||||
|
//^ Erase the page of flash (1024 bytes on this stm32)
|
||||||
|
// erased the chunk
|
||||||
|
// now we program it
|
||||||
|
uint16_t *data = (uint16_t*) buffer;
|
||||||
|
HAL_FLASH_Unlock();
|
||||||
|
for (uint8_t i = 0; i < (length / 2); i++) {
|
||||||
|
resetWatchdog();
|
||||||
|
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, FLASH_ADDR + (i * 2),
|
||||||
|
data[i]);
|
||||||
|
}
|
||||||
|
HAL_FLASH_Lock();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void flash_read_buffer(uint8_t *buffer, const uint16_t length) {
|
||||||
|
|
||||||
|
uint16_t *data = (uint16_t*) buffer;
|
||||||
|
for (uint8_t i = 0; i < (length / 2); i++) {
|
||||||
|
data[i] = *((uint16_t*) (FLASH_ADDR + (i * 2)));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "Setup.h"
|
#include "Setup.h"
|
||||||
#include "../../configuration.h"
|
#include "../../configuration.h"
|
||||||
|
#include "BSP.h"
|
||||||
#define FLASH_ADDR \
|
#define FLASH_ADDR \
|
||||||
(0x8000000 | \
|
(0x8000000 | \
|
||||||
0xFC00) /*Flash start OR'ed with the maximum amount of flash - 1024 bytes*/
|
0xFC00) /*Flash start OR'ed with the maximum amount of flash - 1024 bytes*/
|
||||||
@@ -19,39 +20,12 @@ volatile systemSettingsType systemSettings;
|
|||||||
|
|
||||||
void saveSettings() {
|
void saveSettings() {
|
||||||
// First we erase the flash
|
// First we erase the flash
|
||||||
FLASH_EraseInitTypeDef pEraseInit;
|
flash_save_buffer((uint8_t*) &systemSettings, sizeof(systemSettingsType));
|
||||||
pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
|
|
||||||
pEraseInit.Banks = FLASH_BANK_1;
|
|
||||||
pEraseInit.NbPages = 1;
|
|
||||||
pEraseInit.PageAddress = FLASH_ADDR;
|
|
||||||
uint32_t failingAddress = 0;
|
|
||||||
HAL_IWDG_Refresh(&hiwdg);
|
|
||||||
__HAL_FLASH_CLEAR_FLAG(
|
|
||||||
FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | FLASH_FLAG_BSY);
|
|
||||||
HAL_FLASH_Unlock();
|
|
||||||
HAL_Delay(10);
|
|
||||||
HAL_IWDG_Refresh(&hiwdg);
|
|
||||||
HAL_FLASHEx_Erase(&pEraseInit, &failingAddress);
|
|
||||||
//^ Erase the page of flash (1024 bytes on this stm32)
|
|
||||||
// erased the chunk
|
|
||||||
// now we program it
|
|
||||||
uint16_t *data = (uint16_t*) &systemSettings;
|
|
||||||
HAL_FLASH_Unlock();
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < (sizeof(systemSettingsType) / 2); i++) {
|
|
||||||
HAL_IWDG_Refresh(&hiwdg);
|
|
||||||
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, FLASH_ADDR + (i * 2),
|
|
||||||
data[i]);
|
|
||||||
}
|
|
||||||
HAL_FLASH_Lock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool restoreSettings() {
|
bool restoreSettings() {
|
||||||
// We read the flash
|
// We read the flash
|
||||||
uint16_t *data = (uint16_t*) &systemSettings;
|
flash_read_buffer((uint8_t*) &systemSettings, sizeof(systemSettingsType));
|
||||||
for (uint8_t i = 0; i < (sizeof(systemSettingsType) / 2); i++) {
|
|
||||||
data[i] = *((uint16_t*) (FLASH_ADDR + (i * 2)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the version is correct were done
|
// if the version is correct were done
|
||||||
// if not we reset and save
|
// if not we reset and save
|
||||||
@@ -80,12 +54,12 @@ void resetSettings() {
|
|||||||
memset((void*) &systemSettings, 0, sizeof(systemSettingsType));
|
memset((void*) &systemSettings, 0, sizeof(systemSettingsType));
|
||||||
systemSettings.SleepTemp = SLEEP_TEMP; // Temperature the iron sleeps at - default 150.0 C
|
systemSettings.SleepTemp = SLEEP_TEMP; // Temperature the iron sleeps at - default 150.0 C
|
||||||
systemSettings.SleepTime = SLEEP_TIME; // How many seconds/minutes we wait until going
|
systemSettings.SleepTime = SLEEP_TIME; // How many seconds/minutes we wait until going
|
||||||
// to sleep - default 1 min
|
// to sleep - default 1 min
|
||||||
systemSettings.SolderingTemp = SOLDERING_TEMP; // Default soldering temp is 320.0 C
|
systemSettings.SolderingTemp = SOLDERING_TEMP; // Default soldering temp is 320.0 C
|
||||||
systemSettings.cutoutSetting = CUT_OUT_SETTING; // default to no cut-off voltage (or 18W for TS80)
|
systemSettings.cutoutSetting = CUT_OUT_SETTING; // default to no cut-off voltage (or 18W for TS80)
|
||||||
systemSettings.version =
|
systemSettings.version =
|
||||||
SETTINGSVERSION; // Store the version number to allow for easier upgrades
|
SETTINGSVERSION; // Store the version number to allow for easier upgrades
|
||||||
systemSettings.detailedSoldering = DETAILED_SOLDERING; // Detailed soldering screen
|
systemSettings.detailedSoldering = DETAILED_SOLDERING; // Detailed soldering screen
|
||||||
systemSettings.detailedIDLE = DETAILED_IDLE; // Detailed idle screen (off for first time users)
|
systemSettings.detailedIDLE = DETAILED_IDLE; // Detailed idle screen (off for first time users)
|
||||||
systemSettings.OrientationMode = ORIENTATION_MODE; // Default to automatic
|
systemSettings.OrientationMode = ORIENTATION_MODE; // Default to automatic
|
||||||
systemSettings.sensitivity = SENSITIVITY; // Default high sensitivity
|
systemSettings.sensitivity = SENSITIVITY; // Default high sensitivity
|
||||||
@@ -93,19 +67,19 @@ void resetSettings() {
|
|||||||
systemSettings.ShutdownTime = SHUTDOWN_TIME; // How many minutes until the unit turns itself off
|
systemSettings.ShutdownTime = SHUTDOWN_TIME; // How many minutes until the unit turns itself off
|
||||||
systemSettings.boostModeEnabled = BOOST_MODE_ENABLED; // Default to having boost mode on as most people prefer it
|
systemSettings.boostModeEnabled = BOOST_MODE_ENABLED; // Default to having boost mode on as most people prefer it
|
||||||
systemSettings.BoostTemp = BOOST_TEMP; // default to 400C
|
systemSettings.BoostTemp = BOOST_TEMP; // default to 400C
|
||||||
systemSettings.autoStartMode = AUTO_START_MODE; // Auto start off for safety
|
systemSettings.autoStartMode = AUTO_START_MODE; // Auto start off for safety
|
||||||
systemSettings.coolingTempBlink = COOLING_TEMP_BLINK; // Blink the temperature on the cooling screen when its > 50C
|
systemSettings.coolingTempBlink = COOLING_TEMP_BLINK; // Blink the temperature on the cooling screen when its > 50C
|
||||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||||
systemSettings.temperatureInF = TEMPERATURE_INF; // default to 0
|
systemSettings.temperatureInF = TEMPERATURE_INF; // default to 0
|
||||||
#endif
|
#endif
|
||||||
systemSettings.descriptionScrollSpeed = DESCRIPTION_SCROLL_SPEED; // default to slow
|
systemSettings.descriptionScrollSpeed = DESCRIPTION_SCROLL_SPEED; // default to slow
|
||||||
systemSettings.powerLimitEnable = POWER_LIMIT_ENABLE; // Default to no power limit
|
systemSettings.powerLimitEnable = POWER_LIMIT_ENABLE; // Default to no power limit
|
||||||
systemSettings.CalibrationOffset = CALIBRATION_OFFSET; // the adc offset in uV
|
systemSettings.CalibrationOffset = CALIBRATION_OFFSET; // the adc offset in uV
|
||||||
systemSettings.powerLimit = POWER_LIMIT; // 30 watts default limit
|
systemSettings.powerLimit = POWER_LIMIT; // 30 watts default limit
|
||||||
systemSettings.ReverseButtonTempChangeEnabled = REVERSE_BUTTON_TEMP_CHANGE; //
|
systemSettings.ReverseButtonTempChangeEnabled = REVERSE_BUTTON_TEMP_CHANGE; //
|
||||||
systemSettings.TempChangeShortStep = TEMP_CHANGE_SHORT_STEP; //
|
systemSettings.TempChangeShortStep = TEMP_CHANGE_SHORT_STEP; //
|
||||||
systemSettings.TempChangeLongStep = TEMP_CHANGE_LONG_STEP; //
|
systemSettings.TempChangeLongStep = TEMP_CHANGE_LONG_STEP; //
|
||||||
systemSettings.KeepAwakePulse= POWER_PULSE_DEFAULT;
|
systemSettings.KeepAwakePulse = POWER_PULSE_DEFAULT;
|
||||||
systemSettings.TipGain = TIP_GAIN;
|
systemSettings.TipGain = TIP_GAIN;
|
||||||
saveSettings(); // Save defaults
|
saveSettings(); // Save defaults
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
#include "../../configuration.h"
|
#include "../../configuration.h"
|
||||||
#include "Buttons.hpp"
|
#include "Buttons.hpp"
|
||||||
extern uint32_t lastButtonTime;
|
|
||||||
void gui_Menu(const menuitem *menu);
|
void gui_Menu(const menuitem *menu);
|
||||||
|
|
||||||
#ifdef MODEL_TS100
|
#ifdef MODEL_TS100
|
||||||
|
|||||||
@@ -5,23 +5,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
|
|
||||||
#include <gui.hpp>
|
|
||||||
#include <main.hpp>
|
#include <main.hpp>
|
||||||
#include "LIS2DH12.hpp"
|
#include "LIS2DH12.hpp"
|
||||||
#include <MMA8652FC.hpp>
|
#include <MMA8652FC.hpp>
|
||||||
#include <history.hpp>
|
|
||||||
#include <power.hpp>
|
#include <power.hpp>
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "Translation.h"
|
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include "stdlib.h"
|
|
||||||
#include "stm32f1xx_hal.h"
|
|
||||||
#include "string.h"
|
|
||||||
#include "TipThermoModel.h"
|
|
||||||
uint8_t PCBVersion = 0;
|
uint8_t PCBVersion = 0;
|
||||||
// File local variables
|
// File local variables
|
||||||
uint32_t currentTempTargetDegC = 0; // Current temperature target in C
|
|
||||||
|
|
||||||
bool settingsWereReset = false;
|
bool settingsWereReset = false;
|
||||||
// FreeRTOS variables
|
// FreeRTOS variables
|
||||||
@@ -51,6 +42,8 @@ int main(void) {
|
|||||||
OLED::setFont(0); // default to bigger font
|
OLED::setFont(0); // default to bigger font
|
||||||
// Testing for which accelerometer is mounted
|
// Testing for which accelerometer is mounted
|
||||||
resetWatchdog();
|
resetWatchdog();
|
||||||
|
resetWatchdog();
|
||||||
|
settingsWereReset = restoreSettings(); // load the settings from flash
|
||||||
if (MMA8652FC::detect()) {
|
if (MMA8652FC::detect()) {
|
||||||
PCBVersion = 1;
|
PCBVersion = 1;
|
||||||
MMA8652FC::initalize(); // this sets up the I2C registers
|
MMA8652FC::initalize(); // this sets up the I2C registers
|
||||||
@@ -64,8 +57,6 @@ int main(void) {
|
|||||||
systemSettings.ShutdownTime = 0; // No accel -> disable sleep
|
systemSettings.ShutdownTime = 0; // No accel -> disable sleep
|
||||||
systemSettings.sensitivity = 0;
|
systemSettings.sensitivity = 0;
|
||||||
}
|
}
|
||||||
resetWatchdog();
|
|
||||||
settingsWereReset = restoreSettings(); // load the settings from flash
|
|
||||||
|
|
||||||
resetWatchdog();
|
resetWatchdog();
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
static TickType_t powerPulseRate = 1000;
|
static TickType_t powerPulseRate = 1000;
|
||||||
static TickType_t powerPulseDuration = 50;
|
static TickType_t powerPulseDuration = 50;
|
||||||
TaskHandle_t pidTaskNotification = NULL;
|
TaskHandle_t pidTaskNotification = NULL;
|
||||||
|
uint32_t currentTempTargetDegC = 0; // Current temperature target in C
|
||||||
|
|
||||||
/* StartPIDTask function */
|
/* StartPIDTask function */
|
||||||
void startPIDTask(void const *argument __unused) {
|
void startPIDTask(void const *argument __unused) {
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user