Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 4, 2019. It is now read-only.

Suport for ESP32 using Arduino libs #74

Open
wants to merge 33 commits into
base: master
Choose a base branch
from

Conversation

Pro
Copy link

@Pro Pro commented Feb 14, 2018

This PR is a follow-up of francoiscampbell#7 and adds support for compiling programs for an Espressif ESP32 chip.

In my tests I used an Adafruit Feather ESP32. It also adds an example for using the Access Point on ESP32

altexdim and others added 30 commits April 23, 2015 16:29
…hey will safely be ignored by the compiler since they don't end in .c or .cpp. Added library include directories for CLion compatibility.
Respect CMake include path when searching for library dependency directories
Now it supports any number of subsettings, and also
single setting values like `name=Arduino`

Additionally this adds a method which allows to replace variables
within a settings value.
E.g.

`tools.avrdude.path={runtime.tools.avrdude.path}`
…H/hardware

This also adds support for 3-rd party hardware definitions like
espressif/esp32

Note that this does not yet add support for compiling esp32
@MrPointer
Copy link
Member

@Pro First of all, welcome to the Arduino CMake organization - Glad to have you on board 😉

I've read parts of the changes you've introduced, but before going any further, I'd like you to read the Contribution Guidelines which drive our development. We won't accept any PRs that don't step up to the guideline's requirements.
Besides, it's probably worth noting that our codebase has been heavily refactored - We no longer use a single Arduino.cmake file. Rather, we split everything into small chunks of cmake files, each containing no more than 2 major functions.

And last, we currently acknowledge the issue of not supporting other platforms than avr, and you can see the full discussion about it in #34. So frankly I don't know if your effort will worth it at the end, since you have to align to our guidelines, refactored codebase, and to provide a good enough solution that will generalize support for custom platform/boards and not just provide support for a specific one.

Thanks again and good luck!
P.S Feel free to ask any questions you need in the process 😃

@Pro
Copy link
Author

Pro commented Feb 15, 2018

Unfortunately I saw your repository too late and I based my changes on another fork (https://github.com/francoiscampbell/arduino-cmake) that's why there are so many conflicts.

With my changes it is possible to easily add other platforms in a generalized way. What I am doing is to read the platform.txt and boards.txt file and based on these settings all the toolchain settings and make/size/upload scripts are generated. All this is done in cmake and some regex magic. A cleaner view on how to achieve that can be seen by checking the diff here: francoiscampbell#8

So all the configurations under /arduino-sdk/hardware are parsed and made available for building.

I tested this with some arduino boards and it worked fine. Then I ran some tests with the Espressif ESP32 and that also works like a charm.

Unfortunately I do not have the time to redo my changes for your much nicer fork, but feel free to reuse any changes from my PR for further improvements of any kind.

You can close this PR if you do not think there is anybody who can transform this to your new format, or leave it open as a reminder for some later TODO item.

For now I will stick to my fork and will use it for further development (with SDK 1.8.5).

@MrPointer
Copy link
Member

Well you pretty much bought me saying that you've added support for parsing the platform.txt file - Shame that it isn't done on our fork version... Will definitely take a look at this code sometime, and keep you updated on any decision we'll make!

On another subject - I honestly think that this fork is the most stable one, sure as hell the most advanced and up-to-date, so it would be kind of a "waste" to continue developing your fork based on francoiscampbell's fork instead of ours. But that's completely your decision 😃

@MrPointer MrPointer self-requested a review February 15, 2018 19:59
@MrPointer MrPointer self-assigned this Feb 15, 2018
@MrPointer MrPointer modified the milestones: 3rd Party Platform Support, Custom Platforms Feb 15, 2018
@Pro
Copy link
Author

Pro commented Feb 15, 2018

I hope that I can work with that version for now, so that I don't need to work on my fork that much, I woul definitely prefer to use your version!

Anyways, if you need some starting points, integrating the parsing of the files in your version should not be that much of work, if you know your code.

Some hints here:

  1. The magic starts here (in this example the platform.txt, but any other .txt in this style is supported):
    load_arduino_style_settings(${PLATFORM}_PROGRAMMERS "${PLATFORM_PATH}/programmers.txt" "")
    https://github.com/Pro/arduino-cmake/blob/1421d0bc1b4a34bea71cf00b3149ab73b70d79f2/cmake/Platform/Arduino.cmake#L762

  2. And here is the corresponding method which loads the .txt file and simply puts all the defined variables in the CMake cache:
    load_arduino_style_settings(SETTINGS_LIST SETTINGS_PATH)
    https://github.com/Pro/arduino-cmake/blob/1421d0bc1b4a34bea71cf00b3149ab73b70d79f2/cmake/Platform/Arduino.cmake#L1695

That's it for parsing the file. Since within the file, each variable may reference another variable, you also need a method which does that replacement based on the current board setting.

The replacement method is this one, it takes a string which contains variables, and it recursively replaces all other variables:
GET_VARIABLE_VALUE_FILLED(SETTING_VALUE BOARD_ID)
https://github.com/Pro/arduino-cmake/blob/1421d0bc1b4a34bea71cf00b3149ab73b70d79f2/cmake/Platform/Arduino.cmake#L1807

To this method you can pass a variable name, and it will give you the filled value (using the previous replace method):
GET_VARIABLE_FILLED(VARIABLE_NAME BOARD_ID)
https://github.com/Pro/arduino-cmake/blob/1421d0bc1b4a34bea71cf00b3149ab73b70d79f2/cmake/Platform/Arduino.cmake#L1892

To split the recipe (e.g. for compiling C files) this method is used:
get_recipe_flags(COMPILE_CMD_VAR COMPILE_FLAGS_VAR BOARD_ID RECIPE_TYPE)
https://github.com/Pro/arduino-cmake/blob/1421d0bc1b4a34bea71cf00b3149ab73b70d79f2/cmake/Platform/Arduino.cmake#L879
It returns the compile command and the arguments for this command

An example usage is shown here:

get_recipe_flags(ARDUINO_COMPILE_CMD ARDUINO_COMPILE_FLAGS ${BOARD_ID} "recipe.cpp.o")
set_target_properties(${CORE_LIB_NAME} PROPERTIES
                COMPILE_FLAGS "${ARDUINO_COMPILE_FLAGS}"
                LINK_FLAGS "${ARDUINO_LINK_FLAGS}")

https://github.com/Pro/arduino-cmake/blob/1421d0bc1b4a34bea71cf00b3149ab73b70d79f2/cmake/Platform/Arduino.cmake#L964

Just search for other usages of the method get_recipe_flags and you find more examples.

The major work was to get the parsing and replacement correct, so that method you can simply copy/paste. Therefore there is not much work to do anymore.

So IMHO if you find a few hours, you can integrate this into your nice work and I'm happy to assist you, if you have questions.

@kigster
Copy link

kigster commented Oct 21, 2018

I for one would also like to vote up the ESP support. It sounds like this is a huge PR (2000+ lines), but it also seems like the possible future merge would produce the absolute best of both worlds — a clean cmake toolchain plus support for custom platform.txt and ESP in particular.

I want to mention also the I am the author of a ruby-based CLI tool arli which was built to manage Arduino Library dependencies using a YAML file describing projects dependencies. The tool can also generate a fresh new project and uses the older version of Arduino-Cmake project as the base.

I would love to switch to the NG version asap, but as I understand this toolchain is a lot smarter about finding the libraries. But does it install them from the internet? Or do libraries need to be installed separately?

Thanks for taking up this monumental project guys! It’s much appreciated by those of us who can’t stand to code inside a Java based text editor that takes five minutes to boot. I’m of course talking about the Arduino IDE. 😉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants