Bluetooth (RN42) bootloader
Posted: Fri Nov 14, 2014 10:48 am
I've been developing a couple of products that communicate with a Smartphone via the Microchip RN42 bluetooth module. With help and advice from Jerry I wrote a bootloader for these so I can update the firmware over the bluetooth link. This has proved reliable so I've stripped out the product-specific code and created what I hope will be a useful module for others who want to do the same.
A few pointers that will be helpful:
This module is currently optimised for the 2xK22 and 4xK22 series. There is no reason why it won't work on others but the original had to be optimised as much as possible to fit in the 2k bootblock of the chip I was using. This meant I wasn't able to use many compiler functions and existing subs and had to write optimised versions. Therefore, if you are intending to use this with a different PIC then you will need to check things like register definitions.
The module assumes the hardware will have at least one button and one LED. The button is used to force the bootloader to run (to allow faulty firmware to be recovered) and the LED indicates various operation states. There is plenty of scope to extend the output options - for example, the original bootloader could output basic information to a 128x64 LCD and another version had red / green / amber LEDs to indicate status. I've created this as a 'minimal hardware' version that should be suitable for most applications, feel free to adapt it to suit!
I run the PIC at 64MHz, partly to generate the 115200 baud necessary to talk to an 'unmodified' RN42. There are various ways to slow down the RN42 baud rate if you can't reliably generate 115200 baud at your chosen clock speed.
I've modified my System.bas to include the ClearRAM function. This ensures all variables are zeroed and saves a bit of code space over initialising them directly. You will get warnings that variables have not been initialised, these can be ignored safely.
The code plus the necessary library files (including Jerry's SetAllDigital routine) are attached.
A few pointers that will be helpful:
This module is currently optimised for the 2xK22 and 4xK22 series. There is no reason why it won't work on others but the original had to be optimised as much as possible to fit in the 2k bootblock of the chip I was using. This meant I wasn't able to use many compiler functions and existing subs and had to write optimised versions. Therefore, if you are intending to use this with a different PIC then you will need to check things like register definitions.
The module assumes the hardware will have at least one button and one LED. The button is used to force the bootloader to run (to allow faulty firmware to be recovered) and the LED indicates various operation states. There is plenty of scope to extend the output options - for example, the original bootloader could output basic information to a 128x64 LCD and another version had red / green / amber LEDs to indicate status. I've created this as a 'minimal hardware' version that should be suitable for most applications, feel free to adapt it to suit!
I run the PIC at 64MHz, partly to generate the 115200 baud necessary to talk to an 'unmodified' RN42. There are various ways to slow down the RN42 baud rate if you can't reliably generate 115200 baud at your chosen clock speed.
I've modified my System.bas to include the ClearRAM function. This ensures all variables are zeroed and saves a bit of code space over initialising them directly. You will get warnings that variables have not been initialised, these can be ignored safely.
The code plus the necessary library files (including Jerry's SetAllDigital routine) are attached.