Tuesday, May 29, 2012

SD Card based bootloader - PSoC 3 : Part 1



So thats the idea basically,wherein on power-up the PSoC3 would check for an SD card,and if its available,read a cyacd file (cy-what? ..I'll get to it.) and program the contents of that into its flash,and fire a software reset and get going.

I'll make this a 3 part series,and here are the links for Part 2 and Part 3.

So lets start.

A couple of points here.

Whats the CYACD file?
Its basically a "smarter" hex file,I'd say."CY-ACD" is short for Cypress application and code data.

When you have a bootloader,and a bootloadable,the bootloadable is fed to the bootloader(over USB,I2C,UART whatever.) as this file.

The contents of this file as described in AN60317 (page 11)

Interesting.So its basically then reading this file,and parsing its data to get our hands on the actual data thats to be written to the flash,and then write it to flash using some APIs.

The one that does the actual writing is

(this screenshot is from the System Reference Guide for cy_boot v2.40 included with PSoC Creator 2)

I guess you can see where I'm going with this.Infact,its all pretty convenient.(Kudos to the guys at CY for making it so! ;-P ).Read the Array Id,Row Address and the data from the CYACD file,and then feed those directly to this API.
(note that we need to call the CySetTemp and CySetFlashEEBuffer functions first. The temperature is needed to adjust the write times to the flash for optimal performance. The Buffer is used to store intermediate data while communicating with the System Performance Controller).

How are we going to interface with the SD card?
Well,2 ways here really.Either you write your own routines,or use the powerful emFile component in PSoC Creator 2 (introduced in Component Pack 1 specifically.) and use that directly.I'm going for the latter,since its already there and is very easy to use and setup,with a ton of API functions ready-to-go outta the box.

If you're still reading,then you've probably noted that parsing the CYACD file isn't just reading text and then calling that Flash writing API.The data in this CYACD file,as mentioned in the first screenshot,is in ASCII and Big Endian.So we will need to read that ASCII stuff,and then convert it to Hex,and then also account for the big-endian-ness of it.

Now that the basic functionality is understood,let me go onto discussing the implementation I had in mind.

What I plan to do is take a stock USB bootloader,and add this SD stuff to it,wherein the code checks for an SD card and a specifically named cyacd file(this could be made smarter,obviously.) and then opens it,reads data,parses it,and writes its data to flash.Thats it! :-)

I'll discuss SD Card interfacing in Part-2.

3 comments:

  1. i couldnt update my component library for emFile. Can u tell me ? I have to do my project about SD Card.

    Thank you

    ReplyDelete
    Replies
    1. Hey,
      sorry for the late reply.You can find the emFile component with component pack 1.(The latest one is Component Pack 3.)
      You may update your PSoC Creator to the latest component pack using the Cypress Update Manager,you can find in the Cypress program group.

      You can find it in the Cypress Component Catalog,under Communications > File System.

      Hope this clears your query.

      Regards,
      kmmankad

      Delete
    2. Oh and,you can check out more info about the emFile component here http://www.cypress.com/?rID=58694

      Delete