Internal flash memory programming.
The functions and other declarations used in this driver are in cy_flash.h. You can include cy_pdl.h to get access to all functions and declarations in the PDL.
Flash memory in PSoC devices provides non-volatile storage for user firmware, user configuration data, and bulk data storage.
Flash operations are implemented as system calls. System calls are executed out of SROM in the privileged mode of operation. Users have no access to read or modify the SROM code. The driver API requests the system call by acquiring the Inter-processor communication (IPC) and writing the SROM function opcode and parameters to its input registers. As a result, an NMI interrupt is invoked and the requested SROM function is executed. The operation status is returned to the driver context and a release interrupt is triggered.
Writing to flash can take up to 20 milliseconds. During this time, the device should not be reset (including XRES pin, software reset, and watchdog) or unexpected changes may be made to portions of the flash. Also, the low-voltage detect circuits should be configured to generate an interrupt instead of a reset.
A Read while Write violation occurs when a flash Read operation is initiated in the same or neighboring (neighboring restriction is applicable just for the CY8C6xx6, CY8C6xx7 devices) flash sector where the flash Write, Erase, or Program operation is working. This violation may cause a HardFault exception. To avoid the Read while Write violation, carefully split the Read and Write operation on flash sectors which are not neighboring, considering both cores in the multi-processor device. If the flash is divided into four equal sectors, you may edit the linker script to place the code into neighboring sectors. For example, use sectors number 0 and 1 for code and sectors 2 and 3 for data storage.
The PSoC 6 MCU user-programmable Flash consists of:
Write operation may be done as Blocking or Partially Blocking, defined as follows:
In this case, the entire Flash block is not available for the duration of the Write (∼16ms). Therefore, no Flash accesses (from any Bus Master) can occur during that time. CPU execution can be performed from SRAM. All pre-fetching must be disabled. Code execution from Flash is blocked for the Flash Write duration for both cores.
This method has a much shorter time window during which Flash accesses are not allowed. Application code execution from Flash is blocked for only a part of Flash Write duration, for both cores. Blocking duration depends upon the API sequence used.
For API sequence Cy_Flash_StartEraseRow() + Cy_Flash_StartProgram() there are four block-out regions during which Read is blocked. See Figure 1.
Block-out | Phase | Duration |
---|---|---|
A | The beginning of the Erase operation | 2ms + 9500 SlowClk cycles |
B | The end of the Erase operation | 0.13ms + 1000 SlowClk cycles |
C | The beginning of the Program operation | 0.8ms + 6000 SlowClk cycles |
D | The end of the Program operation | 0.13ms + 1000 SlowClk cycles |
This allows both cores to execute for about 80% of Flash Write operation - see Figure 1. This capability is important for communication protocols that rely on fast response.
For the Cy_Flash_StartWrite() function, the block-out period is different for the two cores. The core that initiates Cy_Flash_StartWrite() is blocked for two periods:
The core that performs read/execute is blocked identically to the previous scenario - see Figure 1.
This allows the core that initiates Cy_Flash_StartWrite() to execute for about 20% of Flash Write operation. The other core executes for about 80% of Flash Write operation.
Some constraints must be planned for in the Partially Blocking mode which are described in detail below.
Writing rules in application flash (this restriction is applicable just for CY8C6xx6, CY8C6xx7 devices):
Suggestion: in case of bootloading, it is recommended to place code for CM4 in either S0 or S1. CM0+ code resides in S0. Write data to S2 and S3 sections.
If you plan to use "cy_em_eeprom" section for different purposes for both of device cores or use Em_EEPROM Middleware together with flash driver write operations you must modify the linker scripts.
For more information, refer to the Middleware/Cypress Em_EEPROM Middleware Library section of the PDL documentation.
See the technical reference manual (TRM) for more information about the Flash architecture.
MISRA Rule | Rule Class (Required/Advisory) | Rule Description | Description of Deviation(s) |
---|---|---|---|
11.4 | A | Casting to different object pointer type. | The cast of the uint32_t pointer to pipe message structure pointer is used to get transmitted data via the IPC (Inter Process Communication) channel. We cast only one pointer, so there is no way to avoid this cast. |
Version | Changes | Reason for Change |
---|---|---|
3.40 | Updated Cy_Flash_OperationStatus() to access protected registers. | Added PSoC 64 device support. |
3.30.4 | Improved documentation. | User experience enhancement. |
3.30.3 | Updated documentation to limit devices with the restrictions. Improved calculation of the CY_FLASH_DELAY_CORRECTIVE macro. | User experience enhancement. |
3.30.2 | Updated documentation to limit devices with the neighboring restriction. | User experience enhancement. |
3.30.1 | Used the CY_RAMFUNC_BEGIN and CY_RAMFUNC_END macros that allocate the function in RAM instead of using the CY_SECTION(".cy_ramfunc") macros. | Removed the code duplication. |
3.30 | Moved ipcWaitMessageStc structure to the RAM section called ".cy_sharedmem". | Support Secure Boot devices. |
Renamed Function Cy_Flash_StartErase() to Cy_Flash_StartEraseRow(). | The driver improvements based on the usability feedback. | |
Added new API functions Cy_Flash_EraseSector, Cy_Flash_StartEraseSector, Cy_Flash_EraseSubsector, Cy_Flash_StartEraseSubsector | The driver improvements based on the usability feedback. | |
3.20 | Flattened the organization of the driver source code into the single source directory and the single include directory. | Driver library directory-structure simplification. |
Added new API function Cy_Flash_InitExt | The driver improvements based on the usability feedback | |
Added register access layer. Use register access macros instead of direct register access using dereferenced pointers. | Makes register access device-independent, so that the PDL does not need to be recompiled for each supported part number. | |
3.11 | Updated driver functionality to correctly use the SysClk measurement counters while partially blocking flash operations | Added arbiter mechanism for correct usage of the SysClk measurement counters |
3.10 | Updated Cy_Flash_SendCmd() code to support single core devices. | Support new devices |
3.0 | New function - Cy_Flash_ProgramRow(); Updated Cy_Flash_RowChecksum(): changed input parameter to take the row address (rowAddr) instead of the row number (rowNum); Renamed macro for disabling RWW support in driver to CY_FLASH_RWW_DRV_SUPPORT_DISABLED. Updated Configuration Considerations documentation section with flash usage constraints. | Improvements made based on usability feedback to use a common interface |
2.0 | Added non-blocking erase function - Cy_Flash_StartErase(). Removed the clear cache function call. | The clear cache operation is removed from the blocking Write/Erase function because in this case it is performed by the hardware. Otherwise it is documented that it is the user's responsibility to clear the cache after executing the non-blocking Write/Erase flash operation. |
Added new Cy_Flash_IsOperationComplete() function to check completeness. Obsoleted Cy_Flash_IsWriteComplete(), Cy_Flash_IsProgramComplete(), and Cy_Flash_IsEraseComplete() functions. Added Cy_Flash_GetExternalStatus() function to get unparsed status where flash driver will be used in security applications with other modules as SecureImage. Added Cy_Flash_Init() function to initialize all needed prerequisites for Erase/Write operations. | Updated driver design to improve user experience. | |
Updated driver implementation to remove MISRA rules deviations. | Driver implementation quality improvement. | |
1.0 | Initial version |
API Reference | |
Macros | |
Functions | |
Enumerated Types | |