2021-10-22 07:33 PM
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.
2021-10-22 07:50 PM
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.
2021-10-22 07:55 PM
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?
2021-10-23 01:30 AM
Maybe you dont understand own idea. In point
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
2021-10-23 02:03 AM
I don't have a ready made example for you.
If you want to use the SPI bootloader, you can find commands here:
2021-10-23 06:17 AM
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.
2021-10-23 01:21 PM
>>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.
2021-11-04 03:01 PM
Hi @TDK ,
Thank you for your suggestions. I got FTDI chip and now I am trying to program stm32 through SPI using STM32cubeprogrammer software. I have connected the microcontroller through SPI1 interface. The SPI connections is as follows with the FTDI cable:
SCK: Pin 11
MISO: Pin 12
MOSI: Pin 13
CS: 10
When I run the STM32CubeProgrammer software and try to detect it in this software, the software does not detect it. I am not sure if the steps that I am following is correct. I selected USB as an interface in the software if that matters (since I am using USB to SPI converter). Any suggestion on this?
2021-11-04 03:05 PM
STM32CubeProgrammer doesn't support an SPI interface.
The USB interface is for USB DFU interface directly to the chip.
2021-11-04 06:40 PM
You'll need to take responsibility for your non-normative programming requirements, this means owning the PC side programming application and implementing the SPI protocol as expressed in the programming document (AN4286).
If you want USB DFU to work in a more seamless fashion expect that you're going to have create a target side DFU Device, and have that interact with your 10 slave devices.