Writing to Internal Flash in PSoC 3 and PSoC 5

Similar documents
CE56273 Associated Part Families: CY8C38xx/CY8C55xx Software: PSoC Creator Related Hardware: CY8CKIT-001 Author: Anu M D

Use the Status Register when the firmware needs to query the state of internal digital signals.

This optional pin is present if the Mode parameter is set to SyncMode or PulseMode. Otherwise, the clock input does not show.

Filter_ADC_VDAC_poll Example Project Features. General Description. Development Kit Configuration

CE PSoC 4: Time-Stamped ADC Data Transfer Using DMA

Use the Status Register when the firmware needs to query the state of internal digital signals.

This optional pin is present if the Mode parameter is set to SyncMode or PulseMode. Otherwise, the clock input does not show.

For one or more fully configured, functional example projects that use this user module go to

HX2VL Development Kit Guide. Doc. # Rev. *A

HX2VL Development Kit Guide. Doc. # Rev. **

Voltage Reference (Vref) Features. General Description. Input/Output Connections. When to Use a Vref Voltage references and supplies

Cypress HX2VL Configuration Utility Blaster User Guide

AN SIO Tips and Tricks in PSoC 3 / PSoC 5. Application Note Abstract. Introduction

CY7C603xx CYWUSB

8 to 1 Analog Multiplexer Datasheet AMux8 V 1.1. Features and Overview

THIS SPEC IS OBSOLETE

Cypress HX2VL Configuration Utility Blaster User Guide

4 to 1 Analog Multiplexer Data Sheet

Shadow Registers Datasheet ShadowRegs V 1.1. Features and Overview

Programmable Threshold Comparator Data Sheet

THIS SPEC IS OBSOLETE

Preliminary. Gas Sensor Analog Front End Datasheet GasSensorAFE V Features and Overview. This datasheet contains Preliminary information.

LPF (Optional) CY8C24x93. Without LPF and ISR to 3* With LPF only** to 3* With ISR only to 3*

GPIF II Designer - Quick Start Guide

Reviving Bit-slice Technology in a Programmable Fashion

Supported Devices: CY8C28x13, CY8C28x33, CY8C28x43, CY8C28x45, CY8C28x52, CY8C21x45, CY8C22x45, CY8C24x93. CY8C24x

PSoC 1 I 2 C Bootloader

PSoC 4 Low Power Comparator (LPComp) Features. General Description. When to Use a LPComp 2.0. Low input offset. User controlled offset calibration

Comparator (Comp) Features. General Description. When to use a Comparator 1.60

Clock Programming Kit

CYClockMaker Programming Kit Guide CY3675. Doc. # Rev. **

Next-Generation Hot-Swap Controllers

DMX512 Receiver Datasheet DMX512Rx V 1.0. Features and Overview

FTG Programming Kit CY3670. Spec. # Rev. *C

Use the IDAC8 when a fixed or programmable current source is required in an application.

24-Bit Pseudo Random Sequence Generator Data Sheet

Programmable Gain Amplifier Datasheet PGA V 3.2. Features and Overview

THIS SPEC IS OBSOLETE

CYClockMaker Programming Kit Guide CY3675. Doc. # Rev. *C

16-Bit Hardware Density Modulated PWM Data Sheet

This Application Note demonstrates an SPI-LIN slave bridge using a PSoC device. Demonstration projects are included.

CY3660-enCoRe V and encore V LV DVK Kit Guide

AN EZ-USB FX3 I 2 C Boot Option. Application Note Abstract. Introduction. FX3 Boot Options

The color of the Clock component waveform symbol will change based on the clock's domain (as shown in the DWR Clock Editor), as follows:

PSoC Creator Component Datasheet

Bootloader project - project with Bootloader and Communication components

CapSense I 2 C/SPI Timer Flash RAM

PSoC Programmer 3.12 Release Notes

The following table lists user modules used in this code example and the hardware resources occupied by each user module.

Incremental ADC Data Sheet

CE CY8CKIT-042-BLE F-RAM Data Logger

CE58957 demonstrates how to implement the fade and toggle feature to the backlight LEDs of CapSense buttons.

Use a DieTemp component when you want to measure the die temperature of a device.

EZ I 2 C Slave. Features. General Description. When to use a EZ I 2 C Slave 1.50

EZ-USB FX3 Development Kit Guide

144-Mbit QDR -II SRAM 2-Word Burst Architecture

Programmer User Guide

This optional pin is present if the Mode parameter is set to SyncMode or PulseMode. Otherwise, the clock input does not show.

PSoC Programmer Release Notes

FM3 MB9B100A/300A/400A/500A Series Inverter Solution GUI User Guide

