NUC123: Dynamic CONFIG value read
This commit is contained in:
parent
c328f805c2
commit
e4ae11e8c6
|
@ -42,13 +42,17 @@
|
||||||
#define NUC123_SECTOR_SIZE 0x200UL
|
#define NUC123_SECTOR_SIZE 0x200UL
|
||||||
|
|
||||||
#define NUC123_LDROM_SIZE 0x1000UL
|
#define NUC123_LDROM_SIZE 0x1000UL
|
||||||
#define NUC123_APROM_SIZE (NUC123_FLASH_SIZE - NUC123_DATAFLASH_SIZE)
|
|
||||||
|
|
||||||
#define NUC123_EFL_CMD_ERASE 0x22UL
|
#define NUC123_EFL_CMD_ERASE 0x22UL
|
||||||
#define NUC123_EFL_CMD_PROG 0x21UL
|
#define NUC123_EFL_CMD_PROG 0x21UL
|
||||||
#define NUC123_EFL_CMD_READ 0UL
|
#define NUC123_EFL_CMD_READ 0UL
|
||||||
#define NUC123_EFL_CMD_CHIPERASE 0x26UL /* Undocumented */
|
#define NUC123_EFL_CMD_CHIPERASE 0x26UL /* Undocumented */
|
||||||
|
|
||||||
|
#if ((NUC123_CONFIG_ENABLED == FALSE) || (NUC123_EFL_ACCESS_CONFIG == TRUE)) && \
|
||||||
|
(NUC123_EFL_ACCESS_APROM == TRUE) && (NUC123_EFL_ACCESS_DATAFLASH == TRUE)
|
||||||
|
#define NUC123_EFL_DYNAMICALLY_CHECK_CONFIG TRUE
|
||||||
|
#endif
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Driver exported variables. */
|
/* Driver exported variables. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -64,48 +68,7 @@ EFlashDriver EFLD1;
|
||||||
/* Driver local variables and types. */
|
/* Driver local variables and types. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
static const flash_descriptor_t efl_lld_descriptors[] = {
|
static flash_descriptor_t efl_lld_descriptor;
|
||||||
#if (NUC123_EFL_ACCESS_APROM == TRUE) || defined(__DOXYGEN__)
|
|
||||||
{.attributes = FLASH_ATTR_ERASED_IS_ONE | FLASH_ATTR_MEMORY_MAPPED |
|
|
||||||
FLASH_ATTR_REWRITABLE,
|
|
||||||
.page_size = NUC123_PAGE_SIZE,
|
|
||||||
.sectors_count = NUC123_APROM_SIZE / NUC123_SECTOR_SIZE,
|
|
||||||
.sectors = NULL,
|
|
||||||
.sectors_size = NUC123_SECTOR_SIZE,
|
|
||||||
.address = (uint8_t *)0,
|
|
||||||
.size = NUC123_APROM_SIZE},
|
|
||||||
#endif
|
|
||||||
#if (NUC123_EFL_ACCESS_DATAFLASH == TRUE) || defined(__DOXYGEN__)
|
|
||||||
{.attributes = FLASH_ATTR_ERASED_IS_ONE | FLASH_ATTR_MEMORY_MAPPED |
|
|
||||||
FLASH_ATTR_REWRITABLE,
|
|
||||||
.page_size = NUC123_PAGE_SIZE,
|
|
||||||
.sectors_count = NUC123_DATAFLASH_SIZE / NUC123_SECTOR_SIZE,
|
|
||||||
.sectors = NULL,
|
|
||||||
.sectors_size = NUC123_SECTOR_SIZE,
|
|
||||||
.address = (uint8_t *)NUC123_DFBADDR,
|
|
||||||
.size = NUC123_DATAFLASH_SIZE},
|
|
||||||
#endif
|
|
||||||
#if (NUC123_EFL_ACCESS_LDROM == TRUE) || defined(__DOXYGEN__)
|
|
||||||
{.attributes = FLASH_ATTR_ERASED_IS_ONE | FLASH_ATTR_MEMORY_MAPPED |
|
|
||||||
FLASH_ATTR_REWRITABLE,
|
|
||||||
.page_size = NUC123_PAGE_SIZE,
|
|
||||||
.sectors_count = NUC123_LDROM_SIZE / NUC123_SECTOR_SIZE,
|
|
||||||
.sectors = NULL,
|
|
||||||
.sectors_size = NUC123_SECTOR_SIZE,
|
|
||||||
.address = (uint8_t *)0x100000,
|
|
||||||
.size = NUC123_LDROM_SIZE},
|
|
||||||
#endif
|
|
||||||
#if (NUC123_EFL_ACCESS_CONFIG == TRUE) || defined(__DOXYGEN__)
|
|
||||||
{.attributes = FLASH_ATTR_ERASED_IS_ONE | FLASH_ATTR_MEMORY_MAPPED |
|
|
||||||
FLASH_ATTR_REWRITABLE,
|
|
||||||
.page_size = NUC123_PAGE_SIZE,
|
|
||||||
.sectors_count = 1,
|
|
||||||
.sectors = NULL,
|
|
||||||
.sectors_size = NUC123_SECTOR_SIZE,
|
|
||||||
.address = (uint8_t *)0x300000,
|
|
||||||
.size = 8},
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Driver local functions. */
|
/* Driver local functions. */
|
||||||
|
@ -164,6 +127,13 @@ static inline unsigned min(unsigned x, unsigned y)
|
||||||
*/
|
*/
|
||||||
void efl_lld_init(void)
|
void efl_lld_init(void)
|
||||||
{
|
{
|
||||||
|
efl_lld_descriptor = (flash_descriptor_t){
|
||||||
|
.attributes = FLASH_ATTR_ERASED_IS_ONE | FLASH_ATTR_MEMORY_MAPPED |
|
||||||
|
FLASH_ATTR_REWRITABLE,
|
||||||
|
.page_size = NUC123_PAGE_SIZE,
|
||||||
|
.sectors = NULL,
|
||||||
|
.sectors_size = NUC123_SECTOR_SIZE,
|
||||||
|
};
|
||||||
|
|
||||||
#if (NUC123_EFL_USE_EFL1 == TRUE)
|
#if (NUC123_EFL_USE_EFL1 == TRUE)
|
||||||
eflObjectInit(&EFLD1);
|
eflObjectInit(&EFLD1);
|
||||||
|
@ -256,7 +226,79 @@ void efl_lld_stop(EFlashDriver* eflp)
|
||||||
*/
|
*/
|
||||||
const flash_descriptor_t* efl_lld_get_descriptor(void* instance)
|
const flash_descriptor_t* efl_lld_get_descriptor(void* instance)
|
||||||
{
|
{
|
||||||
return efl_lld_descriptors + ((EFlashDriver *)instance)->bank;
|
size_t dataflash_size;
|
||||||
|
void* dfbaddr;
|
||||||
|
|
||||||
|
#if (NUC123_EFL_DYNAMICALLY_CHECK_CONFIG == TRUE)
|
||||||
|
|
||||||
|
uint32_t ispcon = FMC->ISPCON;
|
||||||
|
|
||||||
|
FMC->ISPCON = ispcon | FMC_ISPCON_CFGUEN_Msk;
|
||||||
|
FMC->ISPCMD = NUC123_EFL_CMD_READ;
|
||||||
|
|
||||||
|
FMC->ISPADR = 0x300000UL;
|
||||||
|
do_ISP();
|
||||||
|
dataflash_size = FMC->ISPDAT;
|
||||||
|
|
||||||
|
if (dataflash_size & 4) {
|
||||||
|
/* DFVSEN = 1 */
|
||||||
|
dataflash_size = 4096;
|
||||||
|
dfbaddr = (void *)0x1F000UL;
|
||||||
|
} else {
|
||||||
|
if (dataflash_size & 1) {
|
||||||
|
/* DFVSEN = 0 & DFEN = 1 */
|
||||||
|
dataflash_size = 0;
|
||||||
|
dfbaddr = (void *)0xFFFFF000UL;
|
||||||
|
} else {
|
||||||
|
/* DFVSEN = 0 & DFEN = 0 */
|
||||||
|
dfbaddr = (void *)FMC->DFBADR;
|
||||||
|
dataflash_size = NUC123_FLASH_SIZE - (uint32_t)dfbaddr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FMC->ISPCON = ispcon;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
dataflash_size = NUC123_CONFIG_DATAFLASH_SIZE;
|
||||||
|
dfbaddr = NUC123_DFBADDR;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
switch (((EFlashDriver *)instance)->bank) {
|
||||||
|
#if (NUC123_EFL_ACCESS_APROM == TRUE)
|
||||||
|
case NUC123_EFL_BANK_APROM:
|
||||||
|
efl_lld_descriptor.address = (uint8_t *)0;
|
||||||
|
efl_lld_descriptor.sectors_count = (NUC123_FLASH_SIZE - dataflash_size) / NUC123_SECTOR_SIZE;
|
||||||
|
efl_lld_descriptor.size = (NUC123_FLASH_SIZE - dataflash_size);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#if (NUC123_EFL_ACCESS_DATAFLASH == TRUE)
|
||||||
|
case NUC123_EFL_BANK_DATAFLASH:
|
||||||
|
efl_lld_descriptor.address = (uint8_t *)dfbaddr;
|
||||||
|
efl_lld_descriptor.sectors_count = dataflash_size / NUC123_SECTOR_SIZE;
|
||||||
|
efl_lld_descriptor.size = dataflash_size;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#if (NUC123_EFL_ACCESS_LDROM == TRUE)
|
||||||
|
case NUC123_EFL_BANK_LDROM:
|
||||||
|
efl_lld_descriptor.address = (uint8_t *)0x100000;
|
||||||
|
efl_lld_descriptor.sectors_count = NUC123_LDROM_SIZE / NUC123_SECTOR_SIZE;
|
||||||
|
efl_lld_descriptor.size = NUC123_LDROM_SIZE;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#if (NUC123_EFL_ACCESS_CONFIG == TRUE)
|
||||||
|
case NUC123_EFL_BANK_CONFIG:
|
||||||
|
efl_lld_descriptor.address = (uint8_t *)0x300000;
|
||||||
|
efl_lld_descriptor.sectors_count = 1;
|
||||||
|
efl_lld_descriptor.size = 8;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
case NUC123_EFL_BANK_NONE:
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return &efl_lld_descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -274,16 +316,16 @@ const flash_descriptor_t* efl_lld_get_descriptor(void* instance)
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
flash_error_t efl_lld_read(void* instance, flash_offset_t offset, size_t n, uint8_t* rp)
|
flash_error_t efl_lld_read(void *instance, flash_offset_t offset, size_t n, uint8_t *rp)
|
||||||
{
|
{
|
||||||
EFlashDriver* devp = (EFlashDriver*)instance;
|
EFlashDriver *devp = (EFlashDriver *)instance;
|
||||||
const flash_descriptor_t *desc = efl_lld_get_descriptor(instance);
|
const flash_descriptor_t *desc = efl_lld_get_descriptor(instance);
|
||||||
flash_error_t err = FLASH_NO_ERROR;
|
flash_error_t err = FLASH_NO_ERROR;
|
||||||
uint32_t data;
|
uint32_t data;
|
||||||
|
|
||||||
osalDbgCheck((instance != NULL) && (rp != NULL) && (n > 0U));
|
osalDbgCheck((instance != NULL) && (rp != NULL) && (n > 0U));
|
||||||
osalDbgCheck(((size_t)offset + n) <= (size_t)desc->size);
|
osalDbgCheck(((size_t)offset + n) <= (size_t)desc->size);
|
||||||
osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
|
osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
|
||||||
"invalid state");
|
"invalid state");
|
||||||
|
|
||||||
/* No reading while erasing.*/
|
/* No reading while erasing.*/
|
||||||
|
@ -327,10 +369,10 @@ flash_error_t efl_lld_read(void* instance, flash_offset_t offset, size_t n, uint
|
||||||
offset += (4 - (offset % 4));
|
offset += (4 - (offset % 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ready state again.*/
|
/* Ready state again.*/
|
||||||
devp->state = FLASH_READY;
|
devp->state = FLASH_READY;
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -96,10 +96,6 @@
|
||||||
/* Derived constants and error checks. */
|
/* Derived constants and error checks. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
#if (NUC123_EFL_ACCESS_DATAFLASH == TRUE) && (NUC123_CONFIG_ENABLED == FALSE)
|
|
||||||
#error "EFL driver data flash access requires NUC123_CONFIG_ENABLED to be set to TRUE"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Driver data structures and types. */
|
/* Driver data structures and types. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
|
@ -190,6 +190,7 @@
|
||||||
#define NUC123_CONFIG_ENABLED FALSE
|
#define NUC123_CONFIG_ENABLED FALSE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (NUC123_CONFIG_ENABLED == TRUE)
|
||||||
/**
|
/**
|
||||||
* @brief Enables or disables data flash
|
* @brief Enables or disables data flash
|
||||||
* @warning If data this is set to @p TRUE, the data flash
|
* @warning If data this is set to @p TRUE, the data flash
|
||||||
|
@ -200,17 +201,19 @@
|
||||||
|
|
||||||
* @note The default is @p TRUE.
|
* @note The default is @p TRUE.
|
||||||
*/
|
*/
|
||||||
#if !defined(NUC123_DATAFLASH_ENABLED) || defined(__DOXYGEN__)
|
#if !defined(NUC123_CONFIG_DATAFLASH_ENABLED) || defined(__DOXYGEN__)
|
||||||
#define NUC123_DATAFLASH_ENABLED TRUE
|
#define NUC123_CONFIG_DATAFLASH_ENABLED TRUE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the data flash size. This is ignored if data flash is disabled.
|
* @brief Sets the data flash size. This is ignored if data flash is disabled.
|
||||||
*/
|
*/
|
||||||
#if !defined(NUC123_DATAFLASH_SIZE) || defined(__DOXYGEN__)
|
#if !defined(NUC123_CONFIG_DATAFLASH_SIZE) || defined(__DOXYGEN__)
|
||||||
#define NUC123_DATAFLASH_SIZE 4096
|
#define NUC123_CONFIG_DATAFLASH_SIZE 4096
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif /* NUC123_CONFIG_ENABLED == TRUE */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -245,41 +248,49 @@
|
||||||
* Persistant configuration settings.
|
* Persistant configuration settings.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if (NUC123_CONFIG_ENABLED == FALSE)
|
#if (NUC123_CONFIG_ENABLED == TRUE)
|
||||||
|
|
||||||
#if (NUC123_DATAFLASH_ENABLED == FALSE)
|
#if (NUC123_CONFIG_DATAFLASH_ENABLED == TRUE)
|
||||||
#error "Setting NUC123_DATAFLASH_ENABLED to FALSE requires NUC123_CONFIG_ENABLED to be TRUE"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (NUC123_DATAFLASH_SIZE != 4096)
|
#if (NUC123_CONFIG_DATAFLASH_SIZE == 4096)
|
||||||
#error "Setting NUC123_DATAFLASH_SIZE to a value other than 4096 requires NUC123_CONFIG_ENABLED to be TRUE"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (NUC123_DATAFLASH_ENABLED == TRUE)
|
|
||||||
|
|
||||||
#if (NUC123_DATAFLASH_SIZE == 4096)
|
|
||||||
/* DFVSEN = 1, nothing else matters */
|
/* DFVSEN = 1, nothing else matters */
|
||||||
#define NUC123_CONFIG0_DATAFLASH 0UL
|
#define NUC123_CONFIG0_DATAFLASH 0UL
|
||||||
/* NUC123_DFBADDR doesn't actually control anything here, but convenient for flash drivers
|
/* NUC123_DFBADDR doesn't actually control anything here, but convenient for flash drivers
|
||||||
which need the starting address */
|
which need the starting address */
|
||||||
#define NUC123_DFBADDR 0x1F000UL
|
#define NUC123_DFBADDR 0x1F000UL
|
||||||
#else
|
#else /* NUC123_CONFIG_DATAFLASH_SIZE != 4096 */
|
||||||
/* DFVSEN = 0, DFEN = 0 */
|
/* DFVSEN = 0, DFEN = 0 */
|
||||||
#define NUC123_CONFIG0_DATAFLASH (NUC123_CONFIG0_DFVSEN_Msk | NUC123_CONFIG0_DFEN_Msk)
|
#define NUC123_CONFIG0_DATAFLASH (NUC123_CONFIG0_DFVSEN_Msk | NUC123_CONFIG0_DFEN_Msk)
|
||||||
#define NUC123_DFBADDR ((0x11000UL - NUC123_DATAFLASH_SIZE) & ~(0xFFUL))
|
#define NUC123_DFBADDR ((0x11000UL - NUC123_CONFIG_DATAFLASH_SIZE) & ~(0xFFUL))
|
||||||
#endif
|
#endif /* NUC123_CONFIG_DATAFLASH_SIZE ?= 4096 */
|
||||||
#else
|
#else /* NUC123_CONFIG_DATAFLASH_ENABLED == TRUE/FALSE */
|
||||||
|
|
||||||
|
#undef NUC123_CONFIG_DATAFLASH_SIZE
|
||||||
|
#define NUC123_CONFIG_DATAFLASH_SIZE 0
|
||||||
/* DFVSEN = 0, DFEN = 1 */
|
/* DFVSEN = 0, DFEN = 1 */
|
||||||
#define NUC123_CONFIG0_DATAFLASH NUC123_CONFIG0_DFVSEN_Msk
|
#define NUC123_CONFIG0_DATAFLASH NUC123_CONFIG0_DFVSEN_Msk
|
||||||
#define NUC123_DFBADDR 0xFFFFFF00UL
|
#define NUC123_DFBADDR 0xFFFFFF00UL
|
||||||
#endif
|
|
||||||
|
#endif /* NUC123_CONFIG_DATAFLASH_ENABLED == TRUE/FALSE */
|
||||||
|
|
||||||
#define NUC123_CONFIG0 \
|
#define NUC123_CONFIG0 \
|
||||||
0xFFFFFFFFUL & (~NUC123_CONFIG0_DATAFLASH) & (~NUC123_CONFIG0_HSE_PINS)
|
0xFFFFFFFFUL & (~NUC123_CONFIG0_DATAFLASH) & (~NUC123_CONFIG0_HSE_PINS)
|
||||||
#define NUC123_CONFIG1 NUC123_DFBADDR
|
#define NUC123_CONFIG1 NUC123_DFBADDR
|
||||||
|
|
||||||
|
#else /* NUC123_CONFIG_ENABLED == FALSE */
|
||||||
|
|
||||||
|
#if defined(NUC123_CONFIG_DATAFLASH_ENABLED)
|
||||||
|
#error \
|
||||||
|
"Defining NUC123_CONFIG_DATAFLASH_ENABLED requires NUC123_CONFIG_ENABLED to be TRUE"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(NUC123_CONFIG_DATAFLASH_SIZE)
|
||||||
|
#error \
|
||||||
|
"Defining NUC123_CONFIG_DATAFLASH_SIZE requires NUC123_CONFIG_ENABLED to be TRUE"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* NUC123_CONFIG_ENABLED == TRUE/FALSE */
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Driver data structures and types. */
|
/* Driver data structures and types. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
Loading…
Reference in New Issue