Hi, i want to use internal flash memory on mcxa-153 frdm development board, i went through the sdk example of flashiap in mcuxpresso ide , to know how to write or read from flash, but those API functions provided in example only works for read operation, any attempt to write to flash throws an bus fault.
below functions didnt work for me :-
FLASH_API->flash_erase_sector(&s_flashDriver, destAdrss, pflashSectorSize, kFLASH_ApiEraseKey);
FLASH_API->flash_program_page(&s_flashDriver, destAdrss, (uint8_t *)s_buffer, sizeof(s_buffer));
but any functions that attempts only to read flash is working fine like example:-
flash_verify_erase_sector(&s_flashDriver, destAdrss, pflashSectorSize);
FLASH_API->flash_verify_program(&s_flashDriver, destAdrss, sizeof(s_buffer), (const uint8_t *)s_buffer, &failedAddress, &failedData);
FLASH_API->flash_get_property(&s_flashDriver, kFLASH_PropertyPflashSectorSize, &pflashSectorSize);
destAdrss given here is last second sector address and block base address is 0x00 :-
#define SECTOR_INDEX_FROM_END 2U
destAdrss = pflashBlockBase + (pflashTotalSize - (SECTOR_INDEX_FROM_END * pflashSectorSize));
Can i please know if am missing something or using these functions wrongly?. Thank You
解決済! 解決策の投稿を見る。
Hello @Gurunath
Sorry above code is for new version SDK v2.16.0.
For SDK v2.14.0, please test below code:
__attribute__ ((weak)) void SystemInit (void) {
SCB->CPACR |= ((3UL << 0*2) | (3UL << 1*2)); /* set CP0, CP1 Full Access in Secure mode (enable PowerQuad) */
#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
SCB_NS->CPACR |= ((3UL << 0*2) | (3UL << 1*2)); /* set CP0, CP1 Full Access in Normal mode (enable PowerQuad) */
#endif /* (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */
SCB->NSACR |= ((3UL << 0) | (3UL << 10)); /* enable CP0, CP1, CP10, CP11 Non-secure Access */
#if defined(__MCUXPRESSO)
extern void(*const g_pfnVectors[]) (void);
SCB->VTOR = (uint32_t) &g_pfnVectors;
#else
extern void *__Vectors;
SCB->VTOR = (uint32_t) &__Vectors;
#endif
/* Enable the LPCAC */
SYSCON->LPCAC_CTRL |= SYSCON_LPCAC_CTRL_LPCAC_MEM_REQ_MASK;
SYSCON->LPCAC_CTRL &= ~SYSCON_LPCAC_CTRL_DIS_LPCAC_MASK;
/* Enable flash RWX when FLASH_ACL in IFR0 is invalid */
if ((*((volatile const uint32_t *)(0x1000000)) == 0xFFFFFFFFU) ||
((*((volatile const uint32_t *)(0x1000000)) == 0x59630000U) &&
(*((volatile const uint32_t *)(0x1000040)) == 0xFFFFFFFFU) &&
(*((volatile const uint32_t *)(0x1000044)) == 0xFFFFFFFFU)))
{
/* Enable MBC register written with GLIKEY index15 */
GLIKEY0->CTRL_0 = 0x00060000U;
GLIKEY0->CTRL_0 = 0x0002000FU;
GLIKEY0->CTRL_0 = 0x0001000FU;
GLIKEY0->CTRL_1 = 0x00290000U;
GLIKEY0->CTRL_0 = 0x0002000FU;
GLIKEY0->CTRL_1 = 0x00280000U;
GLIKEY0->CTRL_0 = 0x0000000FU;
/* Enable RWX for GLBAC0 */
MBC0->MBC0_MEMN_GLBAC[0] = 0x7700U;
/* Use GLBAC0 for all flash block */
// for (uint8_t i = 0; i < 2U; i++)
// {
// MBC0->MBC_INDEX[0].MBC_DOM0_MEM0_BLK_CFG_W[i] = 0x00000000U;
// }
MBC0->MBC_DOM0[0].MBC0_DOM_MEM0_BLK_CFG_W0 = 0x00000000U;
MBC0->MBC_DOM0[0].MBC0_DOM_MEM0_BLK_CFG_W1 = 0x00000000U;
/* Disable MBC register written */
GLIKEY0->CTRL_0 = 0x0002000FU;
}
SystemInitHook();
}
BR
Alice
Hello @Gurunath
1) "below functions didn't work for me :"
->> Please describe more detail about how it didn't work. What the return status of "flash_program_page "?
2) Does the flashiap work well on your side? Please run it first.
BR
Alice
Hi, i tried to run the example as it is without modification, but it didnt work, it gave an hard fault(bus error).
this error occurs only when functions like erase_sector or program_page were called(mostly those that performs write to flash).
Since in example, erase sector is being called first, execution doesnt return from function call due to this error, so the error message was not print based on return value.
i have got these active faults when run,
Active faults
Bus Fault (BFSR)
BFARVALID (7) BusFault Address Register (BFAR) valid flag
PRECISERR (1) Precise data bus error
Hard Fault (HFSR)
FORCED (30) Indicates a forced hard fault, generated by escalation of a fault with configurable priority that cannot be handled, either because of priority or because it is disabled
Hello @Gurunath
This is because in the default state after booting, the flash is protected by the ROM using the MBC and no erase/write operations are allowed. There are two ways to solve this:
__attribute__ ((weak)) void SystemInit (void) {
SCB->CPACR |= ((3UL << 0*2) | (3UL << 1*2)); /* set CP0, CP1 Full Access in Secure mode (enable PowerQuad) */
#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
SCB_NS->CPACR |= ((3UL << 0*2) | (3UL << 1*2)); /* set CP0, CP1 Full Access in Normal mode (enable PowerQuad) */
#endif /* (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */
SCB->NSACR |= ((3UL << 0) | (3UL << 10)); /* enable CP0, CP1, CP10, CP11 Non-secure Access */
#if defined(__MCUXPRESSO)
extern void(*const g_pfnVectors[]) (void);
SCB->VTOR = (uint32_t) &g_pfnVectors;
#else
extern void *__Vectors;
SCB->VTOR = (uint32_t) &__Vectors;
#endif
/* Enable the LPCAC */
SYSCON->LPCAC_CTRL |= SYSCON_LPCAC_CTRL_LPCAC_MEM_REQ_MASK;
SYSCON->LPCAC_CTRL &= ~SYSCON_LPCAC_CTRL_DIS_LPCAC_MASK;
/* Enable flash RWX when FLASH_ACL in IFR0 is invalid */
if ((*((volatile const uint32_t *)(0x1000000)) == 0xFFFFFFFFU) ||
((*((volatile const uint32_t *)(0x1000000)) == 0x59630000U) &&
(*((volatile const uint32_t *)(0x1000040)) == 0xFFFFFFFFU) &&
(*((volatile const uint32_t *)(0x1000044)) == 0xFFFFFFFFU)))
{
/* Enable MBC register written with GLIKEY index15 */
GLIKEY0->CTRL_0 = 0x00060000U;
GLIKEY0->CTRL_0 = 0x0002000FU;
GLIKEY0->CTRL_0 = 0x0001000FU;
GLIKEY0->CTRL_1 = 0x00290000U;
GLIKEY0->CTRL_0 = 0x0002000FU;
GLIKEY0->CTRL_1 = 0x00280000U;
GLIKEY0->CTRL_0 = 0x0000000FU;
/* Enable RWX for GLBAC0 */
MBC0->MBC_INDEX[0].MBC_MEMN_GLBAC[0] = 0x7700U;
/* Use GLBAC0 for all flash block */
for (uint8_t i = 0; i < 2U; i++)
{
MBC0->MBC_INDEX[0].MBC_DOM0_MEM0_BLK_CFG_W[i] = 0x00000000U;
}
/* Disable MBC register written */
GLIKEY0->CTRL_0 = 0x0002000FU;
}
SystemInitHook();
}
BR
Alice
Hi Alice, Thanks for clearing my doubt, i tried modifying system_init(), as you said but am getiing an error as mentioned below:
/device/system_MCXA153.c:98:17: error: 'MBC_Type' has no member named 'MBC_INDEX'
98 | MBC0->MBC_INDEX[0].MBC_MEMN_GLBAC[0] = 0x7700U;
| ^~
../device/system_MCXA153.c:103:21: error: 'MBC_Type' has no member named 'MBC_INDEX'
103 | MBC0->MBC_INDEX[0].MBC_DOM0_MEM0_BLK_CFG_W[i] = 0x00000000U;
can you please help me with this?
Thank you
Hello @Gurunath
Sorry above code is for new version SDK v2.16.0.
For SDK v2.14.0, please test below code:
__attribute__ ((weak)) void SystemInit (void) {
SCB->CPACR |= ((3UL << 0*2) | (3UL << 1*2)); /* set CP0, CP1 Full Access in Secure mode (enable PowerQuad) */
#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
SCB_NS->CPACR |= ((3UL << 0*2) | (3UL << 1*2)); /* set CP0, CP1 Full Access in Normal mode (enable PowerQuad) */
#endif /* (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */
SCB->NSACR |= ((3UL << 0) | (3UL << 10)); /* enable CP0, CP1, CP10, CP11 Non-secure Access */
#if defined(__MCUXPRESSO)
extern void(*const g_pfnVectors[]) (void);
SCB->VTOR = (uint32_t) &g_pfnVectors;
#else
extern void *__Vectors;
SCB->VTOR = (uint32_t) &__Vectors;
#endif
/* Enable the LPCAC */
SYSCON->LPCAC_CTRL |= SYSCON_LPCAC_CTRL_LPCAC_MEM_REQ_MASK;
SYSCON->LPCAC_CTRL &= ~SYSCON_LPCAC_CTRL_DIS_LPCAC_MASK;
/* Enable flash RWX when FLASH_ACL in IFR0 is invalid */
if ((*((volatile const uint32_t *)(0x1000000)) == 0xFFFFFFFFU) ||
((*((volatile const uint32_t *)(0x1000000)) == 0x59630000U) &&
(*((volatile const uint32_t *)(0x1000040)) == 0xFFFFFFFFU) &&
(*((volatile const uint32_t *)(0x1000044)) == 0xFFFFFFFFU)))
{
/* Enable MBC register written with GLIKEY index15 */
GLIKEY0->CTRL_0 = 0x00060000U;
GLIKEY0->CTRL_0 = 0x0002000FU;
GLIKEY0->CTRL_0 = 0x0001000FU;
GLIKEY0->CTRL_1 = 0x00290000U;
GLIKEY0->CTRL_0 = 0x0002000FU;
GLIKEY0->CTRL_1 = 0x00280000U;
GLIKEY0->CTRL_0 = 0x0000000FU;
/* Enable RWX for GLBAC0 */
MBC0->MBC0_MEMN_GLBAC[0] = 0x7700U;
/* Use GLBAC0 for all flash block */
// for (uint8_t i = 0; i < 2U; i++)
// {
// MBC0->MBC_INDEX[0].MBC_DOM0_MEM0_BLK_CFG_W[i] = 0x00000000U;
// }
MBC0->MBC_DOM0[0].MBC0_DOM_MEM0_BLK_CFG_W0 = 0x00000000U;
MBC0->MBC_DOM0[0].MBC0_DOM_MEM0_BLK_CFG_W1 = 0x00000000U;
/* Disable MBC register written */
GLIKEY0->CTRL_0 = 0x0002000FU;
}
SystemInitHook();
}
BR
Alice
Thanks for the solution, It solved the issue.