Home | pfodApps/pfodDevices | WebStringTemplates | Java/J2EE | Unix | Torches | Superannuation | CRPS Treatment | | About Us
 

Forward Logo (image)      

nRF52 STM32 Programmer
2022

by Matthew Ford 20th Feb 2022 (originally posted 20th Feb 2022)
© Forward Computing and Control Pty. Ltd. NSW Australia
All rights reserved.

Building a CMSIS-DAP programmer
from an STM32F103C8 (“BluePill”)

Introduction

This tutorial covers building an CMSIS-DAP programmer for nRF52 devices from the ubiquitous STM32F103C8 “BluePill”. Over the years there have been a number of CMSIS-DAP programmers for nRF52 that can be used with Arduino via Easy Very Low Power BLE in Arduino - 2022. Most of these are no longer available. This tutorial covers building your own using an STM32F103C8 board and pre-compiled hex files. No source code building, which is problematic on Windows, is required.

Background

Most of the programmers and BLE modules used in the previous Very Low Power BLE made Easy with Arduino – 2019 tutorial are no longer available or exorbitantly expensive.

This project was originally posted in December 2018 and used a BlackMagic programming module and a Redbear Programmer for programming the Redbear Nano V2 board. Later when the Redbear Programmer was no longer available, it was replaced with a Particle Debugger. Redbear Nano V2 is discontinued and the Particle Debugger and the BlackMagic programmer are out-of-stock. The Particle Debugger appears to still be a current item, just not available as at Feb 2022. Also the original project used a SkyLab Bluetooth Module SKB369 or a GT832E_01 as an alternative to the Redbear Nano V2. The SKB369 is still available but at a quoted price of US$190 each as at January 2022.

The GT832E_01 (nRF52832 version), is used here as an example. It is still available at ~US$15 each, as at Jan 2022, but that price is also higher than previously. Other alternative nRF52832 modules will be covered as samples become available. The BLM_KTB522 available from via Aliexpress for ~US$6 each does not have an external low frequency 32Khz RTC crystal so should be programmed using the Generic nRF52832 (LFC RC osc) board setting. There is a XL52832-D01 from Aliexpress for ~US$5 with lots of I/O pins and Adafruit also has an in-expensive nrf52832 bare module, ~US$10, also with lots of I/O pins. See Easy Very Low Power BLE in Arduino – 2022 for details on using these BLE modules.

Building the CMSIS-DAP programming module

The programmer is built by flashing an STM32F103C8 (BluePill) clone as a CMSIS-DAP device. A ST-Link V2 clone is used to program the BluePill. The BluePill and the the ST-Link V2 cost about US$6 in total (plus shipping)

To build the programmer first prepare the BluePill as described here.

Then install STM32CubeProgrammer and prepare the ST-Link V2 as described here.

Then remove the ST-Link V2 from the computer and wire it to the BluePill as shown above. (Important: The order of the ST-LINK V2 GND,SWDIO and SWCLK pins can be different to what is shown in the photo above. CHECK the order on your ST-LINK V2 clone carefully)

Connect the ST-Link to the “BluePill” header.
ST-Link V2 ↔ “BluePill”
SWDCLK ↔ SWCLK
SWDIO ↔ SWO
GND ↔ GND
3.3V ↔ 3V3

Recheck your connections! Note carefully the Red wire goes to 3V3 on both ends and ALL the wires on the ST-Link are connected to the second row of pins.

Note: Boot0 jumpers is set to 1 while the Boot1 jumpers is left on the 0 side as shown below

Plug the ST-Link V2 into the USB port. (An STM ST link dongle driver will load if necessary)

Download and unzip the CMSIS-DAP-V1-F103.zip file to get the CMSIS-DAP-V1-F103.hex file and load it into the STM32CubeProgrammer

Click Download to load the program. When it completes unplug the ST-Link V2 and unwire the BluePill and
move the Boot0 jumper back to 0

Plug in the BluePill and load the mbed Serial Port driver.

The mbed serial port works by default on Mac, Linux. However on Windows you need to install a driver. See mbed Serial Port Driver Install for Windows 7 for detailed step-by-step instructions. For Windows 10 (and 8?) you will need to disable checking for signed drivers see How to Install Unsigned Drivers in Windows 10 (untested)

Building the programming / testing board

The 2019 version of this project use a BlackMagic or Redbear/Particle Programmer. They are not longer available so this programmer use “BluePill” CMSIS-DAP programmer built above. That also supports GDB single step source level debugging, but that was not used in developing this low power library and you should be able to use the usual Arduino print statements to do any debugging you need for your sketch. However you will need a USB to 3V3 TTL Serial converter to send the print statements output to your computer.

