Platformio

Development environment specific, Arduino, Eclipse, VS2013,Em::Blocks etc
Post Reply
pirimmsr
Posts: 1
Joined: Sat Dec 03, 2016 12:03 am

Re: Platformio

Post by pirimmsr » Sat Dec 03, 2016 12:24 am

I got the blink.ino example working on the BluePill board under Win8 with the following platformio.ini settings:

Code: Select all

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_port = COM10
upload_protocol = serial
Needed to change the LED from PB1 to PC13 as follows

Code: Select all

#define BOARD_LED PC13

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin PB1 as an output.
  pinMode(BOARD_LED, OUTPUT);
}
Kenjutsu helped me get going with his statement about 57600 baud. I had to change line 11 in C:\Users\{user}\.platformio\packages\tool-stm32duino\serial_upload.bat FROM:

Code: Select all

stm32flash -g 0x8000000 -b 230400 -w %str% %1
TO:

Code: Select all

stm32flash -g 0x8000000 -b 57600 -w %str% %1

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

Re: Platformio

Post by michael_l » Tue Dec 06, 2016 1:17 pm

If you want to use SPI, you'll have to add

Code: Select all

lib_deps=SPI
for platformio to find SPI libs.

Code: Select all

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
[color=#BF0000]lib_deps = SPI[/color]

[platformio]
src_dir=.


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

Re: Platformio

Post by michael_l » Tue Mar 28, 2017 5:01 pm

Has anybody got UPLOAD_MODE=dfu working with platformio so that the actual code and USB works ?

I can build and upload (dfu) with platformio but after flashing there's no COM port.

Compiling with Arduino IDE is quite time-consuming especially with old laptops so it would be so great to get platformio working.

Any hints where to start looking ?

User avatar
martinayotte
Posts: 1172
Joined: Mon Apr 27, 2015 1:45 pm

Re: Platformio

Post by martinayotte » Tue Mar 28, 2017 5:26 pm

but after flashing there's no COM port
In your compile flags, do you have the "-DSERIAL_USB" defined ?

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

Re: Platformio (solved)

Post by michael_l » Tue Mar 28, 2017 6:29 pm

martinayotte wrote:
but after flashing there's no COM port
In your compile flags, do you have the "-DSERIAL_USB" defined ?
I'm actually flashing to BluePill but using genericSTM32F103CB because it has 128kB defined in platformio config. Is this a problem ?

according to build log
log.zip
(4.63 KiB) Downloaded 8 times
there is -DSERIAL_USB

here's one row from build process:

Code: Select all

arm-none-eabi-g++ -o .pioenvs\genericSTM32F103CB\lib\SdFat\FatLib\FatFilePrint.o -c -fno-rtti -fno-exceptions -g -Os -ff
unction-sections -fdata-sections -Wall -mthumb -nostdlib -mcpu=cortex-m3 --param max-inline-insns-single=500 -march=armv
7-m -DF_CPU=72000000L -DGENERIC_STM32F103C -DPLATFORMIO=30300 -DARDUINO_GENERIC_STM32F103C -DMCU_STM32F103CB -DARDUINO=1
0610 -DBOARD_generic_stm32f103c -DERROR_LED_PORT=GPIOB -DERROR_LED_PIN=1 -DDEBUG_LEVEL=DEBUG_NONE -D__STM32F1__ -DARDUIN
O_ARCH_STM32F1 -DVECT_TAB_ADDR=134225920 -DSERIAL_USB -DGENERIC_BOOTLOADER -IC:\Users\michael\.platformio\packages\framewor
k-arduinoststm32\STM32F1\cores\maple -IC:\Users\michael\.platformio\packages\framework-arduinoststm32\STM32F1\system\libmap
le -IC:\Users\michael\.platformio\packages\framework-arduinoststm32\STM32F1\system\libmaple\include -IC:\Users\michael\.platfo
rmio\packages\framework-arduinoststm32\STM32F1\system\libmaple\usb\stm32f1 -IC:\Users\michael\.platformio\packages\framewor
k-arduinoststm32\STM32F1\system\libmaple\usb\usb_lib -IC:\Users\michael\.platformio\packages\framework-arduinoststm32\STM32
F1\variants\generic_stm32f103c -IC:\Users\michael\.platformio\packages\framework-arduinoststm32\STM32F1\libraries\SPI\src -
IC:\Users\michael\.platformio\packages\framework-arduinoststm32\STM32F1\libraries\SdFat\src C:\Users\michael\.platformio\packa
ges\framework-arduinoststm32\STM32F1\libraries\SdFat\src\FatLib\FatFilePrint.cpp

One difference I found is that Arduino build uses -Og and platformio uses -Os flag for optimization


EDIT:

Further studying.. there seems to be more difference in linking phase:

This is from platformio:

Code: Select all

arm-none-eabi-g++ -o .pioenvs\genericSTM32F103CB\firmware.elf -Os -Wl,--gc-sections,--relax -mthumb -mcpu=cortex-m3 -Wl,-T"jtag.ld" .pioenvs\genericSTM32F103CB\src\BPCB.ino.o -LC:\Users\michael\.platformio\platforms\ststm32\ldscripts -LC:\Users\michael\.platformio\packages\framework-arduinoststm32\STM32F1\variants\generic_stm32f103c\ld -L.pioenvs\genericSTM32F103CB -Wl,--start-group .pioenvs\genericSTM32F103CB\libFrameworkArduinoVariant.a .pioenvs\genericSTM32F103CB\libFrameworkArduino.a -lc -lgcc -lm -lstdc++ -lnosys -lc .pioenvs\genericSTM32F103CB\lib\libFreeRTOS821.a .pioenvs\genericSTM32F103CB\lib\libSPI.a .pioenvs\genericSTM32F103CB\lib\libArduinoJson_ID64.a .pioenvs\genericSTM32F103CB\lib\libSdFat.a -Wl,--end-group

This is from Arduino IDE:

Code: Select all

"C:\Users\michael\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -Og -Wl,--gc-sections -mcpu=cortex-m3 "-TC:\Users\michael\Documents\Arduino\hardware\Arduino_STM32\STM32F1\variants\generic_stm32f103c/ld/bootloader_20.ld" "-Wl,-Map,C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp/BPCB.ino.map" "-LC:\Users\michael\Documents\Arduino\hardware\Arduino_STM32\STM32F1\variants\generic_stm32f103c/ld" -o "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp/BPCB.ino.elf" "-LC:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp" -lm -lgcc -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\sketch\BPCB.ino.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\FreeRTOS821\MapleFreeRTOS821.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\FreeRTOS821\utility\croutine.c.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\FreeRTOS821\utility\event_groups.c.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\FreeRTOS821\utility\heap_1.c.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\FreeRTOS821\utility\list.c.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\FreeRTOS821\utility\port.c.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\FreeRTOS821\utility\queue.c.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\FreeRTOS821\utility\tasks.c.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\FreeRTOS821\utility\timers.c.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SPI\SPI.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\MinimumSerial.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\SdFatUtil.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\FatLib\FatFile.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\FatLib\FatFileLFN.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\FatLib\FatFilePrint.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\FatLib\FatFileSFN.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\FatLib\FatVolume.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\FatLib\FmtNumber.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\FatLib\StdioStream.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\FatLib\fstream.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\FatLib\istream.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\FatLib\ostream.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\SdCard\SdSpiCard.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\SdCard\SdSpiCardEX.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\SdCard\SdioCardEX.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\SdCard\SdioTeensy.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\SpiDriver\SdSpiESP8266.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\SpiDriver\SdSpiSAM3X.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\SpiDriver\SdSpiSTM32F1.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\libraries\SdFat\SpiDriver\SdSpiTeensy3.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\core\wirish\start.S.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\core\wirish\start_c.c.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\core\wirish\syscalls.c.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\core\board.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\core\wirish\boards.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp\core\wirish\boards_setup.cpp.o" "C:\Users\michael\AppData\Local\Temp\buildd7c89daa834f4d59c2e0edd41c4c10b1.tmp/core\core.a" -Wl,--end-group
platformio is not linking many files that arduino build does

EDIT2:

Arduino is linking with this parameter

"-TC:\Users\michael\Documents\Arduino\hardware\Arduino_STM32\STM32F1\variants\generic_stm32f103c/ld/bootloader_20.ld"

Platformio does:

-T"jtag.ld"

hmm.. is that correct ?


EDIT3:

Yes, seems that wrong linker script was the problem. I think I solved it:

I added bolded rows to arduino.py ( platformio\platforms\ststm32\builder\frameworks )

if "stm32f103r" in board.get("build.mcu", ""):
env.Replace(LDSCRIPT_PATH="bootloader.ld")
elif "stm32f103c" in board.get("build.mcu", ""):
env.Replace(LDSCRIPT_PATH="bootloader_20.ld")

elif board.get("upload.boot_version", 0) == 2:
env.Replace(LDSCRIPT_PATH="bootloader_20.ld")


.. and it works again
Last edited by michael_l on Wed Apr 05, 2017 8:23 am, edited 1 time in total.

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

Re: Platformio

Post by michael_l » Wed Mar 29, 2017 7:15 am

Another issue with platformio build is that it seems to create much larger flash file than Arduino IDE.

EDIT:

Added bolded rows to arduino.py and the size is approximately the same than with Arduino build.

env.Append(
CCFLAGS=[
"--param", "max-inline-insns-single=500",
"-march=armv7-m",
"-fno-exceptions",
"-fno-rtti",
"-fno-threadsafe-statics",

],

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

Re: Platformio

Post by stevestrong » Tue Apr 04, 2017 4:59 pm

Hi there,
I am currently trying to use PlatformIO for generic C8 projects, and managed to successfully build a simple blinky project.
It also uploads over DFU (manual reset):

Code: Select all

Uploading .pioenvs\genericSTM32F103CB\firmware.bin
maple_loader v0.1
Resetting to bootloader via DTR pulse
Reset via USB Serial Failed! Did you select the right serial port?
Searching for DFU device [1EAF:0003]...
Assuming the board is in perpetual bootloader mode and continuing to attempt dfu programming...

Found it!

Opening USB Device 0x1eaf:0x0003...
Found Runtime: [0x1eaf:0x0003] devnum=1, cfg=0, intf=0, alt=2, name="STM32duino bootloader v1.0  Upload to Flash 0x8002000"
Setting Configuration 1...
Claiming USB DFU Interface...
Setting Alternate Setting ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
Transfer Size = 0x0400
bytes_per_hash=283
Starting download: [##################################################] finished!
error resetting after download: usb_reset: could not reset device, win error: The system cannot find the file specified.
state(8) = dfuMANIFEST-WAIT-RESET, status(0) = No error condition is present
 
Done!
 
Resetting USB to switch back to runtime mode
 [SUCCESS] Took 12.78 seconds
but...
the serial port does not appear after reset.

One of the reasons I think is that it uses the compiler "gcc version 4.8.4 20140725 (release)" instead of the 4.8.3 Q1 as standard for Arduino iDE.

Does anyone know how to configure PlatformIO to use the Arduino default compiler?

For info, here is my INI:

Code: Select all

[env:genericSTM32F103CB]
platform = ststm32
board = genericSTM32F103CB
framework = arduino
upload_protocol = dfu
upload_port = "Maple DFU"
build_flags = -v

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

Re: Platformio

Post by michael_l » Tue Apr 04, 2017 5:47 pm

stevestrong wrote:Hi there,
I am currently trying to use PlatformIO for generic C8 projects, and managed to successfully build a simple blinky project.
It also uploads over DFU (manual reset):

Code: Select all

Uploading .pioenvs\genericSTM32F103CB\firmware.bin
maple_loader v0.1
Resetting to bootloader via DTR pulse
Reset via USB Serial Failed! Did you select the right serial port?
Searching for DFU device [1EAF:0003]...
Assuming the board is in perpetual bootloader mode and continuing to attempt dfu programming...

Found it!

Opening USB Device 0x1eaf:0x0003...
Found Runtime: [0x1eaf:0x0003] devnum=1, cfg=0, intf=0, alt=2, name="STM32duino bootloader v1.0  Upload to Flash 0x8002000"
Setting Configuration 1...
Claiming USB DFU Interface...
Setting Alternate Setting ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
Transfer Size = 0x0400
bytes_per_hash=283
Starting download: [##################################################] finished!
error resetting after download: usb_reset: could not reset device, win error: The system cannot find the file specified.
state(8) = dfuMANIFEST-WAIT-RESET, status(0) = No error condition is present
 
Done!
 
Resetting USB to switch back to runtime mode
 [SUCCESS] Took 12.78 seconds
but...
the serial port does not appear after reset.

One of the reasons I think is that it uses the compiler "gcc version 4.8.4 20140725 (release)" instead of the 4.8.3 Q1 as standard for Arduino iDE.

Does anyone know how to configure PlatformIO to use the Arduino default compiler?

For info, here is my INI:

Code: Select all

[env:genericSTM32F103CB]
platform = ststm32
board = genericSTM32F103CB
framework = arduino
upload_protocol = dfu
upload_port = "Maple DFU"
build_flags = -v
Please check my previous post about linker script. You may need to hack it a little. In my case platformio build put "jtag.ld" which was wrong. Because I'm using stm32duino bootloader

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

Re: Platformio

Post by stevestrong » Tue Apr 04, 2017 5:54 pm

@micahel_I, modifying the linker script you could set the correct compiler version?

I doubt, because it seems that PlatformIO uses for build the "toolchain-gccarmnoneeabi" folder.

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

Re: Platformio

Post by michael_l » Tue Apr 04, 2017 6:03 pm

stevestrong wrote:@micahel_I, modifying the linker script you could set the correct compiler version?

I doubt, because it seems that PlatformIO uses for build the "toolchain-gccarmnoneeabi" folder.
Oh yes, sorry I didn't answer to your question about the compiler.

I had the same problem with platformio what you have ( no usb serial ) and fixed it with linker script. Oh and I use upload_port=serial and I have to manually reset it to get uploading started. I'll try upload_port=dfu like you.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest