Skip to main content
Visitor II
October 23, 2021
Question

Uploading firmware through SPI interface (STM32L031)

  • October 23, 2021
  • 3 replies
  • 5529 views

Hello,

I am working on a project. One of the requirement is to be able to upload firmware and communicate with the microcontroller is via SPI interface. The layout of the project is as follows:

1) There are 10 microcontrollers in total. Each running separately and each of them connected to their own sensor. Say for example: temperature sensor.

2) The microcontroller (Stm32L0) is supposed to get firmware update from the computer. In other words, the computer will control if the microcontroller in in DFU mode (to update firmware) or in application/run mode (this is when the computer will read the sensor values from the microcontroller).

3) The communication between microcontroller and computer can happen via only SPI interface. Since, the computer does not have SPI interface breakout, I was thinking of using USB-SPI converter to perform the task as stated in point 2.

4) Now, for one microcontroller, one USB-SPI converter could work. What happens if there is 10 microcontroller? I was thinking of using multiplexer for this.

Do you have any suggestions on USB-SPI converter or multiplexer for this? Also, do you see any problem with this setup?

P.S. I don't have any other option except to use SPI in this project.

    This topic has been closed for replies.

    3 replies

    Super User
    October 23, 2021

    A single microcontroller shouldn't have an issue communicating with 10 different sensors. Usually you don't have 1 micro per sensor. A setup with a single microcontroller is much more manageable and quicker to develop.

    Usually USB to SPI converters have other additional GPIO pins that can be used as CS pins to control multiple slaves. Or to interface with a pin expander chip.

    Here is one from a reputable company. No doubt you can find cheaper if you sacrifice quality.

    https://ftdichip.com/products/c232hm-ddhsl-0-2/

    You'll need more pins if you want to control the BOOT0/NRST pins on each micro to boot up into bootloader mode. You could also jump to bootloader mode in software, although this is less robust since it relies on your firmware working.

    stf2lrnAuthor
    Visitor II
    October 23, 2021

    Thank you @TDK​ . The project requires me to have 10 different microcontrollers. Also, I will not have a physical access to BOOT0/NRST pins. So, the firmware update will need to be performed through SPI interface. Do you know of any example file/code which I can use as a base to update firmware/communicate during run-mode through SPI?

    Super User
    October 23, 2021

    I don't have a ready made example for you.

    If you want to use the SPI bootloader, you can find commands here:

    https://www.st.com/resource/en/application_note/dm00081379-spi-protocol-used-in-the-stm32-bootloader-stmicroelectronics.pdf

    Graduate II
    October 23, 2021

    Maybe you dont understand own idea. In point

    1. run separately but

    in 4. multiplexed, that say is on same GND usw. and who control multiplexer when point 1.?

    In 2. yes you can send over your SPI protocol command to switch to DFU and after update to switch back or better reset to app

    And only SPI is based why, in real you will use USB on PC usw...

    Try add 11-th MCU as master

    Graduate II
    October 23, 2021

    >>Try add 11-th MCU as master

    Implement the USB-to-SPI in another STM32, that can either multiplex the SPI bus back to the PC, or take the update image once, and then dispatch it to the other 10 devices.

    Visitor II
    October 23, 2021

    Hi @Community member​ 

    The design you're presenting is pretty unusual, the complexity seems unnecessarely high, maybe a bad design or maybe I'm just missing your application and your very own needs.

    Back to your question, i found these 2 files from ST-Mother:

    file:///C:/Users/work/AppData/Local/Temp/dm00081379-spi-protocol-used-in-the-stm32-bootloader-stmicroelectronics.pdf

    searching online the document that do wour job is the one listed by @TDK​ , and then AN2606 at page STM32L031 conferm that the SPI1 is enables and ready to fire in STM32L031.

    For the SPI configuration in the case of direct connection you will need 10 CS pins one for device, or at least 4 pins multiplexed to generate a maximum of 16 single codes.

    Other way (if supported) is to connect the devices in deasy chain but this will slower the update process since data packet for the last MCU will have to pass trough all the other ones.