0

In another words, is it possible to develop a custom bootloader so sketches can be uploaded via serial connection made using the RX/TX pins and not via the USB connector (I am using Pro Micro boards)? Thanks!

migrated from electronics.stackexchange.com Feb 20 at 5:34

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • 3
    This is definitely possible. Bootloader is just a program which can communicate whatever hardware is available and write memory and jump to it. – Eugene Sh. Feb 19 at 16:03
  • This should be possible by adapting the serial bootloader typically used on the ATmega328p (etc) to your ATmega32u4. The details of doing so however do not really fit in a question on a Stack Exchange site unless you explain a specific difficulty. Make sure to do some searching, it is quite possible someone has already done this project. Also consider if switching to an Arduino type board that simply has an ATmega328p (especially a compact one without a 2nd chip as a USB bridge, though you can bypass that) might be the simplest route to fill your need. – Chris Stratton Feb 19 at 16:22
  • Makes sense, thanks for your answers, sorry I did make a search for that prior to asking but couldn't find any simple answer to this question. – Olivier Feb 19 at 20:38
1

Yes. You can develop a bootloader for the ATmega32u4 that will receive firmware over any interface (UART, SPI, I2C etc.).

Loading via UART is a solved problem. Look for the AVR109 bootloader.

1

Yes, there is an Optiboot fork supporting ATmega32U4 supporting hardware UART to upload Arduino sketches.

Also, a detailed instructable post explaining how to use it with Arduino Pro Micro.

1

No need to have a specific bootloader. The basic bootloader can do that (in Arduino that's the case so I hope this answer will apply in your case. But if not, the principle is certainly the same).

Once you perform a reset on the board, the bootloader look at the serial port during a short time. If something come, it checks if it's an hex file and if yes it send it to flash. The USB just use the RX input.

So you can send data using a direct connection or using for example a Bluetooh like HC-05. I do that for some project in order to update via Android: the Android app send an order to the Arduino, through Bluetooth. Receiving this, the Arduino RESET itself, and then the Android App send immediatly data.

On Arduino side: connect for example A0 to RESET PIN and perform a digitalWrite(PIN_RESET,HIGH); Have also a look at Reset an Arduino Uno in code

After the RESET, the board will reply with 0x14 0x10 (so it send this to TX and so if you have a bluetooh module, you'll received than on your Android App (eg))

You must then send 0x50 0x20 to the board to tell it you enter programming mode. Then send 0x75 0x20 to get the id of the board in order to be sure you will send the HEX file for the right hardware. You will receive 0x14 XXX 0x10 where XXX = id of the board

Then you can send the HEX file.

For that, you will send it by blocks of 128 bytes

So start by dividing the HEX to know the number of blocks then loop against this number: Start at ADR=0 (adresse dest in flash) and send:

For each block:

1) Send 0x55, low byte of ADR, high byte of ADR, 0x20

2) check reply (must be 0x14 0x10)

3) Send the 128 bytes: 0x64, 0x00, 0x80, 0x46 then the 128 bytes and finish by 0x20 (0x80 is the size)

4) check reply (must be 0x14 0x10)

5) update ADR. Take care: ADR is a word pointer (2 bytes). So ADR = ADR+0X40

Loop on num of blocks

Finish the job by sending 0x51 0x20 (exit programing mode)

Some details:

  • 0x46 before the 128 bytes tells you want to write in flash. Other codes are available eg for checking, getting data etc..

    • It seems mandatory to send each time 128 bytes. So if your last block is smaller, you need to add some '\0' to get a total of 128. I've been unable to get good results trying to change the 0x80 value and send less bytes. :(

It's not very easy and need tests to get a good code but that really fine to be able to have an Arduino the user can update.

Hope this will help.

Your Answer

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