Author Topic: Application code update on PIC using boot loaders (UART, or USB?)  (Read 3999 times)

0 Members and 1 Guest are viewing this topic.

Offline newtekuserTopic starter

  • Frequent Contributor
  • **
  • Posts: 401
  • Country: us
From what I've read, using MCC classic or Melody on supported PIC family it should be possible to implement a boot loader to update the application code using I2C, UART. USB is not listed although that may be possible.
Implementing this through UART opens this possibility to cheaper PICs that don't come with USB support, such as the PIC18F57Q43, or even the PIC18F46K40 which appears to be supported by MCC.
However, performing updates over UART requires a serial-to-USB converter and is not as elegant as using USB.

My question is, is it acceptable to require customers to purchase a serial-to-USB converter to perform SW updates? Providing one with the product eats from profit margins and going with USB requires a PIC with more capabilities which is more expensive.
I also don't see a way to implement this over USB with MCC or Melody (have not done extensive research on this though), or is this not supported with PIC MCUs?

I know, STM32, ARM supports this out of the box, but strictly asking about PIC here.

 
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11707
  • Country: us
    • Personal site
Re: Application code update on PIC using boot loaders (UART, or USB?)
« Reply #1 on: December 18, 2023, 09:53:23 pm »
My question is, is it acceptable to require customers to purchase a serial-to-USB converter to perform SW updates?
Depends on the product type. If you are doing something industrial, then you can make a healthy profit selling overpriced update cables. For consumer products - not at all.

In either case people will think your product is junk stuck in the past for 20 years. But in many cases industrial customers are used to that. People that are used to iPhones will not bother.

And expecting people to buy a random cable on Amazon is not a way to go, so you would have to carry and support that programming cable. And I don't see a world where this makes any sense when MCUs with USB are dirt cheap.
« Last Edit: December 18, 2023, 10:35:07 pm by ataradov »
Alex
 
The following users thanked this post: newtekuser

Offline Foxxz

  • Regular Contributor
  • *
  • Posts: 124
  • Country: us
Re: Application code update on PIC using boot loaders (UART, or USB?)
« Reply #2 on: December 18, 2023, 10:36:45 pm »
Or stick a USB-UART IC and USB C port on the product and call it done.
 
The following users thanked this post: newtekuser

Offline newtekuserTopic starter

  • Frequent Contributor
  • **
  • Posts: 401
  • Country: us
Re: Application code update on PIC using boot loaders (UART, or USB?)
« Reply #3 on: December 19, 2023, 01:26:31 am »
Thanks ataradov and Foxxz!

Do I need to switch to PIC32 for USB boot loading capability? Found this nifty article: https://hades.mech.northwestern.edu/index.php/Programming_HID_Bootloader_on_PIC32
I see that even the PIC24 family is limited to boot loading over UART/CAN.
The price of a USB-UART IC is tempting though.
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3523
  • Country: it
