From 5fec1105c03e4d298e96287bb97a98db05c6e125 Mon Sep 17 00:00:00 2001 From: JakubBrachTieto Date: Thu, 9 Feb 2017 23:55:56 +0100 Subject: [PATCH] FIX for Flash problems (#1252) Platform crash on Flash Write - FIXED Platform crash on Flash Erase - FIXED --- examples/Makefile-da15000 | 4 +- examples/platforms/da15000/README.md | 6 ++- .../platforms/da15000/custom_config_qspi.h | 7 +++ examples/platforms/da15000/flash.c | 50 +++++-------------- .../da15000/openthread-core-da15000-config.h | 2 + 5 files changed, 28 insertions(+), 41 deletions(-) diff --git a/examples/Makefile-da15000 b/examples/Makefile-da15000 index 2ccbb95ca..2584b4b88 100644 --- a/examples/Makefile-da15000 +++ b/examples/Makefile-da15000 @@ -72,8 +72,8 @@ endif TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST)))).. AbsTopSourceDir := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))).. -CONFIG_FILE = OPENTHREAD_PROJECT_CORE_CONFIG_FILE='\"openthread-core-da15000-config.h\"' -CONFIG_FILE_PATH = $(AbsTopSourceDir)/examples/platforms/da15000/ +CONFIG_FILE = OPENTHREAD_PROJECT_CORE_CONFIG_FILE='\"openthread-core-da15000-config.h\"' +CONFIG_FILE_PATH = $(AbsTopSourceDir)/examples/platforms/da15000/ COMMONCFLAGS := \ -fdata-sections \ diff --git a/examples/platforms/da15000/README.md b/examples/platforms/da15000/README.md index d37ac5f51..c8b6fa05b 100755 --- a/examples/platforms/da15000/README.md +++ b/examples/platforms/da15000/README.md @@ -5,7 +5,9 @@ This directory contains example platform drivers for the [Dialog Semiconductor D [da15000]: https://support.dialog-semiconductor.com/connectivity/product/openthread-sandbox **NOTE:** Each Thread node requires a unique EUI-64. -Please make sure all Thread nodes in your network have a unique EUI-64 by setting NODE_ID in radio.c to a unique value. +Please make sure all Thread nodes in your network have a unique EUI-64 by setting HARDCODED_NODE_ID in radio.c to a unique value. + +**NOTE:** Current version works only with DA15000 rev. BA ## Build Examples (How to build and flash): ```bash @@ -113,7 +115,7 @@ Board will indicate state of device according to LED blink speed. ## Remarks * Validation - The DA15000 example has been validated by Dialog Semiconductor with commit 0bc2efe included. + The DA15000 example has been validated by Dialog Semiconductor with commit d250105 included. * Build environment diff --git a/examples/platforms/da15000/custom_config_qspi.h b/examples/platforms/da15000/custom_config_qspi.h index 2d420bed7..2181f46fc 100755 --- a/examples/platforms/da15000/custom_config_qspi.h +++ b/examples/platforms/da15000/custom_config_qspi.h @@ -115,4 +115,11 @@ /* Include bsp default values */ #include "bsp_defaults.h" + +/*************************************************************************************************\ + * Open Thread specific config + */ + +#define SETTINGS_CONFIG_BASE_ADDRESS (0x7B000) + #endif /* CUSTOM_CONFIG_QSPI_H_ */ diff --git a/examples/platforms/da15000/flash.c b/examples/platforms/da15000/flash.c index b5102712e..111fc0290 100644 --- a/examples/platforms/da15000/flash.c +++ b/examples/platforms/da15000/flash.c @@ -33,10 +33,8 @@ #include "platform/alarm.h" #include "openthread-config.h" -#define FLASH_SECTOR_SIZE 0x1000 -#define FLASH_PAGE_SIZE 0x0100 -#define FLASH_BUFFER_SIZE 0x2000 // 8kB -#define FLASH_OFFSET 0x7B000 // Flash memory size is 512kB (0x7D000) and starts from 0x8000000. Offset point to 500kB position +#define FLASH_SECTOR_SIZE 0x1000 +#define FLASH_BUFFER_SIZE 0x2000 #define W25Q_READ_STATUS_REGISTER1 0x05 @@ -46,27 +44,27 @@ static uint32_t sWaitStatusTimeout; -QSPI_SECTION static inline uint8_t qspi_get_erase_status(void) +QSPI_SECTION static uint8_t qspi_get_erase_status(void) { QSPIC->QSPIC_CHCKERASE_REG = 0; return HW_QSPIC_REG_GETF(ERASECTRL, ERS_STATE); } +volatile bool DisableErase = false; + // Erase QSPI memory section as non-blocking function. Remember to check utilsFlashStatusWait before write or read!! ThreadError utilsFlashErasePage(uint32_t aAddress) { - uint32_t flash_offset = (aAddress + FLASH_OFFSET) & ~(FLASH_SECTOR_SIZE - 1); + uint32_t flash_offset = (aAddress) & ~(FLASH_SECTOR_SIZE - 1); - if (aAddress > FLASH_BUFFER_SIZE) + if (DisableErase) { - return kThreadError_InvalidArgs; + return kThreadError_None; } - /* Setup erase block page */ - HW_QSPIC_REG_SETF(ERASECTRL, ERS_ADDR, (flash_offset >>= 4)); - /* Fire erase */ - HW_QSPIC_REG_SETF(ERASECTRL, ERASE_EN, 1); + qspi_automode_init(); + qspi_automode_erase_flash_sector(flash_offset); CACHE->CACHE_CTRL1_REG = CACHE_CACHE_CTRL1_REG_CACHE_FLUSH_Msk; @@ -113,44 +111,22 @@ ThreadError utilsFlashInit(void) uint32_t utilsFlashWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize) { - uint32_t flash_offset = (aAddress + FLASH_OFFSET); - return flash_offset; -} - -uint32_t utilsFlashWrite2(uint32_t aAddress, uint8_t *aData, uint32_t aSize) -{ - - uint32_t flash_offset = (aAddress + FLASH_OFFSET); size_t offset = 0; size_t written; - while (flash_offset < (aAddress + FLASH_OFFSET) + aSize) - { - qspi_automode_erase_flash_sector(flash_offset); - flash_offset += FLASH_SECTOR_SIZE; - } - - flash_offset = (aAddress + FLASH_OFFSET); - while (offset < aSize) { - written = qspi_automode_write_flash_page(flash_offset + offset, aData + offset, + written = qspi_automode_write_flash_page(aAddress + offset, aData + offset, aSize - offset); offset += written; } - return flash_offset; + return offset; } uint32_t utilsFlashRead(uint32_t aAddress, uint8_t *aData, uint32_t aSize) { - - size_t written = 0; - size_t offset = 0; - uint32_t flash_offset = (aAddress + FLASH_OFFSET); - - memcpy(aData, (void *)(MEMORY_QSPIF_BASE + flash_offset), aSize); - + memcpy(aData, (void *)(MEMORY_QSPIF_BASE + aAddress), aSize); return aSize; } diff --git a/examples/platforms/da15000/openthread-core-da15000-config.h b/examples/platforms/da15000/openthread-core-da15000-config.h index 8aa8ca69d..e15ef3804 100644 --- a/examples/platforms/da15000/openthread-core-da15000-config.h +++ b/examples/platforms/da15000/openthread-core-da15000-config.h @@ -34,6 +34,8 @@ #ifndef OPENTHREAD_CORE_DA15000_CONFIG_H_ #define OPENTHREAD_CORE_DA15000_CONFIG_H_ +#define SETTINGS_CONFIG_BASE_ADDRESS (0x7B000) + /** * @def OPENTHREAD_CONFIG_ENABLE_SOFTWARE_ACK_TIMEOUT *