AN1090. NoBL : The Fast SRAM Architecture. Introduction. NoBL SRAM Description. Abstract. NoBL SRAM Operation

12-Mbit (512 K 24) Static RAM

PSoC Designer Release Notes

CY8C29/27/24/23/21xxx, CY8CLED02/04/08/16, CY8CLED0xD, CY8CLED0xG, CY8C28x45, CY8CPLC20, CY8CLED16P01, CY8C28xxx. Main UM

Use the Status Register when the firmware needs to query the state of internal digital signals.

AN PSoC 3 and PSoC 5 SFF-8485 Serial GPIO (SGPIO) Initiator Interface. Application Note Abstract. Introduction

PSoC Blocks. CY8C20xx6/6A/6AS/6H/6L, CY8C20xx7/7S, CY7C643xx, CY7C604xx, CYONS2xxx, CYONSxNxxxx, CYRF89x35, CY8C20065, CY8C24x93, CY7C69xxx

This section describes the various input and output connections for the Voltage Fault Detector.

CE95314 PSoC 3, PSoC 4, and PSoC 5LP EZI2C

Libraries Guide. Arithmetic Libraries User Guide. Document #: Rev. *A

The AMuxSeq is capable of having between 2 and 32 analog inputs. The paired inputs are present when the MuxType parameter is set to "Differential.

Automatic reload of the period to the count register on terminal count

Digital Logic Gates. Features. General Description. Input/Output Connections. When to Use a Logic Gate. Input 1. Input 2. Inputs 3-8 * 1.

Digital Multiplexer and Demultiplexer. Features. General Description. Input/Output Connections. When to Use a Multiplexer. Multiplexer 1.

PSoC Programmer Release Notes

Use the Status Register when the firmware needs to query the state of internal digital signals.

Base Timer Channel (BT) Features. General Description. When to Use a PDL_BT Component 1.0

This section describes the various input and output connections for the Voltage Fault Detector.

Release Notes SRN065 PSoC Programmer Version Release Date: November 9, 2009

4K x 8 Dual-Port Static RAM and 4K x 8 Dual-Port SRAM with Semaphores

H O S T. FX2 SX2 Back - to - Back Setup. Project Objective. Overview

This section describes the various input and output connections for the SysInt Component.

This input determines the next value of the output. The output does not change until the next rising edge of the clock.

Supports one or two address decoding with independent memory buffers. Memory buffers provide configurable Read/Write and Read Only regions

PSoC 6 Current Digital to Analog Converter (IDAC7)

PSoC Creator Quick Start Guide

PSoC 4 Current Digital to Analog Converter (IDAC)

Capable of adjusting detection timings for start bit and data bit

One 32-bit counter that can be free running or generate periodic interrupts

PSoC 4 Voltage Comparator (Comp) Features. General Description. When to Use Comparator Low input offset. User controlled offset calibration

THIS SPEC IS OBSOLETE

Setting Oscillation Stabilization Wait Time of the main clock (CLKMO) and sub clock (CLKSO)

Multifunction Serial Interface (PDL_MFS) Features. General Description. When to Use a PDL_MFS Component. Quick Start 1.0

THIS SPEC IS OBSOLETE

1-Mbit (64K x 16) Static RAM

THIS SPEC IS OBSOLETE

W H I T E P A P E R. Introduction. Devices. Energy Comparison of Cypress F-RAM and EEPROM

Comparator (Comp) Features. General Description. When to use a Comparator Low input offset. User controlled offset calibration

Optional Pause Pulse for constant frame length of 282 clock ticks

For More Information Please contact your local sales office for additional information about Cypress products and solutions.

Transcription:

Writing to Internal Flash in PSoC 3 and PSoC 5 Code Example Objective CE62384 demonstrates how to write to the internal flash to change its contents during run time. CE62384 Associated Part Families: CY8C3xxx and CY8C5xxx Software: PSoC Creator Related Hardware: CY8CKIT-001 Author: Anup Mohan Overview In this code example, a string ( Hello World ) is stored as an array in the flash. Initially the string is displayed on LCD. When the user presses the switch, the string Hello World is replaced with a new string PSoC Rocks!. The flash is programmed with the new string. A reload switch is also present which when pressed programs the flash string array with the original string Hello World. Component List Instance Name Component Name Component Category Comments Pin_NewData Digital Input Pin Ports and Pins Configured for resistive pull-up drive mode, falling edge interrupt Pin_Reload Digital Input Pin Ports and Pins Configured for resistive pull-up drive mode, falling edge interrupt ISR_NewData Interrupt System Default configuration ISR_Reload Interrupt System Default configuration LCD Character LCD Display Default configuration July 22, 2011 Document No. 001-62384 Rev *B 1

Top Design The following figure shows the components and their routing. When the switch connected to Pin_NewData is pressed, the string PSoC Rocks! is written to the flash and displayed on the LCD. When switch connected to Pin_Reload is pressed, the string Hello World is written to the flash and displayed on the LCD. The following figure shows pin placement (as in.cydwr file) July 22, 2011 Document No. 001-62384 Rev *B 2

Component Configuration Pin_NewData In CY8CKIT-001 the switches when pressed will connect the input signal to ground. Hence the digital input pin Pin_NewData which is connected to a switch is configured to have a resistive pull-up drive mode. The pin will be in logic high state by default and when switch is pressed the pin will be driven low. The pin interrupt is configured to trigger on a falling edge to detect the switch press. The Pin_Reload component has the same configuration as that of Pin_NewData. The other components are left to the default configuration. Design Wide Resources The project uses the default system wide resources settings. See the design wide resources (cydwr file) for the settings. July 22, 2011 Document No. 001-62384 Rev *B 3

Operation This code example demonstrates how to write to the flash during run time. Flash is mainly organized in rows, each row containing maximum of 256 bytes (device specific) of data and maximum of 32 bytes (device specific) for error correcting codes (ECC). ECC is used to store the error correcting code that corresponds to the flash row and is computed automatically. ECC can also be used for storing data. This code example covers writing to the flash locations excluding the ECC locations. Flash is programmed during run time through system performance controller (SPC) calls. The flash APIs available in CyFlash.h abstract these SPC calls for simplicity. The example code deals only with writing to the data space and does not cover configuring the ECC space. Most applications require modifying a constant data or constant array stored in the flash. The SPC allows programming flash in rows. SPC does not do byte writes and thus updates the whole row. The entire row is erased first and then programmed. Hence, to update a constant data stored in the flash, the entire row in which the constant data is located should be read back and saved. The entire row should be programmed again with only the constant data value updated and all other data unchanged. Let us take the scenario of updating a constant array stored in the flash. We need to analyze three different cases for this. Case 1: If the array has 256 elements and it fits completely in a single row. In this case, you need to find out the row number, erase the entire row, and program the row with the modified array. There is no need to read the row before update because the whole row can be overwritten. Case 2: If the size of the array is less than 256 and the array is placed somewhere inside the row and the array starts at an offset from the row start. In this case, follow the given steps. First read back and save the entire row and find out where the array starts. Update the array with the bytes to be written. Finally, program the entire row with modified data and other saved elements all in the same position as they were before. Case 3: If the data array is spread across two rows. In this case, you need to find out the row in which the array starts and the offset position in the row. Then that particular row and the next row should be programmed as mentioned in Case 2. In the code example, a string Hello World is stored as an array in the flash. The array has 11 elements in it. Therefore, while writing the firmware we need to consider Case 2 and Case 3 as mentioned above. The firmware is written in such a manner that it accommodates the necessary steps required for both Case 2 and Case 3. Important Flash API s used in the code are as follows. cystatus CySetTemp(void) This API executes an SPC command to get the temperature of the die. The other flash functions need the temperature to maximize the efficiency of the flash write algorithms. cystatus CySetFlashEEBuffer(uint8 * buffer) This API sets the address of the temporary storage area for SPC commands used to write flash. This buffer is used for other purpose when the flash functions are not in use. The argument (buffer) defines the address of block of memory to store temporary memory. The size of the block of memory is SIZEOF_FLASH_ROW + SIZEOF_ECC_ROW. The caller must make the first call to CySetTemp and CySetFlashEEBuffer functions. The temperature is needed to adjust the write times to the flash for optimal performance. The buffer stores intermediate data while communicating with the SPC. July 22, 2011 Document No. 001-62384 Rev *B 4

