Dangerous Prototypes

In development => Project logs => Topic started by: JTR on December 13, 2011, 02:51:27 am

Title: "Diolan Plus" bootloader.
Post by: JTR on December 13, 2011, 02:51:27 am
Due to the number of requests I have seem about in various forums I am reworking the Diolan bootloader and the new version will be called Diolan Plus bootloader.

This port is based on Ian's port that removed the extended instructions and the encryption system. The encryption probably can be put back in but this is out of scope for my efforts.

Main changes that I hope all will work are:

Support for every PIC18 (non-J) USB PIC.

18F14K50
18F13K50
18F2450
18F2455
18F2458
18F2550
18F2553
18F4450
18F4455
18F4458
18F4550
18F4553

Support for both instruction mode options using the same code.

Refactored so that only two files ever need to be modified and these are prefixed with USER_ in the file name.

Single linker file for all PIC and all options.

I have added "noob assist" (TM) that allows users to define their crystal speed and required CPU speed. There is documentation and error checking to ensure that they are applicable to the target PIC.

To port over to a new PIC I would expect it to take less than 5 minutes the first time through and less than one minute once you know that really in most cases only two values need to be entered and the correct PIC selected in MPLAB.

I have the guts of it working now and it is in the tidy up, additional testing and feature creep stage. Oh, I have to do something with the VID and PID settings. forgot about that until now.

Hope to post this on my web site soonish.

Edit: Also fixed a bug with a missing return instruction in the bootloader read code...
Title: Re: "Diolan Plus" bootloader.
Post by: ian on December 13, 2011, 08:46:26 am
It should support the J pics easily too, I ported it to the 18F24J50. As I recall there are two issues. 1. You need to bank switch before a few of the USB registers are used since it is pure ASM. 2. J does not like to Sleep between USB interrupts, so I changed the sleep level to something else (don't remember, but it is documented well in my version of the code). I can upload it for your reference, or I think it is in the diolan folder of the DP SVN.
Title: Re: "Diolan Plus" bootloader.
Post by: JTR on December 13, 2011, 10:50:34 am
Hi Ian, yes I have no doubt that the firmware can support the J series and that may well be something for the future. If I add it now then there is so much more testing and documentation to do. I seem to remember that the J series are not consistent with each other in the non access SPRs too. Not sure if that applies to the USB SPRs or not. Will be a hell of a headache if it does. Already the 18F1xK50 require banked instructions for some of the SPRs but there are only two family members and they are the same as each other.

Anyway, I do not have any hardware with a j series pic to test with and my bread board still has the PIC2464GB002 mock-up on it.

The problem with supporting the J-series is that the config word is stored in code space and at this time I do not know how the host side software addresses this. I am pretty sure that Diolan never wrote the software to be aware of the config word issue but there may be a work around or some way to fudge a workable solution.

For stage two I will look further into this. At this time I am not doing anything that requires changes to the host side code but maybe there is someone here who can collaborate on that.

I will check the Diolan folder to see what you have done and see if that sheds some more light. If it is n ot there please upload it so I can have a look.

For now this is just meant to be a quick recreational project and a good tutorial on USB config word settings etc.

The thing that I am really please about is that it is now compatible with either the standard or extended instruction set and can handle the WDT being enabled. All working well.
Title: Re: "Diolan Plus" bootloader.
Post by: JTR on December 14, 2011, 02:01:49 am
Turns out that all the J series have the same USB SPRs in the banks they are in with the 14K50 so most of the hard work is already done. :)
Title: Re: "Diolan Plus" bootloader.
Post by: arhi on December 14, 2011, 02:36:15 am
I have no experience (never heard of) diolan bootloader so in few sentences - how it differs (why is it better then) to mchip hid bootloader? God side of the mchip hid bootloader is that there's a client for every os out there (I made the linux and osx version myself) and is proven to work good. Is diolan bootloader smaller? public domain? (I understand that it allows for encryption but that's completely unimportant feature for open source projects)
Title: Re: "Diolan Plus" bootloader.
Post by: ian on December 14, 2011, 09:21:44 am
Diolan is USB HID and licensed GPL. The original update utility is far too complicated, but we have a couple different ones now that also work with it under every OS. The main reason we use it is because A) compiles to 800words (or whatever, bootloader area) without optimizations (it is ASM), and B) we can actually distribute the source ;)
Title: Re: "Diolan Plus" bootloader.
Post by: arhi on December 14, 2011, 11:09:12 am
I hate the "asm" part
I love the 800words - wait, that means that original linker script works, no need for custom linker script?! How big is mchip's I haven't used it for a while?
We can distribute source - YEAH

Do we have a link to the work you guy's did on that bl?
Title: Re: "Diolan Plus" bootloader.
Post by: JTR on December 14, 2011, 11:11:26 am
Yes, what Ian said. You will not say get the microchip HID bootloader in the boot block of some PIC18s. It is w-a-y to big. The Diolan bootloader missed the boat by using the extended instruction set. Ian fixed that part and now I have made it very simple to adapt to the other PIC18s. I have little doubt that slowly it will become the defacto goto bootloader for PIC18 USB PICs. It even fits nicely in the PIC18F13K50. Try doing that with the microchip HID bootloader.  :)

Attached is the zipped up PDF for the documentation.
Title: Re: "Diolan Plus" bootloader.
Post by: ian on December 14, 2011, 11:53:42 am
I forgot about the extended instruction issues.

MCs will fit 800words, but you need full optimizations on (even the non-free ones).

Our ports (18F and 18FxxJ) are here:
http://code.google.com/p/dangerous-prot ... HID-Diolan (http://code.google.com/p/dangerous-prototypes-open-hardware/source/browse/#svn%2Ftrunk%2FBootloaders%2FUSB-HID-Diolan)
Title: Re: "Diolan Plus" bootloader.
Post by: arhi on December 14, 2011, 12:20:24 pm
niiiiiiiiice
Title: Re: "Diolan Plus" bootloader.
Post by: JTR on December 15, 2011, 01:05:03 am
Quote from: ian
I forgot about the extended instruction issues.

MCs will fit 800words, but you need full optimizations on (even the non-free ones).
/
Quote

Me thinks you are confusing the microchip FS USB bootloader and the microchip HID bootloader. The FS USB bootloader can be squeeze into the boot block (0 - 0x7FF) but the microchip HID bootloader is substantially larger and and takes up the whole of Block 0 (0 - 0xFFF.)