There are two versions of the programming / testing board. Either of these is cheaper than the 2019 version. The second alternative is about half the price.

The first alternative, which is used here for programming and testing, combines one “BluePill” CMSIS-DAP programmer, one (old) Sparkfun CP2102 USB to TTL Serial converter (no longer available) and a MAX8881 5V to 3V3 regulator. The second (cheaper) alternative uses just two (2) “BluePill” boards. One programmed as the CMSIS-DAP programmer and the second programmed as a USB to Serial (115200) converter (as described here). Either of the “BluePill” boards can be used to provide the 3V3 supply for the nRF52832.

Originally the second (cheaper) alternative was going to be used, but while using a rats nest to test the circuit, one of the “BluePill” was shorted out (one flash and its ash) and stopped working. The 3V3 volts now reads 4.5V. So the other (more expensive) alternative was build using components to hand. It is recommended you buy a couple of spare “BluePill” boards in case this happens to you.

There is the schematic for the programming / testing board. First alternative (pdf version).

Parts List (Alternative 1 as pictured above)

Approximate cost as at Feb 2022, ~US$63.5 including USB cables and USB supply (excluding shipping and an nRF52832 module)

ST-Link V2 clone – ~US$2.75 from Aliexpress
“BluePill” STM32F103C8 clone – ~US$2.75 from Aliexpress Note: Purchase the C8 version not the slightly cheaper C6 and a PC13 pcb version as marked in the photo above on the right near B8 B9
USB A to Micro USB cable – ~US$1 from Aliexpress
1 x 1K8 1/2W metal film resistor – US$1 (8off) from Jaycar RR0578 or Aliexpress
Arduino IDE and the STM32 V2.2.0 addon installed via the IDE board manager
STM32CubeProgrammer – free with registration

