Platformio

Development environment specific, Arduino, Eclipse, VS2013,Em::Blocks etc
michael_l
Posts: 337
Joined: Mon Aug 24, 2015 6:11 pm

Re: Platformio

Post by michael_l » Wed Apr 05, 2017 7:26 pm

stevestrong wrote:I think I have found a more appropriate way to adapt linking and upload parameters.
This is a method which can be applied for each chip variant in part, independent on the project and board.
The solution is to edit the respective JSON files, to be found under "\.platformio\platforms\ststm32\boards"

For the blue pill I am using env:genericSTM32F103CB (because of extra flash size ;) ), which corresponds to "genericSTM32F103CB.json" with following content (adapted already):

Code: Select all

{
  "build": {
    "core": "maple",
    "cpu": "cortex-m3",
    "extra_flags": "-DARDUINO_GENERIC_STM32F103C -DMCU_STM32F103CB",
    "f_cpu": "72000000L",
    "hwids": [
        ["0x1EAF", "0x0003"],
        ["0x1EAF", "0x0004"]
    ],
    "ldscript": "bootloader_20.ld",
    "mcu": "stm32f103cb",
    "variant": "generic_stm32f103c"
  },
  "frameworks": ["arduino"],
  "name": "STM32F103CB (20k RAM. 128k Flash)",
  "upload": {
    "disable_flushing": false,
    "maximum_ram_size": 20480,
    "maximum_size": 131072,
    "protocol": "dfu",
    "require_upload_port": false,
    "use_1200bps_touch": false,
    "wait_for_upload_port": false
  },
  "url": "http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32f1-series/stm32f103/stm32f103cb.html",
  "vendor": "Generic"
}
Here I could set the upload method to "dfu" and the ld script to "bootlader_20".
Upload over DFU works flawlessly, including automatic reset before and after upload.

Of course, the bluepill JSON can also be edited accordingly.

Now its time to go further and combine PlatformIO with Eclipse for debugging... :mrgreen:

This is much better solution than my 'hack' :-) Good work.

Yes, platformio can generate project file for Eclipse so that part should be easy. It also configures some ready build targets. I have done that already and it seems to be working quite okay. I've used it with OpenOCD debugging but before that I had to change -Os ---> -Og from one of the python files. Can't remember which one

stevestrong
Posts: 1743
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Platformio

Post by stevestrong » Sat Apr 08, 2017 6:16 pm

I've spent two days to play around with PlatformIO.
I must say, it is a very nice package, I like it a lot
Pros:
- simple generate/import "Arduino" projects
- hackable INI
- easy connection with Eclipse as editor and/or debug tool (OpenOCD) - no need for Sloeber!

The only thing I am not satisfied is the editor feature of ATOM. A simple dragging of selected code lines is not possible, which I consider a basic feature of any editor - Npp does it very nicely, Eclipse too.

But anyway, there is no perfect solution, and I think I will use only Eclipse (Neon 3) as editor, combined with PlatformIO as build/config tool from now on.
Is there a need for a wiki entry for this?

michael_l
Posts: 337
Joined: Mon Aug 24, 2015 6:11 pm

Re: Platformio

Post by michael_l » Sat Apr 08, 2017 8:21 pm

Wiki might be a good idea because it didn't work for me out of the box with Stm32Duino bootloader (linker script change or .json file modification needed).

stevestrong
Posts: 1743
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Platformio

Post by stevestrong » Sat Apr 08, 2017 8:37 pm

Well, it did not worked out of the box for me either, but changing the json file offers a relative easy way to adapt it to stm32duino needs.
Taken into account that there are a lot of stm32 variants, i think it is a good possibility to quickly personalize it.
And the changes are immediately active, no need to restart the ide ;)
I could setup two different configurations (DFU and STlink upload) using two different json files, and switched through quickly changing one line in the ini file. After couple of seconds (needed to re-index the project) was the new config active and build was ready to go.
And also a good feature: if you change one file, only that file will be recompiled so that the consecutive build is done in 3 seconds. Very fast!

stevestrong
Posts: 1743
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Platformio

Post by stevestrong » Sun Apr 09, 2017 1:00 pm

I started to add some info to the new wiki, see here: http://wiki.stm32duino.com/index.php?ti ... PlatformIO
Anyone is welcome to add more info + comment.

michael_l
Posts: 337
Joined: Mon Aug 24, 2015 6:11 pm

Re: Platformio

Post by michael_l » Sun Apr 09, 2017 2:19 pm

Looks good. One thing could be added that platformio is an independent from the ATOM ide. You can create projects from command line:

pio init --ide=eclipse --board=genericSTM32F103CB

Build with: pio run
Clean: pio run -t clean

As well as upload : pio run -t upload

there is also serial monitor. I have a .bat file that builds and uploads and starts Serial monitor after 3 seconds.

EDIT: Here, I can not attach .bat files so here it is. Adjust timeout accordingly. 3 secs seems to be just about enough.

Code: Select all

platformio  run -t upload
timeout 3
platformio device monitor --baud=230400 --port=COM17
Last edited by michael_l on Sun Apr 09, 2017 4:27 pm, edited 2 times in total.

stevestrong
Posts: 1743
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Platformio

Post by stevestrong » Sun Apr 09, 2017 4:21 pm

@michael, I added your info.
Can you share with us the batch file? I would add it to the wiki.

michael_l
Posts: 337
Joined: Mon Aug 24, 2015 6:11 pm

Re: Platformio

Post by michael_l » Sun Apr 09, 2017 4:28 pm

stevestrong wrote:@michael, I added your info.
Can you share with us the batch file? I would add it to the wiki.
Yes, I added info about the .bat contents in the previous post. I could not attach .bat files here.

stevestrong
Posts: 1743
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Platformio

Post by stevestrong » Sun Apr 09, 2017 4:50 pm

I wonder if it would be possible to add a separate entry in the "Build target" list of PlatformIO commands in Eclipse.
The I could start the serial terminal within Eclipse.
EDIT
This is possible by inserting to the .cproject file as the last target (end of file minus 4 lines) the following lines:

Code: Select all

			<target name="PlatformIO: Open serial terminal" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
				<buildCommand>platformio</buildCommand>
				<buildArguments>-f -c eclipse</buildArguments>
				<buildTarget>device monitor --baud=230400 --port=COM4</buildTarget>
				<stopOnError>true</stopOnError>
				<useDefaultCommand>true</useDefaultCommand>
				<runAllBuilders>false</runAllBuilders>
			</target>
Unfortunately, only Rx is working, no transmission is possible (at least I don't know how it should work).
And the line endings are doubled, so you always get an empty new line between two serial output lines.

Also, after changing the INI file, PlatformIO needs couple of seconds to re-index the project. How can you detect in Eclipse when PlatfromIO finished the the indexing?

zmemw16
Posts: 1449
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Platformio

Post by zmemw16 » Sun Apr 09, 2017 5:34 pm

michael_l wrote:
stevestrong wrote:@michael, I added your info.
Can you share with us the batch file? I would add it to the wiki.
Yes, I added info about the .bat contents in the previous post. I could not attach .bat files here.
rename the file by adding '.txt' i.e. my.bat ==> my.bat.txt or just zip it.

stephen

Post Reply