top of page

Events Group

Public·297 members

Serial Boot Loader for PIC24F Devices: Firmware Design and Communication Protocols



What is a Microchip Pic24f Serial Boot Loader?




If you are working with Microchip's PIC24F microcontrollers, you may have encountered the need to update or modify the firmware of your device without removing it from the circuit board. This can be done by using a boot loader, which is a small piece of code that resides in a protected area of the device's memory and allows you to program or reprogram the rest of the memory through a communication channel.




Microchip Pic24f Serial Boot Loader



A serial boot loader is a type of boot loader that uses the UART module as the communication channel. UART stands for Universal Asynchronous Receiver/Transmitter, and it is a hardware interface that allows serial data transmission between two devices. By using a serial boot loader, you can connect your PIC24F device to a computer or another device through a standard serial interface, such as RS-232, and transfer firmware data using a simple protocol.


A serial boot loader has many advantages over other methods of programming or updating your PIC24F device, such as using an external programmer or debugger. Some of these advantages are:


  • It reduces the cost and complexity of your hardware design, as you don't need any additional components or connectors for programming.



  • It increases the flexibility and convenience of your firmware development, as you can easily make changes or fixes without removing or replacing your device.



  • It extends the lifespan and functionality of your application, as you can add new features or improve performance by updating your firmware remotely.



In this article, we will explain how a Microchip Pic24f Serial Boot Loader works, how to use it, and what are its advantages and limitations. We will also provide some tips and troubleshooting advice for common issues and errors that you may encounter when using a serial boot loader for your PIC24F device.


How does a Microchip Pic24f Serial Boot Loader work?




A Microchip Pic24f Serial Boot Loader is based on an application note (AN1157) published by Microchip Technology Inc., which describes the firmware design and communication protocols of a serial boot loader for 16-bit PIC24F devices. The application note also provides source code examples and documentation for implementing the boot loader on different PIC24F devices.


The basic operation and firmware design of the boot loader are summarized in Figure 1 below:



Figure 1: Bootloader functional block diagram


The boot loader consists of four main components:


  • The UART module, which is used to receive and transmit data between the PIC24F device and the source device (e.g., a computer).



  • The transmit/receive engine, which filters and parses the data received through the UART module, storing it into a data buffer in RAM.



  • The command interpreter, which evaluates the command information within the buffer and performs the appropriate operation (e.g., writing data into memory, reading data from memory, reading firmware version).



  • The memory modules, which include the flash program memory, where the application firmware is stored, and optionally, the EEPROM data memory, where the configuration settings and other data are stored.



The boot loader firmware is located in a reserved area of the flash program memory, which is protected from being overwritten by the application firmware. The boot loader firmware can be programmed into the PIC24F device using an external programmer or debugger, such as the MPLAB ICD 3 or the PICkit 3.


The boot loader firmware is executed when the PIC24F device is powered on or reset. The boot loader checks the state of a predefined pin (usually RB5), which is used as a boot mode selector. If the pin is low, the boot loader enters the application mode, where it jumps to the application firmware and runs it normally. If the pin is high, the boot loader enters the boot mode, where it initializes the UART module and waits for commands from the source device.


Communication protocols and settings for the UART module




The UART module is configured to use a baud rate of 115200 bps, 8 data bits, no parity bit, and 1 stop bit. These settings can be changed by modifying the source code of the boot loader firmware, but they must match the settings of the source device.


The communication protocol between the PIC24F device and the source device is based on a simple command-response scheme. The source device sends a command packet to the PIC24F device, which processes it and sends back a response packet. The command packet consists of a header byte, a command byte, an optional data length byte, optional data bytes, and a checksum byte. The response packet consists of a header byte, a status byte, an optional data length byte, optional data bytes, and a checksum byte. The header byte is always 0x55, and the checksum byte is calculated as the XOR of all bytes in the packet except for the header byte.


The following table shows the format of the command and response packets:



Byte


0


1


2


3


...


N-1


N


Command Packet


0x55 (Header)


Command


Data Length (Optional)


Data (Optional)


...


Data (Optional)


Checksum


Response Packet


0x55 (Header)


Status


Data Length (Optional)


Data (Optional)


...


Data (Optional)


Checksum


The receive/transmit buffer and its mapping in PIC24FJXXXGAXXX devices




The receive/transmit buffer is a 512-byte array in RAM that is used to store the data received or transmitted through the UART module. The buffer is divided into two sections: a 256-byte section for receiving data, and a 256-byte section for transmitting data. The buffer pointer is initialized to point to the beginning of each section.


The buffer pointer is incremented or decremented according to the direction of data transfer and wraps around when it reaches the end or the beginning of each section. For example, if the buffer pointer points to address 0x200 for receiving data, and 10 bytes are received, then the buffer pointer will point to address 0x20A. If another byte is received, then the buffer pointer will wrap around and point to address 0x000.