cystatus CyWriteRowData(uint8 arrayid, uint16 rowaddress, uint8 * rowdata) This API allows a row to be erased and programmed. If the array is a flash array and ECC is used for configuration storage, the function first reads the ECC data in the row and concatenates the rowdata. Erase the row and program the complete row to flash. The argument arrayid specifies the ID of the array that contains the sector to be erased. This parameter determines whether to program flash or EEPROM array. The number of arrays that are flash and the number of arrays that are EEPROM are specific to the exact part selected. The following lists the array IDs are assigned to Flash and EEPROM. 0x00-0x3E: (63) Flash arrays 0x3F: (1) Selects all Flash arrays(for parallel programming) 0x40-0x7F: (64) Embedded EEPROM arrays In the project, we use the arrayid 0x00. Argument rowaddress specifies row number to erase and then program. The third and final argument rowdata specifies the address of the data to be programmed. The size of this row is SIZEOF_FLASH_ROW. Other APIs are also available for configuring the ECC and enabling or disabling the flash for different power modes. These APIs are not discussed in this example code. For more details, see the System Reference Guide available in PSoC Creator under Help Documentation. Following are the major steps covered in the code: Read the address of the string array ( Hello World ) and check if the array starts at the beginning of the row or starts at an offset location. Check whether the array is spread across two rows. If Pin_NewData switch is pressed then read back the entire flash row, modify only the string array contents to PSoC Rocks! and write the new string array into that particular flash row. If the data is spread across two rows perform the same operation as specified in the earlier step for the second row also. While doing this across two rows, care is taken to ensure other data apart from the array placed in those are not corrupted. If Reload switch is pressed, read back the entire flash row and replace only the string array contents with its original contents ( Hello World ), which was saved initially in a backup array. Necessary action as mentioned in step 4 is taken here if the data is spread across two rows. Hardware Connections Connect P0[6] to SW1 on DVK. (Switch press to display PSoC Rocks! on the LCD). Connect P1[2] to SW2 on DVK. (Switch press to reload the initial contents and display Hello World on the LCD). For details about the Kit hardware see CY8CKIT-001 PSoC Development Kit Guide. July 22, 2011 Document No. 001-62384 Rev *B 5

Output Use the device selector window (Project->Device Selector) in PSoC Creator to select the appropriate device and device revision. If you are using a PSoC 3 device (for example, CY8C3866AXI-040) with production revision, then use the following selection. Similarly, select appropriate device number to work with the PSoC 5 device family (for example, CY8C5588AXI-060). Note For engineering samples, device revision is marked on the package as part of the device number. Production silicon will not have an ES marking. Build the Project and Program the device. Press SW4 (Reset Switch) to reset the device. The string Hello World will be displayed on the LCD. Press SW1 and the string PSoC Rocks! is displayed on the LCD. If SW2 is pressed the string Hello World is displayed on the LCD. When the device is reset, the displayed string depends on the state at which the device was reset. This is because we program string array in the flash. A sample LCD output is as follows. July 22, 2011 Document No. 001-62384 Rev *B 6

Document History Document Title: Writing to Internal Flash in PSoC 3 and PSoC 5 CE62384 Document Number: 001-62384 Revision ECN Orig. of Change Submission Date Description of Change ** 2958721 ANUP 06/22/2010 New Example Project *A 3153970 ANUP 01/25/2010 1) The components in the project are updated to the latest version. 2) The component version number is deleted from the component table in the documentation. 3) The project has been updated to support PSoC3 ES3 Silicon. *B 3324821 ANUP 07/22/2011 Updated title, Overview section, and Component List table. Updated figures in Top Design Section. Updated figure for Pin_NewData in Component Configuration section. PSoC is a registered trademark of Cypress Semiconductor Corp. PSoC Creator is a trademark of Cypress Semiconductor Corp. All other trademarks or registered trademarks referenced herein are the property of their respective owners. Cypress Semiconductor 198 Champion Court San Jose, CA 95134-1709 Phone: 408-943-2600 Fax: 408-943-4730 http://www.cypress.com/ Cypress Semiconductor Corporation, 2010-2011. The information contained herein is subject to change without notice. Cypress Semiconductor Corporation assumes no responsibility for the use of any circuitry other than circuitry embodied in a Cypress product. Nor does it convey or imply any license under patent or other rights. Cypress products are not warranted nor intended to be used for medical, life support, life saving, critical control or safety applications, unless pursuant to an express written agreement with Cypress. Furthermore, Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress products in life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges. This Source Code (software and/or firmware) is owned by Cypress Semiconductor Corporation (Cypress) and is protected by and subject to worldwide patent protection (United States and foreign), United States copyright laws and international treaty provisions. Cypress hereby grants to licensee a personal, non-exclusive, non-transferable license to copy, use, modify, create derivative works of, and compile the Cypress Source Code and derivative works for the sole purpose of creating custom software and or firmware in support of licensee product to be used only in conjunction with a Cypress integrated circuit as specified in the applicable agreement. Any reproduction, modification, translation, compilation, or representation of this Source Code except as specified above is prohibited without the express written permission of Cypress. Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress reserves the right to make changes without further notice to the materials described herein. Cypress does not assume any liability arising out of the application or use of any product or circuit described herein. Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress product in a life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges. Use may be limited by and subject to the applicable Cypress software license agreement. July 22, 2011 Document No. 001-62384 Rev *B 7