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!

I also need to modify a Teensy core (Teensy41).
Now that issue 1367 is implemented, is there a better/easier way to use my own fork of GitHub - PaulStoffregen/cores: Teensy Core Libraries for Arduino ?
I’ve tried using [env:override_framework] without success.
Do I still need to make my own framework-arduinoteensy package?
I don’t understand how platform-teensy actually refers to PaulStoffregen’s cores.

The platform refers to the package name

and then the registry holds the package PlatformIO Registry

including the download links. These packages are uploaded by PlatformIO staff. So, platform-teensy never has a direct reference to https://github.com/PaulStoffregen/cores, only to the framework-arduinoteensy, which is the Teensy core (with added package.json).

In the special case of https://github.com/PaulStoffregen/cores, it doesn’t have the actual core package used by the Arduino IDE (there’s no platform.txt, boards.txt, libraries etc), the core is actually better packaged at Teensyduino: Download and Install Teensy support into the Arduino IDE.

Please show the full platformio.ini.

Thanks for your help! The sorts of dumb thing I have been trying are:

[env:teensy41]
platform = teensy  
framework = arduino
board = teensy41
;lib_deps =
;   https://github.com/PaulStoffregen/RadioHead.git

[env:override_framework]
platform = teensy
;platform_packages =
  ; use upstream Git version
  ;framework-arduinoteensy @ https://github.com/esp8266/Arduino.git
platform_packages =
   cores @ https://github.com/spinorkit/teensy-cores.git

which results in :
Processing override_framework (platform: teensy)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Tool Manager: Installing git+https://github.com/spinorkit/teensy-cores.git
git version 2.33.0.windows.2
Cloning into ‘C:\Users\Kit.platformio.cache\tmp\pkg-installing-xg24vzsv’…
remote: Enumerating objects: 374, done.
remote: Counting objects: 100% (374/374), done.
remote: Compressing objects: 100% (300/300), done.
remote: Total 374 (delta 161), reused 154 (delta 64), pack-reused 0
Receiving objects: 100% (374/374), 718.21 KiB | 1.07 MiB/s, done.
Resolving deltas: 100% (161/161), done.
Error: Could not find one of ‘package.json’ manifest files in the package
The terminal process “C:\Users\Kit.platformio\penv\Scripts\platformio.exe ‘run’” terminated with exit code: 1.

I notice that C:\Users\Kit.platformio\packages\framework-arduinoteensy\package.json contains

{
  "name": "framework-arduinoteensy",
  "version": "1.156.0",
  "description": "Arduino Wiring-based Framework for Teensy boards",
  "keywords": [
    "framework",
    "arduino",
    "teensy"
  ],
  "homepage": "https://www.arduino.cc/reference/en",
  "repository": {
    "type": "git",
    "url": "https://github.com/PaulStoffregen/cores"
  }
}

I wondered if putting a similar package.json into my fork of /PaulStoffregen/cores would work?

Sure, just change the version. The package.json is all metadata, not really used in the build process. But there must be at least a package.json with the correct name field to identify the package.

Thanks! I added the package.json. The build then resulted in:
Processing override_framework (platform: teensy)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Tool Manager: Installing git+https://github.com/spinorkit/teensy-cores.git
git version 2.33.0.windows.2
Cloning into ‘C:\Users\Kit.platformio.cache\tmp\pkg-installing-han0gqjy’…
remote: Enumerating objects: 375, done.
remote: Counting objects: 100% (375/375), done.
remote: Compressing objects: 100% (303/303), done.
remote: Total 375 (delta 161), reused 152 (delta 62), pack-reused 0 eceiving objects: 96% (360/375)
Receiving objects: 100% (375/375), 718.96 KiB | 3.71 MiB/s, done.
Resolving deltas: 100% (161/161), done.
Tool Manager: cores@1.156.9+sha.56bc4ab has been installed!
Verbose mode can be enabled via -v, --verbose option
Error: BoardConfig: Board is not defined

This put the cores folder at:
C:\Users\Kit.platformio\packages\cores

whereas it probably should be at
C:\Users\Kit.platformio\packages\framework-arduinoteensy\cores

So I tried:

[env:override_framework]
platform = teensy
platform_packages =
   framework-arduinoteensy/cores @ https://github.com/spinorkit/teensy-cores.git

but that still resulted in the cores folder being at C:\Users\Kit.platformio\packages\cores

You misunderstand the example and the syntax, you shouldn’t create a new [env:..], you should place the platform_packages in that environment in which you want to override stuff. Also you can’t just rename the framework-arduinoteensy package as cores, you need to specify the right name. So,

[env:teensy41]
platform = teensy  
framework = arduino
board = teensy41
platform_packages =
  framework-arduinoteensy @ https://github.com/spinorkit/teensy-cores.git

as the whole platformio.ini.

But, there’s then the problem that your repo is not a correct Teensy core package. As said above, the original Teensy ‘cores’ repo is highly misleading because it misses a bunch of stuff. You should be starting from https://dl.registry.platformio.org/download/platformio/tool/framework-arduinoteensy/1.156.0/framework-arduinoteensy-1.156.0.tar.gz and add your needed code changes and then upload that as a whole as your repo.

1 Like

Thanks again for all your help! This platformio.ini is now working:

[env:teensy41]
platform = teensy 
framework = arduino
board = teensy41
platform_packages =
   framework-arduinoteensy @ https://github.com/spinorkit/pio-arduinoteensy.git