EEPROM works and is upgraded and simplified

This commit is contained in:
philsson 2016-09-29 13:07:23 +02:00
parent a11e12b943
commit 7271ac3138
8 changed files with 155 additions and 3 deletions

View File

@ -18,7 +18,7 @@
<folderInfo id="fr.ac6.managedbuild.config.gnu.cross.exe.debug.481240413." name="/" resourcePath="">
<toolChain id="fr.ac6.managedbuild.toolchain.gnu.cross.exe.debug.295955206" name="Ac6 STM32 MCU GCC" superClass="fr.ac6.managedbuild.toolchain.gnu.cross.exe.debug">
<option id="fr.ac6.managedbuild.option.gnu.cross.mcu.728056451" name="Mcu" superClass="fr.ac6.managedbuild.option.gnu.cross.mcu" value="STM32F411RETx" valueType="string"/>
<option id="fr.ac6.managedbuild.option.gnu.cross.board.1263844362" name="Board" superClass="fr.ac6.managedbuild.option.gnu.cross.board" value="REVOLUTION" valueType="string"/>
<option id="fr.ac6.managedbuild.option.gnu.cross.board.1263844362" name="Board" superClass="fr.ac6.managedbuild.option.gnu.cross.board" value="ghghgg" valueType="string"/>
<option id="fr.ac6.managedbuild.option.gnu.cross.fpu.671755796" name="Floating point hardware" superClass="fr.ac6.managedbuild.option.gnu.cross.fpu" value="fr.ac6.managedbuild.option.gnu.cross.fpu.fpv4-sp-d16" valueType="enumerated"/>
<option id="fr.ac6.managedbuild.option.gnu.cross.floatabi.1146149208" name="Floating-point ABI" superClass="fr.ac6.managedbuild.option.gnu.cross.floatabi" value="fr.ac6.managedbuild.option.gnu.cross.floatabi.hard" valueType="enumerated"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="fr.ac6.managedbuild.targetPlatform.gnu.cross.430339287" isAbstract="false" osList="all" superClass="fr.ac6.managedbuild.targetPlatform.gnu.cross"/>
@ -115,7 +115,7 @@
<folderInfo id="fr.ac6.managedbuild.config.gnu.cross.exe.release.811843261." name="/" resourcePath="">
<toolChain id="fr.ac6.managedbuild.toolchain.gnu.cross.exe.release.952021771" name="Ac6 STM32 MCU GCC" superClass="fr.ac6.managedbuild.toolchain.gnu.cross.exe.release">
<option id="fr.ac6.managedbuild.option.gnu.cross.mcu.1696125784" name="Mcu" superClass="fr.ac6.managedbuild.option.gnu.cross.mcu" value="STM32F411RETx" valueType="string"/>
<option id="fr.ac6.managedbuild.option.gnu.cross.board.1384448238" name="Board" superClass="fr.ac6.managedbuild.option.gnu.cross.board" value="REVOLUTION" valueType="string"/>
<option id="fr.ac6.managedbuild.option.gnu.cross.board.1384448238" name="Board" superClass="fr.ac6.managedbuild.option.gnu.cross.board" value="ghghgg" valueType="string"/>
<option id="fr.ac6.managedbuild.option.gnu.cross.fpu.727746173" name="Floating point hardware" superClass="fr.ac6.managedbuild.option.gnu.cross.fpu" value="fr.ac6.managedbuild.option.gnu.cross.fpu.fpv4-sp-d16" valueType="enumerated"/>
<option id="fr.ac6.managedbuild.option.gnu.cross.floatabi.762455993" name="Floating-point ABI" superClass="fr.ac6.managedbuild.option.gnu.cross.floatabi" value="fr.ac6.managedbuild.option.gnu.cross.floatabi.hard" valueType="enumerated"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="fr.ac6.managedbuild.targetPlatform.gnu.cross.2039604312" isAbstract="false" osList="all" superClass="fr.ac6.managedbuild.targetPlatform.gnu.cross"/>

View File

@ -0,0 +1,20 @@
/*
* eeprom.h
*
* Created on: 29 sep. 2016
* Author: Philip
*/
#ifndef CONFIG_EEPROM_H_
#define CONFIG_EEPROM_H_
/* Defines where emulated EEPROM starts from - OBS! Also defined in LinkerScript.id */
#define EEPROM_BASE_ADDR 0x080E0000
void writeEEPROM();
void readEEPROM();
#endif /* CONFIG_EEPROM_H_ */

View File

