This code example shows how to write flash memory row.
The device used in this code example (CE) is:
The board used for testing is:
- PSOC™ 4 HVMS Lite Kit (KIT_PSoC4-HVMS-128K_LITE)
- PSOC™ 4 HVMS Lite Kit (KIT_PSoC4-HVMS-64K_LITE)
This code example writes 128 bytes data in a row of flash memory area using Write row System call. Then, when System call operation success and, source and destination data match, LED7 turns on. If System call operation fails or, source and destination data do not match, LED6 turns on.
PSOC™ HV MS flash memory has the following features:
- Supports AEC-Q100 Automotive Grade 1 temperature range (Ambient temperature = –40°C to 125°C)
- Up to 64 KB (MS-64K)/ 128 KB (MS-128K) of flash with error correction code (ECC)
- 1 KB of SFlash for trimming and wounding information with ECC
- Flash macro data: 72-bit width (64-bit data + 8-bit parity)
- ECC parity calculated in hardware
- Erased flash (all zeros) will not cause ECC errors on read
- Eight ECC bits allow a single error correction and double error detection
- ECC error injection
- Implement flash write protect register
- Flash controller with data buffers to accelerate flash memory accesses
- System performance controller interface (SPCIF) with ECC provides program and erase functionality
- Flash endurance: 100 K cycles at 85°C ambient, 10 K cycles at 125°C ambient
- Program disturb: 100 K cycles at 125°C ambient
- Data retention: Up to 15 years
- Core power supply: VCCD = 1.8 V
More details can be found in:
- PSOC™ 4 HVMS Series
This Code Example has been developed for:
Figure 1. KIT_PSOC4-HVMS-128K_LITE (Top View)
The firmware is implemented in main.c and performs the following functions:
- Define the size of the flash memory row and initialize data to write
- Initialize and board peripherals
- Set the write data
- Configure LEDs for results (LED_OK / LED_ERROR)
- Write data to flash memory row and confirm read data
- Confirm results on the LED_OK (User LED7) or LED_ERROR (User LED6)
ModusToolbox™ Device configurator
This code example project can be created or imported using ModusToolbox™ IDE. To configure the project in the Quick Panel, click on Device Configurator
Figure 2. Select Device Configurator
Figure 3. System Clock Settings
The basic idea is to set the data to be written and the flash row to which it should be written, and execute flash memory write/read access.
- Using memset to set the source data.
- Using memcmp to compare the written value with the value written in the destination flash memory address.
- Cy_GPIO_Write(); reflects the states of flash row access on the LED (LED_OK/LED_ERROR).
- Using to erase a flash row and programs it with the new data by Cy_Flash_WriteRow().
- Define the size of the flash memory by CY_FLASH_SIZEOF_FLASH.
- CY_FLASH_DRV_SUCCESS is an enumerator when the status of the System call is success.
Before testing this code example:
- Power the board through the dedicated power connector
- Connect the board to the PC through the USB interface
- Build the project using the dedicated Build button
Figure 5. Build Project
or by right-clicking the project name and selecting "Build Project"
- To program the board, in the Quick Panel, scroll down, and click [Project Name] Program (KitProg3_MiniProg4)
-
After programming, the code example will start automatically and flash row access result is displayed to LED. If LED_OK (User LED7) lights then it passed, when LED_ERROR (User LED6) lights then it failed.
-
You can debug the example to step through the code. In the IDE, use the [Project Name] Debug (KitProg3_MiniProg4) configuration in the Quick Panel. For details, see the "Program and debug" section in the Eclipse IDE for ModusToolbox™ software user guide.
Note: (Only while debugging) On the CM7 CPU, some code in main() may execute before the debugger halts at the beginning of main(). This means that some code executes twice: once before the debugger stops execution, and again after the debugger resets the program counter to the beginning of main(). See KBA231071 to learn about this and for the workaround.
Relevant Application notes are:
ModusToolbox™ is available online:
Associated PSOC™ 4 HVMS MCUs can be found on:
More code examples can be found on the GIT repository:
For additional trainings, visit our webpage:
For questions and support, use the PSOC™ 4 HVMS Forum: