Microchip USB Bootloader?
I seems to be impossible to add a attachment here, so the bootloader is available for download here :
http://rapidshare.com/files/6382930/Bo ... .rar.html [/b]
At this moment only P18F4550, P18F4455, P18F2550, P18F2455 can be programmed (auto detection).
The bootloader is only tested with a very small example (at this moment I use the demo version of mikroC) with the PICDEM Demoboard from Microchip. So do'nt shoot me if it fails .....
If you have any comments and/or improvement requests post them here.
Luc Vercruysse
http://rapidshare.com/files/6382930/Bo ... .rar.html [/b]
At this moment only P18F4550, P18F4455, P18F2550, P18F2455 can be programmed (auto detection).
The bootloader is only tested with a very small example (at this moment I use the demo version of mikroC) with the PICDEM Demoboard from Microchip. So do'nt shoot me if it fails .....
If you have any comments and/or improvement requests post them here.
Luc Vercruysse
Lucky Luc wrote:I seems to be impossible to add a attachment here, so the bootloader is available for download here :
http://rapidshare.com/files/6382930/Bo ... .rar.html [/b]
At this moment only P18F4550, P18F4455, P18F2550, P18F2455 can be programmed (auto detection).
The bootloader is only tested with a very small example (at this moment I use the demo version of mikroC) with the PICDEM Demoboard from Microchip. So do'nt shoot me if it fails .....
If you have any comments and/or improvement requests post them here.
Luc Vercruysse
File not found !
Is it posible to upload it again?
Thanks
link
I am not using P18 devices anymore. So I do not support this project anymore.
You can find the delphi source and exe here.
http://rapidshare.com/files/56364250/PICBOOT.rar.html
Good luck
You can find the delphi source and exe here.
http://rapidshare.com/files/56364250/PICBOOT.rar.html
Good luck
Re: Microchip USB Bootloader?
HI all
i have run bootlaoder and now i have chnage my code its size is now large enough
when i compile the code it will give me error
"Routine exceed page boundaries 4096"
PLZ plz help me to fixed it
i have run bootlaoder and now i have chnage my code its size is now large enough
when i compile the code it will give me error
"Routine exceed page boundaries 4096"
PLZ plz help me to fixed it
- slavisa.zlatanovic
- mikroElektronika team
- Posts: 1321
- Joined: 07 Apr 2009 09:39
Re: Microchip USB Bootloader?
Hi sakender!
Please send me your project and I'll give my best to help you.
You can send it to my email: slavisa.zlatanovic@mikroe.com
Please send me your project and I'll give my best to help you.
You can send it to my email: slavisa.zlatanovic@mikroe.com
Best regards
Slavisa
Slavisa
Microchip USB Bootloader For PIC18F14K50
I came across this old topic and I think I may be able to help people new to HID bootloaders. It took me a while but I got a program to work with Microchip's HID Bootloader for PIC18F14K50 and it can all be done in mikroBasic mikroC in the attachement or the mikroC code at the end of the post. You cannot directly use the hex file that is generated. ":020000040000FA" must be added to the top of the hex file - you can use notepad to do it or just run my VBScript which adds it for you and creates a second hex file in the parent folder. I have question for the mikroE team, is there now way for the compiler to automatically add the line when compiling (maybe using external tools)?
I have not tested PIC18F2X5X or PIC18F4X5X but I believe changes needed are to the lines where 0x1000 should be changed to the PIC specific address mentioned by Microchip:
If you need to use USB HID in your code then these lines should be changed to match your PIC settings (data length is specified in USB descriptor using mikroElektronika's HID Terminal tool):
I also included Microchip's boot loader modified by me which uses EEPROM to detect if a program has been programmed by the user. The bootloader will only go to the users program if EEPROM(255) is 170. If it 85 then it will still go into bootloader mode but writes 170 so it will not go back - write 85 in you program then reset to enter bootloader mode once. My template will work with Microchip's original bootloader or my bootloader (PIC18F14K50 only).
I have not tested PIC18F2X5X or PIC18F4X5X but I believe changes needed are to the lines where 0x1000 should be changed to the PIC specific address mentioned by Microchip:
Code: Select all
OrgAll(0x1000);
void Vectors() org 0x1000 {
Code: Select all
//USB Constants
const unsigned int USBRamStart=0x280;
const unsigned short USBInDataLength=64, USBOutDataLength=64;
Code: Select all
//All files to include
//Constants
const
VRefSet = 4096;
//Regular variables
unsigned int ADCIn = 0, Vdd = 0, VRefIn = 0;
//USB Constants
const unsigned int USBRamStart=0x280;
const unsigned short USBInDataLength=64, USBOutDataLength=64;
//USB Variables
unsigned short USBCount;
unsigned short USBInData[USBInDataLength] absolute USBRamStart+USBInDataLength;
unsigned short USBOutData[USBOutDataLength] absolute USBRamStart;
//Declare needed functions
#define Lo(param) ((char *)¶m)[0]
#define Hi(param) ((char *)¶m)[1]
#define Higher(param) ((char *)¶m)[2]
#define Highest(param) ((char *)¶m)[3]
void main();
void ADC_Init() {
//Turn on ADC Module
ADCON0.ADON = 1;
//Set VDD as positive voltage refrence
ADCON1.PVCFG0 = 0;
ADCON1.PVCFG1 = 0;
//Set VSS as negative voltage refrence
ADCON1.NVCFG0 = 0;
ADCON1.NVCFG1 = 0;
//Enable accurate Fixed Voltage Refrence and set to 4.096V
REFCON0.FVR1EN = 1;
REFCON0.FVR1S0 = 1;
REFCON0.FVR1S1 = 1;
/*
//Set FVR as positive voltage refrence
ADCON1.PVCFG0 = 0;
ADCON1.PVCFG1 = 1;
*/
//Set ADC Conversion clock to dedicated ACD Clock T_AD~=1.7us
ADCON2.ADCS0 = 1;
ADCON2.ADCS1 = 1;
ADCON2.ADCS2 = 1;
//ADC needs about 20us so T_AD=12
ADCON2.ACQT0 = 1;
ADCON2.ACQT1 = 0;
ADCON2.ACQT2 = 1;
//Right justify ADC results
ADCON2.ADFM = 1;
}
unsigned int ADC_Get_Sample(unsigned short Channel) {
unsigned int Result = 0;
//Select channel and enable ADC
ADCON0 = (Channel << 2) + 1;
//Start ADC conversion then wait until it is finished
ADCON0.GO = 1;
while (ADCON0.GO);
//Right justified calculation
Lo(Result) = ADRESL;
Hi(Result) = ADRESH;
//Left justified calculation
//Result = ADRESH << 2 + ADRESL >> 6;
return Result;
}
void interrupt() {
//USB Interrupt
USB_Interrupt_Proc();
}
void interrupt_low() {
}
//Remapping needed to use with boot loader
void Vectors() org 0x1000 {
asm {
goto _main //0x1000
nop
nop
goto _interrupt //0x1008
nop
nop
nop
nop
nop
nop
goto _interrupt_low //0x1018
}
}
void main() {
//Make sure entire program starts at 0x1000 which is where the boot loader finishes for PIC18F14K50
OrgAll(0x1000);
//ASM Command to avoid optimization which ensures Vectors will be remapped correctly
asm { goto Skip_Vectors }
Vectors();
asm { Skip_Vectors: }
//Initialize variables
for (USBCount = 0; USBCount < 64; USBCount++) {
USBOutData[USBCount] = 0;
}
//Initialize pins
TRISC = 0; //Set PORTC as output
//TRISB.B5 = 0; //Set RB5 at indicator output
RABPU_bit = 0; //Enable weak pull-up on all ports
ANSEL = 0; //Disable ADC on all pins
ANSELH = 0; //Disable ADC on all pins
//ADC Setup and Enable for RB4
TRISB.B4 = 1;
ANSELH.ANS10 = 1;
ADC_Init();
//Enable USB
HID_Enable(&USBInData, &USBOutData);
//Initialize ADC readings
for (USBCount = 0; USBCount < 16; USBCount++) {
VRefIn = VRefIn + ADC_Get_Sample(15);
}
VRefIn = VRefIn >> 4; //>> 4 is Equivalent to dividing by 16
//Calculate VDD based on the VRef reading
Vdd = (unsigned long int) (1023 * VRefSet / VRefIn);
//Main process loop
while (1) {
//Check if the reset button is pressed; if it is then goto the begging of the bootload and since it is 0 the microcontoller will go into boot loader mode
if (PORTA.B3 == 0) {
HID_Disable();
EEPROM_Write(255,85); //Causes entry to boot loader once
delay_ms(5);
asm { reset }
}
//LED indicator to see if the device has been programmed properly
//PORTC = 0b10101010;
PORTB.B5 = 1;
delay_ms(25);
//PORTC = 0b01010101;
PORTB.B5 = 0;
delay_ms(25);
//Read ADC Input
ADCIn = ADC_Get_Sample(10);
ADCIn = (ADCIn + ADC_Get_Sample(10)) / 2;
//Display voltage as digital output
PORTC = Swap(ADCIn >> 2);
//Write to USB if data was read
if (HID_Read()) {
USBOutData[0] = ADCIn >> 2;
USBOutData[1] = Hi(ADCIn);
USBOutData[2] = Lo(ADCIn);
USBOutData[3] = Hi(Vdd);
USBOutData[4] = Lo(Vdd);
USBOutData[5] = Hi(VRefIn);
USBOutData[6] = Lo(VRefIn);
HID_Write(&USBOutData, USBOutDataLength);
}
}
//Disable USB
HID_Disable();
}
- Attachments
-
- [Template] Boot Loader.7z
- Inlcudes:
mikroBasic Boot Loader Template
mikroC Boot Loader Template
Visual Basic 2010 (PC) Sample Program That Reads ADC
Modified Microchip HID Bootloader To Allow Software Device Reset into Bootloader Mode - (247.44 KiB) Downloaded 445 times
Re: Microchip USB Bootloader For PIC18F14K50
It is easy to implement, however I am afraid this will cause trouble to users and therefore additional tech support to us.gcp6ca wrote: I have question for the mikroE team, is there now way for the compiler to automatically add the line when compiling (maybe using external tools)?
Re: Microchip USB Bootloader?
Can you not allow an option to select if the user wants the option or not - similar to MPLAB's MPLINK hex file format? Or is that what you think will need tech support? Can you not offer way to do it without any tech support - it can be supported by other users of the forum (what currently goes on)?
If it is still not possible can allow a user selected script/program to be able to run before/after building project like MPLAB allows?
The 32-bit hex format option is sometimes the only modification that people miss - one of the steps I did not get for a while. I think it is a good idea for mikroElektronika to support HID Bootloaders (Microchips or your own) because it allows using the very common USB interface for upgrading firmware. User code is much easier to write in mikroC than in MPLAB C18 - especially for beginners.
Also how can I share the templates in the user projects section?
If it is still not possible can allow a user selected script/program to be able to run before/after building project like MPLAB allows?
The 32-bit hex format option is sometimes the only modification that people miss - one of the steps I did not get for a while. I think it is a good idea for mikroElektronika to support HID Bootloaders (Microchips or your own) because it allows using the very common USB interface for upgrading firmware. User code is much easier to write in mikroC than in MPLAB C18 - especially for beginners.
Also how can I share the templates in the user projects section?
Re: Microchip USB Bootloader?
At the moment you can install a tool in Tools->Preferences->Tools and you can assign a shortcut to it.
After compiling you can run that tool and to modify the HEX as you need.
To share the templates, simply modify the file named "autocomplete.ini" and post it online on Libstock
We will consider your ideas, they are in place.
Thanks for support.
After compiling you can run that tool and to modify the HEX as you need.
To share the templates, simply modify the file named "autocomplete.ini" and post it online on Libstock
We will consider your ideas, they are in place.
Thanks for support.
Re: Microchip USB Bootloader?
Dear all,
I'm now in the same situation than most of person in this topics (and many others). I would like to use a USB bootloader with my 18F4550. I have read many posts about the subjet but I'm still not able to make my program working good using the booloader. So, I have some questions:
1) when you speak about the Microchip bootloader, are you speaking about the one used with the PICDEM FS USB Board?
If we have a look to doc DS51526B (page 22: chapter 3.5) of the Microchip documentation, we have an explaination of the organisation of the bootloader and in Table 3-1 how to configure the CONFIG Data PIC.
The bootloader uses space between adress 0000h and 07FFh. When you programm the CONFIG data PIC, you lock this space: CONFIG5L = 0x0F. The problem is that mikroE compilers (basic, C,...) write some data in this space that cause some problem and non working programm.
2) On topic http://www.mikroe.com/forum/viewtopic.p ... 70&start=0, mikroElektronika team give a solution by modifying the P18F4550.mlk file. In mikroBasic PRO, this file doesn't look to have #pragma SetPage(PAGE0... code inside. What we have to modifie then in this file?
In our programm, we must add too at the begening,
That normaly permit to move the code to this adress in memory, but mB still put some code at the begining: $000. The reason is given at the bottom of this topic : http://www.mikroe.com/forum/viewtopic.p ... 4&hilit=bo
An other point is to add ":020000040000FA" at the begining of the .hex file. OK, why not.
3) SO, at the end, does somebody has an universal solution to be able to bootload any programm compiled with mB, mC, mP..., using a USB bootloader and with witch bootloader? Do you have a source code of such a working program + bootloader?
I think that a tutorial or something like this could be a good initiative of mikroE Team. Many person will be happy to read it!
Thanks everybody and have a good day. Best regards,
PierreD35
I'm now in the same situation than most of person in this topics (and many others). I would like to use a USB bootloader with my 18F4550. I have read many posts about the subjet but I'm still not able to make my program working good using the booloader. So, I have some questions:
1) when you speak about the Microchip bootloader, are you speaking about the one used with the PICDEM FS USB Board?
If we have a look to doc DS51526B (page 22: chapter 3.5) of the Microchip documentation, we have an explaination of the organisation of the bootloader and in Table 3-1 how to configure the CONFIG Data PIC.
The bootloader uses space between adress 0000h and 07FFh. When you programm the CONFIG data PIC, you lock this space: CONFIG5L = 0x0F. The problem is that mikroE compilers (basic, C,...) write some data in this space that cause some problem and non working programm.
2) On topic http://www.mikroe.com/forum/viewtopic.p ... 70&start=0, mikroElektronika team give a solution by modifying the P18F4550.mlk file. In mikroBasic PRO, this file doesn't look to have #pragma SetPage(PAGE0... code inside. What we have to modifie then in this file?
In our programm, we must add too at the begening,
Code: Select all
main:
OrgAll(0x800) ' store bootloader code
If you don't arrive to do this, you can use any interups.Best way to do this would be if you could just force the USB bootloader to be stored with offset
equal to the size of this jump table. This is around 200 bytes at the beginning of the memory.
An other point is to add ":020000040000FA" at the begining of the .hex file. OK, why not.
3) SO, at the end, does somebody has an universal solution to be able to bootload any programm compiled with mB, mC, mP..., using a USB bootloader and with witch bootloader? Do you have a source code of such a working program + bootloader?
I think that a tutorial or something like this could be a good initiative of mikroE Team. Many person will be happy to read it!
Thanks everybody and have a good day. Best regards,
PierreD35
Re: Microchip USB Bootloader?
Download Microchip's latest Application Libraries from:
http://www.microchip.com/stellent/idcpl ... e=en547784
After it is installed you will find the HID bootloader (user code starts at 0x1000):
...\Microchip Solutions v2011-07-14\USB\Device - Bootloaders\HID
Firmware is "USB Device - HID - HID Bootloader - C18 - PIC18F4550.hex" and the PC software is "HIDBootLoader" which is v2.90 and does not require ":020000040000FA" in the hex file anymore.
The HID Bootloader will not program any instructions that are in the range of 0x0 to 0x1000.
You can find working code for mikroBasic and mikroC here:
Template information based on your questions:
http://www.microchip.com/stellent/idcpl ... e=en547784
After it is installed you will find the HID bootloader (user code starts at 0x1000):
...\Microchip Solutions v2011-07-14\USB\Device - Bootloaders\HID
Firmware is "USB Device - HID - HID Bootloader - C18 - PIC18F4550.hex" and the PC software is "HIDBootLoader" which is v2.90 and does not require ":020000040000FA" in the hex file anymore.
The HID Bootloader will not program any instructions that are in the range of 0x0 to 0x1000.
You can find working code for mikroBasic and mikroC here:
Code: Select all
http://www.libstock.com/projects/view/55/microchip-hid-bootloader-template-and-adc-over-hid-for-pic18f-pic18f14k50-pic18f27j53-pic18f2553-pic18f4553-tested
- Microchip application libraries use the PICDEM FS USB Board for testing PIC18F4550. Microchip's original bootloader uses a 12MHz crystal input (PICDEM FS USB) and the custom template bootloader uses a 8MHz crystal (EasyPIC6).
Using the template there is no need to modify any mikroBasic files.