2014年10月28日星期二

PSoC bootloaders ZZ

eewiki.net/display/microcontroller/PSoC+Bootloaders#PSoCBootloaders-HowBootloadersWork

Creating PSoC Bootloaders

Cypress makes it very simple to create bootloader programs.  This section will walk through the process of creating a bootloader application in PSoC Creator 3.0 for PSoC 3, 4, and 5LP devices.  PSoC Creator 3.0 can be downloaded for free here.
  1. Open PSoC Creator 3.0.
  2. Navigate to File -> New -> Project.
  3. Select Empty PSoC 3, 4, 5LP Design - whichever device family you are using.
  4. Type a descriptive name for your bootloader program in the "Name" field.  I usually indicate which device family I'm using, which serial port I'm using, and the fact that it's a bootloader.  i.e. PSoC4_UART_Bootloader
  5. Browse to whatever directory you wish to save the project in.
  6. Click the '+ Advanced' button.
  7. Select your specific device.
  8. Select "Bootloader" as the application type and click 'OK'.
  9. PSoC Creator should bring up the schematic view.  If not, double click "TopDesign.cysch" from the Project Explorer window.
  10. From the Component Catalog, drag the desired communication port for your bootloader into your design.  For example, if you would like a UART-based bootloader, click and drag the UART component into your design.
  11. Double-click on your component after it has been added to the design to configure it.  Name it whatever you would like and setup your desired communication settings.  For a UART, you will need to verify the baud rate, number of data bits, parity type, number of stop bits, and flow control setting.  You will also need to change the RX and TX buffer sizes to 64 bytes if using UART.  If using I2C, you'll need to use an I2C Slave component.  You'll need to verify the slave address and data rate.  You can use any serial com you would like, or create your own custom serial com.  However, that is out of the scope of this page.  Apply any changes and click 'OK'.
  12. From the Component Catalog, drag a Bootloader component into your design.
  13. Double-click on the Bootloader to configure it.  Name it whatever you'd like.  Your com port should be available in the Communication Component drop-down.  The Wait Time defines how long the bootloader will wait for the start signal from the Host before passing control to the application program.  Multi-application bootloader is out of the scope of this page.  Every other option can be set however you wish.  I usually leave default settings.  Apply any changes and click 'OK'.
  14. Open the .cydwr file for your project from the Project Explorer window.  Assign physical pins to your communication port.  Save and close the .cydwr file.
  15. Open the main.c file from the Project Explorer window.  Nothing needs to be changed in main.c for the bootloader to function properly.  You could light up an LED before starting the bootloader, if you wish, but for a simple bootloader program, main.c can be left alone.
  16. Save and build the project.  This will create bootloader .hex and .elf files and in the Debug folder of your project directory.  These files are necessary for your Bootloadable application.
    • For PSoC3 devices, they will be in your project directory under <project name>.cydsn -> DP8051 -> DP8051_Keil_9xx -> Debug. 
    • For PSoC4 devices, they will be in your project directory under <project name>.cydsn -> CortexM0 -> ARM_GCC_4xx -> Debug. 
    • For PSoC5 devices, they will be in your project directory under <project name>.cydsn -> CortexM3 -> ARM_GCC_4xx -> Debug.
  17. Program the bootloader to your device like you would normally program a PSoC device using Debug -> Program from within your bootloader project.  You can also use PSoC Programmer to program your device.
Congratulations!  If you completed all of these steps, you just created and flashed a bootloader to your PSoC device!  Give yourself a pat on the back...but not too hard.  We don't need anybody getting hurt.  We haven't even used our bootloader yet!  Now we need to create a Bootloadable application.

Creating PSoC Bootloadable Applications

Cypress makes it very simple to create a bootloadable application from scratch.  This section will walk through the process of creating a bootloadable application in PSoC Creator 3.0 for PSoC 3, 4, and 5LP devices.
  1. Open PSoC Creator 3.0.
  2. Navigate to File -> New -> Project.
  3. Select Empty PSoC 3, 4, 5LP Design - whichever device family your are using.
  4. Type a descriptive name for your bootloadable program in the "Name" field.  I usually type my application name preceded by which device family I'm using, which serial port I'm using, and the fact that it's bootloadable.  i.e. PSoC4_UART_Bootloadable_TempSensor.
  5. Browse to whatever directory you wish to save the project in.
  6. Click the '+ Advanced' button.
  7. Select your specific device.
  8. Select "Bootloadable" as the application type and click 'OK'.
  9. PSoC Creator should bring up the schematic view.  If not, double click "TopDesign.cysch" from the Project Explorer window.
  10. Click and drag a Bootloadable component into your schematic from the Component Catalog.  Double-click the Bootloadable to configure it.  The General tab can be left alone.  Under the Dependencies tab, you will need to map the project to the bootloader .hex and .elf files you previously created.
  11. At this point you should develop your program exactly as you would any other PSoC application.  Add any components you need for your design and develop firmware in main.c as you normally would.
  12. Save and build your bootloadable program.  Just like any normal PSoC project, building will create a program .hex file in the Debug folder of your project directory.  However, for a bootloadable project, a .cyadc file will also be generated.  This is the file needed by the Bootloader Host application that actually uploads the device firmware using your bootloader.
    • For PSoC3 devices, the .cyacd file will be in your project directory under <project name>.cydsn -> DP8051 -> DP8051_Keil_9xx -> Debug. 
    • For PSoC4 devices, the .cyacd file will be in your project directory under <project name>.cydsn -> CortexM0 -> ARM_GCC_4xx -> Debug. 
    • For PSoC5 devices, the .cyacd file will be in your project directory under <project name>.cydsn -> CortexM3 -> ARM_GCC_4xx -> Debug.
Cheers! If you completed all of these steps, you just created a bootloadable application that can be uploaded to your device using the bootloader that you already programmed to memory.  Now we need to upload the bootloadable program using Bootloader Host.

Using Bootloader Host

Bootloader Host is included by default in the PSoC Creator installation.  You can use this application to upload PSoC bootloadable programs to a PSoC device containing the mapped bootloader program.  This section will walk through the process of uploading a bootloadable application using Bootloader Host. 
Bootloader Host supports numerous serial communication protocols.  However, keep in mind, you will need to physically connect the target device to the PC somehow.  In many cases, the only connectivity options on a PC are USB or RS232.  You may need some sort of bridge device to actually connect your target to the PC.
USB / UART Bridges:
    • TTL-232R-3V3:  This is a USB to 3.3V TTL bridge cable from FTDI.  If your bootloader uses UART, this can be used to connect the UART of your target to the USB port of a PC.
    • CYUSBS232:  This kit contains a USB to RS232 bridge device that can be used to connect your target to the USB port of a PC if your bootloader uses UART.
USB / I2C Bridges:
    • CY8CKIT-002:  Miniprog3 can be used as a USB to I2C bridge if your bootloader uses I2C.
    • CY3240-I2USB:  This kit contains a USB to I2C bridge device that can be used to connect your target to the USB port of a PC if your bootloader uses I2C.
    • If using the PSoC4 Pioneer Kit, the on-board PSoC5LP device can be used as a USB to I2C bridge device (no external bridge device needed for bootloading).

没有评论:

发表评论