A HID base bootloader is always going to require more space because they require extra code for the USB (HID class requests, HID descriptors etc.) The microchip HID bootloader is so large because there was never any chance that it was going to fit in the boot block (being written in C) so it made sense not to try to minimize the size as there was nothing to gain. It may as well be a full USB stack and not worry about using the extra code space up to the end of block 0 as that was not going to be available to the user app in any case (as the bootloader is going to be write protected.)

Freed from the constraints of having to be minimal, the microchip HID bootloader firmware was written to be universal. That is for the PIC18, PIC24 and PIC32. With all the extra code space it implements a bootloader descriptor system that holds all the various variables about the bootloader like the PIC family,  memory regions and size the bootloader space, size of the PIC, erase block size, write block size etc and passes them to the host.

This system means that anyone who writes a host side downloader for the PIC18 has in effect gone 95% of the way to also writing one compatible for the PIC24 and PIC32. The hard work (customization) is actually done inside the firmware and the host software is what becomes easily portable and not the firmware.

My personal opinion on this system is that it is great for the PIC24 and PIC32 but it is not so great for the PIC18 that is much more memory constrained. However I sort of think that microchip wanted the bootloader to be portable across families for marketing reasons. They have always pitched upward device "migration" as a strong point.

My reckoning is that a smaller HID based bootloader for the PIC18s is something that the world is missing. Now I think the work of Diolan -> Dangerous Prototypes -> JTR has provided it.
Title: Re: "Diolan Plus" bootloader.
Post by: JTR on December 15, 2011, 04:31:08 am
From the dangerous prototypes port (both 2550 and 24J50)

;-----------------------------------------------------------------------------
;      read_code
;-----------------------------------------------------------------------------
; DESCR :
; INPUT : boot_cmd
; OUTPUT: boot_rep
; NOTES : Assume TBLPTRU=0
;-----------------------------------------------------------------------------
read_code
   rcall   load_address_size8      ; TBLPTR=addr cntr=size8 & 0x3C
   lfsr   FSR0, boot_rep + CODE_OFFS   ; FSR0=&boot_rep.data

        ; while( cntr-- )
read_code_loop
   tblrd*+
   movff   TABLAT, POSTINC0
   decfsz   cntr
   bra   read_code_loop
   

;-----------------------------------------------------------------------------
;      write_code
;-----------------------------------------------------------------------------

Notice that the read code is missing a RETURN instruction and falls through to the write code...
Title: Re: "Diolan Plus" bootloader.
Post by: ian on December 15, 2011, 08:41:57 am
You're probably right, I have not messed with Microchips bootloaders in years and probably got it all mixed up.

I'd have to look at our source and the original source to understand what is going on in read/write code. I thought it did the read loop until done (decfsz cntr) and then fell through to the next write loop for more data. I don't recall making any changes here, but that doesn't mean I didn't mess it up somehow :)
Title: Re: "Diolan Plus" bootloader.
Post by: JTR on December 15, 2011, 08:50:28 am
[quote author="ian"]You're probably right, I have not messed with Microchips bootloaders in years and probably got it all mixed up.

I'd have to look at our source and the original source to understand what is going on in read/write code. I thought it did the read loop until done (decfsz cntr) and then fell through to the next write loop for more data. I don't recall making any changes here, but that doesn't mean I didn't mess it up somehow :)[/quote]

Actually, you deleted the goto encrypt which of course would of had the return.

I have looked at the J series stuff and I see that your firmware sort of hard coded some stuff to work around the config word problem. I guess I could do that with all the J series but there are other issues. Like for example the 64k limit.

I cannot get the host side app to recompile and make the changes needed on the host side, I think I need the WDK installed or something.

It would be great to include all the J series but at this stage it seems out of reach unless I can recompile the host code. It is starting to look rather daunting.
Title: Re: "Diolan Plus" bootloader.
Post by: ian on December 15, 2011, 08:58:10 am
I would forget the original diolan code and take a look at robot's multi-os version, way easier to compile app. Diolan's app was crazy hard to compile, and had WAY too much junk for such a simple app (not to mention the 5GB WDK download that failed on me 6 times...):
https://github.com/robots/ols-fwloader (https://github.com/robots/ols-fwloader)
Title: Re: "Diolan Plus" bootloader.
Post by: JTR on December 15, 2011, 09:06:32 am
Ok! Now that is a great heads-up. I sort of thought that there was something else that DP used. Downloading now...

Will see if I can make sense of this one.
Title: Re: "Diolan Plus" bootloader.
Post by: JTR on December 15, 2011, 10:18:23 am
No joy with that. Complains that config.h is missing.
Title: Re: "Diolan Plus" bootloader.
Post by: JTR on December 16, 2011, 03:48:20 am
erase_code
;!!!18f24j50 change!!! setup the write
movlw 0x08
movf boot_cmd + ADDR_HI_OFFS, W
clrf boot_cmd + ADDR_LO_OFFS

That should be:

erase_code
;!!!18f24j50 change!!! setup the write
movlw 0x08
movwf boot_cmd + ADDR_HI_OFFS
clrf boot_cmd + ADDR_LO_OFFS
Title: Re: "Diolan Plus" bootloader.
Post by: ian on December 16, 2011, 09:42:30 am
Is this a serious bug? I'm sorry, I'm not great at ASM - hacking it mostly. My limited knowledge leads me to guess they do the same thing, but I would have to dig through the PIC18 instruction reference to be sure.
Title: Re: "Diolan Plus" bootloader.
Post by: JTR on December 16, 2011, 09:59:00 am
[quote author="ian"]Is this a serious bug? I'm sorry, I'm not great at ASM - hacking it mostly. My limited knowledge leads me to guess they do the same thing, but I would have to dig through the PIC18 instruction reference to be sure.[/quote]

Certainly they do not do the same thing but it is not serious IF the host software is doing what it should. However that assumption sort of defeats the purpose of the change you were trying to make, to protect the bootloader space below 0x800 which on the J series cannot be protected separately and is always at risk, therefore, of being overridden.