Sparkfun USB to TTL 3V3 (out-of-stock) + USB Cable A to B for Serial Debug
(alternative Adafruit CP2104 Friend - USB to Serial Converter + USB Cable A to Micro B ~ US$6 + US$3)
SparkFun USB Mini-B Breakout (or Adafruit's Mini-B version) ~US$2 (OR you can use a Micro-B break out board and matching cable instead)
USB cable - A/MiniB – 3ft ~US$4 to suit SparkFun' Mini-B breakout board

USB supply ~ US$8 to power the nRF52832 chip via the breakout board and MAX8881EUT33 regulator
MAX8881EUT33+T 3v3 Digikey MAX8881EUT33+TCT-ND ~US$2.5

2 x 10uF 25V Ceramic capacitors e.g. Digikey 445-7705-1-ND ~ US$2 mounted between tracks on copper side of vero board
1 x 0.1uF 50V Ceramic capacitor e.g. Digikey 478-10836-1-ND ~ US$0.5 mounted between tracks on copper side of vero board
1 x 0.1uF Ceramic capacitor e.g. Digikey 478-2472-ND ~ US$0.5
1 x 330R 1/4W 1% resistor e.g. Digikey S330CACT-ND ~US$0.1
1 x 1K5 1/4W 1% resistor e.g. Digikey RNF14FTD1K50CT-ND ~US$0.1
4 x 1K 1/4W 1% resistor e.g. Digikey RNF14FTD1K00CT-ND ~US$0.4
470uF 25V Low ESR capacitor e.g. Digikey 399-6127-ND ~ US$1
2 x 4 pin and 1 x 2pin female headers sockets e.g. Sparkfun PRT-11269 ~US$2 cut down the 8pin header
6 x 6 pin male header pins e.g. Sparkfun PRT-00116 ~US$1.5
female to female jumper e.g. Adafruit ID: 1951 ~US$2
male to male jumper e.g. Adafruit ID: 1956 ~US$2
3mm x 12mm nylon screws, e.g. Jaycar HP0140 ~AUD$3
3mm x 12mm nylon tapped spacers, e.g. Jaycar HP0924 ~AUD$10
Vero board (strip copper) e.g. Jaycar HP9540 ~AUD$5.5
plastic sheet to insulate bottom of vero board e.g. cut out of plastic lid

GT832E_01 nRF52832 BLE module ~ US$15 from Aliexpress

The programmer/test board was constructed on vero board. The MAX8881 regulator provides 3.3V from the 5V USB supply. When running your low power BLE project from a very low current source, then the Power OK (POK) and Shutdown (SHDN) pins on the MAX8881 can be used to hold off the nRF52 until the 470uF supply capacitor has charged up enough current to supply the chip's start up current surge (see the Remote Controlled Light Switch project for the details).

In this circuit, the 470uF low ESR (Equivalent Series Resistance) is used to filter the chip's current pulses when it transmits. This allows you to use a multimeter to get a good idea of the average supply current. The supply current is measured across two shunt resistors in the GND line. For high currents, short out terminals 1 to 3 to remove the resistors. For medium currents short out terminals 2 to 3 to remove the 1K5 resistor. For the very low currents, that will be achieved in this tutorial, leave the terminals 1,2,3 open. The multimeter, or oscilloscope, is connected across the Current Monitor Test Points. If using an oscilloscope, connect the GND clip lead to the USB GND side of the shunt resistors (Supply GND).

A small header board is used to connect the SWCLK and SWDIO leads and at the same time short out the Current Monitor Resistors so that programming, which draws more current, does not fail on low voltage. There is also another header for the Tx and Rx for the Arduino Serial Debugging connection. The SWCLK, SWDIO, Tx and Rx leads all have 1K resistors in series to protect against miss wiring to the nRF52832 pins. The 1K resistors limit the maximum current that flow via the in-chip I/O protection diodes to 3.3mA.

Regardless whether you use the 3V3 lead or another external supply to power the nRF52832, the negative (GND) return from the nRF52832 should be connected to the Target GND lead so that the return current will flow through the current monitoring resistors. If using and external supply, connect its -ve lead NOT to the nRF52832, but to the Supply GND lead.

Second (cheaper) Alternative 2 using two (2) “BluePill”

(pdf version)

Parts List (Alternative 2)

Approximate cost as at Feb 2022, ~US$38 including USB cables (excluding shipping and an nRF52832 module)

ST-Link V2 clone – ~US$2.75 from Aliexpress
2x “BluePill” STM32F103C8 clone – ~US$5.5 from Aliexpress Note: Purchase the
C8 version not the slightly cheaper C6 and a PC13 pcb version as marked in the photo above on the right near B8 B9
2x USB A to Micro USB cable – ~US$2 from Aliexpress
2 x 1K8 1/2W metal film resistor – US$1 (8off) from Jaycar RR0578 or Aliexpress
Arduino IDE and the STM32 V2.2.0 addon installed via the IDE board manager
STM32CubeProgrammer – free with registration

1 x 330R 1/4W 1% resistor e.g. Digikey S330CACT-ND ~US$0.1
1 x 1K5 1/4W 1% resistor e.g. Digikey RNF14FTD1K50CT-ND ~US$0.1
4 x 1K 1/4W 1% resistor e.g. Digikey RNF14FTD1K00CT-ND ~US$0.4
2 x 4 pin and 1 x 2pin female headers sockets e.g. Sparkfun PRT-11269 ~US$2 cut down the 8pin header
6 x 6 pin male header pins e.g. Sparkfun PRT-00116 ~US$1.5
female to female jumper e.g. Adafruit ID: 1951 ~US$2
male to male jumper e.g. Adafruit ID: 1956 ~US$2
3mm x 12mm nylon screws, e.g. Jaycar HP0140 ~AUD$3
3mm x 12mm nylon tapped spacers, e.g. Jaycar HP0924 ~AUD$10
Vero board (strip copper) e.g. Jaycar HP9540 ~AUD$5.5
plastic sheet to insulate bottom of vero board e.g. cut out of plastic lid

GT832E_01 nRF52832 BLE module ~ US$15 from Aliexpress

Installing the low power support for the nRF52832 in Arduino

See Easy Very Low Power BLE in Arduino – 2022 for how to install the Arduino support for low power nRF52832 and how to program the BLE modules and remove the program protection.

Conclusion

This tutorial has shown how you can build your own CMSIS-DAP programmer from the ubiquitous STMF103C8 “BluePill” to work with Easy Very Low Power BLE in Arduino – 2022 . Use this if other programmers become un-available.



AndroidTM is a trademark of Google Inc. For use of the Arduino name see http://arduino.cc/en/Main/FAQ


The General Purpose Android/Arduino Control App.
pfodDevice™ and pfodApp™ are trade marks of Forward Computing and Control Pty. Ltd.




Forward home page link (image)

Contact Forward Computing and Control by
©Copyright 1996-2024 Forward Computing and Control Pty. Ltd. ACN 003 669 994