The receive/transmit buffer is mapped to different addresses in different PIC24F devices. For PIC24FJXXXGAXXX devices, which have 16 KB of RAM, the buffer is mapped to addresses 0x000-0x1FF. For other PIC24F devices, which have more than 16 KB of RAM, the buffer is mapped to addresses 0x800-0x9FF. This mapping can be changed by modifying the source code of the boot loader firmware, but it must not overlap with other memory regions used by the boot loader or the application firmware.


The command interpreter and its supported commands




The command interpreter is a function that evaluates the command information within the receive buffer and performs the appropriate operation. The command interpreter is called by the main loop of the boot loader firmware whenever a complete command packet is received. The command interpreter checks the validity of the command packet, such as the header byte, the checksum byte, and the data length byte. If the command packet is valid, the command interpreter executes the command and sends back a response packet. If the command packet is invalid, the command interpreter sends back an error code and discards the packet.


The command interpreter supports six commands, which are summarized in Table 3 below:



Command


Command Byte


Data Length Byte


Data Bytes


Description


Read Version


0x00


0x00


N/A


Reads the version number of the boot loader firmware.


Read Flash


0x01


0x04


Address (2 bytes), Length (2 bytes)


Reads data from the flash program memory at a specified address and length.


Write Flash


0x02


Variable


Address (2 bytes), Data (variable)


Writes data to the flash program memory at a specified address.


Erase Flash


0x03


0x04


Address (2 bytes), Length (2 bytes)


Erases data from the flash program memory at a specified address and length.


Read EEPROM


0x04


0x02


Address (1 byte), Length (1 byte)


Reads data from the EEPROM data memory at a specified address and length.


Write EEPROM


0x05


Variable


Address (1 byte), Data (variable)


Writes data to the EEPROM data memory at a specified address.


How to use a Microchip Pic24f Serial Boot Loader?




To use a Microchip Pic24f Serial Boot Loader, you need to have the following hardware and software components:



  • A PIC24F device with the boot loader firmware programmed into it.



  • A source device that can communicate with the PIC24F device through a serial interface, such as a computer or another microcontroller.



  • A serial cable or adapter that connects the PIC24F device and the source device. The cable or adapter must match the voltage levels and pinout of both devices. For example, if you are using a computer as the source device, you may need a USB-to-serial converter or a level shifter to connect it to the PIC24F device.



  • A power supply that provides sufficient voltage and current to the PIC24F device and any other components in your circuit.



  • A software application that can send and receive serial data and commands to and from the PIC24F device. You can use any software that supports serial communication, such as a terminal emulator or a custom application. Microchip provides a free software tool called PIC24F Serial Bootloader Utility, which is designed specifically for using the serial boot loader for PIC24F devices. You can download it from .



  • An application firmware file that you want to program or update into your PIC24F device. The file must be in hexadecimal format (.hex) and must not exceed the available flash program memory space of your device.




The steps to configure and program your PIC24F device using the serial boot loader are as follows:



  • Connect your PIC24F device to your source device using the serial cable or adapter. Make sure that both devices are powered off before connecting them.



  • Select a pin on your PIC24F device that will be used as the boot mode selector. By default, this pin is RB5, but you can change it by modifying the source code of the boot loader firmware. Connect this pin to a switch or a jumper that can pull it high or low.



  • Power on your source device and launch your software application for serial communication. Configure your software application to use the same settings as the UART module of your PIC24F device, such as baud rate, data bits, parity bit, and stop bit.



  • Power on your PIC24F device and set the boot mode selector pin to high. This will make your PIC24 F device enter the boot mode, where it will initialize the UART module and wait for commands from your source device.



  • Send a Read Version command (0x55 0x00 0x00) from your source device to your PIC24F device. You should receive a response packet with the status byte (0x00 for success) and the version number of the boot loader firmware (e.g., 0x01 0x00 for version 1.0).



  • Send a Write Flash command (0x55 0x02 data length address data checksum) from your source device to your PIC24F device. The data length byte indicates the number of data bytes to be written, which must be a multiple of 64. The address bytes indicate the starting address of the flash program memory where the data will be written, which must be aligned to a 64-byte boundary. The data bytes contain the hexadecimal data to be written, which must match the data length byte. The checksum byte is calculated as the XOR of all bytes in the command packet except for the header byte.



  • Repeat step 6 until all the data in your application firmware file is written to your PIC24F device. You can use the Read Flash command (0x55 0x01 0x04 address length checksum) to verify that the data is written correctly.



  • Set the boot mode selector pin to low and reset your PIC24F device. This will make your PIC24F device enter the application mode, where it will run your application firmware normally.




What are the advantages and limitations of a Microchip Pic24f Serial Boot Loader?




A Microchip Pic24f Serial Boot Loader is a useful and convenient tool for programming or updating your PIC24F device without removing it from the circuit board. However, it also has some advantages and limitations that you should be aware of before using it.


