Uploading a sketch

From STM32duino wiki
Jump to: navigation, search

Using Arduino IDE

The preferred upload method can be selected in the IDE over menu Tools -> Upload method.

Currently, there are four supported upload methods:

  • STM32duino bootloader
  • Serial
  • STLink
  • BMP (Black Magic Probe)

Upload via STM32duino bootloader

You need to previously have the drivers for the Serial and DFU (upload devices) installed (TODO: internal link to driver installation), and the STM32dunio bootloader (TODO: internal link to bootloader).

After a successful build process, the IDE outputs the following message:

maple_loader v0.1
Resetting to bootloader via DTR pulse
[Reset via USB Serial Failed! Did you select the right serial port?]
Searching for DFU device [1EAF:0003]...
Assuming the board is in perpetual bootloader mode and continuing to attempt dfu programming...

dfu-util - (C) 2007-2008 by OpenMoko Inc.

This action is accompanied by a beep sound and the on-board LED will start blinking. The the upload tool will upload the generated binary file to the board.

  • If you cannot hear any beep sound nor see the LED of the board blinking, the following message may appear:
Couldn't find the DFU device: [1EAF:0003]

In this case you should manually reset the board when the first text in red is printed in the IDE output window. If you don't do this within 3 seconds, the upload will fail, and you will have to repeat the upload procedure. Under Linux the timing may be very sensitive. It seems that you want to release the reset button to enter the fast blink upload mode just before the compilation finishes. It may be useful to use the Arduino verify button so that it will compile before trying an upload, because the first compile can be slow, even for something as simple as a blink sketch. Then when you try to upload, it will compile again, but much faster and with more predictable timing to allow you to coordinate the release of the reset button.

The first time you try to upload a sketch by USB after installing the STM32duino bootloader, there may be no port available to select in the arduino/tools/port/ menu. That's Ok, it may still work. The second time though, you may have to select a port.

Upload via Serial

For this method an additional USB to Serial adapter is needed. The serial wires of the adapter should be connected to the Rx/Tx pins (PA9/PA10) of the STM32 device.

A full description is available in the video Roger posted here. [1]

TODO: continue description.

Upload via ST Link

For this method you have to use a STLink V2 [2] device connected to the PC over USB and to your board via the SWD interface.

For another guide to uploading by ST Link comptatible devices see the Github wiki: [3]

Also, be sure that the necessary driver for Windows is installed and the STLink adapter is updated to the latest firmware (version V2J27S6 or later).

You can use the official ST-Link V2 programmer or one of the many clones.

There are several versions of the cloned ST-Link V2 adapters available, they may break out different numbers of pins, depending on the manufacturer, but all should have at least the pins listed below.

We only need three pins for basic programming and debugging of the STM32FXXX devices, (four if you are powering the board from the programmer) using Serial Debug Wire (SWD).

Connect to following pins of the programmer to the corresponding pins on the STM board:

   3.3V (Optional)  NOTE: Not needed if powering the target board from USB or an external supply.  
                    Check your board schematic to see which pin is best for this. 
                    Pin 1 (and optionally pin 2) of the 20 way JTAG/SWD header, if fitted are designated as VCC 
                    which should be 3.3V on the board, but test with a multimeter if you are in any doubt. 
                    Avoid sending 3.3V to the target board if using an external supply or you may damage the board, programmer, USB port or external supply.  
   GND          -   Pin 4,6,8,10,12,14,16,18,20 of the 20 way header if fitted, or any other available GND pin.
                    NOTE:If your board has a separate analog and digital GND, use the digital GND.

   SWCLK (PA14) -   Pin 9 on the 20 way header if fitted. aka JTCK/SWCLK/PA14
   SWDIO (PA13) -   Pin 7 on the 20 way header if fitted. aka JTMS/SWDIO/PA13 

After a successful build process, the IDE outputs something similar to the following message:

STM32 ST-LINK CLI v2.1.0
STM32 ST-LINK Command Line Interface

ST-LINK SN : [serial_numer_of_the_adapter]
ST-LINK Firmware version : V2J27S6
Connected via SWD.
SWD Frequency = 1800K.
Connection mode : Normal.
Device ID:0x410 
Device flash Size : 64 Kbytes
Device family :STM32F10xx Medium-density

Loading file...
Flash Programming:
  File : C:\Users\[user]\AppData\Local\Temp\buildbf9409c1ae369e3d22510a2824c2116e.tmp\Blink.ino.bin
  Address : 0x08000000
Flash memory programming...
±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± 0%
Flash memory programmed in 0s and 594ms.
Programming Complete.

MCU Reset.

Application started.
  • If you get the message:
No target connected
Unable to connect to ST-LINK!

This means that the ST-Link V2 adapter cannot communicate with the board. In this case check the hardware wires. Or, as alternative, you can also supply the 3.3V to the board only over the adapter, removing the USB cable, if any. Finally, if none of these helps, you should manually reset the board within 3 second after the upload process begins (red text printed in the output window).

Upload via BMP (Black Magic Probe)

To Do. Details on how to upload a sketch via BMP (Black Magic Probe).

Using Eclipse

It is possible to setup a project under Eclipse using the system files of the Arduino environment.

Arduino with Eclipse

The same upload methods are supported as listed above.

The preferred upload method can be picked up by clicking the current project in the Project Explorer window and selecting via menu: File -> Properties -> Arduino. Acknowledge your selection by clicking "Apply", then "OK".