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_LDROM_SIZE 0x1000UL
|
||||
#define NUC123_APROM_SIZE (NUC123_FLASH_SIZE - NUC123_DATAFLASH_SIZE)
|
||||
|
||||
#define NUC123_EFL_CMD_ERASE 0x22UL
|
||||
#define NUC123_EFL_CMD_PROG 0x21UL
|
||||
#define NUC123_EFL_CMD_READ 0UL
|
||||
#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. */
|
||||
/*===========================================================================*/
|
||||
|
@ -64,48 +68,7 @@ EFlashDriver EFLD1;
|
|||
/* Driver local variables and types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
static const flash_descriptor_t efl_lld_descriptors[] = {
|
||||
#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
|
||||
};
|
||||
static flash_descriptor_t efl_lld_descriptor;
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
|
@ -164,6 +127,13 @@ static inline unsigned min(unsigned x, unsigned y)
|
|||
*/
|
||||
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)
|
||||
eflObjectInit(&EFLD1);
|
||||
|
@ -256,7 +226,79 @@ void efl_lld_stop(EFlashDriver* eflp)
|
|||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -96,10 +96,6 @@
|
|||
/* 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. */
|
||||
/*===========================================================================*/
|
||||
|
|
|
@ -190,6 +190,7 @@
|
|||
#define NUC123_CONFIG_ENABLED FALSE
|
||||
#endif
|
||||
|
||||
#if (NUC123_CONFIG_ENABLED == TRUE)
|
||||
/**
|
||||
* @brief Enables or disables data flash
|
||||
* @warning If data this is set to @p TRUE, the data flash
|
||||
|
@ -200,17 +201,19 @@
|
|||
|
||||
* @note The default is @p TRUE.
|
||||
*/
|
||||
#if !defined(NUC123_DATAFLASH_ENABLED) || defined(__DOXYGEN__)
|
||||
#define NUC123_DATAFLASH_ENABLED TRUE
|
||||
#if !defined(NUC123_CONFIG_DATAFLASH_ENABLED) || defined(__DOXYGEN__)
|
||||
#define NUC123_CONFIG_DATAFLASH_ENABLED TRUE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Sets the data flash size. This is ignored if data flash is disabled.
|
||||
*/
|
||||
#if !defined(NUC123_DATAFLASH_SIZE) || defined(__DOXYGEN__)
|
||||
#define NUC123_DATAFLASH_SIZE 4096
|
||||
#if !defined(NUC123_CONFIG_DATAFLASH_SIZE) || defined(__DOXYGEN__)
|
||||
#define NUC123_CONFIG_DATAFLASH_SIZE 4096
|
||||
#endif
|
||||
|
||||
#endif /* NUC123_CONFIG_ENABLED == TRUE */
|
||||
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
|
@ -245,41 +248,49 @@
|
|||
* Persistant configuration settings.
|
||||
*/
|
||||
|
||||
#if (NUC123_CONFIG_ENABLED == FALSE)
|
||||
#if (NUC123_CONFIG_ENABLED == TRUE)
|
||||
|
||||
#if (NUC123_DATAFLASH_ENABLED == FALSE)
|
||||
#error "Setting NUC123_DATAFLASH_ENABLED to FALSE requires NUC123_CONFIG_ENABLED to be TRUE"
|
||||
#endif
|
||||
#if (NUC123_CONFIG_DATAFLASH_ENABLED == TRUE)
|
||||
|
||||
#if (NUC123_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)
|
||||
#if (NUC123_CONFIG_DATAFLASH_SIZE == 4096)
|
||||
/* DFVSEN = 1, nothing else matters */
|
||||
#define NUC123_CONFIG0_DATAFLASH 0UL
|
||||
/* NUC123_DFBADDR doesn't actually control anything here, but convenient for flash drivers
|
||||
which need the starting address */
|
||||
#define NUC123_DFBADDR 0x1F000UL
|
||||
#else
|
||||
#else /* NUC123_CONFIG_DATAFLASH_SIZE != 4096 */
|
||||
/* DFVSEN = 0, DFEN = 0 */
|
||||
#define NUC123_CONFIG0_DATAFLASH (NUC123_CONFIG0_DFVSEN_Msk | NUC123_CONFIG0_DFEN_Msk)
|
||||
#define NUC123_DFBADDR ((0x11000UL - NUC123_DATAFLASH_SIZE) & ~(0xFFUL))
|
||||
#endif
|
||||
#else
|
||||
#define NUC123_DFBADDR ((0x11000UL - NUC123_CONFIG_DATAFLASH_SIZE) & ~(0xFFUL))
|
||||
#endif /* NUC123_CONFIG_DATAFLASH_SIZE ?= 4096 */
|
||||
#else /* NUC123_CONFIG_DATAFLASH_ENABLED == TRUE/FALSE */
|
||||
|
||||
#undef NUC123_CONFIG_DATAFLASH_SIZE
|
||||
#define NUC123_CONFIG_DATAFLASH_SIZE 0
|
||||
/* DFVSEN = 0, DFEN = 1 */
|
||||
#define NUC123_CONFIG0_DATAFLASH NUC123_CONFIG0_DFVSEN_Msk
|
||||
#define NUC123_DFBADDR 0xFFFFFF00UL
|
||||
#endif
|
||||
|
||||
#endif /* NUC123_CONFIG_DATAFLASH_ENABLED == TRUE/FALSE */
|
||||
|
||||
#define NUC123_CONFIG0 \
|
||||
0xFFFFFFFFUL & (~NUC123_CONFIG0_DATAFLASH) & (~NUC123_CONFIG0_HSE_PINS)
|
||||
#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. */
|
||||
/*===========================================================================*/
|
||||
|
|
Loading…
Reference in New Issue