The idea was good and I have no doubt that it would save some grief from the occasional wayward running host, just as intended. I would suggest that it aught to be fixed next release. Not really big enough to worry about it retrospectively.
Title: Re: "Diolan Plus" bootloader.
Post by: JTR on December 16, 2011, 10:03:49 am
Actually chances are the biggest risk to the bootloader would come from a wayward running PIC. Even something going wrong on the main app or a voltage dip. If it is coded as I showed and the code is executed at worst it will trash the user app but leave the bootloader alone. That is the real difference and no doubt what you wanted.
Title: Re: "Diolan Plus" bootloader.
Post by: ian on December 16, 2011, 10:26:53 am
Thank you for the explanation.
Title: Re: "Diolan Plus" bootloader.
Post by: JTR on December 19, 2011, 04:33:27 am
She's coming along nicely. Managed to get Robots loader compiling and have modified it to handle all the PIC18 USB parts including the J series and up to 128K bytes memory and 256 bytes EEPROM. Also supports R/W of the user ID and reading of the config words.


c:00Workingdiolan plusdownloaderrobots-ols-fwloader-fb4a14abinDebug>ols-f
wloader -f BOOT -t HEX -v 0x04D8 -p 0xFD0B -R -r readback.hex
Bootloader version 0.2.2
Found PIC18F14K50 target, DEVID 0x4760 REV: 0x05
Usable memory range 0x800-0x03fff
Device has 0x100 bytes of data EEPROM
Reading flash
Writing file 'readback.hex'

c:00Workingdiolan plusdownloaderrobots-ols-fwloader-fb4a14abinDebug>pause

Press any key to continue . . .
Title: Re: "Diolan Plus" bootloader.
Post by: ian on December 19, 2011, 12:23:02 pm
Nice work!
Title: Re: "Diolan Plus" bootloader.
Post by: JTR on December 19, 2011, 12:40:29 pm
[quote author="ian"]Nice work![/quote]

Why thank-you Sir. Thanks for putting me on to Robots loader. The code is so much better to work with than Diolan's.

I have since added utilities to allow separate areas of memory to be targeted for read, write, verify, blank and erase.  Everything I have done is working :)

This is not far off being finished (except for the J-series testing....)
Title: Re: "Diolan Plus" bootloader.
Post by: ian on December 19, 2011, 01:16:19 pm
Yes, the diolan software was a nightmare. I remember it took 3 people to help me get it compiling so I could make 2 or three tiny changes.

Sorry to hijack the thread, but do you think this error could be USB stack related? The IR TOy is not resuming from suspend:
viewtopic.php?f=29&t=3336#p32819 (http://dangerousprototypes.com/forum/viewtopic.php?f=29&t=3336#p32819)
Title: Re: "Diolan Plus" bootloader.
Post by: JTR on January 06, 2012, 11:17:52 pm
There was some communication to me over this. I received an email saying so but it appears the DP forum has dropped it from my inbox and generally I delete the email notifications from DP once read lest they fill my email client to overflowing. I am sure someone contacted me, if you are here please try again.
Title: Re: "Diolan Plus" bootloader.
Post by: superfro on April 09, 2012, 11:06:27 pm
Is there a link to the updated Diolan Plus bootloader ?  I'm looking to run Diolan on a 18f14k50 but there's no need to port Diolan twice.  Thanks.
Title: Re: "Diolan Plus" bootloader.
Post by: asbala on April 10, 2012, 08:55:02 pm
I think it would be great, if you somebody can upload the diolan plus bootloader for pic18f14k50.
Thank you.
Title: Re: "Diolan Plus" bootloader.
Post by: robots on April 10, 2012, 11:23:59 pm
[quote author="JTR"][quote author="ian"]Nice work![/quote]
Why thank-you Sir. Thanks for putting me on to Robots loader. The code is so much better to work with than Diolan's.
[/quote]

Glad you found it usefull :-)
Title: Re: "Diolan Plus" bootloader.
Post by: day on April 30, 2012, 04:05:39 pm
Hi all, great work with the bootloader port!

I am struggling trying to get the code to run on a PIC18F14K50 and would really appreciate any help at all. I have attached a zip with my 2nd attempt, 2 'USBTrace' Logs and a uart debug output file.

The 'USBTrace' Logs show a successful connection to a PIC18F4550 device (a Tiertex dev board) and an unsuccessful attempt to a Microchip Low Pin Count Dev Board.

The UART Debug Output file contains to UART output for both the 4550 and 14K50.

The code I have attached has modifications (from this topics origional 2550 code) to the linker script (USB ram Allocation), the size of the 'SetUpPkt' and control transfer array and some of the RAM address' associated with USB data. I have marked them as !MODIFIED!

I have stripped back all the mods I have tried to this 2nd attempt as nothing I did in the first made any difference.

I do not have a great deal of experience with assembler but I cannot see what is different from the working 2550/4550 code and the not working 14K50 code other than the memory allocations. I have also checked the linker map output file for both setups and also the working HID bootloader in the Microchip examples and have tried several configurations of array sizes for those mentioned above. I have even gone through the HID example C code and checked in back against the 2550 assembler and where I have found differences I have modified the assembler but as none of this changed anything i haven't included it in the zip. If anybody would like to look at it I could upload that also.

I am not just asking for my problem to be solved for me, I would really like to understand what the problem is and why I have missed it. I am used to C and generally have had little experience with linker scripts and such (usually the C compiler just sorts everything out) but I am keen to learn.

Once again any help at all would be greatfully received.

Day
Title: Re: "Diolan Plus" bootloader.
Post by: ian on May 01, 2012, 07:48:57 am
Hi Day,

Just curious - exactly which version are you using? For the 18F24J50 port I had to swap banks for some registers.
Title: Re: "Diolan Plus" bootloader.
Post by: day on May 01, 2012, 09:32:47 pm
Hi Ian, thanks for that nudge. You must find it very tedious when people like me ask for advice when I really should know better!

Time to get to grips with assembler!

Many thanks

Day
Title: Re: "Diolan Plus" bootloader.
Post by: ian on May 07, 2012, 05:56:21 pm
I can't tell if that meant it was helpful or not :) I'm always happy to give google new content to index. If you need an example pls let me know, I'll hunt it down.

Update... Here's an example from version in our svn. You can find the mods in the files by searching the 18F24J50 keyword to see where I had to do it:

http://code.google.com/p/dangerous-prot ... asm.asm#86 (http://code.google.com/p/dangerous-prototypes-open-hardware/source/browse/trunk/Bootloaders/USB-HID-Diolan/18F24J50/bootloader/boot_asm.asm#86)

