Re: EEPROM ,Worcking
Posted: Mon Mar 30, 2015 8:06 am
If you go in the megabytes range then probably the SD card is the correct choice, alternatively some huge dedicated flash memory connected on FSMC or SPI.
Giovanni
Giovanni
deadlyboy wrote:but as ulikoehler said : if you don't hate them you just haven't used them enough
Code: Select all
err = f_open(&FileObject, "0:chtest.txt", FA_READ | FA_OPEN_EXISTING);Code: Select all
/**
* @brief Writes one or more blocks.
*/
sdcWrite(&SDCD1,0,myBuffer,1)
sdcRead(&SDCD1,0,myBuffer1,1);
Code: Select all
static void initializeEEPROMEmulation(void) {
//Allow all flash operations
FLASH_Unlock();
//Format EEPROM if there is no valid page
EE_Init();
//Initialize values to 0 if no stored value is present
uint16_t dummy; //Just a dummy, data argument to EE_ReadVariable() must be != NULL
if(EE_ReadVariable(EEPROM_FIRST_VARIABLE, &dummy) == 1) { //Not found
EE_WriteVariable(EEPROM_FIRST_VARIABLE, 0);
EE_WriteVariable(EEPROM_SECOND_VARIABLE, 0);
EE_WriteVariable(EEPROM_THIRD_VARIABLE, 0);
}
}
Code: Select all
/**
* Virtual addresses
* stored in the EEPROM emulation
*/
const uint16_t VirtAddVarTab[NB_OF_VAR] = {
//Describe variables here
0x5555,
0x5556,
0x5558,
};
#define EEPROM_FIRST_VARIABLE (VirtAddVarTab[0])
#define EEPROM_SECOND_VARIABLE (VirtAddVarTab[1])
#define EEPROM_THIRD_VARIABLE (VirtAddVarTab[2])
Code: Select all
/*
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
* ST32F030F4 memory setup.
*/
__main_stack_size__ = 0x0100;
__process_stack_size__ = 0x0800;
MEMORY
{
/* 16k flash, but 2k used for EEPROM */
flash : org = 0x08000000, len = 14k
ram : org = 0x20000000, len = 4k
}
__ram_start__ = ORIGIN(ram);
__ram_size__ = LENGTH(ram);
__ram_end__ = __ram_start__ + __ram_size__;
ENTRY(ResetHandler)
SECTIONS
{
. = 0;
_text = .;
startup : ALIGN(16) SUBALIGN(16)
{
KEEP(*(vectors))
} > flash
constructors : ALIGN(4) SUBALIGN(4)
{
PROVIDE(__init_array_start = .);
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE(__init_array_end = .);
} > flash
destructors : ALIGN(4) SUBALIGN(4)
{
PROVIDE(__fini_array_start = .);
KEEP(*(.fini_array))
KEEP(*(SORT(.fini_array.*)))
PROVIDE(__fini_array_end = .);
} > flash
.text : ALIGN(16) SUBALIGN(16)
{
*(.text.startup.*)
*(.text)
*(.text.*)
*(.rodata)
*(.rodata.*)
*(.glue_7t)
*(.glue_7)
*(.gcc*)
} > flash
.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > flash
.ARM.exidx : {
PROVIDE(__exidx_start = .);
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
PROVIDE(__exidx_end = .);
} > flash
.eh_frame_hdr :
{
*(.eh_frame_hdr)
} > flash
.eh_frame : ONLY_IF_RO
{
*(.eh_frame)
} > flash
.textalign : ONLY_IF_RO
{
. = ALIGN(8);
} > flash
. = ALIGN(4);
_etext = .;
_textdata = _etext;
.stacks :
{
. = ALIGN(8);
__main_stack_base__ = .;
. += __main_stack_size__;
. = ALIGN(8);
__main_stack_end__ = .;
__process_stack_base__ = .;
__main_thread_stack_base__ = .;
. += __process_stack_size__;
. = ALIGN(8);
__process_stack_end__ = .;
__main_thread_stack_end__ = .;
} > ram
.data :
{
. = ALIGN(4);
PROVIDE(_data = .);
*(.data)
. = ALIGN(4);
*(.data.*)
. = ALIGN(4);
*(.ramtext)
. = ALIGN(4);
PROVIDE(_edata = .);
} > ram AT > flash
.bss :
{
. = ALIGN(4);
PROVIDE(_bss_start = .);
*(.bss)
. = ALIGN(4);
*(.bss.*)
. = ALIGN(4);
*(COMMON)
. = ALIGN(4);
PROVIDE(_bss_end = .);
} > ram
}
PROVIDE(end = .);
_end = .;
__heap_base__ = _end;
__heap_end__ = __ram_end__;
Code: Select all
/* Exported constants --------------------------------------------------------*/
/* Define the size of the sectors to be used */
#define PAGE_SIZE ((uint32_t)0x0400) /* Page size = 1KByte */
/* EEPROM start address in Flash */
#define EEPROM_START_ADDRESS ((uint32_t)0x08003800) /* EEPROM emulation start address:
from sector2, after 14KByte of used
Flash memory */
/* Pages 0 and 1 base and end addresses */
#define PAGE0_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x0000))
#define PAGE0_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (PAGE_SIZE - 1)))
#define PAGE1_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x0400))
#define PAGE1_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (2 * PAGE_SIZE - 1)))
/* Used Flash pages for EEPROM emulation */
#define PAGE0 ((uint16_t)0x0000)
#define PAGE1 ((uint16_t)0x0001)
/* No valid page define */
#define NO_VALID_PAGE ((uint16_t)0x00AB)
/* Page status definitions */
#define ERASED ((uint16_t)0xFFFF) /* Page is empty */
#define RECEIVE_DATA ((uint16_t)0xEEEE) /* Page is marked to receive data */
#define VALID_PAGE ((uint16_t)0x0000) /* Page containing valid data */
/* Valid pages in read and write defines */
#define READ_FROM_VALID_PAGE ((uint8_t)0x00)
#define WRITE_IN_VALID_PAGE ((uint8_t)0x01)
/* Page full define */
#define PAGE_FULL ((uint8_t)0x80)
/* Variables' number */
#define NB_OF_VAR ((uint8_t)0x05)