SWDFlasher-STM32 is an imp application that can be used to flash the STM32F100 MCU. Its agent downloads a firmware image via HTTPS and then transmits it to the device, which uses the SWD protocol to program the MCU.
To make use of SWDFlasher-STM32 you will require:
- An imp004m Breakout Board or imp003 Breakout Board.
- An STM32VLDISCOVERY evaluation board.
Note Other imp-based hardware may be used but the application has only been tested using the devices listed above. The implementation method applies to any STM32F10xxx MCU but has been tested only with the STM32F100RBT6B (installed on the STM32VLDISCOVERY board).
You will need three wires to bridge the following pins on the imp and the STM32VLDISCOVERY/STM32F100RBT6B:
imp | STM32VLDISCOVERY |
---|---|
GND | GND |
C | SWCLK |
D | SWDIO |
On the STM32VLDISCOVERY, remove the jumpers from the CN3 connector of your MCU; the SWCLK and SWDIO are those shown connected to the imp below:
Note Almost any GPIO pins can be used on the imp’s side, but you will need to specify your pin choice in the code. Look for the SWDFSTM32_SWCLK_PIN and SWDFSTM32_SWDIO_PIN constants in the main device code (toward to the top of the listing).
SWDFlasher-STM32 requires the URL of a binary firmware image.
The URL should be added to the code in the Main.agent.nut file (almost at the end of the file):
const IMAGE_URL = "<LINK_TO_YOUR_FIRMWARE_IMAGE>";
We have included two simple sample images in the firmware folder. You can use them to try the code by adding their online locations to the code as shown above. They are made for the STM32VLDISCOVERY board and blink its blue LED. The different versions of the firmware apply different blinking frequencies.
To use one of the sample images you need to obtain a direct link to the files on GitHub:
- Copy to the clipboard one of the following links:
- Paste the link into the code as a value of the IMAGE_URL constant as shown in the code snippet above.
STM32F10xxx firmware images can be provided to you in any of a number of different formats. However, this application only supports the binary format. If you have an image in a different format, you will first need to convert it to binary. This can be done using the objcopy (or arm-none-eabi-objcopy) utility from the GNU ARM Embedded Toolchain.
For example, the following command:
arm-none-eabi-objcopy -I ihex your_firmware_image.hex -O binary your_firmware_image.bin
converts an image from Intel HEX format to binary.
You may need to use HTTP authentication to download your chosen firmware image. However, this application only supports Basic HTTP Authentication. If you can download your chosen firmware image using Basic HTTP Authentication, add your access details to the CREDENTIALS constant in the agent code as follows:
const CREDENTIALS = "<USERNAME>:<PASSWORD>";
Note If you use the sample firmware from this repository, or firmware from another source which doesn’t require authentication, please leave the constant empty.
SWDFlasher-STM32 is provided as a set of multiple files which must be combined before being uploaded to the impCloud™ for deployment to your chosen device group and the device assigned to it. There are two ways to perform this assembly:
Once you have built and run the application, please see the Start Flashing section.
The application’s source code has the following structure:
src/agent
— the agent code.src/device
— the device code.src/shared
— code included in both the agent and device code.
To build the project, use Builder. Just call it for the Main.agent.nut and Main.device.nut files. To do so, run these commands from the src
directory:
pleasebuild agent/Main.agent.nut > agent.nut
pleasebuild device/Main.device.nut > device.nut
You will get two new files — agent.nut
and device.nut
— which you can then copy into the impCentral™ code editor on either the AWS impCloud or the Azure impCloud, depending on which of these impClouds hosts your account and imp hardware. Now run the application.
This application has been written using Electric Imp’s Sublime Plug-in. All configuration settings and pre-processed files have been excluded. If you wish to use this option, follow these steps:
- Follow these instructions to install the plug-in and create a project.
- Replace the
src
folder in your newly created project with thesrc
folder found in this repository. - Update the
settings/electric-imp.settings
file’s device-file and agent-file keys to the following (on Windows use\\
instead of/
):
"device-file": "src/device/Main.device.nut",
"agent-file": "src/agent/Main.agent.nut"
When the application is running, you should make an HTTP GET request to the agent’s /flash
endpoint to start flashing. Just click on the agent’s URL in the impCentral code editor, then append /flash
to the URL in the browser link field, and press Enter:
This message in the logs states successful flashing: Flashing finished with status: OK
.
The flashing process may take some time. The speed of flashing is approximately 450 bytes per second (measured during the testing with the imp003 and STM32VLDISCOVERY). During the process, you should see messages like Chunk requested/Chunk received
appear in the log.
Code licensed under the MIT License.