Advantages of a Microchip Pic24f Serial Boot Loader




Some of the advantages of using a serial boot loader for your PIC24F device are:



  • It reduces the cost and complexity of your hardware design, as you don't need any additional components or connectors for programming.



  • It increases the flexibility and convenience of your firmware development, as you can easily make changes or fixes without removing or replacing your device.



  • It extends the lifespan and functionality of your application, as you can add new features or improve performance by updating your firmware remotely.



  • It supports different communication protocols and settings for the UART module, such as baud rate, data bits, parity bit, and stop bit. You can change these settings by modifying the source code of the boot loader firmware, but you must make sure that they match the settings of your source device.



  • It supports different PIC24F devices with different memory sizes and configurations. You can adapt the boot loader firmware to different devices by modifying some parameters and macros in the source code, such as buffer size, buffer address, memory size, memory address, and boot mode selector pin.




Limitations of a Microchip Pic24f Serial Boot Loader




Some of the limitations of using a serial boot loader for your PIC24F device are:



  • It consumes some flash program memory space for storing the boot loader firmware. The size of the boot loader firmware depends on the features and options that you enable or disable in the source code, but it is typically around 2 KB. This means that you have less space available for your application firmware.



  • It requires a dedicated pin on your PIC24F device for selecting the boot mode. This pin must be connected to a switch or a jumper that can pull it high or low. This means that you have one less pin available for other purposes in your application.



  • It requires a serial interface between your PIC24F device and your source device. This interface must match source device that can communicate with the PIC24F device through a serial interface, such as a computer or another microcontroller.



  • A serial cable or adapter that connects the PIC24F device and the source device. The cable or adapter must match the voltage levels and pinout of both devices. For example, if you are using a computer as the source device, you may need a USB-to-serial converter or a level shifter to connect it to the PIC24F device.



  • A power supply that provides sufficient voltage and current to the PIC24F device and any other components in your circuit.



  • A software application that can send and receive serial data and commands to and from the PIC24F device. You can use any software that supports serial communication, such as a terminal emulator or a custom application. Microchip provides a free software tool called PIC24F Serial Bootloader Utility, which is designed specifically for using the serial boot loader for PIC24F devices. You can download it from this link.



  • An application firmware file that you want to program or update into your PIC24F device. The file must be in hexadecimal format (.hex) and must not exceed the available flash program memory space of your device.




The steps to configure and program your PIC24F device using the serial boot loader are as follows:



  • Connect your PIC24F device to your source device using the serial cable or adapter. Make sure that both devices are powered off before connecting them.



  • Select a pin on your PIC24F device that will be used as the boot mode selector. By default, this pin is RB5, but you can change it by modifying the source code of the boot loader firmware. Connect this pin to a switch or a jumper that can pull it high or low.



  • Power on your source device and launch your software application for serial communication. Configure your software application to use the same settings as the UART module of your PIC24F device, such as baud rate, data bits, parity bit, and stop bit.



  • Power on your PIC24F device and set the boot mode selector pin to high. This will make your PIC24 the voltage levels and pinout of both devices. For example, if you are using a computer as the source device, you may need a USB-to-serial converter or a level shifter to connect it to the PIC24F device.



  • It requires a software application that can send and receive serial data and commands to and from the PIC24F device. You can use any software that supports serial communication, such as a terminal emulator or a custom application. However, you need to make sure that the software can handle the communication protocol and the command format of the serial boot loader.



  • It has some limitations on the flash program memory address and length that can be read, written, or erased by the serial boot loader. For example, the address must be aligned to a 64-byte boundary, and the length must be a multiple of 64 bytes. These limitations are due to the flash memory architecture and programming algorithm of the PIC24F devices.




Conclusion




In this article, we have explained what a Microchip Pic24f Serial Boot Loader is, how it works, how to use it, and what are its advantages and limitations. We have also provided some tips and troubleshooting advice for common issues and errors that you may encounter when using a serial boot loader for your PIC24F device.


A serial boot loader is a useful and convenient tool for programming or updating your PIC24F device without removing it from the circuit board. However, it also has some requirements and constraints that you should be aware of before using it. By following the instructions and guidelines in this article, you should be able to use a serial boot loader for your PIC24F device successfully and efficiently.


We hope that you have found this article informative and helpful. If you have any questions or feedback, please feel free to contact us or leave a comment below. We would love to hear from you!


FAQs




Here are some frequently asked questions about the Microchip Pic24f Serial Boot Loader:



  • Where can I download the source code and documentation of the serial boot loader for PIC24F devices?



You can download them from this link, which is the official website of Microchip Technology Inc. You will find an application note (AN1157) that describes the firmware design and communication protocols of the serial boot loader, as well as source code


About

Welcome to the group! You can connect with other members, ge...
bottom of page