Table of Contents

Advertisement

Quick Links

AN84858
PSoC 4 Programming Using an External
Microcontroller (HSSP)

About this document

Scope and purpose
AN84858 shows you how to implement PSoC™ 4 device programming with an external microcontroller by using
modular C code. In this process, called Host Sourced Serial Programming (HSSP), the host microcontroller
programs PSoC 4 through the serial wire debug (SWD) interface. The C code is written so that it can be ported to
any microcontroller with minimal changes, speeding up HSSP application development for PSoC 4.
More code examples? We heard you.
To access an ever-growing list of hundreds of PSoC code examples, please visit our
You can also explore the video training library here.

Table of contents

About this document ....................................................................................................................... 1
Table of contents ............................................................................................................................ 1
1
Introduction .......................................................................................................................... 3
1.1
Types of Programmers ............................................................................................................................ 3
1.2
Terms and Definitions ............................................................................................................................. 3
2
HSSP Firmware Architecture ................................................................................................... 5
2.1
SWD Protocol Physical Layer .................................................................................................................. 6
2.2
SWD Protocol Packet Layer ..................................................................................................................... 6
2.3
Fetching Programming Data ................................................................................................................... 6
2.4
HSSP Programming Steps ....................................................................................................................... 7
2.5
HSSP Timeout Parameters ..................................................................................................................... 7
2.6
HSSP Programming Data ........................................................................................................................ 8
2.7
Main Application Code ............................................................................................................................ 8
2.8
HSSP Error Status .................................................................................................................................... 8
3
Hardware Connections for HSSP Programming ........................................................................ 10
4
Porting the HSSP Application to a Host Programmer ................................................................. 11
4.1
Files That Must Be Ported ..................................................................................................................... 11
4.2
Code Changes Required While Porting ................................................................................................. 11
5
Calculating HSSP Timeout Parameters .................................................................................... 13
5.1
DEVICE_ACQUIRE_TIMEOUT ................................................................................................................. 13
5.2
SROM_POLLING_TIMEOUT ................................................................................................................... 14
5.3
XRES_PULSE_100US ............................................................................................................................. 15
6
Interface for Receiving HSSP Programming Data ...................................................................... 17
7
HSSP Timing Validation ......................................................................................................... 19
8
Power Cycle Mode Programming............................................................................................. 20
9
Testing the Example Projects ................................................................................................. 21
9.1
For CY8CKIT-038 PSoC 4 Development Kit ........................................................................................... 21
Application Note
www.infineon.com
Please read the Important Notice and Warnings at the end of this document
page 1 of 45
code examples web
page.
001-84858 Rev. *N
2021-03-23

Advertisement

Table of Contents
loading

