2

I have an STM32F4 microcontroller connected to an Android (4.4) USB Host port. I would like to do a firmware upgrade of the microcontroller from the Android device.

===================                           ===================
|   Android 4.4   | <=======================> |   STM32F405xx   |
|     Device      | USB Host      USB Device  | Microcontroller |
===================                           ===================

Traditionally, STM32 microcontrollers can have their firmware upgraded using the PC tool called DfuSe Utility provided by ST. But I need to do this from an Android device instead. The source for their tools are provided.

Questions:

  1. Can the firmware for the microcontroller be upgraded using the standard USB Host libraries from Android in Java?
  2. Or does this need to be done using the NDK, and port the DfuSe source? If so, which libraries should be used to access USB from the NDK?

Which direction should be taken and how can this be done?

Ryan R
  • 8,342
  • 15
  • 84
  • 111
  • The NDK likely makes things harder, not easier. Most likely you can do what you need, the question would be if there's any situation in this where you need to start talking to a device quite quickly after it enumerates, however I don't believe that is the case as I don't believe the factory ROM USB bootloader has a timeout. Another possible challenge is that the DFU-mode device may show up to the user as something from ST, rather than your product (a point which liu_tanyi's custom bootloader does have in its advantage). – Chris Stratton Jan 18 '15 at 02:39
  • Yes you are correct. When in DFU mode the STM32 device shows up with a different Product ID (`PID`). I would be really happy if this can all be done from Java. My initial thoughts are to use a control transfer like so: `mConnection.controlTransfer(requestType, request, value, index, buffer, length, length, timeout);` Is this a good way of going about it? – Ryan R Jan 20 '15 at 20:26

2 Answers2

2

We ended up creating our own solution to program a STM32 microcontroller directly from Android over USB using DFU without using the NDK. We open sourced the project here:

https://github.com/UmbrelaSmart/android-stm32-dfu-programmer

Ryan R
  • 8,342
  • 15
  • 84
  • 111
0

In my project I just program the STM32 as a virtual com port device and define a group of simple communication protocol to erase/write the internal flash of STM32. I think you can do the same for the Andriod but I don't know if there is existing driver for a virtual com port in android.

But no matter how, once you can transmit a byte to and from STM32, you can let it program itself. The basic function of a bootloader is really simple which is just receive data and write them where they should be.

liu_tianyi
  • 21
  • 1
  • 2
  • That's true, and might be practically simpler. The factory ROM USB loader though does have the advantage (on the chips where it is present) of being safer from accidental deletion - ie, the device is less brickable than a developer-created bootloader might be. On the other hand, with your scheme the product keeps its own identity when it enumerates for upgrade, instead of showing up as an ST DFU device. – Chris Stratton Jan 18 '15 at 02:37
  • Thanks I never considered this approach. I am currently communicating with the STM32 device over USB via simple HID interface. I could possibly send the binary file and have the device reflash itself. Can you give some direction on how you were able to transfer, store and then command the STM32 to reflash itself? Can you point me to some good resources and code? – Ryan R Jan 20 '15 at 20:25
  • There's an ST app note on self flashing; they like to revamp their websute so you will need to find the current location yourself. – Chris Stratton Jan 20 '15 at 20:31