Code: [Select]
usb_state_machine_actif
btfss UIR, ACTVIF
bra usb_state_machine_actif_end
;!!!18f24j50 change!!!
movlb 0x0f ;select the correct bank
btfss UIE, ACTVIE
bra usb_state_machine_actif_end
movlb 0x00 ;back to main bank
UD_TX 'A'
bcf UCON, SUSPND
;!!!18f24j50 change!!!
movlb 0x0f ;select the correct bank
bcf UIE, ACTVIE
movlb 0x00 ;back to main bank
bcf UIR, ACTVIF

I do not know if this applies to your chip, but I assume it is not present in the '+' version posted in this thread.
Title: Re: "Diolan Plus" bootloader.
Post by: day on May 08, 2012, 12:27:12 pm
Hi Ian,

sorry yes i've got it working now. I was grateful you suggested where to start looking rather than giving me working code as I have learnt so much more by working it out myself. I have never used assembly other than to run say a few instructions in a C environment. eg asm{bcf TRISC, 1; bsf PORTC, 1;}

I assume that not understanding bank switching is fairly low on the assembler ability scale and sometimes on forums you get made fun of and told to quit what you are doing "if you don't know something as basic as that", so I appreciate your helpfulness and now I have something useful and relevant from which to learn a new skill.

Thanks

Day
Title: Re: "Diolan Plus" bootloader.
Post by: pjkim on May 17, 2012, 08:48:58 pm
I built the Soldering Iron Driver v1.5 and am trying to get it working. There are some serious button debounce issues with the current hardware/firmware, ie no hardware or firmware debouncing. I am currently debating whether to debounce in hardware vs software. I could add an Arduino to software debounce the switches and send clean signals into the driver board but that would be a truly ugly solution. Or use a 7414 schmitt inverter-- less ugly but that would still require several passives per button.

Ahri seems to have used the hardware approach in his build. I guess I could go that route but I would like to contribute to the project by coding a software debounce so that everyone making the v1.5 board won't have to make a debouncing circuit.

I have very little experience with PICs and no experience with PIC usb bootloaders. I have however programmed an MSP430 to debounce three switches concurrently and independently. If I can get the USB bootloader for the 18F2550 working, it would make testing/reprogramming easy enough that I will try to implement software debouncing.

My question is this: how do I get the USB bootloader to work? In particular:
http://code.google.com/p/dangerous-prot ... bootloader (http://code.google.com/p/dangerous-prototypes-open-hardware/source/browse/#svn%2Ftrunk%2FBootloaders%2FUSB-HID-Diolan%2F18F2550%2Fbootloader) work without changes or will I need to make changes in particular for the Soldering iron driver?
2) When I burn this to the PIC, do I need to set flags a certain way or is this set in the hex file?
3) When I compile the soldering iron driver firmware, are there certain flags, settings that need to be set, ie start of program in memory, reset/interupt vectors, etc?
[/list]

Another thing-- where can I find the original code for "diolan plus?" I downloaded the modified version for the 18F2550 from the google code site for dangerousprototypes but can't seem to locate the root diolan plus source code. From the description, it seems that there may be enlightening information in there.
Title: Re: "Diolan Plus" bootloader.
Post by: arakis on May 18, 2012, 10:07:23 am
Usually when using a bootloader you have to export the hex file from MPLAB and move the memory to a specific location...We used the same hardware setup(oscilater etc) as the LCD backpack, so the same bootloader should work...I say should because we never got around to testing it yet, stuff always keeps poping up :)

as for the debouncing, I think software is the best way, since that is what we will do for the final release for sure....Thanks for testing it out, and playing around with it. I have mine assembled and will join you in a week tops...

BTW what programer do you have, for programing PICs?
Title: Re: "Diolan Plus" bootloader.
Post by: pjkim on May 18, 2012, 07:47:34 pm
Thanks arakis. I agree that software debouncing is the best solution. I will try out the LCD backpack bootloader. Is this the right one? trunk/ LCD_Backpack_PIC_HD44780/ bootloader

You mentioned moving the memory to a specific location. How do you do this and where do you move it to? Do you have to move anything else such as interrupt vectors? Does anything else need to be changed in the firmware code when using a bootloader? Here is the body of the linker file from the above project:
Code: [Select]
 CODEPAGE   NAME=vectors    START=0x0            END=0x1B         PROTECTED
//CODEPAGE  NAME=bootldr    START=0x1C          END=0x0AFF
CODEPAGE  NAME=bootldr    START=0x1C          END=0x07FF
//CODEPAGE  NAME=apppage    START=0x0B00        END=0x0B01
CODEPAGE  NAME=apppage    START=0x0800        END=0x0801
CODEPAGE  NAME=idlocs    START=0x200000      END=0x200007      PROTECTED
CODEPAGE  NAME=config    START=0x300000      END=0x30000D      PROTECTED
CODEPAGE  NAME=devid      START=0x3FFFFE      END=0x3FFFFF      PROTECTED
CODEPAGE  NAME=eedata    START=0xF00000      END=0xF000FF      PROTECTED

DATABANK  NAME=gpr0      START=0x0            END=0x0FF
//DATABANK  NAME=gpr1      START=0x100          END=0x1FF
//DATABANK  NAME=gpr2      START=0x200          END=0x2FF
//DATABANK  NAME=gpr3      START=0x300          END=0x3FF
DATABANK  NAME=usb4      START=0x400          END=0x490          PROTECTED
DATABANK  NAME=usb5      START=0x500          END=0x580          PROTECTED
//DATABANK  NAME=usb4      START=0x400          END=0x4FF          PROTECTED
//DATABANK  NAME=usb5      START=0x500          END=0x5FF          PROTECTED
//DATABANK  NAME=usb6      START=0x600          END=0x6FF          PROTECTED
//DATABANK  NAME=usb7      START=0x700          END=0x7FF          PROTECTED
ACCESSBANK NAME=accesssfr  START=0xF60          END=0xFFF          PROTECTED
I have an old serial JDM clone from Olimex-- picked it up for about $15 a few years back.
Title: Re: "Diolan Plus" bootloader.
Post by: arhi on May 20, 2012, 04:27:50 am
wrt debouncing, I added it (found few minutes today between work): viewtopic.php?f=56&t=2457&p=40688#p40688 (http://dangerousprototypes.com/forum/viewtopic.php?f=56&t=2457&p=40688#p40688)

