PlatformIO Community

How to modify Teensy core files?

I need to modify some of the Teensy core files to add support for single wire serial, but I couldn’t find out where PlatformIO is taking the source code files from.

Ideally those source code files should also be integrated directly in the project so other developers do not also have to modify the files. Is there a way to do this?

2 Likes

Depending on your operating system, the files will be coming from

  • Linux (Mac also?): ~/.platformio/packages/
  • Windows: %userprofile%/.platformio/packages/

But that is not the best way to do things, as changes would be lost if the platform files are updated, and it isn’t project specific. I was just thinking you could do a pre-build script that made the changes, but I don’t know what that would look like, or was feasible…

I’m working on a Mac and I already looked into the .platformio folder, but I didn’t find the Teensy core source files. In the Teensy board folders are the exact same files as in this GitHub repository.

I have not figured out yet how this build process works and where it get’s the source files. But I guess it should be possible to copy the files into the project and create a custom board as described here. Has anyone already done this and is there a guide how to do this?

1 Like

So no packages/framework-arduinoteensy folder? Have you actually compiled something for the teensy, so that all required packages are installed?

With PIO, Teensy needs framework-arduinoteensy and toolchain-gccarmnoneeabi to build, and tool-teensy to upload. framework-arduinoteensy has all the core files and teensy libraries. `toolchain-gccarmnoneeabi is the compiler toolchain.

You can see some of this when you look at the platform-teensy/platform.json @ https://github.com/platformio/platform-teensy/blob/develop/platform.json

1 Like

Thanks for the hint. I found the core sources in the packages/framework-arduinoteensy folder and I was able to modify the files to implement the singe wire serial function.

Do you think it would be possible to implement this framework including the changes directly into the project?

I’ve never fiddled with that level of change, so it would be more in the realms of something for @maxgerhardt or @ivankravets to comment on. Is this not something that might be useful to be integrated into the teensy core proper? Something to ask Paul Stoffregen maybe?

I’ve managed to create a separate platform and framework package including the changes for single wire serial. So the changes will not be overwritten by automatic updates. But the two folders still have to be copied manually to the .platformio folder. Maybe it would be possible to copy the two directories automatically using a Python script.

@maxgerhardt @ivankravets Is this the right way to publish a project that needs changes to the core framework files of the device or is there a better way? Would it also be possible to copy the two directories automatically?

@TheNetStriker

I’ve managed to create a separate platform and framework package including the changes for single wire serial. So the changes will not be overwritten by automatic updates. But the two folders still have to be copied manually to the .platformio folder. Maybe it would be possible to copy the two directories automatically using a Python script.

Is this the right way to publish a project that needs changes to the core framework files of the device or is there a better way? Would it also be possible to copy the two directories automatically?

This seems like a fab solution - one that I’m struggling to implement myself. Is there anyway you could point me at or publish a reasonably detailed “how to” on this. It seems to be what would be needed as a first step towards generalising another board to be included in a more broad distro by uploading and sharing with the community.

Basically it’s high time https://github.com/platformio/platformio-core/issues/1367 get’s implemented so this becomes easier.

You have modified your framework core files. Thus in the PIO architecture, you’ve modified the framework-arduinoteensy package. These sources for these packages and the packages themselves are defined in the platform’s platform.json file.

Example

So the actual clean way would be to fork the platform-teensy repository, modiy the platform.json to point to a different package repository which you control, and in this manifest add a new version of the framework-arduinoteensy and the download link to where you have your modified files.

Example from manifest.json from bintray:

  "framework-arduinoteensy": [
    {
      "sha1": "baa3e3c8e7e411b8f5f7918d11fecce08a7c531b", 
      "system": "*", 
      "url": "https://dl.bintray.com/platformio/dl-packages/framework-arduinoteensy-1.135.0.tar.gz", 
      "version": "1.135.0"
    }, 
    {
      "sha1": "3cc0670966ce4fd855762f30ba05b2cc0541580b", 
      "system": "*", 
      "url": "https://dl.bintray.com/platformio/dl-packages/framework-arduinoteensy-1.136.0.tar.gz", 
      "version": "1.136.0"
    }, 
...

Finally you must instruct your project to use the new platform with the changes pacakges by saying

platform = <git link to your platform-teensy fork here>
2 Likes

Thanks for the hint. I didn’t know that I can simply point the platform to a GitHub link. I created a fork of the platform and simply added a manifest.json to my GitHub project. The platform and modified package is now downloaded automatically. Thanks for the quick help!