Cloning an existing platform to make a custom platform

I am having an issue getting Platformio to ‘find’ a custom package I created by cloning an existing package. The package I started with was atmelsam - I copied the platfroms\atmelsam directory to atemlsamFB1 directory; Copied the packages\framework-arduino-sam to framework-arduino-samB1.

I then modified platform.json by adding:
“framework-arduino-samFB1”: {
“type”: “framework”,
“optional”: true,
“owner”: “platformio”,
“version”: “~1.6.12”
},

and changed the “package” variable from “framework-arduino-sam” to “framework-arduino-samB1” as shown below;
“version”: “8.1.0”,
“frameworks”: {
“arduino”: {
“package”: “framework-arduino-samFB1”,
“script”: “builder/frameworks/arduino.py”
},

I also modified package.json;
{
“name”: “framework-arduino-samFB1”,
“version”: “1.6.12”,
“description”: “The official Arduino Wiring-based Framework for ATSAM3 microcontrollers”,
“keywords”: [
“framework”,
“arduino”,
“microchip”,
“sam”
],

And finally modified arduino-sam.py changing the framework_package variable as follows;
env = DefaultEnvironment()
platform = env.PioPlatform()
board = env.BoardConfig()

framework_package = “framework-arduino-samFB1”
if board.get(“build.core”, “”).lower() != “arduino”:
framework_package += “-%s” % board.get(“build.core”).lower()
FRAMEWORK_DIR = platform.get_package_dir(framework_package)

I modified platform.py;
self.frameworks[“arduino”][“package”] = framework_package
if not board.get(“build.mcu”, “”).startswith(“samd”):
self.packages[“framework-arduino-samFB1”][“optional”] = True

After all of that I get:

Error: Platform Manager: Installing atmelsamFB1
Error: Could not find the package with ‘atmelsamFB1’ requirements for your system ‘windows_amd64’

What did I miss?

Why am I doing this? I am compiling code to run in flash bank 1 only - I was able to modify the original atmelsam to do exactly that and it worked. But since I want to compile programs for both normal compiling as well as compiling for just flash bank 1 I cloned the atmelsam with all the changes that worked into atmelsamFB1.

No. That’s a really hacky way and it doesn’t take into account the .piopm file that probably still has "name" : "atmelsam" in it. That’s probably why it doesn’t see it as “installed” and tries to download it from the PIO Registry – where it doesn’t exist, of course.

Also, when you change the name of the platform, then the class name also needs to be adpated accordingly

You should not duplicate the atmelsam folder directly in .platformio\platforms. Copy it to a different folder and in a test project, symlink to it with, e.g.

platform = symlink://C:/Users/Max/Desktop/dev/atmelsamFB1

with that, PlatformIO will just use the given folder and does not do a real install.

Hi Max, thank you for that. I have a few questions as there is a lot going on under the hood of platfromIO. and am still learning how it works. I would copy the platform\atmelsamFB1 to the project directory and symlink it.

  1. Where would I put the platform = symlink… command? Execute from the CLI or embed in a sys file?
  2. What about the packages\framework-arduino-samFB1? Copy that a well to the project?

Appreciate it!
Thank you!

In the platformio.ini of the project. According to the output you currently have platform = atmelsamFB1 in there.

And: it doesn’t need to be copied inside the project, just any folder will do.

See above. You can also use symlink:// in version field of the package in the platform.json.

Or, just to give a different perspective: If all you need to do is just replace the framework-arduino-sam pacakge with a different package, duplicating the entire platform and modifying builder scripts is 400% overkill. You could just use a platform_packages directive to source the framework-arduino-sam package from a different source, i.e., your fork.

And even if you have a custom board you want to add, you can put that board definition in the boards/ folder of the project.

HI Max:

We are getting closer to a solution.
I copied my modified platfrom/atmelsam and packages/framework-arduino-sam to a different directory. My attempt at having platfromio use both is mixed.
The platform = symlink://C::… command does work and redirect to the copied platform/atmelsam.

The board = attribute redirect also works

However the system is still using the original packages/framework-arduin-sam, not the copied one. Not sure what I am missing here - I tried platform_packages = symlink://C: and without the symlink, as seen in my platfromio.ini file below (the first one is commented out)

[env:due]
platform = symlink://C:/Users/me/Documents/PlatformIO/Projects/customBoards/platforms/atmelsam
board = C:/Users/me/Documents/PlatformIO/Projects/customBoards/platforms/atmelsam/boards/dueFB1
framework = arduino
;platform_packages = symlink://C:/Users/me/Documents/PlatformIO/Projects/customBoards/packages/framework-arduino-sam
platform_packages = C:/Users/me/Documents/PlatformIO/Projects/customBoards/packages/framework-arduino-sam

I am not sure why the redirect for platform_packages is still going to the original package not the copied package.

I’ve never seen a syntax like that. Since you already redirected the platform, you automatically have all the boards in that platform’s boards/ folder available to you, so you should be able to just write board = dueFB1.

This is not a correct declaration because it’s missing which package it’s supposed to replace. So if you wanted to replace the source for framework-arduino-sam with that folder, I’d have expected

platform_packages =
   framework-arduino-sam@symlink://C:/Users/me/Documents/PlatformIO/Projects/customBoards/packages/framework-arduino-sam

Now looks like we have a bunch of errors…
Resolving due dependencies…
Platform Manager: Installing symlink://C:/Users/me/Documents/PlatformIO/Projects/customBoards/platforms/atmelsam
Platform Manager: atmelsam@8.1.0 has been installed!
Tool Manager: Installing symlink://C:/Users/me/Documents/PlatformIO/Projects/customBoards/packages/framework-arduino-sam
Tool Manager: framework-arduino-sam@1.6.12 has been installed!
Updating metadata for the vscode IDE…
Error: Processing due (platform: symlink://C:/Users/me/Documents/PlatformIO/Projects/customBoards/platforms/atmelsam; board: dueFB1; framework: arduino)

Platform Manager: Installing symlink://C:/Users/me/Documents/PlatformIO/Projects/customBoards/platforms/atmelsam
Platform Manager: atmelsam@8.1.0 has been installed!
Tool Manager: Installing symlink://C:/Users/me/Documents/PlatformIO/Projects/customBoards/packages/framework-arduino-sam
Tool Manager: framework-arduino-sam@1.6.12 has been installed!
Platform Manager: Installing symlink://C:/Users/me/Documents/PlatformIO/Projects/customBoards/platforms/atmelsam
Platform Manager: atmelsam@8.1.0 has been installed!
Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelsam/dueFB1.html
PLATFORM: Atmel SAM (8.1.0) > Arduino Due (->Flash Bank 1<-)
HARDWARE: AT91SAM3X8E 84MHz, 96KB RAM, 285.30KB Flash
DEBUG: Current (atmel-ice) External (atmel-ice, blackmagic, jlink, stlink)
PACKAGES:

  • framework-cmsis @ 1.40500.0 (4.5.0)
  • framework-cmsis-atmel @ 1.2.2
  • toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)
    TypeError: expected str, bytes or os.PathLike object, not NoneType:
    File “C:\Users\me.platformio\penv\lib\site-packages\platformio\builder\main.py”, line 187:
    env.SConscript(“$BUILD_SCRIPT”)
    File “C:\Users\me.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Script\SConscript.py”, line 597:
    return _SConscript(self.fs, *files, **subst_kw)
    File “C:\Users\me.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Script\SConscript.py”, line 285:
    exec(compile(scriptdata, scriptname, ‘exec’), call_stack[-1].globals)
    File “C:\Users\me\Documents\PlatformIO\Projects\customBoards\platforms\atmelsam\builder\main.py”, line 127:
    target_elf = env.BuildProgram()
    File “C:\Users\me.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Util.py”, line 737:
    return self.method(*nargs, **kwargs)
    File “C:\Users\me.platformio\penv\lib\site-packages\platformio\builder\tools\piobuild.py”, line 60:
    env.ProcessProgramDeps()
    File “C:\Users\me.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Util.py”, line 737:
    return self.method(*nargs, **kwargs)
    File “C:\Users\me.platformio\penv\lib\site-packages\platformio\builder\tools\piobuild.py”, line 120:
    env.BuildFrameworks(env.get(“PIOFRAMEWORK”))
    File “C:\Users\me.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Util.py”, line 737:
    return self.method(*nargs, **kwargs)
    File “C:\Users\me.platformio\penv\lib\site-packages\platformio\builder\tools\piobuild.py”, line 331:
    SConscript(env.GetFrameworkScript(name), exports=“env”)
    File “C:\Users\me.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Script\SConscript.py”, line 660:
    return method(*args, **kw)
    File “C:\Users\me.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Script\SConscript.py”, line 597:
    return _SConscript(self.fs, *files, **subst_kw)
    File “C:\Users\me.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Script\SConscript.py”, line 285:
    exec(compile(scriptdata, scriptname, ‘exec’), call_stack[-1].globals)
    File “C:\Users\me\Documents\PlatformIO\Projects\customBoards\platforms\atmelsam\builder\frameworks\arduino.py”, line 42:
    env.SConscript(os.path.join(“arduino”, “arduino-%s.py” % MCU_FAMILY))
    File “C:\Users\me.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Script\SConscript.py”, line 597:
    return _SConscript(self.fs, *files, **subst_kw)
    File “C:\Users\me.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Script\SConscript.py”, line 285:
    exec(compile(scriptdata, scriptname, ‘exec’), call_stack[-1].globals)
    File “C:\Users\me\Documents\PlatformIO\Projects\customBoards\platforms\atmelsam\builder\frameworks\arduino\arduino-sam.py”, line 38:
    SYSTEM_DIR = os.path.join(FRAMEWORK_DIR, “system”)
    File “C:\Users\me.platformio\python3\lib\ntpath.py”, line 78:
    path = os.fspath(path)
    ========================== [FAILED] Took 0.48 seconds ==========================

Here is the platfromio.ini
[env:due]
platform = symlink://C:/Users/me/Documents/PlatformIO/Projects/customBoards/platforms/atmelsam
board = dueFB1
framework = arduino
platform_packages = framework-arduino-sam@symlink://C:/Users/me/Documents/PlatformIO/Projects/customBoards/packages/framework-arduino-sam

Looks like FRAMEWORK_DIR is None because it can’t find the right package after all. Does C:/Users/me/Documents/PlatformIO/Projects/customBoards/packages/framework-arduino-sam/package.json still have its original unaltered name? The platform.json is also unmodified?

Yes, they are the same as the original.

Since the developed platform and packages are now in their own folder, close VSCode, delete all folders in C:\Users\me.platformio\packages\ and C:\Users\me.platformio\platforms\ and reopen VSCode. Does it still fail to initialize?

I deleted all subfolders/files under both the .platfromio subs.
Upon restart platfromio relaoded following under packages:
contrib-piohome
framework-cmsis
framework-cmsis-atmel
toolchain-gccarmnoneeabi
tool-scons

under platfroms:
jjust a file: atmelsam.pio-link

But Looks like same errors

Resolving due dependencies…
Platform Manager: Installing symlink://C:/Users/tzarnowski/Documents/PlatformIO/Projects/customBoards/platforms/atmelsam
Platform Manager: atmelsam@8.1.0 has been installed!
Tool Manager: Installing platformio/toolchain-gccarmnoneeabi @ ~1.70201.0
Unpacking
Tool Manager: toolchain-gccarmnoneeabi@1.70201.0 has been installed!
Tool Manager: Installing symlink://C:/Users/tzarnowski/Documents/PlatformIO/Projects/customBoards/packages/framework-arduino-sam
Tool Manager: framework-arduino-sam@1.6.12 has been installed!
Tool Manager: Installing platformio/framework-cmsis @ ~1.40500.0
Unpacking
Tool Manager: framework-cmsis@1.40500.0 has been installed!
Tool Manager: Installing platformio/framework-cmsis-atmel @ ~1.2.2
Unpacking
Tool Manager: framework-cmsis-atmel@1.2.2 has been installed!
Updating metadata for the vscode IDE…
Error: Processing due (platform: symlink://C:/Users/tzarnowski/Documents/PlatformIO/Projects/customBoards/platforms/atmelsam; board: dueFB1; framework: arduino)

Platform Manager: Installing symlink://C:/Users/tzarnowski/Documents/PlatformIO/Projects/customBoards/platforms/atmelsam
Platform Manager: atmelsam@8.1.0 has been installed!
Tool Manager: Installing symlink://C:/Users/tzarnowski/Documents/PlatformIO/Projects/customBoards/packages/framework-arduino-sam
Tool Manager: framework-arduino-sam@1.6.12 has been installed!
Platform Manager: Installing symlink://C:/Users/tzarnowski/Documents/PlatformIO/Projects/customBoards/platforms/atmelsam
Platform Manager: atmelsam@8.1.0 has been installed!
Tool Manager: Installing platformio/tool-scons @ ~4.40400.0
Downloading 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
Unpacking
Tool Manager: tool-scons@4.40400.0 has been installed!
Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelsam/dueFB1.html
PLATFORM: Atmel SAM (8.1.0) > Arduino Due (->Flash Bank 1<-)
HARDWARE: AT91SAM3X8E 84MHz, 96KB RAM, 285.30KB Flash
DEBUG: Current (atmel-ice) External (atmel-ice, blackmagic, jlink, stlink)
PACKAGES:

  • framework-cmsis @ 1.40500.0 (4.5.0)
  • framework-cmsis-atmel @ 1.2.2
  • toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)
    TypeError: expected str, bytes or os.PathLike object, not NoneType:
    File “C:\Users\tzarnowski.platformio\penv\lib\site-packages\platformio\builder\main.py”, line 187:
    env.SConscript(“$BUILD_SCRIPT”)
    File “C:\Users\tzarnowski.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Script\SConscript.py”, line 597:
    return _SConscript(self.fs, *files, **subst_kw)
    File “C:\Users\tzarnowski.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Script\SConscript.py”, line 285:
    exec(compile(scriptdata, scriptname, ‘exec’), call_stack[-1].globals)
    File “C:\Users\tzarnowski\Documents\PlatformIO\Projects\customBoards\platforms\atmelsam\builder\main.py”, line 127:
    target_elf = env.BuildProgram()
    File “C:\Users\tzarnowski.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Util.py”, line 737:
    return self.method(*nargs, **kwargs)
    File “C:\Users\tzarnowski.platformio\penv\lib\site-packages\platformio\builder\tools\piobuild.py”, line 60:
    env.ProcessProgramDeps()
    File “C:\Users\tzarnowski.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Util.py”, line 737:
    return self.method(*nargs, **kwargs)
    File “C:\Users\tzarnowski.platformio\penv\lib\site-packages\platformio\builder\tools\piobuild.py”, line 120:
    env.BuildFrameworks(env.get(“PIOFRAMEWORK”))
    File “C:\Users\tzarnowski.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Util.py”, line 737:
    return self.method(*nargs, **kwargs)
    File “C:\Users\tzarnowski.platformio\penv\lib\site-packages\platformio\builder\tools\piobuild.py”, line 331:
    SConscript(env.GetFrameworkScript(name), exports=“env”)
    File “C:\Users\tzarnowski.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Script\SConscript.py”, line 660:
    return method(*args, **kw)
    File “C:\Users\tzarnowski.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Script\SConscript.py”, line 597:
    return _SConscript(self.fs, *files, **subst_kw)
    File “C:\Users\tzarnowski.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Script\SConscript.py”, line 285:
    exec(compile(scriptdata, scriptname, ‘exec’), call_stack[-1].globals)
    File “C:\Users\tzarnowski\Documents\PlatformIO\Projects\customBoards\platforms\atmelsam\builder\frameworks\arduino.py”, line 42:
    env.SConscript(os.path.join(“arduino”, “arduino-%s.py” % MCU_FAMILY))
    File “C:\Users\tzarnowski.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Script\SConscript.py”, line 597:
    return _SConscript(self.fs, *files, **subst_kw)
    File “C:\Users\tzarnowski.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Script\SConscript.py”, line 285:
    exec(compile(scriptdata, scriptname, ‘exec’), call_stack[-1].globals)
    File “C:\Users\tzarnowski\Documents\PlatformIO\Projects\customBoards\platforms\atmelsam\builder\frameworks\arduino\arduino-sam.py”, line 38:
    SYSTEM_DIR = os.path.join(FRAMEWORK_DIR, “system”)
    File “C:\Users\tzarnowski.platformio\python3\lib\ntpath.py”, line 78:
    path = os.fspath(path)
    ========================== [FAILED] Took 4.87 seconds ==========================

Looks like same errors:

here is the content of the atmelsam.pio-link file:

{“cwd”: “C:\Users\me\Documents\PlatformIO\Projects\due FB1 test”, “spec”: {“owner”: null, “id”: null, “name”: “atmelsam”, “requirements”: null, “uri”: “symlink://C:/Users/me/Documents/PlatformIO/Projects/customBoards/platforms/atmelsam”}}

In that file, find the code

and append

print(" == USED FRAMEWORK PACKAGE: %s ==" % framework_package)
print("Framework dir: " + str(FRAMEWORK_DIR))

what is the output?

== USED FRAMEWORK PACKAGE: framework-arduino-sam ==
Framework dir: None

Is framework-arduino-sam still a declared package in the platform.json? What is its version field?

"framework-arduino-sam": {
  "type": "framework",
  "optional": true,
  "owner": "platformio",
  "version": "~1.6.12"
},

Can you post your modified platform + framework online? It could be any minor detail I’m not seeing at this point.

terryzar/Platformio-Cloning: Clone of platformio package and platform for atmelsam to compile code for flash bank 1 on SAM3X8E (github.com)

I did not load over the entire framework-arduino-sam package. Cores, Firmwares, libraries and system have not been changed.