Summary of Contents for Infineon PSoC 4

  • Page 1: Table Of Contents

    C code. In this process, called Host Sourced Serial Programming (HSSP), the host microcontroller programs PSoC 4 through the serial wire debug (SWD) interface. The C code is written so that it can be ported to any microcontroller with minimal changes, speeding up HSSP application development for PSoC 4.
  • Page 2 PSoC 4 Programming Using an External Microcontroller (HSSP) Table of contents For Kits with Onboard PSoC 5LP Programmer (KitProg) ..............21 For Kits with Onboard PSoC 5LP Programmer (KitProg2) ..............25 Tips and Tricks for Debugging HSSP Issues ................29 Summary ..........................
  • Page 3: Introduction

    This application note explains how to implement a host programmer to program a PSoC 4 device. For more information on the PSoC 4 architecture and to learn how to create projects for PSoC 4 using the PSoC Creator™ software, see AN79953 –...
  • Page 4 Bootloaders can use any standard communication interface (such as, USB, I C, SPI, and UART) to update − the firmware, while HSSP uses an SWD or JTAG interface to program the flash. PSoC 4 supports only SWD interfaces. Application Note 4 of 45 001-84858 Rev.
  • Page 5: Hssp Firmware Architecture

    PSoC 4 Programming Using an External Microcontroller (HSSP) HSSP Firmware Architecture HSSP Firmware Architecture HSSP for the target device is implemented in multiple layers using modular C code. These layers are as follows: SWD Protocol Physical layer SWD Protocol Packet layer...
  • Page 6: Swd Protocol Physical Layer

    PSoC 4 Programming Using an External Microcontroller (HSSP) HSSP Firmware Architecture All layers used in the firmware architecture, as shown in Figure 1, are discussed in the following sections. SWD Protocol Physical Layer Files that constitute the SWD Protocol Physical layer are described:...
  • Page 7: Hssp Programming Steps

    PSoC 4 Programming Using an External Microcontroller (HSSP) HSSP Firmware Architecture Note: See the section Interface for Receiving HSSP Programming Data for information on how to modify the HSSP source code. HSSP Programming Steps This layer includes the files named ProgrammingSteps.c and ProgrammingSteps.h. These files contain the top- level functions of the HSSP application.
  • Page 8: Hssp Programming Data

    PSoC 4 Programming Using an External Microcontroller (HSSP) HSSP Firmware Architecture Timestamp definitions are derived from the electrical timing specifications provided in the Device Programming Specifications. The values of these timestamp parameter definitions in Timeout.h are for a PSoC 5LP host programmer running at a clock frequency of 63 MHz.
  • Page 9 PSoC 4 Programming Using an External Microcontroller (HSSP) HSSP Firmware Architecture This function returns the status byte. Use the status byte to infer error details from the bit field definitions. Figure 2 for the bit fields returned by this function.
  • Page 10: Hardware Connections For Hssp Programming

    Hardware Connections for HSSP Programming HSSP programming in PSoC 4 uses the SWD interface pins (SWDIO and SWDCK) and the external reset pin (XRES). The host programmer pin drive mode requirements are explained in the “Physical Layer” section in the...
  • Page 11: Porting The Hssp Application To A Host Programmer

    PSoC 4 Programming Using an External Microcontroller (HSSP) Porting the HSSP Application to a Host Programmer Porting the HSSP Application to a Host Programmer The project A_Hssp_Programmer, provided with this application note, uses PSoC 5LP as the host programmer for the target device. In the HSSP application, the host programmer can be any other microcontroller. This section explains the changes required to port the HSSP application code to the specific host used to program the target device.
  • Page 12 PSoC 4 Programming Using an External Microcontroller (HSSP) Porting the HSSP Application to a Host Programmer HexImage.c, HexImage.h: These files contain the data to be programmed into the target device, defined as • an array of constants. For the PSoC 5LP host programmer, the data to be programmed is stored in the flash memory of the host PSoC 5LP.
  • Page 13: Calculating Hssp Timeout Parameters

    PSoC 4 Programming Using an External Microcontroller (HSSP) Calculating HSSP Timeout Parameters Calculating HSSP Timeout Parameters Modify the values of the timeout parameters defined in the Timeout.h file according to the host programmer used. A separate test project, “C_Hssp_TimeoutCalc,” is provided with the application note. This project illustrates the procedure to calculate the timeout parameters for a PSoC 5LP host programmer.
  • Page 14: Srom_Polling_Timeout

    PSoC 4 Programming Using an External Microcontroller (HSSP) Calculating HSSP Timeout Parameters Measure the LOW pulse width on the test pin for one iteration of the device-acquiring sequence by using an oscilloscope. Then, calculate this macro as follows: DEVICE_ACQUIRE_TIMEOUT = (X ms/low pulse width), where X is the maximum time window for acquiring the...
  • Page 15: Xres_Pulse_100Us

    PSoC 4 Programming Using an External Microcontroller (HSSP) Calculating HSSP Timeout Parameters TESTPIN_OUTPUT_LOW; for(timestamp = 0; timestamp < 10; timestamp++) Read_IO (CPUSS_SYSREQ, &statusCode); /*performing SROM_SYSREQ_BIT | SROM_PRIVILEGED_BIT */ statusCode &= (SROM_SYSREQ_BIT | SROM_PRIVILEGED_BIT); /* Make the pin high after sending SWD clock train */ TESTPIN_OUTPUT_HIGH;...
  • Page 16 PSoC 4 Programming Using an External Microcontroller (HSSP) Calculating HSSP Timeout Parameters /* Do Nothing */ /* Make the pin high after end of the delay */ TESTPIN_OUTPUT_HIGH; The A_HSSP_Programmer and B_HSSP_Pioneer projects implement a 100-µs delay using the CyDelayUs () API.
  • Page 17: Interface For Receiving Hssp Programming Data

    PSoC 4 Programming Using an External Microcontroller (HSSP) Interface for Receiving HSSP Programming Data Interface for Receiving HSSP Programming Data The files DataFetch.c and DataFetch.h contain the functions to fetch the data to be programmed into the target device. In the example project, the programming data is stored in the on-chip flash memory of the PSoC 5LP host programmer in the files HexImage.c and HexImage.h.
  • Page 18 PSoC 4 Programming Using an External Microcontroller (HSSP) Interface for Receiving HSSP Programming Data for(i = 0; i<BYTES_PER_FLASH_ROW; i++) rowData[i] = /* PLACE THE UART BUFFER ARRAY HERE */ Application Note 18 of 45 001-84858 Rev. *N 2021-03-23...
  • Page 19: Hssp Timing Validation

    PSoC 4 Programming Using an External Microcontroller (HSSP) HSSP Timing Validation HSSP Timing Validation The host programmer must meet the timing specifications for the target device programming to achieve a robust HSSP implementation. Those specifications are given in “Appendix D. Timing Specifications of the SWD Interface”...
  • Page 20: Power Cycle Mode Programming

    These functions are - SetXresHigh(),SetXresLow(). 3. If an I/O pin of the host processor is used to power the PSoC 4 device directly to toggle the power from the host side, ensure that the I/O pin can source the current required for device operation as specified in the respective PSoC 4 device datasheet.
  • Page 21: Testing The Example Projects

    0.1 uF Figure 4 Host/Target Connections The hex file included by default in this project toggles pin P1[6] of PSoC 4 at 1-Hz frequency and displays “PSoC Programmed” on the character LCD mounted on the CY8CKIT-001 DVK after a successful programming operation.
  • Page 22 P12[4] P12[4] To test this project, follow these steps: Prepare the B_Hssp_Pioneer project: Generate the files containing the programming data (HexImage.c, HexImage.h) for your target PSoC 4 device using the HexFile Parser. Replace the existing HexImage.c and HexImage.h files with the generated ones.
  • Page 23 The status LED starts to blink, indicating that PSoC 5LP is in the bootloader mode. Figure 6 shows the PSoC 4 Pioneer Kit and the location of the status LED and reset switch. Figure 6 PSoC 4 Pioneer Kit 3. Bootload the HSSP project to PSoC 5LP: Open the bootloader host tool.
  • Page 24 PSoC 4 Programming Using an External Microcontroller (HSSP) Testing the Example Projects 4. Install the USBUART driver for the kit: Unplug and reconnect the USB cable. If Windows fails to install the USBUART drivers, open the Device Manager. Make sure that USBUART is present in the Other devices list.
  • Page 25: For Kits With Onboard Psoc 5Lp Programmer (Kitprog2)

    PSoC 4 Programming Using an External Microcontroller (HSSP) Testing the Example Projects Figure 9 Upgrade Firmware using PSoC Programmer For Kits with Onboard PSoC 5LP Programmer (KitProg2) To test the HSSP project on kits listed in Table 10, use the B_Hssp_Pioneer project attached with this application note.
  • Page 26 PSoC 4 Programming Using an External Microcontroller (HSSP) Testing the Example Projects Double-click the bootloadable Component in TopDesign.cysch. Select the Dependencies tab and click Browse associated with the Bootloader HEX file as shown in Figure Navigate to the PSoC 5LP Bootloader Files > KitPog2 folder provided with the application note and select KitProg2_Bootloader.hex for the Bootloader HEX file field.
  • Page 27 PSoC 4 Programming Using an External Microcontroller (HSSP) Testing the Example Projects 3. Bootload the HSSP project to PSoC 5LP: Open the bootloader host tool. Choose Tools > Bootloader Host in PSoC Creator. Click on the Filter button, and then click on the Show USB Device’ checkbox.
  • Page 28 PSoC 4 Programming Using an External Microcontroller (HSSP) Testing the Example Projects If the programming operation fails, the terminal displays the step and error code that you can use to debug the project. Figure 13 Terminal Display 6. Reprogram PSoC 5LP with the kit firmware: Open PSoC Programmer.
  • Page 29: Tips And Tricks For Debugging Hssp Issues

    HSSP operation. This includes making the correct pin connections between the host processor and the target PSoC 4 device, powering of all the PSoC 4 voltage domains, and ensuring the host SWD pins drive mode settings are configured appropriately. See the “Physical Layer” section of the respective device...
  • Page 30: Summary

    The HSSP application is useful for developing in-system programming solutions for PSoC 4 devices. It provides a cheap and robust method for programming PSoC 4 devices using an onboard embedded microcontroller as a host programmer. The portable and modular C code provided with this application note greatly reduces the time it takes to develop such HSSP applications.
  • Page 31: Related Documentation

    PSoC 4100M/4200M Family: PSoC 4 Architecture Technical Reference Manual (TRM) • PSoC 41X7_BLE/42X7_BLE Family: PSoC 4 BLE Architecture Technical Reference Manual (TRM) • PSoC 4100S and PSoC 4100S Plus: PSoC 4 Architecture Technical Reference Manual (TRM) • PSoC 4000S: PSoC 4 Architecture Technical Reference Manual (TRM) •...
  • Page 32: List Of Attached Projects

    Related Documentation section. B_Hssp_Pioneer: This is the PSoC 4 HSSP application project for testing on the PSoC 4 Pioneer Kit. It uses • the onboard PSoC 5LP programmer to program PSoC 4 devices. C_Hssp_TimeoutCalc: This project is used to calculate the timestamp parameters used in the PSoC 4 HSSP •...
  • Page 33: Appendix A: Hex File Parser Application

    Appendix A: Hex File Parser Application The data for programming PSoC 4 is available in the hex file (.hex) format, which is explained in the section “Appendix B. Intel Hex File Format“ of the programming specifications document of the respective device listed...
  • Page 34: Adding The Generated Files To Psoc Creator Example Project

    PSoC 4 Programming Using an External Microcontroller (HSSP) Appendix A: Hex File Parser Application Figure 15 Hex File Parser Application Select the hex file that needs to be programmed by clicking Open Source P4 Hex File and navigating to the location of the file.
  • Page 35 PSoC 4 Programming Using an External Microcontroller (HSSP) Appendix A: Hex File Parser Application Figure 16 Adding Files to PSoC Creator Project 3. After these files are selected, the Workspace Explorer window appears, as follows: Figure 17 Project Workspace showing HexImage.c and HexImage.h Files If you need to replace these files in the project with those corresponding to a different hex file, delete the existing files from the Workspace Explorer and project folder by right-clicking and deleting the files.
  • Page 36: Using The Heximage.c, Heximage.h Files For The Psoc 4Xxxl/ Psoc 41X8_Ble/ 42X8_Ble/ 41Xxs Plus Family Devices

    PSoC 4 Programming Using an External Microcontroller (HSSP) Appendix A: Hex File Parser Application 14.2.1 Using the HexImage.c, HexImage.h Files for the PSoC 4xxxL/ PSoC 41x8_BLE/ 42x8_BLE/ 41XXS Plus Family Devices: The HSSP code examples use a PSoC 5LP device as a host programmer to program the target PSoC 4device.
  • Page 37: Appendix B: Status Codes For Srom Request

    If the value read from the register is in the form 0xF00000YY, it indicates failure, and YY indicates the reason for failure. Table 12 shows the list of error codes. For more details, see the “Nonvolatile Memory Programming” chapters of the respective PSoC 4 Architecture Technical Reference Manuals (TRM) listed in the Related Documentation section.
  • Page 38 PSoC 4 Programming Using an External Microcontroller (HSSP) Appendix B: Status Codes for SROM Request Status Code Description (32-Bit Value in CPUSS_SYSARG Register) 0xF0000012 Invalid Flash Clock: The CY8C40xx family of devices must set the IMO to 48 MHz and the HF clock source to the IMO clock before write/erase operations.
  • Page 39: Appendix C: Bit Field Definitions Of Hssp Error Status Register

    For details on the timing requirements to enter the PSoC 4 programming mode, see “Step 1: Acquire Chip” in the programming specifications document of the respective device listed in the Related Documentation section.
  • Page 40: Bit 5 - Srom Polling Timeout Error

    Bit 5 – SROM Polling Timeout Error Flash programming in PSoC 4 is done by using SROM APIs. This bit is set when the PollSromStatus() function returns an error status. The CPUSS_SYSREQ register is polled for the status code for 1 second. This bit is set if the time exceeds 1 second or if the status code returned by this function corresponds to FAILURE.
  • Page 41: Appendix D: Hssp Functions

    PSoC 4 Programming Using an External Microcontroller (HSSP) Appendix D: HSSP Functions Appendix D: HSSP Functions The following tables list the public functions defined in each layer of the HSSP firmware architecture. These functions are used to communicate between the layers of the HSSP firmware, as Figure 1 shows.
  • Page 42 PSoC 4 Programming Using an External Microcontroller (HSSP) Appendix D: HSSP Functions Function Description functions. Returns “true” if all SWD transactions succeeded (ACKed). Write_IO Writes a 32-bit data into the specified address of the CPU address space. This function is implemented by using the Write_DAP() function. Returns “true”...
  • Page 43 PSoC 4 Programming Using an External Microcontroller (HSSP) Appendix D: HSSP Functions Function Description VerifyChecksum() Verifies whether the checksum data read from the target device matches the hex file checksum data. ExitProgrammingMode() Exits the target device programming mode by generating an active LOW pulse signal on the XRES pin.
  • Page 44: Revision History

    PSoC 4 Programming Using an External Microcontroller (HSSP) Revision history Revision history Revision Date of release Description of changes 2013-05-14 New Application Note for HSSP applications on PSoC 4 2013-07-22 Removed submit document feedback link 2013-11-05 Updated associated project 2013-12-17...
  • Page 45 Do you have a question about this Except as otherwise explicitly approved by Infineon information given in this application note. Technologies in a written document signed by...

This manual is also suitable for:

An84858

Table of Contents