Re: Application code update on PIC using boot loaders (UART, or USB?)
« Reply #4 on: December 19, 2023, 10:46:37 am »
As long as the microcontroller can program its own flash you can implement a bootloader.
The real question is: do you want to write your own (complete flexibility on the target device, the features, the protocol, the transport medium, the loader application) or not? (you can only use the target supported by who provides the bootloader, you are subjected to the features and limitations of who wrote the bootloader, you are restrained to the medium provided by who wrote the bootloader, you have to use the application written by who made the bootloader in case you can't customize it with your logo or whatever)

If you don't want to write your own, stick to whatever microchip offers, but then you'll probably need to move to a part that is unnecessarely big/complex, because they don't care about supporting every chip with their code generators.

But I've written plenty bootloaders myself using uart, USB (HID or Vendor, will have to do with CDC next month), LIN, CAN, for any possible target. It's just firmware, saying that PIC24 can't do USB loaders is laughable.
writing a bootloader is nothing special over any other part of the firmware, it just requires some design effort on your part, as with everything.

It's MCC that is a gigantic unredeemable piece of shit, the much older MLA which is based on did have USB bootloaders for PIC16, PIC18, PIC24. They just don't want to provide them anymore because having a graphical interface to generate every possible variation is HARD to do. According to MCC you can do USB CDC and HID, but not Audio or Vendor, as if there was something special about them (hah.)

Anyway: Most of our products are configured/updated using UART. However, of the thousands we send out every year, the actual customers that are required to update the configuration/firmware are very few. So we bought a lot of USB-TTL cables for 2€ each on aliexpress, changed the connector so it fits our programming interface and provide them to said customers. Fir even fewer exceptions, we do not send out firmware in alpha state and once the unit is installed it's very likely it is never touched again for years
 
The following users thanked this post: newtekuser

Offline newtekuserTopic starter

  • Frequent Contributor
  • **
  • Posts: 401
  • Country: us
Re: Application code update on PIC using boot loaders (UART, or USB?)
« Reply #5 on: December 19, 2023, 05:17:24 pm »
As long as the microcontroller can program its own flash you can implement a bootloader.
The real question is: do you want to write your own (complete flexibility on the target device, the features, the protocol, the transport medium, the loader application) or not? (you can only use the target supported by who provides the bootloader, you are subjected to the features and limitations of who wrote the bootloader, you are restrained to the medium provided by who wrote the bootloader, you have to use the application written by who made the bootloader in case you can't customize it with your logo or whatever)

If you don't want to write your own, stick to whatever microchip offers, but then you'll probably need to move to a part that is unnecessarely big/complex, because they don't care about supporting every chip with their code generators.

But I've written plenty bootloaders myself using uart, USB (HID or Vendor, will have to do with CDC next month), LIN, CAN, for any possible target. It's just firmware, saying that PIC24 can't do USB loaders is laughable.
writing a bootloader is nothing special over any other part of the firmware, it just requires some design effort on your part, as with everything.

It's MCC that is a gigantic unredeemable piece of shit, the much older MLA which is based on did have USB bootloaders for PIC16, PIC18, PIC24. They just don't want to provide them anymore because having a graphical interface to generate every possible variation is HARD to do. According to MCC you can do USB CDC and HID, but not Audio or Vendor, as if there was something special about them (hah.)

Anyway: Most of our products are configured/updated using UART. However, of the thousands we send out every year, the actual customers that are required to update the configuration/firmware are very few. So we bought a lot of USB-TTL cables for 2€ each on aliexpress, changed the connector so it fits our programming interface and provide them to said customers. Fir even fewer exceptions, we do not send out firmware in alpha state and once the unit is installed it's very likely it is never touched again for years

Thank you for the perspective and further clarification on boot loaders!
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5134
  • Country: ro
  • .
Re: Application code update on PIC using boot loaders (UART, or USB?)
« Reply #6 on: December 19, 2023, 05:44:00 pm »
Another option could be to have a SD card slot or a custom slot in which user would insert a eeprom / flash memory chip and boot the device.

Both options are very lightweight and could be emailed to customer and customer could insert them in a slot and be fairly fool proof. 
A SD card is under 50 cents if bought in volume... and for the SD card, that would require user to have a card reader/writer and be smart enough to format a SD card as fat16/fat32 (or you could make available a raw disk image and a free software to write the raw disk image to the sd card)  so that your pic could read the file system. 

For the second option, you could have pins for spi and/or i2c, voltage and ground, and some way of detecting card is inserted (for example inserting the card shorts two pins together or pulls a pin to ground)
 
The following users thanked this post: newtekuser

Offline newtekuserTopic starter

  • Frequent Contributor
  • **
  • Posts: 401
  • Country: us
Re: Application code update on PIC using boot loaders (UART, or USB?)
« Reply #7 on: December 19, 2023, 06:13:19 pm »
Another option could be to have a SD card slot or a custom slot in which user would insert a eeprom / flash memory chip and boot the device.

Both options are very lightweight and could be emailed to customer and customer could insert them in a slot and be fairly fool proof. 
A SD card is under 50 cents if bought in volume... and for the SD card, that would require user to have a card reader/writer and be smart enough to format a SD card as fat16/fat32 (or you could make available a raw disk image and a free software to write the raw disk image to the sd card)  so that your pic could read the file system. 

For the second option, you could have pins for spi and/or i2c, voltage and ground, and some way of detecting card is inserted (for example inserting the card shorts two pins together or pulls a pin to ground)

Hadn't though of that, thanks a bunch!
 

Offline 8goran8

  • Contributor
  • Posts: 30
  • Country: cs
Re: Application code update on PIC using boot loaders (UART, or USB?)
« Reply #8 on: December 20, 2023, 04:11:21 pm »
I also don't see a way to implement this over USB with MCC or Melody (have not done extensive research on this though), or is this not supported with PIC MCUs?


I used Microchip MLA as the basis for creating bootloaders for PIC18 and PIC24 devices. It's not an ideal way and that job requires a lot of time, but in the end I was satisfied with what was done. When you install Microchip MLA (I used v2018_11_26), in the bootloaders folder, you will get a number of examples for these microcontroller families.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4292
  • Country: us
Re: Application code update on PIC using boot loaders (UART, or USB?)
« Reply #9 on: December 20, 2023, 06:01:09 pm »
There was/is the USB BitWhacker. It showed up slightly before the ATmega8 Arduino, and was very similar - microcontroller with USB bootloader directly programmable from a PC via USB. Very similar, at least on the surface, to an Arduino.  But it lacked the simplifying software framework, and the marketing/evangelism, and didn't go much of anywhere
https://www.schmalzhaus.com/UBW
 

Offline newtekuserTopic starter

  • Frequent Contributor
  • **
  • Posts: 401
  • Country: us
Re: Application code update on PIC using boot loaders (UART, or USB?)
« Reply #10 on: December 20, 2023, 09:10:39 pm »
I also don't see a way to implement this over USB with MCC or Melody (have not done extensive research on this though), or is this not supported with PIC MCUs?


I used Microchip MLA as the basis for creating bootloaders for PIC18 and PIC24 devices. It's not an ideal way and that job requires a lot of time, but in the end I was satisfied with what was done. When you install Microchip MLA (I used v2018_11_26), in the bootloaders folder, you will get a number of examples for these microcontroller families.

Unfortunately not able to look into MLA because it doesn't install on Mac. If I start the installer normally, OSX complains that the developer could not be verified. If I override the warning, it just crashes.
Software is not just ready for Apple silicon these days, or microchip just does not give a damn about it |O |O |O |O
 

Offline 8goran8

  • Contributor
  • Posts: 30
  • Country: cs
Re: Application code update on PIC using boot loaders (UART, or USB?)
« Reply #11 on: December 20, 2023, 10:08:04 pm »
Here you can find the Microchip USB MLA:
https://github.com/MicrochipTech/mla_usb

If you want, I can send you source codes for some examples.
 
The following users thanked this post: newtekuser

Offline newtekuserTopic starter

  • Frequent Contributor
  • **
  • Posts: 401
  • Country: us
Re: Application code update on PIC using boot loaders (UART, or USB?)
« Reply #12 on: December 20, 2023, 11:25:11 pm »
Here you can find the Microchip USB MLA:
https://github.com/MicrochipTech/mla_usb

If you want, I can send you source codes for some examples.

That would be very helpful  :-+
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf