I am trying to install MFS over NAND FLASH in TWRK70F120, such as it is expected to be done with new "NAND Flash File System patch for Freescale MQX™ RTOS 4.0.0 ". Basically, I am following the installed example that uses shell commands.
Here is my initiallization code for NAND FLASH Device:
_mqx_int error_code;
MQX_FILE_PTR nandflash_handle;
MQX_FILE_PTR filesystem_handle;
_S8 filesystem_name[] = "d:";
_U8 NandFlash_Install_FileSystem(void)
{
if (_io_nandflash_wl_install(&_bsp_nandflash_wl_init, NAND_FLASH_DEVICE) != MQX_OK)
{
return NAND_FLASH_FILE_SYSTEM_ERROR;
}
nandflash_handle = fopen(NAND_FLASH_DEVICE, NANDWL_OPEN_FORCE_REPAIR_WHEN_FAILED); // BREAKPOINT 1
if ( nandflash_handle == NULL ) // BREAKPOINT 2
{
return NAND_FLASH_FILE_SYSTEM_ERROR;
}
......
......
return NAND_FLASH_FILE_SYSTEM_OK;
}
Line commented with "BREAKPOINT 1" is always executed, so the fopen function associated to NAND FLASH is called. But line with comment "BREAKPOINT 2" is not executed because an assert fails on this function from MQX Library:
bool PageOrderMap::isOccupied
(
/* [IN] Logical index */
unsigned logicalIndex
) const
{ /* Body */
assert(logicalIndex < m_entryCount); // ASSERT ERROR
unsigned coarse = logicalIndex / BITS_PER_WORD;
unsigned fine = logicalIndex % BITS_PER_WORD;
return ((m_occupied[coarse] >> fine) & 0x1) != 0;
} /* Endbody */
This happens every time I enter on a debug session, but is not happening if I reset the CPU (without leaving debug session).
The method PageOrderMap::isOccupied(..) is called from RtStatus_t PersistentMap::retrieveSection(...), who passes a logicalIndex that is out of scope for me when debugging. I have no evidences about what causes this situation. I hope anebody can help.
Hi Jessica,
I just downloaded the FFS and applied it to the MQX4.0.
I compiled the RTOS and FFS per the FFS release notes.
I loaded the example:
C:\Freescale\Freescale_MQX_4_0\ffs\examples\mfs_nandflash\cw10
I'm using CW10.3 (with updates) and TWR-K70 (jumpers setup per the FSK_MQX_getting_started.pdf section 7).
I followed the instruciton on the terminal (I'm connected up to the TWR-SER serial port) when running the example. I did have to look up what the drive letter is to format ("format a:").
The example worked fine for me.
If you have the TWR-K70 it would be good to test the example and assuming no problems compare the code to your code base.
Regards,
David
Hello David,
I'm having the same setup as you except that I'm using MQX 4.0.1.
Still the example does not work. I opened a separate question: FFS on NANDFLASH of TWR-K70 (MQX 4.0.1)
Maybe you've got an idea.
Thanks!
Hi David,
Thank you for running the test to check this. I will do the same again (I tried it yet...).
(Previous to this response, I posted another one telling my problem allocating memory while installing partition manager over SD card. It was due to an error on my code, so I have deleted my last message. Sorry for the confussion.)
Hi all,
I can confirm the FFS example works fine on the tower, and nothing reported in my first post is happening. I removed my code and started again, and now I have a program that does exactly the same that the example does, except for the fact that my program does not use the shell, but it executes the same actions:
void NandFlash_Task(uint_32 input)
{
_S32 i;
_S32 result;
if (_io_nandflash_wl_install(&_bsp_nandflash_wl_init, FFS_DEVICE) != MQX_OK)
{
printf("Can't install FFS!\n");
_task_block();
}
NandFlash_EraseChip(); // equal to nanderasechip command
result = NandFlash_MFS_Open(); // equal to fsopen command
if(result == NAND_FLASH_MUST_REPAIR)
{
_task_block();
}
else if(result == NAND_FLASH_MUST_FORMAT)
{
NandFlash_MFS_Format(); // equal to format command
}
}
With my new functions, I can format Nand Flash (I am able to read the correct free disk space after this), BUT this never happens the first time I enter in the debug session (because the assert error always appears), and I need to reset the CPU to get the Nand Flash formatted. So the problem is still here...
The question must be: what can cause this assert error?
Hi Jessica,
If it is working with the Tower and the shell example, try adding in a "_time_delay(10);" in a couple of places of your code.
With the shell example there is a shell task running that is taking up some amount of time. Maybe with your code the RTOS needs a bit of processing time between NAND function calls.
Please keep us posted.
Regards,
David
Hi David,
After many days testing my software, I saw there is an assert error only when entering in debug mode, but it doesn't happen if I download the code without debugging. So I decided to continue my development without keep in mind this problem, because it was causing me a big delay...
Now I can open and close a file in the Nand Flash and what I want is to copy a file from SD to Nand Flash file system. I have checked that the file is succesfully copied (I can read all the bytes using the shell example), but I can't read it on my program! A critical problem is happening when FFS library tries to wirte a sector (ddi_ldl_write.cpp):
RtStatus_t DriveWriteSector
(
/* [IN] Unique tag for the drive to operate on. */
DriveTag_t tag,
/* [IN] Sector to write; 0-based at the start of the drive. */
uint32_t u32SectorNumber,
/* [IN] Pointer to buffer of sector data to write. */
const SECTOR_BUFFER * pSectorData
)
{ /* Body */
/* Get drive depending on its tag */
LogicalDrive * drive = DriveGetDriveFromTag(tag);
if (!drive)
{
return ERROR_DDI_LDL_LDRIVE_INVALID_DRIVE_NUMBER;
}
else if (!drive->isInitialized())
{
return ERROR_DDI_LDL_LDRIVE_NOT_INITIALIZED;
} /* Endif */
#if defined(USE_NAND_STACK) && defined(NO_SDRAM)
if (drive->getMedia()->getPhysicalType() != kMediaTypeMMC)
{
static RtStatus_t s_RetValue;
TX_THREAD *pCurrentThread;
tx_mutex_get(&g_NANDThreadSafeMutex, TX_WAIT_FOREVER);
pCurrentThread = tx_thread_identify();
if (pCurrentThread != NULL)
{
os_thi_SaveStackContext(&g_NewNandStackContext, pCurrentThread, &g_OldNandStackContext, 40);
}
s_RetValue = drive->writeSector(u32SectorNumber, pSectorData);
if (pCurrentThread != NULL)
{
os_thi_RestoreStackContext(&g_OldNandStackContext, pCurrentThread);
}
tx_mutex_put(&g_NANDThreadSafeMutex);
return s_RetValue;
} /* Endif */
#endif /* Defined(USE_NAND_STACK) && defined(NO_SDRAM) */
return drive->writeSector(u32SectorNumber, pSectorData); // HERE THE PROGRAM BREAKS!
} /* Endbody */
Any suggestions about in which cases can occur this? I am checking all my program to find what I am making wrong: I checked the seek mode, options passed when opening the file, ...
Hi Jessica,
Please check what target you are building with.
Many of the default MQX applications builds use the "Int RAM Debug" target which may fit into the available onchip RAM to run but then you have a limited heap space.
Using the other targets has the program( .code) in flash and the internal SRAM or DRAM used for the .data/.bss space.
Please try using one of the other targets.
Regards,
David