Project creation
- Create an empty directory, here called "test_pio"
- what I usually do is "right click" "Open with Code"
- in VSCode I have 3 plugins installed
- C/C++
- Native Debug
- PlatformIO
Actually, I'm not sure if the PlatformIO plugin is needed here, as I work with the command line, if I open any terminal outside VSCode and I type "pio", I get the help, so one way or another, make sure that opening a terminal in VSCode at least, allows pio to run:
- Get familiar with the command lines for example by running :
test_pio> pio boards
...
test_pio> pio device list
COM6
----
Hardware ID: USB VID:PID=0483:374B LOCATION=1-10
Description: STMicroelectronics STLink Virtual COM Port (COM6)
Note that the device list should show the STLink if it is connected- I'm using a Nucleo-F030 but any other could fit using its ST-LinkV2-1
- Check lots of wiki on the web on how to connect the BluePill STM32 and don't forget the Reset PIN
- As you have checked the names in the help boards already the command to start a new project is "pio init --board bluepill_f103c8" which results in the following output
test_pio> pio init --board bluepill_f103c8
The current working directory D:\Projects\STM32\platformio\test_pio will be used for project.
You can specify another project directory via
`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.
The next files/directories have been created in D:\Projects\STM32\platformio\test_pio
platformio.ini - Project Configuration File
src - Put your source files here
lib - Put here project specific (private) libraries
Project has been successfully initialized!
Useful commands:
`platformio run` - process/build project from the current directory
`platformio run --target upload` or `platformio run -t upload` - upload firmware to embedded board
`platformio run --target clean` - clean project (remove compiled files)
`platformio run --help` - additional information
- One single important file was created (other directories less important) which is the platformio.ini
; http://docs.platformio.org/page/projectconf.html
[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = mbed
The default framework selected was the mbed, but the bluepill_f103c8 is also supported by the arduino
- create a new file under src called "main.cpp" with this content
#include "mbed.h"
DigitalOut myled(PC_13);
int main()
{
while(1)
{
myled = 1; // LED is ON
wait(0.2); // 200 ms
myled = 0; // LED is OFF
wait(1.0); // 1 sec
}
}
Inside of PlatformIO
Now part of the mystery of platformIO is beeing revealed, if we navigate to where the framework-mbed is we find the rest of the company, and it tells already that the arduino is using the stm32duino, the tool-stlink that we'll see later on,...
Before compiling, how did the magic of the platformIO got to know the PC_13 that I set for the LED ?
.platformio\packages\framework-mbed\targets\TARGET_STM\TARGET_STM32F1\TARGET_BLUEPILL_F103C8\PinNames.h
from which here is an extract, PIOs are defined as enums, and this was done for us by Mr mBed.
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************* */
#ifndef MBED_PINNAMES_H
#define MBED_PINNAMES_H
#include "cmsis.h"
#include "PinNamesTypes.h"
#ifdef __cplusplus extern "C" {
#endif
typedef enum { PA_0 = 0x00, PA_1 = 0x01, PA_2 = 0x02, PA_3 = 0x03,
Still before hitting compile, how is the compiler going to know which cpu do we use, on the main, we only included mr mBed. Well that is something done for us by the nice platformIO people here, who leverage the powers of python, and json files for configuration which keep us in familiar environment with the VSCode which configuration is also json, not sure if that's related but that's currently the fashion.
looking at the file .platformio\platforms\ststm32\boards\bluepill_f103c8.json there is the rest of the magic that's going to help our compiler
{
"build": {
"core": "stm32",
"cpu": "cortex-m3",
"f_cpu": "72000000L",
"ldscript": "stm32f103xb.ld",
"mcu": "stm32f103c8t6",
"variant": "stm32f1"
},
"frameworks": [
"mbed",
"arduino"
],
"name": "BluePill F103C8",
"upload": {
"maximum_ram_size": 20480,
"maximum_size": 65536,
"protocol": "stlink"
},
"url": "http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32f1-series/stm32f103/stm32f103c8.html",
"vendor": "Generic"
}
and there we see that this blue pill supports mbed and arduino by this current platformIO version, we even have a link to the official ST datasheets. The Generic vendor is about the BluePill which design is Open I think.
can we hit compile now ? We still don't know which compiler is going to jump, but let's see.
I could not find where the build log is, if someone know please let me know, otherwise please mr platformIO give us a build log output by default or at least with an option. As I'm under windows using the Power shell the pipe is as follows with the run command
Compiling by calling "pio run"
- hit the "run" which is all what is about compiling, flashing,... with sub options, and I do like the --verbose option
pio run -v | Out-File build.log
Although everything is piped to a file, well not everything as I get lots of yellow output on my screen have no clue why, if someone could tell me ?And here more revelations in the build log (download link) from which an extract
[04/08/17 20:24:33] Processing bluepill_f103c8 (platform: ststm32, board: bluepill_f103c8, framework: mbed)
Collected 8 compatible libraries
Looking for dependencies...
Project does not have dependencies
arm-none-eabi-gcc -o .pioenvs\bluepill_f103c8\FrameworkMbed-hal-d30ab\mbed_gpio.o -c -std=gnu99...
Well it's the good old gcc with its arm-non-eabi-gcc which is in a directory we spotted earlier:".platformio\packages\toolchain-gccarmnoneeabi\bin" and this is the toolchain exactly as you would have installed it from the official site.Note that the good thing about windows is that after installing 10 IDEs using amr-gcc, I have it duplicated 10 times on my drive, that's why we pay for bigger drives and faster cpus to search them, but at least, all of them are one click install without worrying about versions, they could all be different I wouldn't realize, go solve that problem under a unified install system.So what's the result what did we got ? Well the nice platformIO even called a gcc helper for us to check the size :arm-none-eabi-size -B -d .pioenvs\bluepill_f103c8\firmware.elf
text data bss dec hex filename
27880 2188 452 30520 7738 .pioenvs\bluepill_f103c8\firmware.elf
[SUCCESS] Took 5.53 seconds
So we have 28 KB to flashJust a summary, please correct me if someone see's I describe it wrong:text : is the program sizedata : is the ram content, but as it is initialized, I think it goes in Flash as wellbss : is the non initialized global data, so doesn't care about it for the flashdec and hex are the total in decimal and hex.So from the flash later on I got the conclusion:>$env:Path += ";C:\Users\User\.platformio\packages\toolchain-gccarmnoneeabi\bin"
>arm-none-eabi-size -B -d .pioenvs\bluepill_f103c8\firmware.elf
>arm-none-eabi-size -h
Flashing by calling also "pio run" or just by your own
- time to run your program, for that the flashing is hidden by the run command with these options:
platformio run --target upload -v
you see the -v option behind, well I like platformIO for such things, when you run it without, it suggests that "-v" would give you more info and actually, only then you see the flashing command line:st-flash write .pioenvs\bluepill_f103c8\firmware.bin 0x08000000
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.