platformio / platform-atmelsam

Atmel SAM: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/atmelsam
Apache License 2.0
79 stars 105 forks source link

CMSIS Builder #81

Open frankleonrose opened 4 years ago

frankleonrose commented 4 years ago

As part of issue #80, the builder here works with CMSIS framework enhancements here https://github.com/frankleonrose/framework-cmsis and successfully builds executables.

I updated the board definitions of FeatherM0 and MoteinoZero to include the 'cmsis' framework because I've actually run the executables on these boards.

valeros commented 4 years ago

Hi @frankleonrose ! Thanks a lot for this PR! Do other boards in this repo also support cmsis framework? Also could you please add several examples with edge cases so we can safely refactor the build script?

frankleonrose commented 4 years ago

Yes, @valeros, most of the other boards support CMSIS. Perhaps all but the "Digistump DigiX" (hmm, looking at the data sheet, maybe that is just another sam3x.).

I'm happy to add examples - do you mean a project file ./examples/project/platformio.ini with envs for a few different boards and a main()?

valeros commented 4 years ago

I'm happy to add examples - do you mean a project file ./examples/project/platformio.ini with envs for a few different boards and a main()?

Yes, a couple of typical examples (blink, uart or something else worth adding to CI) will be enough.

frankleonrose commented 4 years ago

All Atmelsam boards build cleanly with framework = cmsis.

frankleonrose commented 4 years ago

@valeros Anything else you'd like to see here?

valeros commented 4 years ago

Hi @frankleonrose ! Looks great! Could we get rid of the commented code here and here ? I took a look at your package repository and noticed there are plenty of files for peripherals. Are they part of another framework? Also, it might be a good idea to split the CMSIS package so each platform can have a separate package with a specific version and structure. WDYT? Thanks!

frankleonrose commented 4 years ago

@valeros No, the entire CMSIS directory is from a single repo - https://github.com/ARM-software/CMSIS_5 - all the driver code is part of the framework. (Actually, I started with the CMSIS framework source files included in PlatformIO package framework-cmsis version 2.50400.181126.) The CMSIS framework should continue to include everything supplied there. In my most recent use case, Minimal-FreeRTOS using CMSIS-FreeRTOS, I rely on CMSIS framework including the RTOS2 headers.

Are you proposing that the complete PlatformIO framework-cmsis should be built by a process like the following?

  1. Start with https://github.com/ARM-software/CMSIS_5
  2. Layer in STM32 platformio/ldscripts/ststm32 and variants/ststm32 from a cmsis-stm32 repo.
  3. Layer in Atmelsam platformio/ldscripts/atmelsam and variants/atmelsam from an cmsis-atmelsam repo.
  4. Layer in other ARM platforms...

Personally, I wouldn't make it more complicated until I had a specific case that wasn't working without breaking it up.

valeros commented 4 years ago

@frankleonrose

all the driver code is part of the framework

I meant files in the variant folder, for example these.

Are you proposing that the complete PlatformIO framework-cmsis should be built by a process like the following?

What I'm suggesting is to create two new independent repositories framework-cmsis-ststm32 and framework-cmsis-atmelsam and each will contain a copy https://github.com/ARM-software/CMSIS_5 with the platform-specific variant layer. Then these repositories will be automatically archived as tar packages and specified in the platform.json file in each platform. This way these packages can be managed independently, and that's probably a good idea because users who want to program atmelsam board with CMSIS framework are not forced to download a mixed package that includes files for totally different platforms.

frankleonrose commented 4 years ago

The STM32 variants have single ~5000 line files per processor whereas Atmel breaks them up by peripheral (~50-300 lines). They contain equivalent content: #defines for control registers.

frankleonrose commented 4 years ago

Per-platform repos: I see what you mean now. And users will still be able to use framework = cmsis because the platform.json file will map that to the appropriate one. Great!

Will you make the repos under the https://github.com/platformio account?

valeros commented 4 years ago

So it would be great if you could tidy up (and probably rename) https://github.com/frankleonrose/framework-cmsis so there are no files related to ststm32 MCUs. After that we can transfer that repository to our account and then merge your PR.

Thanks!

frankleonrose commented 4 years ago

Done.

RudolphRiedel commented 3 years ago

I just updated the Atmel SAM platform package again and it still does not allow bare metall CMSIS programming. And I really do wonder why with this pull request open since 2019-10.

chepo92 commented 3 years ago

@frankleonrose great work! while I can compile with the examples provided with the framework-cmsis in your repo, I can't get a SAM4 to compile, have you tried it ?

kroppt commented 3 years ago

An upstream commit adds the CMSIS packages: https://github.com/platformio/platform-atmelsam/commit/abbfb1b6ca74c27e8ca6e47e9132a4c31c883d05 So I think this PR needs updating.

glingy commented 2 years ago

I couldn't find if this was actually merged or still being actively worked on elsewhere, so I fixed the merge conflicts in a new fork: https://github.com/glingy/platform-atmelsam/tree/feat-cmsis-build-2 I am currently using this (with samc21 board) with no issues and as far as I can tell, all debugging features still work as intended. I can't test it much to be sure with other boards, but it seems to be working and I would love to have this integrated as a default option.

glingy commented 2 years ago

Also @kroppt, Those cmsis packages are within the Arduino framework if I'm not mistaken. Someone else correct me if I'm wrong, but from what I can understand, the Arduino Framework uses the cmsis libraries and so it includes them. However, this is for "bare" programming using just the cmsis header files without the Arduino framework as well.

RudolphRiedel commented 2 years ago

Very nice, I did now what I should have been doing a while ago. I replaced the AtmelSAM with this new branch, configured a new board file and now my Atmel Studio project builds in platformio. There are a few kinks left and open questions but the important part is that it builds.

board_same51j19a.zip

kroppt commented 2 years ago

@glingy framework-cmsis is very generic. It's something you'd have to download yourself if you were doing this manually: https://github.com/ARM-software/CMSIS_5. I think we're on the same page about that.

One problem I see with both the old and updated solutions is that the framework-cmsis from @frankleonrose includes the platformio and variants folders, which PIO's current framework-cmsis does not have. For generic STM32 devices, the linker scripts are provided through tool-ldscripts-stm32, so I think we need an equivalent: tool-ldscripts-atmelsam.

In my own hack, I created a local package tool-ldscripts-atmelsam with the linker script for my board, and modified the platform to use those.

Ultimately, if this gets merged, it will have to jive with the existing frameworks. We will be in a better place if we use the latest framework-cmsis with a new repository for tool-ldscripts-atmelsam. Then, when it gets merged, the PIO team would take over distribution of tool-ldscripts-atmelsam, removing the need for the custom repository. At least that's how I think it will work.

glingy commented 2 years ago

That sounds like a much better plan, and I hadn’t seen the ldscripts tool before. I’ll take a look at that