Using the Arduino IDE with Swan
Installation Prerequisites
- Download and install STM32CubeIDE and STM32CubeProgrammer if you don't already have them installed. Be sure to follow these installation notes when installing STM32CubeProgrammer.
Linux only setup required for accessing the device in DFU mode and virtual COM port.
Create a
/etc/udev/rules.d/
rule for the device in DFU mode.(echo '# DFU (Internal bootloader for STM32 MCUs)'; echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="df11", MODE="0664", GROUP="plugdev"') | sudo tee /etc/udev/rules.d/49-stdfu-permissions.rules > /dev/null
Create a
/etc/udev/rules.d/
rule for the device's virtual COM port.(echo '# Virtual COM Port for STM32 MCUs'; echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", MODE="0664", GROUP="plugdev"') | sudo tee /etc/udev/rules.d/49-stvcp-permissions.rules > /dev/null
Add active user to
plugdev
group in/etc/group
.sudo usermod -aG plugdev $USER
Installing STM32duino in the Arduino IDE
Add the following URL to the Additional Boards URL in Preferences:
https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
After restarting Arduino, go to the Tools > Boards > Boards Manager... menu option, search for "STM32 MCU based boards", and install version
2.1.0
or greater.Restart Arduino.
Using STM32duino in the Arduino IDE
Under Tools > Board, select "STM32 Boards groups", and then "Blues Wireless boards."
Next, under Tools > Board Part Number, select "Swan R5."
Lastly, under Tools > USB support (if available), select "CDC (generic 'Serial' supersede U(S)ART)."
Programming Swan with Arduino IDE
To program Swan in the Arduino IDE, you can use a programmer like the STLINK-V3MINI or program via a USB cable connected to your computer.
Programming Swan with the STLink-V3Mini (Recommended)
Under Tools > Upload method, select "STM32CubeProgrammer (SWD)."
Plug the STLink-V3Mini into your computer over USB.
Plug the Swan into a power source (e.g. a LiPo battery or your computer via USB to use the serial monitor).
Plug the Cortex-Debug connector from the STLink-V3Mini into the Swan.
Skip to the Blink the Onboard LED instructions below.
Programming Swan without the STLink-V3Mini
Under Tools > Upload method, select "STM32CubeProgrammer (DFU)."
Connect the Swan's Micro USB port to your computer with a USB cable.
Press and hold the
BOOT
button on the Swan, press and releaseRESET
, then releaseBOOT
to cause the Swan to jump into its bootloader. This sequence must be done every time you want to upload firmware to the Swan.Proceed to the Blink the Onboard LED instructions below.
Blink the Onboard LED
In the Arduino IDE, use File > New to create a new sketch.
Overwrite the provided boilerplate code with the following to cause the onboard LED to blink repeatedly:
// the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_BUILTIN, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second }
Upload this sketch to the Swan.