Programming a stand alone STM32F103C8T6 (Blue Pill) with Arduino

What are you developing?
andrevargas22
Posts: 3
Joined: Wed Jun 23, 2021 4:56 pm

Programming a stand alone STM32F103C8T6 (Blue Pill) with Arduino

Post by andrevargas22 »

Hi there everyone,

Sorry if this has already been addressed, I just can't find anything about it and I've been searching for ages.

I'm used to projects using stand-alone Atmega chips and Arduino Bootloader, there are plenty of tutorials online and it's simple to do. I've done several PCBs with just the MCU, a couple of capacitors, a crystal, and the SPI pins, and that's all you need to upload the Arduino bootloader and upload your code with an Arduino IDE. I'm sure many of you are familiar with this process.

But my problem now is that I need to do something similar with an STM32F103C8T6. I made a prototype for a project using a Blue Pill board. I'm using PlatformIO and uploading the code with a ST-LINK V2 using the Arduino framework. Essentially an Arduino code, as you can see from this snippet of my platformio.ini file:

Code: Select all

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_port = COM[11]
The prototype is working, the code works, everything is good, the world is perfect, so it's time to advance a step further.

My goal is to build a PCB for my project using a stand-alone STM32F103C8T6 chip like this: https://br.mouser.com/ProductDetail/STM ... 2FDA%3D%3D

And I would like to be able to upload the same code I already did with my ST-LINK v2, obviously making small necessary adjustments. I just don't know exactly how to do it. I'm assuming it's not just cloning the schematics to my board, connecting the ST-LINK to the DCLK and DIO, and hitting upload on the IDE. Is there a way to, say, upload an Arduino bootloader? Is there some proper way to do this? Or do I have to rely on a STM32CubeIDE and rewrite my entire code?

Thanks!
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Programming a stand alone STM32F103C8T6 (Blue Pill) with Arduino

Post by mrburnette »

andrevargas22 wrote: Tue Jun 29, 2021 2:25 pm ...
And I would like to be able to upload the same code I already did with my ST-LINK v2, obviously making small necessary adjustments. I just don't know exactly how to do it. I'm assuming it's not just cloning the schematics to my board, connecting the ST-LINK to the DCLK and DIO, and hitting upload on the IDE. Is there a way to, say, upload an Arduino bootloader? Is there some proper way to do this? Or do I have to rely on a STM32CubeIDE and rewrite my entire code?
Actually, if you have a working prototype board, you can always use the silicon-based serial loader; optionally the ST-Link. A bootloader is simply not required. You can use "Roger's core: or the Official STM core.

Serial uploader ... just so simple: App Note
Image

There is a forum section for board builders:
viewforum.php?f=14
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Programming a stand alone STM32F103C8T6 (Blue Pill) with Arduino

Post by mrburnette »

andrevargas22 wrote: Tue Jun 29, 2021 2:25 pm ...
I'm used to projects using stand-alone Atmega chips and Arduino Bootloader, there are plenty of tutorials online and it's simple to do. I've done several PCBs with just the MCU, a couple of capacitors, a crystal, and the SPI pins, and that's all you need to upload the Arduino bootloader and upload your code with an Arduino IDE. I'm sure many of you are familiar with this process.
...
DSCF2058a.jpg
DSCF2058a.jpg (62.96 KiB) Viewed 8477 times
Yes, "old" days ... a 16MHz version that had the xtal (under the Yellow and Green wires) and 2 load caps... barely visible on the far-side of the chip. The bottom of the board has a couple of diodes to create a V-USB circuit for the PC USB input as characters.

Through the miracle of time-travel:
https://forum.arduino.cc/t/hid-serial-r ... r/218347/2
ag123
Posts: 1798
Joined: Thu Dec 19, 2019 5:30 am
Answers: 28

Re: Programming a stand alone STM32F103C8T6 (Blue Pill) with Arduino

Post by ag123 »

stm32f103cx can be programmed from the serial uart pins or swd pins
if you do some (google) search you would find app notes like this
AN2586 Application note Getting started with STM32F10xxx hardware development
https://www.google.com/url?sa=t&rct=j&q ... rpxnqMgodq
those outline the basic hardware to use a stm32f103cx

then there is
AN2606 Application note STM32TM microcontroller system memory boot mode
https://stm32.eu/wp-content/uploads/201 ... 2606-1.pdf
which tells you that to use the uart boot loader you would need to set the boot0 pin

the easier way to get started is to get an existing board e.g. blue pill stm32f103c8 or better still stm32f401/f411 black pill or even nucleo boards and experiment with them. the (reversed) schematics can be found from various web searches.
nucleos and some vendors e.g. olimex, adafruit etc publish schematics for their boards.
for stm32f401/f411, after setting boot0 it can actually use the usb dfu protocol to install firmware, that makes it more convenient as you won't need a separate serial dongle etc, simply set boot0 connect usb and flash away
a key feature is the use of external crystals in most stm32 boards, this gives you accurate clocks and makes it stable for usb comms
these boards are 'underutilised' in the sense that they make good / accurate daq devices such as logic analyzers low sample rates oscilloscopes etc
i think it is possibly even possible to implement 'time of flight' distance measurements measuring light (e.g. infrared) bounces phase shifts and timing.
but normally that needs nanoseconds measurement speeds, so something may be missing or that it is a matter of knowhow.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Programming a stand alone STM32F103C8T6 (Blue Pill) with Arduino