as for the bootloader, 18f2550 works perfect with microchip hid bootloader, it's easy to use it and works like a charm. I just don't see a point in soldering iron having usb port so I never bothered adding bootloader to this project :D
Title: Re: "Diolan Plus" bootloader.
Post by: arakis on May 21, 2012, 10:02:48 am
[quote author="pjkim"]Thanks arakis. I agree that software debouncing is the best solution. I will try out the LCD backpack bootloader. Is this the right one? trunk/ LCD_Backpack_PIC_HD44780/ bootloader

You mentioned moving the memory to a specific location. How do you do this and where do you move it to? Do you have to move anything else such as interrupt vectors? Does anything else need to be changed in the firmware code when using a bootloader? Here is the body of the linker file from the above project:
Code: [Select]
 CODEPAGE   NAME=vectors    START=0x0            END=0x1B         PROTECTED
//CODEPAGE  NAME=bootldr    START=0x1C          END=0x0AFF
CODEPAGE  NAME=bootldr    START=0x1C          END=0x07FF
//CODEPAGE  NAME=apppage    START=0x0B00        END=0x0B01
CODEPAGE  NAME=apppage    START=0x0800        END=0x0801
CODEPAGE  NAME=idlocs    START=0x200000      END=0x200007      PROTECTED
CODEPAGE  NAME=config    START=0x300000      END=0x30000D      PROTECTED
CODEPAGE  NAME=devid      START=0x3FFFFE      END=0x3FFFFF      PROTECTED
CODEPAGE  NAME=eedata    START=0xF00000      END=0xF000FF      PROTECTED

DATABANK  NAME=gpr0      START=0x0            END=0x0FF
//DATABANK  NAME=gpr1      START=0x100          END=0x1FF
//DATABANK  NAME=gpr2      START=0x200          END=0x2FF
//DATABANK  NAME=gpr3      START=0x300          END=0x3FF
DATABANK  NAME=usb4      START=0x400          END=0x490          PROTECTED
DATABANK  NAME=usb5      START=0x500          END=0x580          PROTECTED
//DATABANK  NAME=usb4      START=0x400          END=0x4FF          PROTECTED
//DATABANK  NAME=usb5      START=0x500          END=0x5FF          PROTECTED
//DATABANK  NAME=usb6      START=0x600          END=0x6FF          PROTECTED
//DATABANK  NAME=usb7      START=0x700          END=0x7FF          PROTECTED
ACCESSBANK NAME=accesssfr  START=0xF60          END=0xFFF          PROTECTED
I have an old serial JDM clone from Olimex-- picked it up for about $15 a few years back.[/quote]

sorry haven't dived into the code yet...I asked about the programmer, because with a better one you could do debugging from MPLAB....which makes life much easier..
Title: Re: "Diolan Plus" bootloader.
Post by: ian on May 24, 2012, 02:05:51 pm
1) Will the bootloader.hex file at http://code.google.com/p/dangerous-prot (http://code.google.com/p/dangerous-prot) ... bootloader work without changes or will I need to make changes in particular for the Soldering iron driver?

Should work fine. As long as your crystal is 20MHz I would assume.

    2) When I burn this to the PIC, do I need to set flags a certain way or is this set in the hex file?

Should all be in the hex.

    3) When I compile the soldering iron driver firmware, are there certain flags, settings that need to be set, ie start of program in memory, reset/interupt vectors, etc?

You need to use a linker (.lkr) file that preserves the first 800 words of flash for the bootloader, and all interrupts need to be redirected to n+ 800. See the IR Toy firmware or the USB stack echo demo for example interrupt relocation and linker files.


Quote
Another thing-- where can I find the original code for "diolan plus?" I downloaded the modified version for the 18F2550 from the google code site for dangerousprototypes but can't seem to locate the root diolan plus source code. From the description, it seems that there may be enlightening information in there.

The code in our SVN is the original diolan bootloader. JTR did some updates that are included in the plus version, so I guess here.
Title: Re: "Diolan Plus" bootloader.
Post by: pjkim on May 24, 2012, 08:06:51 pm
Thanks Ian.
I have the 20MHz crystal. If I burn the bootloader onto the SID board, the bootloader seems to work OK. When I short PGD and PGC on the ICSP header, the board enumerates as a USB device. I can use the fw_update program to burn the new firmware built with the .lkr file from the LCD backpack source. The fw_update program recognizes the USB device, burns the new firmware and verifies correctly.

Problem is that the new firmware does not seem to work properly-- the LCD screen remains blank and there are no signs of activity. I reset the low and high priority interrupt vectors the same way as the main.c from the LCD backpack project. When I look at the .hex file, the address does start in low 0x800s.

If the board is recognized as a valid USB device by the OS and the fw_update program burns the new firmware and verifies, can I assume that the bootloader is fine and that it must be a problem in my build of the firmware, i.e. reset/interrupt vectors not set correctly or lkr file contains errors. Any other possibilities?

