1
\$\begingroup\$

I was wondering if I could have some advice. I need to design a PCB which will have a USB-micro interface. The design will be manufactured with a lot of units and can't be programmed before distribution.

I want to write a driver Linux/Windows driver so that when the device is plugged in for the first time it can be programmed. The project is analogous to an RGB controlled mouse or keyboards. Is this possible?

Most examples I have seen require some sort of ISP programming, but if I could replicate that on the PCB (onboard ISP) I wonder if it would be possible. Curious to hear thoughts on this.

The product will be a mouse pad with an RGB LED. Essentially the colour of the LED will be controlled by in-game telemetry data (this is already supplied and a communication protocol is set up).

The hardware will be retrofit onto these units and needs to have a driver which will initialise the microcontroller to be ready to recieve packets from the game software. Open to any microcontroller (leaning toward STM32L433 SMD) and ISP/ICSP. Since the actual hardware requirements are minimal the difficulty is in the programming and driver work.

\$\endgroup\$
7
  • \$\begingroup\$ this seems like an XY question... why are you unable to program the device before distribution? \$\endgroup\$ Commented Mar 28, 2024 at 4:52
  • \$\begingroup\$ We need a lot more information. What MCU is this? I understand that you want a USB interface towards the PC, but can you insert a (common) programming device between the PC and the MCU? Why do you think you need a specific OS driver for this? Are you aware that a standard OS is able to add a script that runs if a specific device connects? Please edit your question to tell us what you considered so far and why you reject options. (Note: SE/EE is not a forum to discuss alternatives and solutions. Please take the tour to learn more.) \$\endgroup\$ Commented Mar 28, 2024 at 6:31
  • \$\begingroup\$ Can you edit the question to include which MCU is being used, to be able to determine the type of ISP (or JTAG) programming interface. Perhaps a footprint for a Tag-Connect programming cable could be used on the PCB to allow programming during manufacture. \$\endgroup\$ Commented Mar 28, 2024 at 7:54
  • \$\begingroup\$ @ChesterGillon yeah this was my backup plan. I examined a few similar HID products and they have ISP footprints where I assume they would’ve been programmed during assembly. But I thought it would be great if that could be avoided, and explore if it’s even possible. Thanks again \$\endgroup\$ Commented Mar 28, 2024 at 9:42
  • 2
    \$\begingroup\$ You are going to ship a product to customers that haven't been tested? In my experience, that is a good way to lose customers. \$\endgroup\$ Commented Mar 28, 2024 at 14:23

3 Answers 3

1
\$\begingroup\$

What you seek may not be viable.

Some (or many) microcontrollers these days come with unerasable factory bootloader. A subset of them can communicate over USB and be programmed with a flashing program on a PC.

The problem is not only about a "driver". Sure the PC needs a driver for the USB device, but the issue is, you need not only a driver like provided by the MCU vendor for the MCU to show up as USB device like DFU programmable USB device, but a custom driver or program to automatically start up and program the MCU with some firmware.

That is a problem, because, as all microcontrollers of same type have identical USB VID/PID pair, the driver cannot know which device was plugged in, so which firmware to program. It might have been a device you manufactured, or some other device, so you can't program a firmware intened to your device to another device which will stop working and there may be no firmware available for that device tha it can be fixed.

Another thing you mention is that like RGB keyboards and mice, Windows not only automatically fetch a correct USB driver for it, it will automatically and forcibly install a program used to configure and control the device. That is a deal between Microsoft and the device vendor to install such a control center, and a security risk. Many such control centers have had gaping security holes that allow bypassing user account control and allowed standard users to become administrators. I was literally shocked by automatic forced installation of such programs even if I simply wanted to borrow a mouse or keyboard and plug it in once for 5 minuted. Computer users are not that stupid that they cannot go to vendor site and download such programs themselves if they need it.

So while a MCU vendor could make a deal with Microsoft to install a MCU flashing program automatically when you plug in an unprogrammed MCU, it is not going to work. The user would not know why this program popped up and what to do with it, or where to get the firmware you need to download to your device.

So while of course possible, you really don't need or want such a driver. Tell users to install the flashing program for your MCU available from MCU vendor site. Then have users plug in the device and make it go to USB firmware update mode. Then instruct users to use the MCU vendor program to upload the correct firmware.

You can also make a program that does all these things for the user without downloading the MCU vendor program, but you need this progra to communicate with the MCU vendor USB driver. So you won't be making the USB driver, just a custom DFU upload program.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for that. Lots of things to think about. I’ve also edited the question with some more details. Please let me know if it gives you any other ideas. Thanks again \$\endgroup\$ Commented Mar 28, 2024 at 9:47
0
\$\begingroup\$

It depends on what "cannot be programmed before distribution" means.

If it means the manufacturer literally can't pre-program any chips before assembly, then no. You can't program a system over USB without at least a little bit of code already somewhere on the receiving end. Bare metal doesn't know how to talk to USB.

If it means the user is expected to write their own code, but you can have some on the embedded device in the first place, the answer is yes. You will need a chip that can act as a bridge between the USB interface and the programmable chip (such as an EEPROM) to manage uploading the code, firmware updates, etc. For writing code, some reputable libraries you can use are libusb on the computer end, and tinyusb on the embedded end.

\$\endgroup\$
5
  • \$\begingroup\$ Yeah to clarify, no pre-programming. So there's no way to add the necessary components of an ISP to the pcb and then when plugged in have a driver program it? Thanks again for your help. \$\endgroup\$ Commented Mar 28, 2024 at 2:39
  • \$\begingroup\$ This is nonsense. Many MCUs have built-in USB interface and non-erasable factory bootloader to program them over USB. You only need an USB brige chip if the MCU does not natively communicate USB, and are forced to use e.g. a standard USB to UART IC to program and communicate with it over UART. \$\endgroup\$ Commented Mar 28, 2024 at 8:44
  • \$\begingroup\$ Essentially it’s not feasible to program the microcontrollers on the factory line. So the proposed solution is the programming automatically when the consumer has it. \$\endgroup\$ Commented Mar 28, 2024 at 9:20
  • \$\begingroup\$ But using an MCU that comes pre-programmed as standard is ok? \$\endgroup\$ Commented Mar 28, 2024 at 9:23
  • \$\begingroup\$ @Finbarr, yeah definitely an option. However I’m attempting to avoid the extra cost associated with pre uploading the hex file. \$\endgroup\$ Commented Mar 28, 2024 at 9:39
0
\$\begingroup\$

There are MCUs that come with a USB boot loader, with a well defined Device Firmware Upgrade (DFU) class.

Some examples:

  • ST: AN1633, AN1577
  • TI: SPMA054 Application Report Tiva™ Application Update Using the USB DFU Class
\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.