Post by mrburnette »

ag123 wrote: Wed Jun 30, 2021 12:28 am ...
the easier way to get started is to get an existing board e.g. se shifts and timing.
...
Op is already in that "place" ... just wanting to evolve to a homebrew board design...
The prototype is working, the code works, everything is good, the world is perfect, so it's time to advance a step further.
andrevargas22
Posts: 3
Joined: Wed Jun 23, 2021 4:56 pm

Re: Programming a stand alone STM32F103C8T6 (Blue Pill) with Arduino

Post by andrevargas22 »

Op is already in that "place" ... just wanting to evolve to a homebrew board design...
Yes, correct. My point is that I'm basically trying to use the code I've already written, which is quite big already, directly into a new standalone MCU chip in a custom board (I didn't know there was a custom board section, apologies).

And I'm assuming that it's not going to work if I just copy paste the schematics of the blue pill in my project, connect the st-link and hit upload, there must be another step in between, something that I should take into consideration designing the pcb. Or will it work?

The easier solution is to make a PCB with a socket to plug a Blue Pill in it, but it doesn't sound too professional, and it's supposed to the produced on large scales.
User avatar
Just4Fun
Posts: 28
Joined: Thu Dec 19, 2019 10:45 am
Answers: 1

Re: Programming a stand alone STM32F103C8T6 (Blue Pill) with Arduino

Post by Just4Fun »

Hi,
you have to start from the "reference" design and hold the relevant HW part for your project to be sure it can run your FW without changes.

Some years ago I did a board compatible with both the Blue Pill and the Maple Mini using a single sided homebrew PCB just to start to play with STM32F103C8T6 and programming it with the USB bootloader (Roger's core) or the ST-LINK v2:

Image
Image

I've played also with others STM32 using the serial bootloader with Arduino IDE as in this board based on a STM32F030R8:

Image

or "coupled" with an FPGA:

Image


If you are interested you can find all the details in the previous links.
andrevargas22
Posts: 3
Joined: Wed Jun 23, 2021 4:56 pm

Re: Programming a stand alone STM32F103C8T6 (Blue Pill) with Arduino

Post by andrevargas22 »

Just4Fun wrote: Wed Jun 30, 2021 1:42 pm Some years ago I did a board compatible with both the Blue Pill and the Maple Mini using a single sided homebrew PCB just to start to play with STM32F103C8T6 and programming it with the USB bootloader (Roger's core) or the ST-LINK v2
Hi! I have the feeling that this is about what I need. Your example "STM32F103 driving a cheap 2004/1602 LCD @5V: controlling contrast & backlight with 2 PWMs, 2 resistors and 1 cap" might help me, but the link to the forum from hackaday says it doesn't exist: viewtopic.php?f=9&t=1171

Do you have that documented elsewhere? Thanks!
ag123
Posts: 1798
Joined: Thu Dec 19, 2019 5:30 am
Answers: 28

Re: Programming a stand alone STM32F103C8T6 (Blue Pill) with Arduino

Post by ag123 »

@Just4Fun
+1 nice board :D
the coin cell is a nice addon
i've been thinking about making one and perhaps mill it with a desktop cnc miller.
But have been lazy to do so as i've a 'surplus' of pre-made boards (e.g. blue pills).
another thing though is the concern about that 0.5mm or so pin spacing, i'm not sure if i'd be able to mill and later solder it without bridges after all

one thing would be if i make a 'bigger' board, i may put a side one section for gnd, 3.3v and 5v rails, i tend to run short of power and gnd pins when i wire up 2 or 3 different modules using 'dupont' cables. well of course there is the breadboards, but 'dupont' cables has kind of become my substitute for breadboards. or maybe i'd make do with an alternative and splice wires for the rails.
User avatar
Just4Fun
Posts: 28
Joined: Thu Dec 19, 2019 10:45 am
Answers: 1

Re: Programming a stand alone STM32F103C8T6 (Blue Pill) with Arduino

Post by Just4Fun »

Thanks guys!
andrevargas22 wrote: Wed Jun 30, 2021 2:23 pm Hi! I have the feeling that this is about what I need. Your example "STM32F103 driving a cheap 2004/1602 LCD @5V: controlling contrast & backlight with 2 PWMs, 2 resistors and 1 cap" might help me, but the link to the forum from hackaday says it doesn't exist: viewtopic.php?f=9&t=1171

Do you have that documented elsewhere? Thanks!
That link was referred to the "old" Roger's stm32duino forum (and also the example was based on the Roger's core), so using the wayback machine I've found the original post here:

https://web.archive.org/web/20190316200 ... f=9&t=1171
Post Reply

Return to “Projects”