So here is what the FreeRTOS mcuxpresso debug plugin says when I expand the task to look at more details (I am using heap4.c for the heap):
Before running either function:
Stack Base: 0x200049c0
Stack Top: 0x20005638
Stack Highwater Mark: 0x200051d0
Stack Usage: 1.1kb/3.12kb
After running and returning from 1 flash function that uses that array as a local variable:
Stack Base: 0x200049c0
Stack Top: 0x20005638
Stack Highwater Mark: 0x20004e50
Stack Usage: 1.98kb/3.12kb
After running the second flash function:
Stack Base: 0x200049c0
Stack Top: 0x20005638
Stack Highwater Mark: 0x20004b98
Stack Usage: 2.66kb/3.12kb
Also here is a copy of the function I am calling to see if it sheds any light onto this behavior. I would imagine the stack top is supposed to go down after the function returns.
“CALLBOX_PARMS” is an 840byte struct I am converting to a 220 sized 32bit array for the 32bit flash memory. Then reading and converting it back into that struct.
CALLBOX_PARMS readFlashParam()
{
uint32_t flashReadBuf[CALLBOX_PARMS_SIZE/4];
uint32_t pflashBlockBase = 0;
uint32_t pflashTotalSize = 0;
uint32_t pflashSectorSize = 0;
flash_security_state_t securityStatus = kFLASH_SecurityStateNotSecure; /* Return protection status */
uint32_t destAdrss; /* Address of the target location */
uint32_t failAddr, failDat;
/* Get flash properties*/
FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflashBlockBaseAddr, &pflashBlockBase);
FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflashTotalSize, &pflashTotalSize);
FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflashSectorSize, &pflashSectorSize);
//Get Flash Base Address
destAdrss = pflashBlockBase + (pflashTotalSize - pflashSectorSize);
memset(flashReadBuf,0,sizeof(flashReadBuf));
uint32_t i = 0;
//Lock Mutex for flash access
OSA_MutexLock(xflashMutex, 20000);
/* Verify programming by reading back from flash directly*/
for (i = 0; i < (CALLBOX_PARMS_SIZE/4); i++)
{
flashReadBuf[i] = *(volatile uint32_t *)(destAdrss + i * 4);
}
OSA_MutexUnlock(xflashMutex);
CALLBOX_PARMS returnStruct;
memcpy(&returnStruct, flashReadBuf, sizeof(returnStruct));
return returnStruct;
}
void saveFlashParam()
{
uint32_t s_buffer[CALLBOX_PARMS_SIZE/4];
//Flash inits
status_t result=0;
uint32_t pflashBlockBase = 0;
uint32_t pflashTotalSize = 0;
uint32_t pflashSectorSize = 0;
flash_security_state_t securityStatus = kFLASH_SecurityStateNotSecure; /* Return protection status */
uint32_t destAdrss; /* Address of the target location */
uint32_t i, failAddr, failDat;
/* Get flash properties*/
FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflashBlockBaseAddr, &pflashBlockBase);
FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflashTotalSize, &pflashTotalSize);
FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflashSectorSize, &pflashSectorSize);
//Convert Param Struct to Byte Struct
int sizeofBuf = sizeof(s_buffer);
memset(s_buffer,0,sizeof(s_buffer));
memcpy(s_buffer, pFParms, sizeof(s_buffer));
/* Check security status. */
result = FLASH_GetSecurityState(&s_flashDriver, &securityStatus);
if (kStatus_FLASH_Success != result)
{
while(1);
}
/* Print security status. */
switch (securityStatus)
{
case kFLASH_SecurityStateNotSecure:
break;
case kFLASH_SecurityStateBackdoorEnabled:
break;
case kFLASH_SecurityStateBackdoorDisabled:
break;
default:
break;
}
//Small flash test to verify its working
if (kFLASH_SecurityStateNotSecure == securityStatus)
{
destAdrss = pflashBlockBase + (pflashTotalSize - pflashSectorSize);
result = FLASH_Erase(&s_flashDriver, destAdrss, pflashSectorSize, kFLASH_ApiEraseKey);
if (kStatus_FLASH_Success != result)
{
while(1);
}
/* Verify sector if it's been erased. */
result = FLASH_VerifyErase(&s_flashDriver, destAdrss, pflashSectorSize, kFLASH_MarginValueUser);
if (kStatus_FLASH_Success != result)
{
while(1);
}
/* Program user buffer into flash*/
result = FLASH_Program(&s_flashDriver, destAdrss, s_buffer, sizeof(s_buffer));
if (kStatus_FLASH_Success != result)
{
while(1);
}
/* Verify programming by Program Check command with user margin levels */
result = FLASH_VerifyProgram(&s_flashDriver, destAdrss, sizeof(s_buffer), s_buffer, kFLASH_MarginValueUser,
&failAddr, &failDat);
if (kStatus_FLASH_Success != result)
{
while(1);
}
}
}