[Solved] Using PlatformIO for compilation


#1

I’m new to the mbed platform and I was hoping to use Visual Studio for coding rather than the online IDE / EmBitz

I found PlatformIO which appears to be a collection of Python scripts which can be used for building programs for various microcontrollers. It was fairly easy to install using these instructions once you have Python 2.7 installed.

I was able to set up a blank Visual Studio project by running this script:

platformio init --ide visualstudio --board lpc11u68

It automatically downloaded and installed the toolchain for the lpc11u68 board (which the Pokitto uses)

Next I cloned the latest PokittoLib from https://github.com/pokitto/PokittoLib and then ran:

platformio lib -g install ./PokittoLib/Pokitto

Which appears to copy the Pokitto lib into C:\Users<username>.platformio\lib\Pokitto

I added the Hello World example main.cpp to my project root and attempted to build. It looks like it managed to find the Pokitto lib correctly (from the #include “Pokitto.h”) but fails to build the library. It appears to be a problem with include paths when trying to find the headers.

C:\Users\James.platformio\lib\Pokitto\POKITTO_CORE\FONTS\TIC806x6.cpp:15:10: fatal error: PokittoFonts.h: No such file or directory

PokittoFonts.h is actually in the parent directory so it makes sense that it fails without setting up explicit include paths. How is this handled in mbed / EmBitz build scripts? Does anyone else have experience building with PlatformIO that can lend a hand?


[Suggestion]Future of PokittoLib - v2.0
Which IDEs are supported?
Potential alternative offline IDEs
#2

Maybe subdirs (that compiler has to search) need to be added to platform.ini :

Awesome initiative by the way. We need to get this working!


#3

I was trying to get pokitto to build with platformio as well as I find the mbed web-ide absolutely unusable and the pio workflow much more sensible.

Ran into the same issue as you and haven’t had time to look in to this yet.

Would love to see the pokitto work with this!


[Suggestion]Future of PokittoLib - v2.0
#4

So, I’m trying to construct a library.json file to include everything needed:

{
    "name": "Pokitto",
    "description": "PokittoLib",
    "keywords": "Pokitto",
    "repository": {
        "type": "git",
        "url": "https://github.com/pokitto/PokittoLib/"
    },
    "build": {
        "flags": [
            "-I Pokitto",
            "-I Pokitto/POKITTO_HW",
            "-I Pokitto/POKITTO_CORE",
            "-I Pokitto/POKITTO_LIBS",
            "-I Pokitto/POKITTO_LIBS/Synth",
            "-I Pokitto/POKITTO_LIBS/MicroPython",
            "-I Pokitto/POKITTO_LIBS/USBDevice/USBSerial",
            "-I Pokitto/POKITTO_LIBS/USBDevice/USBDevice",
            "-I Pokitto/POKITTO_SIM",
            "-I Pokitto/POKITTO_SIM/tinydir",
            "-I Pokitto/POKITTO_XTERNALS",
            "-I Pokitto/libpff"
        ]
    }
}

However I’m running in to issues with tinydir:

In file included from /home/dreamer/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/dirent.h:7:0,
from lib/PokittoLib/Pokitto/POKITTO_SIM/tinydir/tinydir.h:54,
from lib/PokittoLib/Pokitto/POKITTO_LIBS/FileIO/FileIO_SIM.cpp:42:
/home/dreamer/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/sys/dirent.h:10:2: error: #error "<dirent.h> not supported"
#error "<dirent.h> not supported"
^~~~~
Compiling .pioenvs/lpc11u68/lib/PokittoLib/Pokitto/POKITTO_LIBS/ImageFormat/BmpImage.o
In file included from lib/PokittoLib/Pokitto/POKITTO_LIBS/FileIO/FileIO_SIM.cpp:42:0:
lib/PokittoLib/Pokitto/POKITTO_SIM/tinydir/tinydir.h:159:22: error: 'DIR' does not name a type
#define _TINYDIR_DIR DIR
^
lib/PokittoLib/Pokitto/POKITTO_SIM/tinydir/tinydir.h:207:2: note: in expansion of macro '_TINYDIR_DIR'
_TINYDIR_DIR *_d;
^~~~~~~~~~~~
lib/PokittoLib/Pokitto/POKITTO_SIM/tinydir/tinydir.h: In function 'int tinydir_open(tinydir_dir*, const char*)':
lib/PokittoLib/Pokitto/POKITTO_SIM/tinydir/tinydir.h:279:7: error: 'tinydir_dir {aka struct tinydir_dir}' has no member named '_d'; did you mean '_e'?
dir->_d = NULL;
^~
_e
lib/PokittoLib/Pokitto/POKITTO_SIM/tinydir/tinydir.h:302:7: error: 'tinydir_dir {aka struct tinydir_dir}' has no member named '_d'; did you mean '_e'?
dir->_d = _tinydir_opendir(path);
^~
_e
lib/PokittoLib/Pokitto/POKITTO_SIM/tinydir/tinydir.h:161:26: error: 'opendir' was not declared in this scope
#define _tinydir_opendir opendir
^
... etc.

#5

I also see this a number of times:

lib/PokittoLib/Pokitto/POKITTO_LIBS/Physics/Shape.h:28:10: fatal error: PokittoApp.h: No such file or directory

Which indeed … there is no PokittoApp anywhere in PokittoLib …


#6

Hi @dreamer

The Pokitto_sim folder should not be included at all. It is only intended for compiling Pokitto code as a PC program.

Ditto for the Physics lib at the moment. Just leave it out.


#7

You’ll also need to remember to add a post-build event to turn the generated .hex into a .bin and to handle the CRC generation.

The post build step as reported by EmBitz is:

arm-none-eabi-objcopy.exe -I ihex .\build\hello.hex -O binary .\build\hello.bin
.\build\lpcrc .\build\hello.bin

#8

Ah, I see.

Thing is if I omit the tinydir I still get:

lib/PokittoLib/Pokitto/POKITTO_LIBS/FileIO/FileIO_SIM.cpp:42:10: fatal error: tinydir.h: No such file or directory
#include "tinydir.h"
^~~~~~~~~~~
compilation terminated.

@Pharap sure, but first I want a successful build :wink:


#9

I think the problem here is that the compiler is trying to compile FileIO_SIM.cpp when it shouldn’t be.

/PokittoLib/Pokitto/POKITTO_LIBS/FileIO/ has both FileIO_HW.cpp and FileIO_SIM.cpp.
The former is the hardware implementation, the latter is the simulator implementation.

PlatformIO needs to be instructed to ignore FileIO_SIM.cpp
Otherwise FileIO_SIM.cpp will need some conditional compilation,
i.e. #if defined(POK_SIM) to the top of FileIO_SIM.cpp and #endif at the bottom.


#10

Ah yes, I’ve been trying to find how to exclude this file.
It seems there is a ‘src_filter’ option but this doesn’t work on libraries.

Your suggestion to check a defined variable helps me get to the next step though.
I then ran in to an issue I reported here: https://github.com/pokitto/PokittoLib/issues/16

And after that:

Compiling .pioenvs/lpc11u68/lib/PokittoLib/Pokitto/POKITTO_LIBS/MicroPython/frozen_mpy.o
lib/PokittoLib/Pokitto/POKITTO_LIBS/ImageFormat/BmpImage.cpp:54:10: fatal error: Pokittodisplay.h: No such file or directory
#include "Pokittodisplay.h"
^~~~~~~~~~~~~~~~~~
compilation terminated.
Compiling .pioenvs/lpc11u68/lib/PokittoLib/Pokitto/POKITTO_LIBS/MicroPython/main.o
*** [.pioenvs/lpc11u68/lib/PokittoLib/Pokitto/POKITTO_LIBS/ImageFormat/BmpImage.o] Error 1

Which is odd because this should’ve been included from Pokitto/POKITTO_CORE


#11

That might be a mistake in the library.
Includes are case sensitive depending on the compiler,
and Pokittodisplay.h doesn’t exist, but PokittoDisplay.h does.


#12

Hah indeed, will open an issue on github :wink:

Still not there yet though.


#13

So, with above suggestions I’m now getting till:

lib/PokittoLib/Pokitto/POKITTO_LIBS/ImageFormat/BmpImage.cpp: In function 'int openImageFileFromSD(char*, uint16_t**, uint8_t**)':
lib/PokittoLib/Pokitto/POKITTO_LIBS/ImageFormat/BmpImage.cpp:66:5: error: 'BITMAPFILEHEADER' was not declared in this scope
BITMAPFILEHEADER bf;
^~~~~~~~~~~~~~~~
lib/PokittoLib/Pokitto/POKITTO_LIBS/ImageFormat/BmpImage.cpp:67:5: error: 'BITMAPINFO' was not declared in this scope
BITMAPINFO bmi;
^~~~~~~~~~
  • whole lot more like these.

Further down the line I also still see that Physics is still included somehow.


#14

Open up a project “HelloWorld” in EmBitz, go to project options and see which files are included. BmpImage for example, is @Hanski’s RLE encoded bitmap optional library.

AFAIremember, Only POKITTO_CORE, POKITTO_HW and POKITTO_LIBS/Synth are actually needed for compilation


#15

Yes somehow pio goes through everything in the lib-directory and tries to link it.
It seems the dependency-graph is not correctly calculated starting from the HelloWorld main.cpp

I will investigate further when I have the time. Thnx for the help :slight_smile:

ps; EmBitz is windows only? I just want a sane command-line workflow that I can integrate with any editor easily (hence PlatformIO)
Also a better way to integrate the mbed lib via a library.json is probably the way to go here.

ps; I created a PR for adding the library in PIO here: https://github.com/platformio/platformio-libmirror/pull/130


#16

I think it’s because it’s trying to precompile it and tries to use all the available .cpp files.
To be honest I’m not entirely sure what dictates which .cpp files get used but EmBitz doesn’t seem to have a problem.

I can’t find anything that says conclusively either way, but I would assume it’s Windows only.

A contradiction in terms? :P

You probably should have waited until it’s all up and running 100% first.


I think it might be possible to get Visual Studio or VS Code compiling without PlatformIO, but you’d have to get them using gcc first and then make sure all the project settings are correct, which can be a bit of a pain.


#17

Pokitto isn’t Visual Studio though right?

Yeah I know, but already looking at how the mbed libraries are included is much different than just git-pulling into a lib/ directory. I’m kind of hoping this will save some headaches somehow :#


#18

I mean getting Pokitto code compiling in Visual Studio.
It depends how good Visual Studio is at using gcc to compile.

Depends if it works or not.
If it’s not working and it gets merged then it might end up causing headaches instead.


#19

I’m certainly open to suggestions on what would be the best workflow. Pokitto is a very evolving project.


#20

im not sure here but is this for the comandline part or the hole IDE? (wich can be vscode or atom)