Editing Bootloader Development

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
Developing Bootloader for the [[DsPIC30F_5011_Development_Board]]
+
Developing Bootloader for the [{{SERVER}}/DsPIC30F_5011_Development_Board DsPIC30F 5011 Development Board]
  
 
==Concepts==
 
==Concepts==
 
*Programming with ICSP (In-Circuit Self Programming) is useful when the target board is produced in batch. The producer can download a program even when the chip is on the target board.
 
*Programming with ICSP (In-Circuit Self Programming) is useful when the target board is produced in batch. The producer can download a program even when the chip is on the target board.
*However, ICSP requires an external programmer (e.g. Microchip ICD2 debugger).
+
*However, ICSP requires an external programmer (e.g. ICD2).
 
*To allow the user to change the program after production but without the need of an external programmer, bootloader becomes useful.
 
*To allow the user to change the program after production but without the need of an external programmer, bootloader becomes useful.
 
*Bootloader is a small program installed via ICSP. Every time the device is reset, the bootloader is run first. The bootloader first detects the default serial channel whether the user wishes to download a new program to the device. If so, the bootloader will pause there, and wait for the user to download the hex file from the PC. The hex file is written to the device via RTSP (Run-time Self Programming) instructions in the bootloader. If a new download is not necessary, the bootloader redirects to the previously installed user's program.
 
*Bootloader is a small program installed via ICSP. Every time the device is reset, the bootloader is run first. The bootloader first detects the default serial channel whether the user wishes to download a new program to the device. If so, the bootloader will pause there, and wait for the user to download the hex file from the PC. The hex file is written to the device via RTSP (Run-time Self Programming) instructions in the bootloader. If a new download is not necessary, the bootloader redirects to the previously installed user's program.
Line 48: Line 48:
 
==dsPicBootloader==
 
==dsPicBootloader==
 
*The bootloader developed by ingenia was open source (unavailable now) and it has been modified to suit our development. Hereafter, the modified version is called dsPicBootloader.
 