Peter
Title: Re: "Diolan Plus" bootloader.
Post by: arhi on May 24, 2012, 10:48:31 pm
I never used diolan so it's time to try it out :D .. it works without changes with 2550? I'll check it now during weekend
Title: Re: "Diolan Plus" bootloader.
Post by: arhi on May 25, 2012, 01:59:49 am
the hex in the dp's repo on google in diolan 18f2550 directory, is it compiled with extended or without extended command set?
Title: Re: "Diolan Plus" bootloader.
Post by: arhi on May 25, 2012, 03:35:07 am
It works with sid now :)
The new HEX is available on source forge sid project page (http://https://sourceforge.net/projects/arhimed-sid/files/)


The hex for bootloader is compiled in a way that bootloader will start every time you restart the device.
If you just power on device your application will start.

You can burn SID_GEN4.X.production.hex directly in to your PIC18F2550 but if you like to use bootloader, it's now possible.

For the blank 18F2550 you
 - erase chip
 - flash diolan-bootloader.hex provided

and you are ready to upgrade firmware trough USB

In order to upgrade firmware trough USB
- download fw_update from diolan site http://www.diolan.com/pic/bootloader_dwn.html (http://www.diolan.com/pic/bootloader_dwn.html)
- connect SID to your USB and to power
- restart SID (by shorting pin1 and pin3 of the ICSP connector and then removing the short - this is pushing MCLR to Vss)
- DIOLAN bootloader will start
- update the firmware using ft_update:
 o ERASE flash
  fw_update.exe -e -vid 0x04d8 -pid 0xfa98 -t no
 o WRITE data
  fw_update.exe -w -t no -vid 0x04d8 -pid 0xfa98 -ix SID_GEN4.X.production.hex
 o VERIFY data
  fw_update.exe -v -t no -vid 0x04d8 -pid 0xfa98 -ix SID_GEN4.X.production.hex

That's it. Now power off SID.

NOTE: There's a bunch of capacitance on the SID's power rails so if you turn SID immediately after this procedure it will think it restarted and will go to bootloader, make sure you wait until all capacitors are empty before you power on the SID. What I do is make sure I disconnected the power and then I short pin's 2 and 3 on the ICSP emptying the cap's on the power rail.

I will look into this diolan bootloader when I catch some time, I just made slight mod to the source so it works with diolan bootloader (it can actually also work with microchip hid bootloader, only you need different linker script, I'll check out how can I use multiple configurations in mplabx and make it possible to select config with bootloader, without bootloader diolan or mchip hid).

Good thing also is that device will work without bootloader also (it adds the jump codes on the proper places :D )
Title: Re: "Diolan Plus" bootloader.
Post by: ian on May 28, 2012, 11:20:31 am
I'm late, but our version is hacked to eliminate the extended mode stuff and compiles in normal mode. I really like the firmware that works with and without too, saves a bunch of time messing around compiling both versions.
Title: Re: "Diolan Plus" bootloader.
Post by: ian on May 28, 2012, 11:20:47 am
@pjkim - I would assume the bootloader is fine.
Title: Re: "Diolan Plus" bootloader.
Post by: pjkim on May 29, 2012, 10:23:28 pm
I have confirmed that the bootloader works. I was having problems with the bootloader that Arhi modified-- I could not get the 18F2550 to go into bootloader mode and/or be recognized by the host OS (win xp). I mixed and matched the bootloader I compiled (described above) and loaded Arhi's firmware and it worked. So the problem I was having before was with my firmware.

BTW, I think that the bootloader hex file on the google code site for the LCD backpack was compiled to have PID and VID both set to 0x0000. I don't know if this was intentional or not. Either way, not too useful to provide a hex file that is nonfunctional-- no upside and as a downside, might confuse people as to why the pre-compiled binary doesn't work.
Title: Re: "Diolan Plus" bootloader.
Post by: ian on May 30, 2012, 04:01:38 pm
Thanks for the heads up on the bootloader, I'll recompile and upload again.
Title: Re: "Diolan Plus" bootloader.
Post by: pjkim on May 31, 2012, 08:21:06 pm
Not sure if this is a bootloader problem or a problem with the soldering iron driver firmware but I will post here because I know both the bootloader people and Arhi  read this thread. I have been having problems with the firmware becoming corrupted. The bootloader works fine because I can reset into bootloader mode and reload the firmware and then everything works fine for a while but every couple of power ons, the LCD screen has a row of solid blocks across the top-- I am guessing this is the native state prior to reset because if the PIC18F is not programmed at all or programmed incorrectly, this is what happens.

So the bootloader is fine but the firmware becomes corrupted. This has happened about a dozen times so far. Some thoughts:

1) Is the bootloader protected from corruption by the config bits? I ask because I find it curious that the bootloader survives intact while the firmware is corrupted. If the hardware is not protecting the bootloader specifically, doesn't this make a rogue bootloader more likely?
2) Is this more likely to be a bootloader, firmware or hardware problem? By hardware, I mean things like RESET/MCLR timing/glitches or Vdd instability. When things are working, they work fine for hours at a time. This seems to be a power on phenomenon.
Title: Re: "Diolan Plus" bootloader.
Post by: arhi on May 31, 2012, 08:50:57 pm
I noticed this too.
The firmware is not corrupted because on the next power-on the firmware will start properly.
The bootloader is not currupted because on the next "reset into bootloader" bootloader will start properly.

Now, I tested this number of times and 99% of the times you see squares - the board actually booted into bootloader (attach usb and you will see). 1% of times it is just stuck - I think this is just bootloader that didn't load properly.

Every time you power on - the bootloader will turn on, then it will check if the "rules to start bootloader" are met and if they are it will boot into bootloader mode, and if not it will jump to firmware. Every time you see squares - it means that bootloader didn't jump to firmware (either because it jumped into bootloader mode or because it go stuck)

What I noticed on the bootloader I burned into pic is that it jumps to bootloader every time it believes pic was RESET. So if you are running your driver normally and then you reset pic (ground mclr) it will boot into bootloader and not into firmware (irrelevant to pgc/pgd pins) - why, I have no clue, I assumed it's intentional.

Now I noticed something else, if you power off SID and then power it back on "soon", it will go into bootloader mode. I then did following.
- power SID off
- SHORT 5V and GND to empty all caps
- power SID on

and firmware loads properly (time between off-on is ~2sec).

I did this 20 times in a row, every time it was same.

Then I did following

- Power SID off
- short cap (takes ~2sec)
- Power SID on
(SID is now running ok)
- short MCLR to gnd (reset)

and here SID goes into BOOTLOADER mode

tried 20 times in a row - same outcome every time

then i did following

- Power SID off
- wait ~2sec
- Power SID on

I did this 20 times and 14 times it booted int bootloader and 6 times it booted firmware

I don't know enough about diolan to know why, but ..

