From b7044bb54ab4d48b0f2be150e3181de387cef47e Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Thu, 28 Aug 2014 13:45:07 +0200 Subject: [PATCH] Add support for user information block reading. (Use IAP for writting) --- core/user_information_block.c | 57 +++++++++++++++++++++++++++ include/core/user_information_block.h | 42 ++++++++++++++++++++ lpc_link_lpc1224.ld | 12 +++++- 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 core/user_information_block.c create mode 100644 include/core/user_information_block.h diff --git a/core/user_information_block.c b/core/user_information_block.c new file mode 100644 index 0000000..56a77e1 --- /dev/null +++ b/core/user_information_block.c @@ -0,0 +1,57 @@ +/**************************************************************************** + * core/user_information_block.c + * + * + * + * Copyright 2013-2014 Nathael Pajani + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *************************************************************************** */ + + +/* The user information block is persistant flash memory block which can be programmed + * and read by user code using IAP calls. + * It can provide the same functionnality as an EEPROM, though the reading access is + * much more simple. + * Writting to the user flash is slightly more complicated though, mainly because flash + * pages in the user information block are big 512 bytes blocks, much more than the + * usual small eeprom pages. + * One must erase a full page before modifying data in it, thus reading it first to RAM, + * modifying the RAM area, erasing the page, and then writting back. + * Reading/modify/write may be limited to the required size, but erase size will always + * be a full page. + */ + +/* The user information block of the LPC1224 has three 512 bytes pages. */ + +/* Actually, the only purpose of this code is to return the address of the begining + * of the user information block in flash, set by the linker from information in + * the liker script (lpc_link_lpc1224.ld). +*/ + +#include + + +extern unsigned int _start_info; +extern unsigned int _end_info; + +/* Get a pointer to the user information */ +void* get_user_info(void) +{ + return (void*)&_start_info; +} + + diff --git a/include/core/user_information_block.h b/include/core/user_information_block.h new file mode 100644 index 0000000..705f478 --- /dev/null +++ b/include/core/user_information_block.h @@ -0,0 +1,42 @@ +/**************************************************************************** + * core/user_information_block.h + * + * + * + * Copyright 2013-2014 Nathael Pajani + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *************************************************************************** */ + +#ifndef USER_INFORMATION_BLOCK_H +#define USER_INFORMATION_BLOCK_H + +#include + +struct user_info { + char name[48]; + uint32_t version; + uint32_t serial_number; + char user_info[8]; +} __attribute__ ((__packed__)); + + +/* Get a pointer to the begining address of the user information block in flash. */ +void* get_user_info(void); + + +#endif /* USER_INFORMATION_BLOCK_H */ + diff --git a/lpc_link_lpc1224.ld b/lpc_link_lpc1224.ld index 9318ad2..16b01a2 100644 --- a/lpc_link_lpc1224.ld +++ b/lpc_link_lpc1224.ld @@ -6,11 +6,13 @@ MEMORY { sram (rwx) : ORIGIN = 0x10000000, LENGTH = 4k flash (rx) : ORIGIN = 0x00000000, LENGTH = 32k + info (rx) : ORIGIN = 0x00040200, LENGTH = 1536 } _sram_size = 4k; _sram_base = 0x10000000; -_end_stack = (_sram_base + _sram_size); +/* Leave 32 bytes for IAP functions, see UM10441 Chapter 20, section 20.8 */ +_end_stack = (_sram_base + _sram_size - 32); ENTRY(Reset_Handler) @@ -49,6 +51,14 @@ SECTIONS { _end_bss = .; } >sram + . = ALIGN(4); + + .user_information_block : + { + _start_info = .; + *(.user_information_block*) + _end_info = .; + } >info . = ALIGN(4); } -- 2.43.0