mirror of
https://github.com/espressif/openthread.git
synced 2026-08-03 01:17:46 +00:00
[cc2538] fix FLASH settings location (#2070)
This commit is contained in:
committed by
Jonathan Hui
parent
ebf3acaa8e
commit
22ab6f26a6
@@ -202,7 +202,6 @@
|
||||
#define SOC_ADC_ADCCON1_RCTRL0 0x00000004 // ADCCON1 RCTRL bit 0
|
||||
#define SOC_ADC_ADCCON1_RCTRL1 0x00000008 // ADCCON1 RCTRL bit 1
|
||||
|
||||
#define FLASH_BASE 0x00200000 // Flash base address
|
||||
#define FLASH_CTRL_FCTL 0x400D3008 // Flash control
|
||||
#define FLASH_CTRL_DIECFG0 0x400D3014 // Flash information
|
||||
|
||||
|
||||
@@ -31,12 +31,54 @@
|
||||
* GCC linker script for CC2538.
|
||||
*/
|
||||
|
||||
_512k_bytes = (512*1024);
|
||||
_256k_bytes = (256*1024);
|
||||
_128k_bytes = (128*1024);
|
||||
_FLASH_page_size = 2048;
|
||||
|
||||
/*
|
||||
* Change for your chip, default is 512k chips
|
||||
*/
|
||||
_FLASH_size_bytes = _512k_bytes;
|
||||
_FLASH_n_pages = (_FLASH_size_bytes / _FLASH_page_size);
|
||||
/* reduce the usable size by: the CCA + settings Page A & B, total 3 pages */
|
||||
_FLASH_usable_size = (_FLASH_size_bytes - (3 * _FLASH_page_size));
|
||||
_FLASH_start = 0x00200000;
|
||||
_FLASH_end = (_FLASH_start + _FLASH_size_bytes);
|
||||
|
||||
/*
|
||||
* The CCA (Customer Configuration Area) is always the last page.
|
||||
* See: http://www.ti.com/lit/ug/swru319c/swru319c.pdf
|
||||
* table 8-2 for more details.
|
||||
*/
|
||||
_FLASH_cca_page = (_FLASH_end - (1 * _FLASH_page_size));
|
||||
|
||||
/*
|
||||
* OpenThread NV storage goes in the settings page.
|
||||
* OpenThread requires at least 2 adjacent pages, call them A and B.
|
||||
*/
|
||||
_FLASH_settings_pageB = (_FLASH_end - (2 * _FLASH_page_size));
|
||||
_FLASH_settings_pageA = (_FLASH_end - (3 * _FLASH_page_size));
|
||||
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x00200000, LENGTH = 0x0007FFD4
|
||||
FLASH_CCA (rx) : ORIGIN = 0x0027FFD4, LENGTH = 0x2C
|
||||
SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K
|
||||
/* would like to use SYMBOLS (from above)here but we cannot
|
||||
* GCC version 4.9 does not support symbolic expressions here.
|
||||
* But later versions do support the feature.
|
||||
*/
|
||||
FLASH (rx) : ORIGIN = 0x00200000, LENGTH = 0x0007c000
|
||||
FLASH_CCA (rx) : ORIGIN = 0x0027FFD4, LENGTH = 0x2c
|
||||
SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K
|
||||
}
|
||||
/*
|
||||
* To safty check what would have been the SYMBOL values
|
||||
* we use these ASSERTS to verify things are still good.
|
||||
*/
|
||||
ASSERT( _FLASH_start == 0x00200000, "invalid flash start address for cc2538")
|
||||
ASSERT( _FLASH_cca_page == 0x0027f800, "invalid cca start address for cc2538")
|
||||
ASSERT( _FLASH_usable_size == 0x0007e800, "Invalid usable size for this config")
|
||||
|
||||
|
||||
|
||||
ENTRY(flash_cca_lock_page)
|
||||
SECTIONS
|
||||
|
||||
@@ -26,25 +26,44 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <openthread/config.h>
|
||||
#include <openthread-core-config.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <openthread/config.h>
|
||||
#include <openthread/platform/alarm-milli.h>
|
||||
|
||||
#include "platform-cc2538.h"
|
||||
#include "rom-utility.h"
|
||||
#include "utils/code_utils.h"
|
||||
#include "utils/flash.h"
|
||||
#include "utils/wrap_string.h"
|
||||
|
||||
#define FLASH_CTRL_FCTL_BUSY 0x00000080
|
||||
|
||||
enum
|
||||
#if SETTINGS_CONFIG_PAGE_SIZE != 2048
|
||||
#error FLASH page size is 2048 on this chip
|
||||
#endif
|
||||
|
||||
#if SETTINGS_CONFIG_PAGE_NUM != 2
|
||||
#error Linker script reserves 2 pages for settings.
|
||||
#endif
|
||||
|
||||
/* The linker script creates this external symbol */
|
||||
extern uint8_t _FLASH_settings_pageA[];
|
||||
|
||||
/* Convert a settings offset to the physical address within the flash settings pages */
|
||||
static uint32_t flashPhysAddr(uint32_t settings_offset)
|
||||
{
|
||||
FLASH_PAGE_SIZE = 0x800,
|
||||
};
|
||||
uint32_t base;
|
||||
|
||||
base = (uint32_t)(&_FLASH_settings_pageA[0]);
|
||||
base = base + settings_offset;
|
||||
return base;
|
||||
}
|
||||
|
||||
static otError romStatusToThread(int32_t aStatus)
|
||||
{
|
||||
@@ -78,9 +97,7 @@ otError utilsFlashInit(void)
|
||||
|
||||
uint32_t utilsFlashGetSize(void)
|
||||
{
|
||||
uint32_t reg = (HWREG(FLASH_CTRL_DIECFG0) & 0x00000070) >> 4;
|
||||
|
||||
return reg ? (0x20000 * reg) : 0x10000;
|
||||
return (SETTINGS_CONFIG_PAGE_SIZE * SETTINGS_CONFIG_PAGE_NUM);
|
||||
}
|
||||
|
||||
otError utilsFlashErasePage(uint32_t aAddress)
|
||||
@@ -91,8 +108,9 @@ otError utilsFlashErasePage(uint32_t aAddress)
|
||||
|
||||
otEXPECT_ACTION(aAddress < utilsFlashGetSize(), error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
address = FLASH_BASE + aAddress - (aAddress & (FLASH_PAGE_SIZE - 1));
|
||||
status = ROM_PageErase(address, FLASH_PAGE_SIZE);
|
||||
address = aAddress - (aAddress & (SETTINGS_CONFIG_PAGE_SIZE - 1));
|
||||
address = flashPhysAddr(address);
|
||||
status = ROM_PageErase(address, SETTINGS_CONFIG_PAGE_SIZE);
|
||||
error = romStatusToThread(status);
|
||||
|
||||
exit:
|
||||
@@ -130,7 +148,7 @@ uint32_t utilsFlashWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize)
|
||||
|
||||
while (size < aSize)
|
||||
{
|
||||
status = ROM_ProgramFlash(data, aAddress + FLASH_BASE, 4);
|
||||
status = ROM_ProgramFlash(data, flashPhysAddr(aAddress), 4);
|
||||
|
||||
while (busy)
|
||||
{
|
||||
@@ -155,8 +173,7 @@ uint32_t utilsFlashRead(uint32_t aAddress, uint8_t *aData, uint32_t aSize)
|
||||
|
||||
while (size < aSize)
|
||||
{
|
||||
uint32_t reg = HWREG(aAddress + FLASH_BASE);
|
||||
uint8_t *byte = (uint8_t *)®
|
||||
uint8_t *byte = (uint8_t *)flashPhysAddr(aAddress);
|
||||
uint8_t maxIndex = 4;
|
||||
|
||||
if (size == (aSize - aSize % 4))
|
||||
|
||||
@@ -66,4 +66,23 @@
|
||||
*/
|
||||
#define OPENTHREAD_CONFIG_ENABLE_SOFTWARE_ENERGY_SCAN 1
|
||||
|
||||
/**
|
||||
* @def SETTINGS_CONFIG_BASE_ADDRESS
|
||||
*
|
||||
* The actual physical address used for the cc2538 is set by the
|
||||
* linker file, the value here is "relative to the base address" set
|
||||
* in the linker file.
|
||||
*/
|
||||
#define SETTINGS_CONFIG_BASE_ADDRESS 0
|
||||
|
||||
/**
|
||||
* @def The CC2538 linker script sets aside 2 pages.
|
||||
*/
|
||||
#define SETTINGS_CONFIG_PAGE_NUM 2
|
||||
|
||||
/**
|
||||
* @def The page size of settings, 2K bytes
|
||||
*/
|
||||
#define SETTINGS_CONFIG_PAGE_SIZE 2048
|
||||
|
||||
#endif // OPENTHREAD_CORE_CC2538_CONFIG_H_
|
||||
|
||||
Reference in New Issue
Block a user