*The bootloader developed by ingenia was open source (unavailable now) and it has been modified to suit our development. Hereafter, the modified version is called dsPicBootloader.
===Download===
 
 
*Repository for download: [http://chungyan5.no-ip.org/vc dsPicBootloader]
 
*Repository for download: [http://chungyan5.no-ip.org/vc dsPicBootloader]
 
**Download projects: "dspic_bootloader" and "intel_hex_parser"
 
**Download projects: "dspic_bootloader" and "intel_hex_parser"
===Usage===
 
*[[Programming_the_Device#Loading_Bootloader_.28Once_only.29 | Instruction]] for usage
 
===Features===
 
 
*Before v1.05.00, the bootloader employs the following settings:
 
*Before v1.05.00, the bootloader employs the following settings:
 
# Use U2ART channel
 
# Use U2ART channel
# Start up using internal FRC, phase-lock-loop x16, without auto-switching of clock source
+
# Start up using internal FRC, phase-lock-loop x16
 
# Watchdog timer disabled
 
# Watchdog timer disabled
 
# Clock switching disabled
 
# Clock switching disabled
 
# Primary oscillator disabled
 
# Primary oscillator disabled
 
# OSC2 Pin functions as digital I/O
 
# OSC2 Pin functions as digital I/O
*In v1.05.00, dsPicBootloader employs the following settings:
+
*From v1.05.00 onwards, dsPicBootloader employs the following settings:
# Use U2ART channel
 
# Start up using internal FRC, phase-lock-loop x16, without auto-switching of clock source
 
# Watchdog timer disabled
 
# '''Clock switching enabled'''
 
# '''Primary oscillator configured to High Speed (OSC2 Pin cannot function as digital I/O)'''
 
*From v1.06.00 onwards, configuration registers can be overwritten, and employs the following settings:
 
 
# Use U2ART channel
 
# Use U2ART channel
 
# Start up using internal FRC, phase-lock-loop x16, without auto-switching of clock source
 
# Start up using internal FRC, phase-lock-loop x16, without auto-switching of clock source
 
# Watchdog timer disabled
 
# Watchdog timer disabled
 
# Clock switching enabled
 
# Clock switching enabled
# '''Primary oscillator disabled''' (if using external crystal crystal, configuration registers need to be erase and change)
+
# Primary oscillator enabled
# '''OSC2 Pin functions as digital I/O'''
+
*From v1.06.00 onwards, configuration registers can be overwritten.
  
  
Line 79: Line 69:
 
*Ingenia developed a programmer (PC-side) that works only in Windows environment. The project for Linux environment is currently suspended.
 
*Ingenia developed a programmer (PC-side) that works only in Windows environment. The project for Linux environment is currently suspended.
 
*A simple programmer (hereafter called dsPicProgrammer) written in Java and based on the library developed by [http://www.rxtx.org/ RXTX] has been developed here. The programmer supports both Linux and Windows environments, and may be used as a substitution for the official programmer developed by ingenia.
 
*A simple programmer (hereafter called dsPicProgrammer) written in Java and based on the library developed by [http://www.rxtx.org/ RXTX] has been developed here. The programmer supports both Linux and Windows environments, and may be used as a substitution for the official programmer developed by ingenia.
===Download===
 
 
*Repository for download: [http://chungyan5.no-ip.org/vc dsPicProgrammer]
 
*Repository for download: [http://chungyan5.no-ip.org/vc dsPicProgrammer]
 
**Download project: "dspicProgrammer"
 
**Download project: "dspicProgrammer"
===Usage===
+
*The programmer has the following specification and limitations:
*[[Programming_the_Device#Download_and_Loading_Firmware | Instruction]] for usage
 
===Features===
 
 
#Can be used on both Linux and Windows platforms.
 
#Can be used on both Linux and Windows platforms.
 
#Adjustable baudrate (9600bps to 115200bps<sup>[1]</sup>).
 
#Adjustable baudrate (9600bps to 115200bps<sup>[1]</sup>).
Line 94: Line 81:
 
#Configuration registers can be changed<sup>[3]</sup>.
 
#Configuration registers can be changed<sup>[3]</sup>.
 
#Can be used with USB-Serial Cables. Below is a list of tested cable:
 
#Can be used with USB-Serial Cables. Below is a list of tested cable:
====USB-to-COM Cable====
+
::[http://www.prolific.com.tw/eng/Products.asp?ID=59 Prolific PL-2303 USB to Serial Bridge Controller]: [http://www.prolific.com.tw/eng/downloads.asp?ID=31 Driver download]
*[http://www.prolific.com.tw/eng/Products.asp?ID=59 Prolific PL-2303 USB to Serial Bridge Controller]: [http://www.prolific.com.tw/eng/downloads.asp?ID=31 Driver download]
+
::[http://www.bafo.com BAFO Technologies BF-810 USB Serial Adapter]:[http://www.bafo.com/menu-support.asp Driver download]
*[http://www.bafo.com BAFO Technologies] BF-810 USB Serial Adapter:[http://www.bafo.com/menu-support.asp Driver download]
+
::[http://www.z-tek.com.cn/en/index.asp Z-TEK ZE400 USB 2.0 TO RS232 Cable]:[http://www.z-tek.com.cn/en/download.asp?driver_lei=windows Driver download]
*[http://www.z-tek.com.cn/entw/en/index.asp Z-TEK] ZE400 USB 2.0 TO RS232 Cable:[http://www.z-tek.com.cn/entw/en/download.asp?driver_lei=windows Driver download]
 
**Comparison on relative speed of communication (on Linux, average over 500 samples)
 
{|border="1" cellspacing="0" cellpadding="5"
 
|+
 
|-
 
! !! Real COM port !! 1 USB-to-COM Cable !! 2 USB-to-COM Cables (Cable A) !! 2 USB-to-COM Cables (Cable B) !! 2 USB-to-COM Cables via Hub (Cable A)  !! 2 USB-to-COM Cables via Hub (Cable B)
 
|-
 
! Average (ms) || 19.47 || 23.81 || 23.91 || 23.75 || 22.72 || 23.06
 
|-
 
! Max (ms) || 36 || 41 || 41 || 35 || 45 || 37
 
|-
 
! Min (ms) || 10 || 10 || 10 || 9 || 9 || 10
 
|}
 
 
 
 
'''NOTE:'''<br>
 
'''NOTE:'''<br>
 
[1] before version 1.5.2, the baudrate bounded at 57600bps.<br>
 
[1] before version 1.5.2, the baudrate bounded at 57600bps.<br>
Line 143: Line 116:
 
           +-------------------+            +------------------------------------+
 
           +-------------------+            +------------------------------------+
  
===Resetting Target Device===
+
* '''Stage 1: User's Configuration'''
*dsPicProgrammer sends a Break character (pull UART-TX to low logic, which is normally high).
+
**Select a COM port channel
*User's program on dsPic detects the break character and reset the chip
+
**Select a baudrate
**NOTE: The user's program is expected to have the following code in order to enable this function. Otherwise, the target board must be restarted manually.
+
**Select the user hex file
 +
          java -jar dsPicProgrammer.jar COM1 19200 foo.hex
 +
* '''Stage 2: Resetting Target Device'''
 +
**dsPicProgrammer sends a Break character (pull UART-TX to low logic, which is normally high).
 +
**User's program on dsPic detects the break character and reset the chip
 +
::NOTE: The user's program is expected to have the following code in order to enable this function. Otherwise, the target board must be restarted manually.
 
   void _ISR _U2RXInterrupt(void)
 
   void _ISR _U2RXInterrupt(void)
 
   {
 
   {
Line 171: Line 149:
 
       _U2RXIF = 0;        //Clear the flag
 
       _U2RXIF = 0;        //Clear the flag
 
   }
 
   }
===Entering Ingenia's Protocol===
+
* '''Stage 3: Entering Ingenia's Protocol'''
*Transmission is conducted in 8N1, i.e. 8-bit, no parity, 1 stop-bit
+
** Transmission is conducted in 8N1, i.e. 8-bit, no parity, 1 stop-bit
*Communication Protocol is reviewed in [http://www.ingenia-cat.com/reference/doc/dt/ibl/16BIT.MAN.1486745188.pdf 16-bit PIC serial bootloader product manual]. The following summarizes the key steps on the PC side.
+
** Communication Protocol is reviewed in [http://www.ingenia-cat.com/reference/pdf/iBL.UG.V1.2.pdf ingenia bootloader user's guide] section 2.1.3. The following summarizes the key steps on the PC side (Refer also to section 2.2.2).
#Autobaud rate detection: dsPicProgrammer continuously sends a character "U" [0x55] via COM port and waits for an acknowledgment character "U", [ACK] = [0x55]
+
:#Autobaud rate detection: dsPicProgrammer continuously sends a character "U" [0x55] via COM port and waits for an acknowledgment character "U", [ACK] = [0x55]
#Version Control: dsPicProgrammer sends the command character [0x03]. On success, dsPicProgrammer receives 3 characters i) Major Version ii) Minor Version iii) Acknowledgment [0x55]
+
:#Version Control: dsPicProgrammer sends the command character [0x03]. On success, dsPicProgrammer receives 3 characters i) Major Version ii) Minor Version iii) Acknowledgment [0x55]
#Device ID Monitoring: dsPicProgrammer sends the read command character [0x01] + 24-bit address [High][Medium][Low] (0xFF0000). Then, it receives 4-byte data [High][Medium][Low][ACK]
+
:#Device ID Monitoring: dsPicProgrammer sends the read command character [0x01] + 24-bit address [High][Medium][Low] (0xFF0000). Then, it receives 4-byte data [High][Medium][Low][ACK]
#Load the user hex file and check integrity
+
:#Load the user hex file and check integrity
#Start Programming: dsPicProgrammer issues the write command character [0x02] + 24-bit address [High][Medium][Low]+ Number of bytes [High][Low] + [data 0] + [data 1] + ... + [data N-1] + [CRC]=(INTEL HEX8 Checksum - Sum modulo 256) and receives [ACK] or [NACK] = [0xFF]
+
:#Start Programming: dsPicProgrammer issues the write command character [0x02] + 24-bit address [High][Medium][Low]+ Number of bytes [High][Low] + [data 0] + [data 1] + ... + [data N-1] + [CRC]=(INTEL HEX8 Checksum - Sum modulo 256) and receives [ACK] or [NACK] = [0xFF]
===Goto User's Program===
+
:NOTE: Writing is in row mode access (i.e. erase and write a whole row, each row has 32 instructions, or 96 bytes because each instruction has 24 bits)
*dsPicProgrammer sends the goto user code command [0x0F]
+
* '''Stage 4: Goto User's Program'''
 
+
**dsPicProgrammer sends the goto user code command [0x0F]
== Further reading ==
 
 
 
* [[PIC Programmers, In Circuit Programming and BootLoaders]]
 

Please note that all contributions to OpenCircuits may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see OpenCircuits:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)