Reading, writing, erasing flash (16F88)


Closed Thread
Results 1 to 27 of 27

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default

    Hi Charles.

    You describe an advanced bootloader that is OK for the most situation, when you are near to the PIC device.

    What I really want to investigate if it is doable: To update firmaware where physical contact to the PIC, its reset button or anything else is not an option.

    Say that you have built and installed a controller in another town and one day you need to change something in the program. You have DSL connection and a RS232/RS485 to a PC/modem/router.

    If you can reach through the Internet the PIC, maybe it is possible to update it too.

    Ioannis

  2. #2
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    There is a lot that can be done when the PIC has the capability to write to its program memory. I would select something more capable/sophisticated than a PIC16 though.

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Yes, it is doable. But your bootloader must set up whatever communication method you are using. For example, if you are trying to do this over the internet, the bootloader has to set up the net connection, then wait for a message from the host (hopefully encrypted) before invoking itself.

    A bootloader generally has only a very short timeout window when it will accept an outside command to invoke itself (otherwise it would negatively impact the start time of the PIC). Since most bootloaders are set up for RS-232 operation, a very short time (1 second or less) is OK. If you are trying to do a load over the net, you have to deal with a lot more latencies and this time must be extended.

    But more of a problem is the possibility of dropped connections. RS-232 is very reliable, but if you are "net-loading" and are halfway through the bootload process and your connection gets broken, are you absolutely certain that you can get it (remotely) restarted? Probably not easy to guarantee when the unit is in China!

    There are a couple of ways around this. If you have a big PIC and your code is small and is relocatable (probably not easy with PBP), then your code can reside in the lower half of the device's FLASH space. Your special code-loader could accept the new program and place it in the upper half of FLASH. After loading the new code, your "old" code would then run a CRC on the new code. If it passed, you would then move your start jump vector to point to the beginning of the new code (in the upper half of FLASH) and run. The next time you run the bootloader, it puts the new code in the lower half of FLASH and moves the jump vector again.

    With PBP, it is probably easier to do this in a slightly different way; with an external EEPROM. Your bootloader would load the new code into the external device, then run a CRC on it and then copy the code from the EEPROM to the PIC. Doing this shouldn't be too hard.

    Please understand that I have not done this myself, I have only pondered how it might be done.
    Charles Linquist

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default

    Hi Charles.

    Thanks for the reply.

    The idea of external EEPROM is nice. Probably must be a fast one, like the RAMTRON FM24C64. Theres is no 10ms delay.

    I am very interested in this, and soon I may have some results to post. My main concern is how to lock the code after updating the old firmware.

    Ioannis

  5. #5
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    It doesn't have to be fast - as long as you have control of the program at the "sending" end. Use a pic with at least a couple of hundred bytes of RAM and buffer the incoming data before you do a write to the EEPROM. You would send a buffer full, then pause and wait for the PIC to send a CTS or ACK, then send another buffer... As long as you do it this way, you can write as slowly as you need to in order to write the FLASH.

    I do a similar thing now, were I create a 2056 byte buffer (2048 bytes of data + CRC + control) in the RAM of an 18F8722, then send EEPROM data to the PIC in Intel Hex format over a 115K baud serial line, and when it is all received, check the CRC, convert it to binary and do the write to EEPROM. After programming the chip reboots (which destroys the 2056 byte buffer so I can now use the RAM space for my program) and starts with the new configuration. In my case, the 1024 bytes of EEPROM was inside the PIC, but it wouldn't have to be.

    This was really designed as a fast way to configure a whole bunch of chips with the same setup, but you could adapt the technique for boot loading.
    Charles Linquist

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default

    Hmm, yes you are right on the spped matter.

    Thanks for the tips.

    One question, why did you use Intel hex format? Is the conversion to and back necessary for your project? It uses abit of MCU power to do that...

    Ioannis

  7. #7
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I mis-spoke, I actually just used HexAscii (0x0f) = "0" + "F" because I couldn't figure out how to make the VB program I used to receive and send the data handle ASCII zeroes and other odd characters.
    Charles Linquist

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default

    OK. Thanks for the details so far.

    Ioannis

Similar Threads

  1. Writing & Reading to iButton EEPROM
    By crhomberg in forum Code Examples
    Replies: 2
    Last Post: - 6th October 2008, 19:40
  2. Writing and reading to a 24LC1025
    By Angus Anderson in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 20th April 2007, 11:49
  3. reading, writing, and displaying from eeprom
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th January 2006, 22:05
  4. 16F88 reading Analog Input
    By thunderstrike44 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th August 2004, 22:41
  5. Writing / Reading EEPROM 24LC256 Problem
    By schmoddel in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th February 2004, 18:55

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts