Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Updated PIC32-Pinguino USB Bootloader
05-02-2014, 09:13 PM, (This post was last modified: 21-03-2014, 01:36 PM by djpark.)
#1
Wink  Updated PIC32-Pinguino USB Bootloader
I am attaching the updated USB HID bootloader for PIC32-Pinguino. The file is PIC32-Pinguino-Bootloader-PS8192.hex in attached PIC32-Pinguino-Bootloader.zip file.

Background:
I needed to use MLA with MPLAB XC32 but wanted to maintain the convenience of using Pinguino's USB bootloader so that the field engineer can update the firmware without using the ICD or PICKit. After digging quite a few days, I managed to understand and got the HEX file generated to be compatible with Pinguino bootloader. But due to the CONFIG difference, the clock timing was incorrect and serial output generated garbled text and SPI didn't work. So I decided to re-produce the bootloader.

Process:
I used UBW32 HID bootloader source with MLA-2011-07-14 as suggested by Brian Schmalz. XC32 is configured with -Os optimization and to produce MIPS16 code to reduce the size. After moving around the memory sections, I managed to get it to fit within boot flash without using program flash.

It is compiled with PIC32MX440F256H processor and should be compatible with many models of PIC32-Pinguino boards.

Changes:
- Bootloader is stored within the boot flash without using the program flash. Bootflash location is write protected.
- EBASE is changed from 0x9D005000 to 0x9D000000 and gives 20KB extra program flash space.
- If attached pic32-pinguino-procdefs.ld file is copied to P32/lkr/PIC32_PINGUINO_OTG (or appropriate folder) as procdefs.ld file, the Pinguino IDE will produce HEX file to take the advantage of the extra program flash.
- It is still compatible with the HEX file produced by Pinguino IDE without changing the procdefs.ld file.
- Watchdog timer post scaler is set to 1:8192 to trigger at about 8 seconds.

It is necessary to use ICD or PICKit to program the board with the updated bootloader. It may be possible to prepare the bootloader to run in the program flash as a regular Pinguino hex file that in turn will download the new bootloader in to the boot flash, perhaps someone may want to try.

DJ

-- edit
The watchdog timer setting was left out in the first attachment package. Now replaced with the new files.
This bootloader is for Pinguino with PIC32MX440F256H processor.

-- edit 2 (important)
To use with the modified linker script for extra flash size, it is necessary to modify the interrupt.c file. The change is listed in the post below.


Attached Files
.hex   PIC32-Pinguino-Bootloader-PS8192.hex (Size: 31.46 KB / Downloads: 35)
.zip   PIC32-Pinguino-Bootloader.zip (Size: 129 KB / Downloads: 82)
.txt   pic32-pinguino-procdefs.ld.txt (Size: 2.46 KB / Downloads: 62)
Reply
05-02-2014, 11:04 PM,
#2
RE: Updated PIC32-Pinguino USB Bootloader
Interesting. I'm concerned you look to have ebase not on a 4K boundary, though. I suppose nothing actually is allowed to go wrong and use it so maybe it doesn't matter?

John
Reply
06-02-2014, 01:55 AM,
#3
RE: Updated PIC32-Pinguino USB Bootloader
Please correct me if I am wrong.

I believe the importance of EBASE in 4K alignment is for the application to be loaded by the bootloader to avoid the erasing of the part of the bootloader during the erase/programming by bootloader. The EBASE used by the bootloader itself is not important as long as it provides enough space for the IVT. It is important to set the boot mem start address to be 4k boundary so that it will be used as ebase for the application to be loaded by the bootloader.

In fact, the ebase address used by Microchip serial bootloader in AN1388 is 0x9FC01E00 that is obviously not in 4k boundary.

DJ
Reply
06-02-2014, 12:18 PM,
#4
RE: Updated PIC32-Pinguino USB Bootloader
Bizarre. The Mchp doc are insistent that ebase be on 4K boundary.

I think MIPS32 is the same.

If it works...

(I don't need another chunk of flash except on MX220, however.)

John
Reply
07-02-2014, 03:47 PM, (This post was last modified: 07-02-2014, 04:01 PM by djpark.)
#5
RE: Updated PIC32-Pinguino USB Bootloader
Found that the first compilation left out the watchdog timer setting to PS1. Now changed to PS8192 and new files uploaded.

Tip for benefit:

The original PIC32-Pinguino-OTG bootloader from Olimex has no write protect bits set for the bootloader portion of program flash and boot flash. If someone 'accidentally' (or unknowingly) try to upload a new bootloader or other hex files generated by MPLAB with standard configuration will also erase part of the bootloader. The bootloader is permanently damaged and needs to be re-flashed with PICKit or ICD.

The updated bootloader stays within the boot flash and it is write protected. Accidental (or intentional) attempt to upload a hex file not meant for Pinguino bootloader will only erase the program flash and the bootloader will survive. It saves lots of trouble!
Reply
20-03-2014, 06:57 PM,
#6
RE: Updated PIC32-Pinguino USB Bootloader
Hi

Thanks for the job !
It is exactly what I was trying to do Smile

Did you try to migrate with latest version MLA ?
I made a quick try, but a file is missing in the new version...


Chris
Reply
21-03-2014, 05:02 AM,
#7
RE: Updated PIC32-Pinguino USB Bootloader
(20-03-2014, 06:57 PM)blinde Wrote: Did you try to migrate with latest version MLA ?
I made a quick try, but a file is missing in the new version...

I went around many (if not all) places including Pinguino SVN looking for the bootloader source code. It looks like the closest one is the bootloader designed for UBW32 judging from the various parameters and behaviors such as reserving the boot software key variable meant for UBW 'BL' command.

I modified the code to match the Pinguino-OTG hardware (led and button) and added a feature to load the hex file at lower memory address to take advantage of extra flash available after shrinking the bootloader to fit within the boot flash.

I used older version of MLA to reduce the size as mentioned by Brian in his web site. I used XC32 with -Os and -mips16 options to minimize the size.

It does work but I need to warn you that it may not work with many programs using ISR. There is a statement in interrupt.c as this.

Code:
    _CP0_SET_EBASE(0xBD005000); // Set an EBase value of 0xBD005000

This hard coded value may is setting ebase address which is in the middle of application flash if the hex file is loaded at 0x9d001000 instead of 0x9d006000 using modified linker file.

I haven't had time to check on this issue and hope someone verify it.

DJ
Reply
21-03-2014, 10:14 AM,
#8
RE: Updated PIC32-Pinguino USB Bootloader
Ok. Thank you for the information.
I didn't use you new linker file. My main need was to have the watchdog working with a longer period before reseting...

Chris
Reply
21-03-2014, 10:19 AM,
#9
RE: Updated PIC32-Pinguino USB Bootloader
If what you need is to change the watchdog timer post scaler, it is easier and simpler to load it in PIC Kit3 and change the configuration before you burn it.

You can find the Olimex bootloader in one one the thread here and my comments on the watchdog in another thread.

DJ
Reply
21-03-2014, 01:32 PM,
#10
RE: Updated PIC32-Pinguino USB Bootloader
(21-03-2014, 05:02 AM)djpark Wrote: It does work but I need to warn you that it may not work with many programs using ISR. There is a statement in interrupt.c as this.

Code:
    _CP0_SET_EBASE(0xBD005000); // Set an EBase value of 0xBD005000

This hard coded value may is setting ebase address which is in the middle of application flash if the hex file is loaded at 0x9d001000 instead of 0x9d006000 using modified linker file.

Tested and confirmed that the hard coded ebase address was causing the programs using interrupt. The interrupt.c is modified as follow so that the vector table is located at the correct address when using the modified linker script for extra flash size.

Code:
--- interrupt.c.orig    Mon Dec 09 22:53:42 2013
+++ interrupt.c    Fri Mar 21 19:05:06 2014
@@ -1060,7 +1060,11 @@
    #if defined(PIC32_PINGUINO_220) || defined(PINGUINO32MX250) || defined(PINGUINO32MX220)
    _CP0_SET_EBASE(0xBD003000); // Set an EBase value of 0xBD003000    
    #else
+    #if _ebase_address==0x9D000000
+    _CP0_SET_EBASE(0xBD000000); // Set an EBase value of 0xBD000000    
+    #else
    _CP0_SET_EBASE(0xBD005000); // Set an EBase value of 0xBD005000    
+    #endif    // _ebase_address
    #endif
    _CP0_SET_INTCTL(0x00000020); // Set the Vector Spacing to non-zero value
    temp = _CP0_GET_CAUSE(); // Get Cause

DJ
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)