Application code update on PIC using boot loaders (UART, or USB?) - Page 1
Forum section: electronics / general

author: newtekuser
author_rank: Frequent Contributor
timestamp: December 18, 2023, 09:36:17 pm
content: 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.

author: ataradov
author_rank: Super Contributor
timestamp: December 18, 2023, 09:53:23 pm
content: Quote from: newtekuser on December 18, 2023, 09:36:17 pmDepends 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.

author: Foxxz
author_rank: Regular Contributor
timestamp: December 18, 2023, 10:36:45 pm
content: Or stick a USB-UART IC and USB C port on the product and call it done.

author: newtekuser
author_rank: Frequent Contributor
timestamp: December 19, 2023, 01:26:31 am
content: 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_PIC32I see that even the PIC24 family is limited to boot loading over UART/CAN.The price of a USB-UART IC is tempting though.

author: JPortici
author_rank: Super Contributor
timestamp: December 19, 2023, 10:46:37 am
content: 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

author: newtekuser
author_rank: Frequent Contributor
timestamp: December 19, 2023, 05:17:24 pm
content: Quote from: JPortici on December 19, 2023, 10:46:37 amThank you for the perspective and further clarification on boot loaders!

author: mariush
author_rank: Super Contributor
timestamp: December 19, 2023, 05:44:00 pm
content: 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)

author: newtekuser
author_rank: Frequent Contributor
timestamp: December 19, 2023, 06:13:19 pm
content: Quote from: mariush on December 19, 2023, 05:44:00 pmHadn't though of that, thanks a bunch!

author: 8goran8
author_rank: Contributor
timestamp: December 20, 2023, 04:11:21 pm
content: Quote from: newtekuser on December 18, 2023, 09:36:17 pmI 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.

author: westfw
author_rank: Super Contributor
timestamp: December 20, 2023, 06:01:09 pm
content: 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 anywherehttps://www.schmalzhaus.com/UBW

author: newtekuser
author_rank: Frequent Contributor
timestamp: December 20, 2023, 09:10:39 pm
content: Quote from: 8goran8 on December 20, 2023, 04:11:21 pmUnfortunately 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

author: 8goran8
author_rank: Contributor
timestamp: December 20, 2023, 10:08:04 pm
content: Here you can find the Microchip USB MLA:https://github.com/MicrochipTech/mla_usbIf you want, I can send you source codes for some examples.

author: newtekuser
author_rank: Frequent Contributor
timestamp: December 20, 2023, 11:25:11 pm
content: Quote from: 8goran8 on December 20, 2023, 10:08:04 pmThat would be very helpful