Hi, today I understood how to modify the linker file with MCUXpresso using "MCU settings"
Now I have two partitions of FLASH and two of RAM.
I had implement this macro:
#define __relocate_code__ __attribute__((section(".myRAM"), long_call))
To define .myRAM I used the "Extra linker script input section"
I found it in Properties -> Settings -> MCU Linker -> Managed Linker Script
This is the right way isn't it?
But It doesn't work.
Maybe I have no understand how to use the macro "__relocate_code__" properly
I attach here the code:
void FlashMemoryInit(void)__relocate_code__;
void FlashMemory(void) __relocate_code__;
********************************************************
void __relocate_code__ FlashMemoryInit(void){
//Clean up Flash, Cache driver Structure
memset(&s_flashDriver, 0, sizeof(flash_config_t));
memset(&s_cacheDriver, 0, sizeof(ftfx_cache_config_t));
//Setup flash driver structure for device and initialize variables.
result = FLASH_Init(&s_flashDriver);
if (kStatus_FTFx_Success != result)
{
error_trap();
}
//Setup flash cache driver structure for device and initialize variables.
result = FTFx_CACHE_Init(&s_cacheDriver);
if (kStatus_FTFx_Success != result)
{
error_trap();
}
//Get flash properties
FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflash0BlockBaseAddr, &pflashBlockBase);
FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflash0TotalSize, &pflashTotalSize);
FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflash0SectorSize, &pflashSectorSize);
//Check security status.
result = FLASH_GetSecurityState(&s_flashDriver, &securityStatus);
if (kStatus_FTFx_Success != result)
{
error_trap();
}
//Print security status.
switch (securityStatus)
{
case kFTFx_SecurityStateNotSecure:
//PRINTF("\r\n Flash is UNSECURE!");
break;
case kFTFx_SecurityStateBackdoorEnabled:
//PRINTF("\r\n Flash is SECURE, BACKDOOR is ENABLED!");
break;
case kFTFx_SecurityStateBackdoorDisabled:
//PRINTF("\r\n Flash is SECURE, BACKDOOR is DISABLED!");
break;
default:
break;
}
}
*********************************************************************
void __relocate_code__ FlashMemory(void)
{
// Test pflash basic operation only if flash is unsecure.
if (kFTFx_SecurityStateNotSecure == securityStatus)
{
/* Pre-preparation work about flash Cache/Prefetch/Speculation. */
FTFx_CACHE_ClearCachePrefetchSpeculation(&s_cacheDriver, true);
#ifndef SECTOR_INDEX_FROM_END
#define SECTOR_INDEX_FROM_END 1U
#endif
destAdrss = pflashBlockBase + (pflashTotalSize - (SECTOR_INDEX_FROM_END * pflashSectorSize));
result = FLASH_Erase(&s_flashDriver, destAdrss, pflashSectorSize, kFTFx_ApiEraseKey);
if (kStatus_FTFx_Success != result)
{
error_trap();
}
// Verify sector if it's been erased.
result = FLASH_VerifyErase(&s_flashDriver, destAdrss, pflashSectorSize, kFTFx_MarginValueUser);
if (kStatus_FTFx_Success != result)
{
error_trap();
}
//Successfully Erased Sector 0x%x -> 0x%x\r\n", destAdrss, (destAdrss + pflashSectorSize));
/////////////////////////////////
//Prepare user buffer to save in FLASH
for (i = 0; i < BUFFER_LEN; i++){
s_buffer[i] = i;
}
//////////////////////////////////
result = FLASH_Program(&s_flashDriver, destAdrss, (uint8_t *)s_buffer, sizeof(s_buffer));
if (kStatus_FTFx_Success != result){
error_trap();
}
//Verify programming by Program Check command with user margin levels
result = FLASH_VerifyProgram(&s_flashDriver, destAdrss, sizeof(s_buffer), (const uint8_t *)s_buffer, kFTFx_MarginValueUser,
&failAddr, &failDat);
if (kStatus_FTFx_Success != result){
error_trap();
}
// Post-preparation work about flash Cache/Prefetch/Speculation.
FTFx_CACHE_ClearCachePrefetchSpeculation(&s_cacheDriver, false);
#if defined(FSL_FEATURE_HAS_L1CACHE) && FSL_FEATURE_HAS_L1CACHE
L1CACHE_InvalidateCodeCache();
#endif // FSL_FEATURE_HAS_L1CACHE
#if defined(__DCACHE_PRESENT) && __DCACHE_PRESENT
// Clean the D-Cache before reading the flash data
SCB_CleanInvalidateDCache();
#endif
// Verify programming by reading back from flash directly
for (uint32_t i = 0; i < BUFFER_LEN; i++)
{
s_buffer_rbc[i] = *(volatile uint32_t *)(destAdrss + i * 4);
if (s_buffer_rbc[i] != s_buffer[i])
{
error_trap();
}
}
//PRINTF("\r\n Successfully Programmed and Verified Location 0x%x -> 0x%x \r\n", destAdrss,(destAdrss + sizeof(s_buffer)));
// Erase the context we have programmed before
// Note: we should make sure that the sector which will be set as swap indicator should be blank
FLASH_Erase(&s_flashDriver, destAdrss, pflashSectorSize, kFTFx_ApiEraseKey);
}else{
//Erase/Program operation will not be executed, as Flash is SECURE!
}
app_finalize();
}
That's all,
It's the copy of the example who I'm talking about today.
I could not go beyond the "FLASH_Erase" function.
Thank you for help
Best regards
Luca