HAL NAND How to Use ¶
- group NAND_How_To_Use
-
How to use the NAND HAL module driver ¶
The FMC NAND main features: ¶
This NAND HAL driver is a generic driver which contains a set of APIs used to configure the FMC NAND banks and to interface with legacy and ONFI (Open NAND Flash Interface) NAND memories.
The NAND HAL driver can be used as follows: ¶
This module provides these different sets of APIs that allow to :
1- Initialize and deinitialize the logical FMC NAND object ( hal_nand_handle_t) and retrieve the associated NAND peripheral instance :
Initialize the logical FMC NAND object and associate it to a physical instance. This functionality is ensured by HAL_NAND_Init() function.
Deinitialize the logical FMC NAND object and disable the NAND bank. This functionality is ensured by HAL_NAND_DeInit() function.
Retrieve the NAND instance by calling HAL_NAND_GetInstance().
2- Configure the FMC NAND to be ready to use and retrieve the current configuration :
Configure the FMC NAND through these steps by following the order below :
Step 1 (FMC configuration) : is the first step to perform once the HAL NAND driver is initialized. This functionality is ensured by HAL_NAND_SetConfig() function.
At this stage, the NAND is partially configured but not yet ready to use.
Step 2 (Memory configuration) : is the second step to perform once the FMC is configured. This functionality is ensured by HAL_NAND_SetConfigMemory() function.
Step 3 (Optional based on the external memory) : is the third step to perform optionally once the FMC and memory are configured. It sets a different timing configuration for the last write access when needed. This functionality is ensured by HAL_NAND_SetLastWriteAccessTiming() function, and it must be called after HAL_NAND_SetConfigMemory().
At this stage, the memory is partially configured but not ready to use.
Step 4 (Partition configuration) : is the fourth step to perform once the FMC and memory are configured. This functionality is ensured by one of these two functions :
HAL_NAND_SetConfigPartition() function to set the NAND memory partition configuration.
HAL_NAND_SetConfigPartitionONFI() function to retrieve automatically and set the NAND partition configuration from the ONFI compliant memory.
At this stage, the memory is fully configured and ready to use for polling process.
For polling process, the timeout values can be modified when the memory is fully configured. This functionality is ensured by these functions :
HAL_NAND_SetExtraCmdTimeout() function to update the extra command timeout.
HAL_NAND_SetPageProgramTimeout() function to update the page program timeout.
HAL_NAND_SetBlockEraseTimeout() function to update the block erase timeout.
Retrieve the current configuration through the following functions :
Retrieve the FMC configuration : This functionality is ensured by HAL_NAND_GetConfig().
Retrieve the memory configuration : This functionality is ensured by HAL_NAND_GetConfigMemory().
Retrieve the timing configuration for the last write access : This functionality is ensured by HAL_NAND_GetLastWriteAccessTiming()
Retrieve the memory partition configuration : This functionality is ensured by HAL_NAND_GetConfigPartition().
Retrieve the NAND start region address : This functionality is ensured by HAL_NAND_GetRegionBaseAddress().
Retrieve the process timeout values : This functionality is ensured by these 3 functions depending on the process :
HAL_NAND_GetExtraCmdTimeout() function to get the extra command timeout.
HAL_NAND_GetPageProgramTimeout() function to get page program timeout.
HAL_NAND_GetBlockEraseTimeout() function to get block erase timeout.
Retrieve the algorithm used for the ECC computation : This functionality is ensured by HAL_NAND_ECC_GetAlgo().
3- Interface with legacy and ONFI NAND memories by controlling the input and output access operations.
Blocking mode :
This functionality is ensured by these polling functions :
HAL_NAND_Reset() function to reset the NAND memory.
HAL_NAND_ReadID() function to read the NAND device identifier.
HAL_NAND_ONFIDetect() function to check whether the NAND memory is ONFI compliant.
HAL_NAND_ONFIReadParameterPage() function to read data structure describing the device’s organization, features, timings and other behavioral parameters.
HAL_NAND_ReadPage() function to read a page from NAND memory data area.
HAL_NAND_ProgramPage() function to program a page in the NAND flash data area.
HAL_NAND_ReadPageSpareArea() function to read the NAND memory spare area.
HAL_NAND_ProgramPageSpareArea() function to program the NAND memory spare area.
HAL_NAND_EraseBlock() function to erase a specified block of the NAND flash memory.
HAL_NAND_ReadStatus() function to read the NAND flash operation status.
HAL_NAND_ReadInPage() function to read data starting at a specified column offset within the selected page.
HAL_NAND_ProgramInPage() function to program data starting at a specified column offset within the selected page.
HAL_NAND_CopyBackRead() function to read data from source location and copy it temporarily in the NAND memory’s internal buffer.
HAL_NAND_CopyBackProgram() function to copy the data held in the NAND internal buffer to a new destination location.
HAL_NAND_ECC_ProgramPage() function to program a page in the NAND flash data area with chunk-by-chunk ECC computation and to store the resulting parity bits in the spare area.
HAL_NAND_ECC_ReadPage() function to read a page from the NAND flash data area with chunk-by-chunk ECC computation and to correct errors using the stored parity bits.
HAL_NAND_ECC_GetErrors() function to retrieve the positions where errors are detected during a read operation.
Non-blocking mode :
The NAND driver provides also control over input and output operations of both ONFI and legacy compliant NAND memories in non-blocking mode.
Send only the read and program commands then it is up to the application to handle data transmit and receive. This functionality is ensured by these functions :
HAL_NAND_SendReadPageCmd() function to send the read page command.
HAL_NAND_EndReadPage() function to finalize the read page process.
HAL_NAND_SendProgramPageCmd() function to send program page command.
HAL_NAND_EndProgramPage() function to finalize the program page process.
4- Manage the FMC NAND peripheral access when it is fully configured : This functionality is ensured by these functions :
HAL_NAND_Enable() function to enable the FMC NAND bank (when disabled).
HAL_NAND_Disable() function to disable the FMC NAND bank (when enabled).
HAL_NAND_IsEnabled() function to retrieve the FMC NAND bank status.
5- Store and retrieve user data : This functionality is ensured by these functions :
HAL_NAND_SetUserData() function to store user data pointer into the handle.
HAL_NAND_GetUserData() function to retrieve user data pointer from the handle.
6- Retrieve the global state, the kernel clock frequency and the NAND instance : This functionality is ensured by these functions :
HAL_NAND_GetState() function to retrieve the global state.
HAL_NAND_GetClockFreq() function to retrieve the clock frequency.