NOTE: PGC/PGD are not shorted!!!
NOTE: the bootloader hex used is one I added to the SVN (no idea if I took one from DP's svn or directly from Diolan)
Title: Re: "Diolan Plus" bootloader.
Post by: pjkim on May 31, 2012, 10:07:31 pm
I think my problem is somewhat different. When this happens to me, powering off and on does not fix the problem, even after waiting for a long time (several hours). Also I am using the LCD backpack bootloader that enters bootloader mode differently. I have not tried shorting to discharge caps but can give it a try. I am fairly certain the firmware is corrupted.

Another thing, when this happens, it is not in bootloader mode because if I connect the USB cable, it is not recognized (I only tried 3 times, so not exhaustive testing).
Title: Re: "Diolan Plus" bootloader.
Post by: arhi on May 31, 2012, 10:10:59 pm
when this happens, try to short the 5V to GND (while SID is turned OFF !!!)
and then try to power it up. If that does not get it running then bootloader messed something up - what - no clue. All mine experience with Diolan bootloader is what you seen in past few posts of this thread
Title: Re: "Diolan Plus" bootloader.
Post by: ian on June 01, 2012, 08:13:02 am
I'm not sure about the original bootloader - doesn't it require extended mode to be enabled? I removed (as I recall) the enter bootloader on reset from the version we use.

For the LCD backpack version - we've used that version pretty extensively and never had repeated corruption issues. You're using DP v1.5 PCB right? It might be a circuit problem?

Another thing to note - some versions of diolan check the EEPROM for a mark that forces the bootloader to start. Is it possible you're storing calibration or other data in this location? I think it's the first byte.
Title: Re: "Diolan Plus" bootloader.
Post by: pjkim on June 01, 2012, 06:27:34 pm
The bootloader does not enter bootloader mode on reset. I am using a DP v1.5 PCB. The big question I have is why the problem is so intermittent-- most times it works just fine. I have been looking for bad joints but they all look good under a magnifying loupe and I can't reproduce problems wiggling components or tapping the board. Looking at the schematic for the SID and the LCD backpack, the reset circuit appears identical, except for the addition of a switch in parallel with a 100nF cap in the SID.

Regarding the EEPROM check, from my grokking the assembler code, it writes a 0x5a to EEPROM position 0x00-- probably at the initial burning of the firmware. At powerup, if the value at 0x00 is still 0x5a, enter bootloader, if not 0x5a, jump to firmware. The SID firmware puts a 0x00 at position 0x00 so this should not be a problem.
Title: Re: "Diolan Plus" bootloader.
Post by: arhi on June 01, 2012, 07:18:13 pm
- check the 5V rail if it is ok? (is it 5V, is it flat (ripple cleaned), does it drop below 4.95?)
- check pgc/pgd pins, are they clear and connected only to icsp
- check mclr pin (is it properly pushed up)

The firmware itself can't cause this, now if bootloader has a bug it can overwrite itself
Title: Re: "Diolan Plus" bootloader.
Post by: rayg on June 06, 2012, 10:55:28 pm
First post here.  I'm having trouble finding  the diolan plus bootloader that's referenced in the pdf on newfoundelectronics  There is a link on newfoundelectronics  to JTR_DP_usbstack_projects.zip,  the link is broken as it happens, but the url is only a couple of missing underscores,  so it can be downloaded unfortunately that's not the diolan plus bootloader.... 

I've checked out a number of svn projects on the dangerousprototypes but I think I'm looking in all the wrong places... :-)

My project is using a 18LF14K50 driving a Silabs Si4705 RDS FM receiver,  I hope it can be open sourced, so an open source bootloader would be very welcome.

PS... sorry I had to delete the links, the forum software thinks i'm a spammer...
Title: Re: "Diolan Plus" bootloader.
Post by: ian on June 08, 2012, 10:09:52 am
Hi rayg,

As far as I know it was never released, but day seemed to get it going on the 18F14K50 here:

viewtopic.php?f=56&t=3269&start=30#p39838 (http://dangerousprototypes.com/forum/viewtopic.php?f=56&t=3269&start=30#p39838)
Title: Re: "Diolan Plus" bootloader.
Post by: Ice9er on August 30, 2012, 11:22:39 pm
Hey guys.  I looked around and didn't see the answer so here goes....
I need to build the bootloader for the pic18f4458 with a 48mhz crystal.
I didn't see any instructions on building for other targets.  How much work would it take to build in the above configuration?  Is that even possible?

Thanks.
Title: Re: "Diolan Plus" bootloader.
Post by: ian on September 10, 2012, 04:16:23 pm
Most pics can't support a 48mhz crystal, They use a slower crystal and the PLL to divide/multiply the clock to 48mhz. 4 and 20 are common values.

You'll need to check the datasheet about the PLL, clock and oscillator setting on that PIC to see what it supports. If it does support 48mhz on the oscillator, then you just set for highspeed clock or HSCLOCK_PLL and a PLL divider of 0 in the configuration bits.
Title: Re: "Diolan Plus" bootloader.
Post by: brdpic on January 09, 2013, 09:08:53 pm
please help me what should be changed to pic18f4550 (12MHz) "Diolan Plus" bootloader.?
Title: Re: "Diolan Plus" bootloader.
Post by: ian on January 10, 2013, 08:38:49 am
Just the crystal and oscillator fuse setting, depending on the crystal and multiplier combination you used.
Title: Re: "Diolan Plus" bootloader.
Post by: brdpic on January 10, 2013, 05:05:23 pm
Yes you are right.
That's just I can not understand, if before writing the *.hex program to "erase", all recorded fine if you do not - error. This is as it should be, or I made ​​a mistake somewhere?

ps
soft:
 - fw_update.exe
 - encoder.exe
Title: Re: "Diolan Plus" bootloader.
Post by: ian on January 11, 2013, 08:06:58 am
Yes, you must always erase the flash before programming, because it is only possible to flip the bits one direction (as I recall).
Title: Re: "Diolan Plus" bootloader.
Post by: arhi on January 11, 2013, 08:09:43 am
[quote author="ian"]Yes, you must always erase the flash before programming, because it is only possible to flip the bits one direction (as I recall).[/quote]

you can flip them in both directions but the process is different hence usually you move a whole block in one direction (erase) and individual bits in another direction (write)
Title: Re: "Diolan Plus" bootloader.
Post by: brdpic on January 11, 2013, 11:31:00 am
Okay, I get it.

The new challenge, the bootloader only works if XINST = 1, and the main program only if XINST = 0. How can this be solved?
Title: Re: "Diolan Plus" bootloader.
Post by: arhi on January 11, 2013, 04:57:32 pm
[quote author="brdpic"]Okay, I get it.

The new challenge, the bootloader only works if XINST = 1, and the main program only if XINST = 0. How can this be solved?[/quote]
You make your program with XINST=1 :)
Title: Re: "Diolan Plus" bootloader.
Post by: brdpic on January 11, 2013, 07:37:12 pm
[quote author="brdpic"]Okay, I get it.

The new challenge, the bootloader only works if XINST = 1, and the main program only if XINST = 0. How can this be solved?[/quote]

I was wrong, "Diolan Plus" bootloader work XINST = 0.

A possible Diolan original made to work with XINST  = 0 or add encryption in "Diolan Plus"?
Title: Re: "Diolan Plus" bootloader.
Post by: ian on January 14, 2013, 09:25:50 am
Quote
I was wrong, "Diolan Plus" bootloader work XINST = 0.

A possible Diolan original made to work with XINST = 0 or add encryption in "Diolan Plus"?

I removed the XINST instructions, there is a 18F24J50 comment at each place, search the code and you should find the changes needed.
Title: Re: "Diolan Plus" bootloader.
Post by: brdpic on January 15, 2013, 09:13:21 am
I can not understand why the read-only memory from the address  0x0800 to  0x5FFF.
Why don't read 0x5FFF...0x7FFF PIC18F4550?
Title: Re: "Diolan Plus" bootloader.
Post by: ian on January 15, 2013, 11:10:46 am
Not sure exactly what you mean, but without looking thr9ough the code my guess is that is the region where the main firmware is stored so it is blocked to the bootloader?
Title: Re: "Diolan Plus" bootloader.
Post by: brdpic on January 15, 2013, 11:41:57 am
Code
Title: Re: "Diolan Plus" bootloader.
Post by: usa303 on September 24, 2013, 02:18:56 pm
Trying to port this bootloader to pic18f45k50 that uses internal high-precision self tuning oscillator.

I changed fuse settings as below:
Code: [Select]
CONFIG  PLLSEL = PLL3X	    ; 3X PLL multiplier selected
CONFIG  CFGPLLEN = OFF      ; PLL turned on during execution
CONFIG  CPUDIV = NOCLKDIV    ; 1:1 mode (for 48MHz CPU)
CONFIG  LS48MHZ  = SYS48X8  ; Clock div / 8 in Low Speed USB mode
CONFIG  FOSC = INTOSCIO      ; HFINTOSC selected at powerup, no clock out
and added standard clock initialization procedure before bootloader starts (OSCTUNE, OSCCON, OSCCON2).

Bootloader starts, but PC writes that "USB device is not recognized".
Any idea what should be changed additionally to get it running?
Title: Re: "Diolan Plus" bootloader.
Post by: Sjaak on September 24, 2013, 04:07:50 pm
Did you use (make) a new linkerscript? the USB stuff should be in a specific memory.
Title: Re: "Diolan Plus" bootloader.
Post by: usa303 on September 24, 2013, 05:36:05 pm
USB banks are the same for 4550 and 45k50 (400h-7FFh), so I simply used original linker script.
Title: Re: "Diolan Plus" bootloader.
Post by: matseng on September 24, 2013, 05:44:16 pm
Is the PID/VID set to something other than 0x0000/0x0000?
Title: Re: "Diolan Plus" bootloader.
Post by: usa303 on September 24, 2013, 06:00:07 pm
They are standard 04d8:ff04 as in original Dioan Plus bootloader.
Title: Re: "Diolan Plus" bootloader.
Post by: neslekkim on September 24, 2013, 06:03:08 pm
where can I find info about the original diolan ?, it seems like this thread starts with previous knowledge in mind?
Title: Re: "Diolan Plus" bootloader.
Post by: Sjaak on September 24, 2013, 07:59:35 pm
[quote author="neslekkim"]where can I find info about the original diolan ?, it seems like this thread starts with previous knowledge in mind?[/quote]

the official page is here: http://www.diolan.com/pic/bootloader.html (http://www.diolan.com/pic/bootloader.html)  I think the work of Ian to port it to the 24j50 is in the logic sniffer or IR toy forum. IIRC the original version was for a different pic and used the extended instruction set.
Title: Re: "Diolan Plus" bootloader.
Post by: nyholku on January 31, 2015, 01:35:07 pm
I know this is an old thread but this comes up in google and what I've got to announce is very much on topi.

To support my EazyCNC Project I I've create a version of the original Diolan bootloader that I call 'diolan-plus2' and which does not use extended instruction set making it compatible with C-compilers and still retains all the features of the original diolan bootloader and fits in the 2kB bootblock.

I've published it in github as per required by GPL but as a new user I'm not allowed to post links here so I hope I will remember to come back here and add the links someday.

br Kusti
Title: Re: "Diolan Plus" bootloader.
Post by: Sleepwalker3 on February 07, 2015, 04:14:50 am
You should be able to post links now.
Title: Re: "Diolan Plus" bootloader.
Post by: arhi on February 07, 2015, 04:47:06 am
https://github.com/nyholku/diolan-plus2 (https://github.com/nyholku/diolan-plus2)
Title: Re: "Diolan Plus" bootloader.
Post by: danbakana on May 20, 2019, 07:04:21 pm
I'm using a PIC4550 with a 16MHz crystal and I'm looking for an USB bootloader to it. I read about Diolan's bootloader , so, I downloaded it and I changed the original project to be programmed to an PIC18F4550 and not a PIC18F4455 as it was originally written. So, I did the following changes on the bootloder's code:

In source files where was originally
Code: [Select]
 #include "P18F4455.INC"
I changed to
Code: [Select]
 #include "P18F4550.INC" 
On the Header files, I remove the file "P18F4455.INC" of the project and add the"P18F4550.INC instead, I downloaded it from here. The compilation succeed and I was able to program the bootloader into the PIC18F4550's flash. I used PIckit3 and MPLABV8 to do it.

I did not encrypt my application using the encoder, I just tried to write it to memory without encrypt it. So, I copied and paste my .hex file application to the bin folder where the fw_update is.
 
I found on the bootloader's project file usb_desc.inc that :
Code: [Select]
#ifndef BOOTLOADER_VID
#define BOOTLOADER_VID 0x0000 ; MUST BE VALID Vendor ID
#endif
#ifndef BOOTLOADER_PID
#define BOOTLOADER_PID 0x0000 ; MUST BE VALID Product ID
#endif

So, I opened the console and typed:

Code: [Select]
fw_update -e -w -v -vid 0x0000 -pid 0x0000 -ix example.hex 

The followed message appears:
U2IO flash erasing: FAILED.
Device is not found.
Operation aborted.

On the device manager of windows 10, It appears as a HID USB device but with a yellow exclamation.
Does someone have some advice or tip of what it is happening ?

I downloaded the diolan-plus2 at github and started to read the documentation (ALL ABOUT THE DIOLAN PLUS BOOTLOADER), but the files that the pdf document refers to, are not at the zip folder that I downloaded from github, so I can't do the modifications. Please, has someone a tip or an adivice ?