@ -30,6 +30,16 @@
#include "stm32f4xx.h"
/* Voltage and current scaling values */
struct
{
uint32_t vcc_scale;
uint32_t i_scale_left;
uint32_t i_scale_right;
} adcScaleStruct_t;
/***********************************************************************
* BRIEF: Configuration of ADC *
* INFORMATION: Also initializes *

View File

@ -23,6 +23,8 @@
#pragma once
extern bool uart1_rx_inverter;
/***********************************************************************
* BRIEF: Init Inverter *
* INFORMATION: Must be ran before inversion can be activated. *

View File

@ -1,4 +1,3 @@
/*
/**********************************************************************
* NAME: adc.h *
* AUTHOR: Philip Johansson *

View File

@ -0,0 +1,99 @@
/*
* eeprom.c
*
* Created on: 29 sep. 2016
* Author: Philip
*/
#include "config/eeprom.h"
#include "drivers/adc.h"
#include "drivers/uart1_inverter.h"
//place in eeprom.h
typedef enum {
EEPROM_ADC_SCALES = 0,
EEPROM_UART1_RX_INV,
// EEPROM_PID_PITCH_KP,
// EEPROM_PID_PITCH_KD,
// EEPROM_PID_PITCH_KI,
// EEPROM_DATA_STRUCT,
// EEPROM_DATA_STRUCT2,
EEPROM_COUNT // Needs to be the last element as is used as counter
} EEPROM_ID_t;
typedef struct
{
uint32_t writeTypeId;
uint32_t size; //Size of the data
void * dataPtr; //pointer to the data, that should be saved to EEPROM
uint32_t padding[];
}EEPROM_DATA_t;
EEPROM_DATA_t eepromArr[EEPROM_COUNT] = {
[EEPROM_ADC_SCALES] =
{
//.writeTypeId = EEPROM_WRITE_TYPE_UINT32,
.size = sizeof(adcScaleStruct_t),
.dataPtr = &adcScaleStruct_t,
},
[EEPROM_UART1_RX_INV] =
{
.size = sizeof(bool),
.dataPtr = &uart1_rx_inverter,
}
};
void writeEepromExtension(uint32_t addr, uint32_t id)
{
for (int i = 0; i < eepromArr[id].size; i ++)
HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, addr + i , *((uint8_t*)(eepromArr[id].dataPtr + i)));
}
void writeEEPROM()
{
/* Add size and a pointer to the data for each value
* Each value when saved will store the data that it points to.
* When loaded the system will know what the value for each id should
* point to and it can read the data directly to that value which is pointed to*/
///////////////// TEST WITHOUT PADDING
uint32_t addrIterator = EEPROM_BASE_ADDR;
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGSERR );
//FLASH_Erase_Sector(((uint32_t)11U),VOLTAGE_RANGE_3);
FLASH_Erase_Sector(((uint32_t)FLASH_SECTOR_11),VOLTAGE_RANGE_3);
for (int i = 0; i < EEPROM_COUNT; i ++)
{
writeEepromExtension(addrIterator, i);
addrIterator += eepromArr[i].size;
}
HAL_FLASH_Lock();
}
void readEepromExtension(uint32_t addr, uint32_t id)
{
for (int i = 0; i < eepromArr[id].size; i++)
*(uint8_t*)(eepromArr[id].dataPtr + i) = *( uint8_t*)(addr + i * sizeof(uint8_t));
}
void readEEPROM()
{
///////////////// TEST WITHOUT PADDING
uint32_t addrIterator = EEPROM_BASE_ADDR;
HAL_FLASH_Unlock();
HAL_Delay(100);
for (int i = 0; i < EEPROM_COUNT; i ++)
{
readEepromExtension(addrIterator, i);
addrIterator += eepromArr[i].size;
}
HAL_FLASH_Lock();
}

View File

@ -24,6 +24,9 @@
#include "utilities.h"
#include <stdlib.h>
/* EEPROM value - Initialized here if EEPROM corrupted or reset */
bool uart1_rx_inverter = 0;
/* A buffer for the ADC to write with DMA */
enum{ ADC_BUFFER_LENGTH = 10 }; // TODO: Make this define instead of enum
uint32_t g_ADCBuffer[160] = {0}; // We allocate more than needed. Gives 10 readings on 16ch

View File

@ -11,11 +11,13 @@
#include "drivers/adc.h"
#include "config/eeprom.h"
#include "drivers/system_clock.h"
#include "stm32f4xx.h"
#include "system_variables.h"
#include "utilities.h"
#include <string.h>
#include "drivers/uart1_inverter.h"
int main(void)
@ -27,6 +29,23 @@ int main(void)
// Configure the system clock to 100 MHz
system_clock_config();
adcScaleStruct_t.vcc_scale = 20;
adcScaleStruct_t.i_scale_right = 10;
adcScaleStruct_t.i_scale_left = 30;
for(;;)
{
writeEEPROM();
readEEPROM();
adcScaleStruct_t.vcc_scale ++;
adcScaleStruct_t.i_scale_right ++;
adcScaleStruct_t.i_scale_left ++;
uart1_rx_inverter = !uart1_rx_inverter;
}
while(true);
int i = 1;