I would like to be able to program and update the PIC18F4550 through USB. The PIC18F4550 already has USB, so, I don't need a USB to serial converter. On the microchip forum, I found this reference about bootloader:

  1. Microchip AN851: PIC16F/18F bootloader via serial: https://www.microchip.com/wwwAppNotes/AppNotes.aspx?appnote=en012031

But, it seems that was made to be a serial bootloader and not a bootloader to works through the PIC18F4550's USB. There are other non official bootloaders on the web, but I don't know if they will do the job. I would like that, once I have programmed the bootloader via ISCP, the subsequently programming be made through USB only.

Can the PIC18F4550 be updated through its USB? If it is, how difficult it will be?

  • 2
    \$\begingroup\$ Just go to Microchip's web site for the device and select the Documentation tab and look for programming. It's here and it tells you how you can program the flash. Note that USB is not mentioned. If you use the USB interface and if you communicate with the host computer as a virtual COM device, you can write your own code on both ends. But I'd have to look to see if the flash can be erased in blocks, while executing out of other blocks (unlikely, but who knows without a more thorough read of the datasheet?) \$\endgroup\$ – jonk May 14 at 22:54

The Diolan bootloader gets good review, and it uses only HID functionality so no drivers need be loaded on the Windows side. Diolan (an Israeli company) has released it under GPL 3.0.

See also here and here.

  • \$\begingroup\$ Thank you Spehro Pfhany. But, I'm concerned with the size of bootloader code, some people say that in the PIC18F4550 it would be a problem. The USB, in my project, will be used only to update the firmware. The PIC18F4550 has: 32K bytes of flash program memory, 2048 bytes SRAM data memory, 256 bytes EEPROM data memory. The bootloader will stay at Flash program memory, is it right ? So, would be a problem a bootloader of 2k or even a 4k ? \$\endgroup\$ – Daniel May 15 at 13:04
  • 1
    \$\begingroup\$ It doesn't sound like a problem to me- 32K is quite a bit of memory (for this type of small MCU) and even 4K is only 12.5% of the total. The only way to find out is to do an analysis specific to your particular situation. \$\endgroup\$ – Spehro Pefhany May 15 at 14:28

It's been many years since I was programming the PIC18F and I had to go back to your datasheet to refresh some of my memory about it. Now that I've taken a moment to recall some details, I think I can spell out your situation a little better. No solution -- that will be for you to work out. But I can point out the issues, at least.

Since about 1990 or so (might be \$\pm 1\:\text{yr}\$ around that point), Microchip has been very good about providing details on how to program their devices. (Note: I think I was the first person to convince Microchip to send such information without a signed non-disclosure because I certainly recall Chip's shocked reaction [owner of Parallax] that year when I told him I had a copy after spending a few weeks convincing Microchip to provide it and told him I hadn't needed to sign anything to get it.) In your case, go to the main Microchip PIC18F4550 web page and find the "Documents" tab and click it. That will take you to the page where you can find the PIC18F2XXX / 4XXX Flash MCU Programming Specification.

Note: Microchip continues to update its datasheets, errata, and other PDF documents related to their MCUs. I will be providing direct links which are valid at the time of this writing. In the future, it's best to go to the main web page mentioned above and proceed from there for the newest PDF documents.

The programming specification tells you how to program the device. There you will quickly see the following:

PIC18F2XXX/4XXX Family devices can be programmed using either the high-voltage In-Circuit Serial Programming™ (ICSP™) method or the low-voltage ICSP method.

This means you've got two hardware options for programming these devices. That's it. Everything else will require software running on the device. (Assuming the hardware supports such things -- not all do -- but it does in this case.)

If you go to the PIC18F2455/2550/4455/4550 Datasheet, you will see in chapter 6 the following:

A write to program memory is executed on blocks of 32 bytes at a time. Program memory is erased in blocks of 64 bytes at a time. A Bulk Erase operation may not be issued from user code.

In effect, this means you can actually write your own code that will modify the flash memory used to store code. In short, you can re-program the device using your own software to do it. Since the PIC18F4550 includes a USB 2.0 compatible peripheral, this means that with the right external added hardware and with the right software you write, you can achieve the goal of updating software over USB.

USB is documented in chapter 17. If you find or write code to support your MCU as a HID device, then one good option might be to act like a virtual COM port over USB. Most host operating systems supporting USB include built-in HID drivers for this purpose and that saves you from having to write your own code on some host computer. The host operating system can, in this case, provide emulation of a COM port using the USB port for the actual physical transport of data back and forth. To the host software, it looks like a COM port. But you will have to write your own driver on the PIC18F4550 to exchange information per the USB 2.0 standard. (No faster than once per millisecond for full speed interrupt transfers and I think at most 64 bytes per transfer -- memory serving.)

You can look for software someone else has already written. If you can't find something that "just works" according to your needs, then it would certainly be a good idea to download Microchip's documentation on their bootloader and its transaction format for transferring code. Might be some useful ideas in both that you can borrow.

It's also a good idea to think for yourself, as well. There are many different ways to organize your software design and you may be able to break up your software into distinct modules that are individually replaceable without having to download everything each and every time. And/or other ideas to consider. So think closely about this and then formulate an approach.

By the way, you linked to AN851, written 2002. But the correct link I get from Microchip's page for the PIC18F4550 is AN1310 -- High-Speed Bootloader for PIC16 and PIC18 Devices, written 2010. Perhaps you could look over that documentation, instead?

  • \$\begingroup\$ Thank you jonk, you did a wonderful explanation.But, I read a bit more and I'm concerned because many people say about the size of bootloader code and that this, in the PIC18F4550, would be a problem. In my project, the USB will be used only to update the firmware and the PIC18F4550 has: 32K bytes of flash program memory, 2048 bytes SRAM data memory, 256 bytes EEPROM data memory. The bootloader will stay at Flash program memory, is it right ? So, would be a problem a bootloader of 2k or even a 4k ? \$\endgroup\$ – Daniel May 15 at 13:08
  • 2
    \$\begingroup\$ @Daniel I can't speak to the memory cost of the loader, neither the size it will be nor if that size is too much for your needs. I'm just trying to point out the issues as well as how you need to read the docs. I don't have software to hand to you as perfect for your needs and never intended that. \$\endgroup\$ – jonk May 15 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.