USB HID Bootloader v1.4.3 over memory

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
bitfogav
Registered User
Registered User
Posts: 148
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

USB HID Bootloader v1.4.3 over memory

Post by bitfogav » Fri Jun 12, 2020 1:48 pm

Hi guys

I have downloaded the latest USB Lib v1.4.3 and replaced the USBsystems.bas v1.4.4 file.

I am trying to compile the program HIDBootloader18F.bas using the 18F2553 Bit Wacker board, I have changed nothing in code apart from uncommenting the Bit Wacker hardware, when I compile the code it goes over the maximum program bytes for the chip.

Now I could just disable the IPC option which will resolve the over program memory issue but I would like to use IPC, is there anything in the library I could change to lower the program memory output?

progmem3.png
progmem3.png (61.85 KiB) Viewed 181 times

Jerry Messina
Swordfish Developer
Posts: 1173
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: USB HID Bootloader v1.4.3 over memory

Post by Jerry Messina » Fri Jun 12, 2020 3:43 pm

Can you live without the status led in the bootloader?

userio.bas:

Code: Select all

public inline sub UserLedOn()
    // << add code to turn on an led >>
    // << comment out code if not used >>
'    STATUS_LED = 1
end sub

public inline sub UserLedOff()
    // << add code to turn off an led >>
    // << comment out code if not used >>
'    STATUS_LED = 0
end sub
Commenting them out gets it to just under 4096 for me (2 bytes to spare!)

Your other option would be to use USBSystem.bas from v1.4.3 for the bootloader

You have to watch out... the "program bytes used" doesn't ensure that it ends up fitting in < $1000
due to some of the intr vector space. You actually have to look at the hex file and make sure there's nothing past $FFF

bitfogav
Registered User
Registered User
Posts: 148
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Re: USB HID Bootloader v1.4.3 over memory

Post by bitfogav » Fri Jun 12, 2020 6:49 pm

Jerry Messina wrote:Can you live without the status led in the bootloader?
Sure, and yes that has lowered the program byte output, thank you Jerry.

Jerry Messina wrote: Your other option would be to use USBSystem.bas from v1.4.3 for the bootloader
Yes I see the difference switching between USBSystem.bas v1.4.3, and USBSystem.bas v1.4.4
A big difference in the program byte output.
But just to be clear the only caveat though would be if I was to use a K50? I would need to use USBsystem.bas v1.4.4 as mentioned here
K50 and USB issue?.

Jerry Messina wrote:You have to watch out... the "program bytes used" doesn't ensure that it ends up fitting in < $1000
due to some of the intr vector space. You actually have to look at the hex file and make sure there's nothing past $FFF
Great tip Jerry, and thank you for this. I did some of my own checks and confirmed this with the following outputs:

This shows the hex file is good:
Shows within &lt; $1000
Shows within < $1000
Inmembytes.png (28.69 KiB) Viewed 170 times
This shows the prog has gone over $1000:
Shows over $1000
Shows over $1000
overprogbytes.png (37.04 KiB) Viewed 170 times

Jerry Messina
Swordfish Developer
Posts: 1173
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: USB HID Bootloader v1.4.3 over memory

Post by Jerry Messina » Fri Jun 12, 2020 7:44 pm

But just to be clear the only caveat though would be if I was to use a K50?
The 18F45K50 was the first datasheet where I saw it mentioned that you shouldn't set the UOWN bit in the same instruction cycle as any other
modifications to the BDnSTAT register. I looked at some of the datasheets for newer 16F chips that have USB and they have the same note.

The old microchip USB stack didn't do this, but at some point they changed the code to follow that note. They do it for all chips now.
As you found out, it makes the code a bit bigger which is a drag. Not by much, but bigger.

My gut feel is that it's an issue with ALL the devices and they just never told anyone about it until recently.

The HIDbootloader.bas is a port from old microchip MLA library code. They had the same problem with code size back then and even have a cut-down version of the HID portion specfically for the bootloader to remove support for some unneeded functions.

I'll have to take another look at that code and see if there's anything that can be trimmed down. I remember doing a lot of that already, but I might be able to squeeze a few more bytes out of it. I could probably do something with the sections that allow programming of the CONFIG and IDLOC sections... maybe make that an #option setting or something.

Would something like that be ok?

I usually remove the ability to reprogram the CONFIG settings in my bootloaders. It's not as flexible (the bootloader settings and app settings have to match), but it's not as risky either. Allowing the CONFIG to get reprogrammed means you risk turning the device into a brick if anything happens while that's going on.

bitfogav
Registered User
Registered User
Posts: 148
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Re: USB HID Bootloader v1.4.3 over memory

Post by bitfogav » Fri Jun 12, 2020 9:12 pm

I'll have to take another look at that code and see if there's anything that can be trimmed down. I remember doing a lot of that already, but I might be able to squeeze a few more bytes out of it. I could probably do something with the sections that allow programming of the CONFIG and IDLOC sections... maybe make that an #option setting or something.

Would something like that be ok?
Jerry I already really appreciate all that you have done and wouldn't like to put any more work on you, but CONFIG and IDLOC isn't something that I plan on using now or in the future on the bootloader and maybe if it was an #option setting then it might also help squeeze out a few more bytes.
This might also help with any future changes/updates.

Jerry Messina
Swordfish Developer
Posts: 1173
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: USB HID Bootloader v1.4.3 over memory

Post by Jerry Messina » Sat Jun 13, 2020 4:09 pm

I modified HIDBootloader18F.bas to reduce its memory footprint.

For the 2553 I think it comes in somewhere around 4076 bytes now when using USBsystem.bas V1.4.4, so you can enable the LED again if you like.
There's also a new setting that will reduce it a bit more as long as you don't need IDLOC programming... '#option REMOVE_IDLOC_SUPPORT = true'
Those two changes should give you a bit more breathing room.

For the 18F45K50, if you want to build the bootloader using USBsystem.bas V1.4.4 you'll have to set that option true.

HIDBootloader18F.bas v1.3 can be found on the wiki page at https://www.sfcompiler.co.uk/wiki/pmwik ... USBLibrary
It's only the single file, so you still need all the others to go along with it.

bitfogav
Registered User
Registered User
Posts: 148
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Re: USB HID Bootloader v1.4.3 over memory

Post by bitfogav » Sat Jun 13, 2020 7:35 pm

That's great, Works perfectly!, and has given me loads of breathing space.. :D Thank you for taking the time to make these changes Jerry, I really appreciate it..

W4GNS
Registered User
Registered User
Posts: 28
Joined: Wed Nov 03, 2010 7:18 pm
Location: Occupied South (Virginia)

Re: USB HID Bootloader v1.4.3 over memory

Post by W4GNS » Sat Jun 13, 2020 7:45 pm

We need to give Jerry a raise in salary :D
Gary W4GNS

Jerry Messina
Swordfish Developer
Posts: 1173
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: USB HID Bootloader v1.4.3 over memory

Post by Jerry Messina » Sat Jun 13, 2020 8:54 pm

David gave me a virtual parking space a while back... now if I could just get my jeep across the pond I'd be in like flint.

I asked for a key to the virtual executive washroom but no go!

User avatar
David Barker
Swordfish Developer
Posts: 1180
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: USB HID Bootloader v1.4.3 over memory

Post by David Barker » Sun Jun 14, 2020 7:57 am

> I asked for a key to the virtual executive washroom but no go!

There's been a shortage of virtual toilet paper - when it abates you can have a key!

Jerry Messina
Swordfish Developer
Posts: 1173
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: USB HID Bootloader v1.4.3 over memory

Post by Jerry Messina » Sun Jun 14, 2020 10:07 pm

What, no eBidet? What kind of backwards place have I signed up for?

I guess I'll just have to stay socially distant and keep working remotely!

Post Reply