Tiny PIC bootloader

Usage for Tiny PIC bootloader

After you browse or enter the name of the hex file, select the COM port and baud rate:

  1. You can keep the TinyBootloader interface opened,  then click WriteFlash, or double-click the tray icon, and after that reset (or power-up) the PIC. If your program is continuously sending serial data to PC, (that will be interpreted as a bootloader response) use the second method:
  2. first press PIC reset, click WriteFlash, then release PIC reset;
  3. Use a hardware (RTS) or software reset (codes to send first).
If all things are set up properly the program will be loaded into the pic and executed.

Write Flash

  1. Connects to the specified port with the chosen baud rate (both are editable, any value can be typed in)

  2. Reads and analyzes the hex file, determines if it's a 16F or 18F code, determine the size, eeprom and config data; check for a goto in the first 4 words, and gives warnings if necessary;

  3. Pings the serial port (with the "Code sent by PC for activation") at a rate given by "Timeout" until there is a response from the PIC or until the "SearchDelay" timeout will expire.

  4. When a response from the PIC is received the PIC type is identified and the user program written.
    (no eeprom or config words are written. if needed, this can be done by using one of the available commands).

Commands

Command line parameter: hex filename to be written.

When using a command line parameter writing flash will start automatically.

 

Some commands that can be written in the Log window:
? help
ontop keep the window on top of the others
logdetails lists detailed stuff happening inside (used only for debugging)
clearallflash clears all flash except the bootloader (actually it fills all flash with FFh)
writeeeprom <addr> <dat> writes the byte <dat> at the address <addr> (numbers can be either dec or hex)
eg:   writeeeprom 0 b6h     - writes B6h in the first eeprom location
writeconfig <adrLow> <dat> only for 18F; writes the configuration byte <dat> at the address 300000h+<addrLow>
eg:   writeconfig 3 FFh     - activates WDT

 

Options

  • List of codes to send first: could be interpreted by a user program as a reset (or activate bootloader command);

  • "SearchDelay" is the amount of time the application will try to contact the pic.

  • "Timeout" is the ping interval; also it acts as a timeout  for all serial operations. If you expect large communication delays, you should increase this (but don't forget to also increase the timeout in tinybld)

  • Reset could also be performed by hardware, "Reset PIC using RTS line". There are several ways to do it; some require that after reset the RTS should remain low, others prefer "RTS to remain active"

Terminal

A rudimentary Terminal, with the following possibilities:
  • Display received data as text, hex dump or character codes.
  • Automatically saves raw data to the specified file (rewrite at every terminal activation).
  • Can send:
    • ascii string
    • one by one characters as you type
    • decimal or hex codes
  • It has a limited (adjustable) display buffer (default 10k)

 

What do you need

Hardware

  • An external programmer is needed (only) the first time in order to write the bootloader into the PIC
  • On your board, you must have the PIC (pins TX,RX) connected to the serial port of the PC (pins Rx,Tx), usually using a MAX232 level converter:

Software

  1. You can use one of the provided .hex files or
  2. Modify tinybld.asm and assemble it using MPASM IDE (or Mpasmwin.exe)
    • Modify "xtal", "baud", "_??_OSC" to what you need; assemble it (for example with .\MPLAB\MCHIP_Tools\Mpasmwin.exe); write the HEX it with a PIC programmer; put the PIC on you board and connect it to the PC serial port.
  3. Requirements for your program:
    • The program must meet this requirement: it must have in the first 4 words of memory a GOTO to the start of the main program. (this is what the majority of the bootloaders require). So in assembler it should look something like this:
      PIC16F PIC16F PIC18F
      org 0
      ;clrf STATUS
      clrf PCLATH
      goto Main
      org 0
      ;clrf STATUS
      pagesel Main
      goto Main
      org 0
      goto Main

       
    • If you use a compiler, search the help for a directive that allows coexistence with a bootloader;

Critics and suggestions at: