0

Is it possible to program chips like the Arduino uno's Atmega328P directly with USB serial from your computer?
Where can i find information on the protocols/standards to do such a thing?

More specifically, I want to be able to make a custom pcb for my Attiny85 chips with a usb connector. I would prefer not to use the arduino IDE.
Is it possible to program this chip like so?

  • 1
    The short answer is no. The longer answer is maybe if you are willing to make some compromises. USB is not a simple protocol and requires considerable hardware and software. In a nut shell, the compromise will likely come in the form that much of your embedded processor's resources will be devoted to supporting the USB port. Further you will likely have to handle programming the embedded processor similar to a field update or upgrade. Much effort for small benefits. – st2000 Aug 20 at 3:34
  • Thanks for the helpful comment @st2000. Im not sure if you are familiar with the Digispark Attiny85. The serial usb pins are connected directly to the uC pins 2 and 3. Do you know how they achieved this? – Ruan Aug 20 at 3:45
  • If RS232 can be described in 4 or 5 sheets of type, then USB is so complex that it requires a book. That said, you can just get by w/only software if you constrain your self to a simple USB peripheral type of a device. Try reading this. – st2000 Aug 20 at 3:58
  • adafruit has attiny with usb bootloader cdn-learn.adafruit.com/downloads/pdf/introducing-trinket.pdf – Juraj Aug 20 at 5:40
  • @st2000 Your "short answer" should be posted as an answer. Stack Exchange considers this question unanswered right now, which looks bad for this site. I like your "answer" except it's not an answer. It's a comment, which is supposed to be used to get the OP to clarify what s/he wants. – Nick Gammon Aug 20 at 6:43
2

Is it possible to program chips like the Arduino uno's Atmega328P directly with USB serial from your computer?

The bare chip? Generally, no.

Some chips that include USB hardware also may include a DFU bootloader in ROM. If your chosen chip has this, then yes you can - you just need to wire it up and use a suitable DFU firmware upload program to install your compiled code into the chip.

However chips that don't have USB will never have a USB DFU bootloader in them. In such cases is is your responsibility to create (or otherwise obtain) a suitable bootloader that you will install into the chip.

Digispark and Adafruit both do that. They take a chip that doesn't have USB and install software that tries to (poorly) emulate USB over GPIO pins1.

For chips that do not have actual USB hardware in them it is far more common to use a UART-based bootloader - simply because this is a much lighter and more "correct" way of doing it.

If you want to use a direct USB connection for your device you should be selecting a chip that has USB built into it (AVR "U" series2, most PIC32, many ARM-based chips) which will allow you to have proper USB communication instead of slow HID and custom (non-standard) protocols only3.

Note that at no point does your choice of bootloader, or method of communication with the bootloader, tie you in to using the Arduino IDE. The IDE just compiles the code then runs an external program that communicates with the bootloader (different bootloaders need different programs to communicate with them). How you compile the software is up to you. How you execute the bootloader upload program is up to you.


  1. Personally I think that's a horrible idea and should NEVER be done. I'm a purist though.
  2. Such as the ATMega32U4 used on the Leonardo and Micro boards.
  3. VUSB can only (barely) run fast enough for USB 1.1. That means only HID protocols are officially supported (keyboard and mouse), and anything else is non-standard and requires special supporting software to work with it.
  • So what youre saying is if I really wanted to create a custom pcb with a usb connector to program, I can either add a UART to USB converter or choose a chip with built in usb? Otherwise there is the slow HID software option... If i were to go with that option where can i find info on the software to do this? – Ruan Aug 20 at 12:05
  • That would be the normal way. Having a UART header on a board is more common than you'd think - even if you have USB available. – Majenko Aug 20 at 12:09
  • I think we are all thinking you should not sacrifice performance of the embedded processor by always supporting a USB port (even when you are not using it). The real Arduino and it's knock offs use a support chip (FTDI or 2nd processor w/a USB port built in). This only cost a few dollars if that and allows the embedded processor to run a minimal Arduino program to support down loading new applications. (The cable in another answer is supposed to have the FTDI chip inside it.) BTW, didn't I point you to the HAD article w/the HID project? That's where you would go to learn more. – st2000 Aug 20 at 14:14
1

Is it possible to program chips like the Arduino uno's Atmega328P directly with USB serial from your computer?

Put a bootloader on the chip first, then an offboard USB/Serial adapter can be used for the serial programming. That's basically what a ProMini is - a bootloaded '328P (in SMD form) with a resonator & decoupling caps and a small voltage regulator - and a header to accept an FTDI Basic for programming serially. If you notice the Black and Green colors next to the FTDI header, those are to match the wire colors on the the FTDI cables that were originally used, before seperate USB cable and FTDI modules became more popular.
https://www.sparkfun.com/products/9718 enter image description here

Instead of the 6-pin FTDI header, you could make an adapter board to go from FTDI to a USB-A 5-pin connector, then on your board have a USB-B-Mini or USB-B-Micro 5-pin connector to bring in the FTDI's 5V, Gnd, DTR, Tx, and Rx signals.

USB wouldn't be coming in directly, but you would have the spacing advantage of the small USB connector, and could program serially from a PC USB port.

Too bad you don't want to use the Arduino IDE, there are supported core codes to add to the IDE for the Attiny85 and other chips like that. Attiny85 with bootloader could then be serially programmed with an offboard USB/Serial adapter.

https://github.com/SpenceKonde/ATTinyCore

ATtinyCore Universal

This core supports the following processors - essentially every ATtiny processor that makes sense to use with Arduino. Click the processor name for part-specific information:

ATtiny2313, 4313

ATtiny24, 44, 84 (With or without Optiboot bootloader)

ATtiny25, 45, 85 (With or without Optiboot bootloader)

ATtiny261, 461, 861 (With or without Optiboot bootloader)

ATTiny87, 167 (with or without Optiboot bootloader)

ATTiny48, 88 (With or without Optiboot bootloader)

ATTiny441, 841 (With or without Optiboot bootloader)

ATTiny1634 (With or without Optiboot bootloader)

ATTiny828 (With or without Optiboot bootloader)

ATtiny43 (no bootloader)

  • Thanks for your excellent answer. I will use the Arduino if it makes my life a whole lot easier. With the usb to FTDI cable you can directly program the Attiny with the help of the github link? – Ruan Aug 20 at 14:21
  • Yes, just add the cores to the IDE. You will need a Programmer to put the Bootload code into the chip; The FTDI route can be used after that. A Programmer connects to the Reset (2), SCK (7), MISO (6), and MOSI (5) pins to access the bootload memory area. – CrossRoads Aug 20 at 14:29
  • I can just use Arduino as programmer right? And programming the chip will automatically remove the previous bootloader from the chip if there is one? – Ruan Aug 20 at 14:34
  • Yes, you can use Arduino as ISP or whatever it's called these days. I have an Atmel AVRISP MKii for a Programmer, so I don't need to fool around with loading a program into an Uno to use it as a Programmer. – CrossRoads Aug 20 at 14:53

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.