-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for ATSAM arm processors #194
Support for ATSAM arm processors #194
Conversation
c085cd5
to
db4b187
Compare
In your defense, this really isn't an easy topic, you need to understand a whole lot more than just the C/C++ source code. So I'm impressed at how much you got working already! (There are some docs on lbuild module API here: https://github.com/modm-io/lbuild#modules) I've added some commits, I figured it's more useful get you started with something that isn't the CMSIS stuff, since that's boring and super verbose. I'll review the rest tomorrow (Europe time, etc). |
Note that there was a bug in lbuild that prevented building because |
I guess it was a bit presumptuous of me to assume all internal memory would have |
The sram sections in the SAM have so many wonky names I just renamed them I have a starting linker file, but I am having the following the error with scons... forgive me I have never used it before:
the stm files build correctly though, and I presume they are also using |
For STM32 the convention was that the continous memory regions were all called SRAM{1,2,3} and the special RAM was called differently (CCM, ITCM, DTCM), and so the Just copy the common_memories() function to your own
I'd just ignore it for now, this is only interesting for the TLSF heap allocator.
This seems like SCons is not calling the right compiler. This is because this line here: -if subs["platform"] in ["stm32"]:
+if subs["core"].startswith("cortex-m"): Probably also want to change this https://github.com/modm-io/modm/blob/develop/tools/build_script_generator/scons/resources/SConscript.in#L110: -%% elif platform in ["stm32"]
+%% elif core.startswith("cortex-m") And this: https://github.com/modm-io/modm/blob/develop/tools/build_script_generator/scons/resources/build_target.py.in#L27 |
Any idea how to program this board? The way I understand the SAMD21 uses the SAM-BA bootloader, which according to the Application Note can be programmed via USB or UART. But the SAM-BA seems to have a non-standard (ie. non-DFU) like protocol, and requires something a custom host binary? https://github.com/atmelcorp/sam-ba Ideally I'd use OpenOCD or DFU to program this (via |
I don't know all the deep details but arduino uses Now I use jtag and segger pretty exclusively, so I haven't used the boot-loader for a while. |
made those fixes I've never generalized the clock setup before and the clock in these chips have a lot of options. For functions like that tutorial link I put in the last comment mentions Atmel Start. The code it generates is ok, but the clock config page is pretty helpful in understanding how the clocks work. It can also output a makefile project instead of atmel studio. |
Don't overdo it with the abstractions. Get something started first in pure C using the CMSIS headers, verify the frequency if possible (usually blinking an LED for a 1s period is enough) and then we can figure out the abstraction.
This is done in the board support package files, specifically in the Note that we use the
Yeah, we've given up on solving the clock tree at C++ compile time, it's just too complicated. I've visualized the clock trees for STM32 already, however, the data is still very complex and probably needs some contraint solver (probably Z3/SAT based). I would therefore build a generic HTML version of that, based on data within modm-devices, that outputs a generic config format, that modm then can specialize into HAL code. So basically you'd have a common config, that can then be reformatted into C, C++, Rust etc. It's basically an OSS clone of those configuration GUIs. |
Any progress? My SAM board is still in the mail, but if you commit whatever you have, I can help you get something working. |
I've been super busy at work the last week and assembling some new SAM boards at home. Made an attempt at the clock module today but for some reason I made an empty shell for the clocks, plan is to run |
a2cf191
to
254eb07
Compare
I've refactored your entire branch to move things into their own commit to make it a little easier to rebase. For SAM or STM32 isn't a The reason why your SAM - if not options[":target"].has_driver("clock:sam"):
+ if not options[":target"].has_driver("gclk:sam"):
return False I've also fixed the linkerscript usage, so that the common linkerscript macros can be used, which will make sure that all the modm linker features work correctly. The example is currently compiling, but I don't have any hardware to test it on yet. These are the currently available
|
thanks for doing that! makes sense mostly but on the SAM chips the clock are configures using three peripherals |
Yes that seems reasonable. The STM32 had it easy, since the three are basically just one big peripheral, so its module structure doesn't translate well. These aren't necesarily user-facing modules, they are depended on by other peripheral modules like
I think so? I'm hesitant because at the moment the naming isn't 100% the same as in the datasheet/reference manual. For example, the USART peripherals are all placed in Since you have a mostly clean-slate, I'd use the datasheet naming, so that your port's naming scheme is consistent. Can't argue with the datasheet after all ;-P |
The |
pulled your latest and built it. Flashed it to my Feather M0-proto and I am able to step through the code in Ozone debugger! so success for the basic build 😄 |
What's your motivation for continuing this port, @TheSlat? You've already gotten so far with modm-devices and the basic startup etc. |
TLDR: yes still interested, just got pulled away temporarily. I'm trying to get my current project out by the end of summer (on a SAML21) so that has pulled me away a bit. I am mainly writing drivers for the peripherals, but hopefully those are also needed at some point and I can port them over to MODM? Even without time to write, I have done a lot of reading in the modm code-base, there is some stuff I haven't seen before (ex: protothreads). Also, I started on some python scripts to download the microchip CMSIS drivers from Atmel START ( an online only analog to cubeMX). Do you make use of that sort of thin in stm32? it is at least a good reference for the differences between models. |
Yes, and the Resumable Functions, which are derived from that. They are both stackless, which is a major pain point (no local variables) and since they are polling, not sleep-friendly. I'm holding out for C++20 coroutines, since their compiler-backed implementation is much better (or at least more consistent) than our macro-hackery.
No, but we should. The quality of these ports wasn't great last time I checked this in depth about 5y ago. I'm very much in favor of adding significantly more data to modm-devices (like the SVD memory maps) than we currently have. Whatever data source helps with that is welcome. I've been quite busy developing lbuild and porting modm over from xpcc, so the basic peripheral interfaces have basically remained the same since 2015. There is some serious ugly in some of them, especially I2cTransactions are super inefficient and none of the implementations are DMA enabled, or even interrupt-based (looking at you, SPI). There are some good reasons to integrate the vendor HAL more into modm, especially for driving very complex peripherals (like Ethernet, USB, DSI, SDMMC). The CubeHAL has some new low-level drivers, which could be interesting for us. |
723dda4
to
50c6e68
Compare
Yes you can! I'd be happy to merge this as is, even without the GPIO API, if the You can either run them directly: Looking at the CI issues, you want to add the (generic) connector bits at least for the bit-bang peripherals (it probably doesn't even need to work, just have the right header). Not sure what's wrong with the TLSF header. There are some USB issues in the startup that needs to be #ifdef'ed. |
I'm mostly interested in getting this merged so that it doesn't go stale. The GPIO API is still very incomplete and not a single peripheral API is implemented, not even UART logging. So the port is fairly still useless. Just as a heads up. |
Actually let me just fix the header issues, since they are pretty damn lame ;-P |
da13daa
to
23cdcbe
Compare
Ok, I fixed all the easy compile issues, for some reason the CMSIS Headers for SAM21E{15,16} are missing, I've disabled them for now:
|
23cdcbe
to
38d3e42
Compare
38d3e42
to
6c4a8d6
Compare
9b2383a
to
2f125fd
Compare
@henrikssn @CrustyAuklet I'm finally going to merge this PR \o/ The next steps are to improve basic GPIO support and implement a basic UART for logging, and then expand into the peripherals of your choice (don't start with I2C, it's horrible). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get to review my own code? It's clearly the best code I've ever seen.
Wohoo thanks! I'll give that blinky example a shot and then see if I'm able to contribute gpio/uart. Is there a good sample PR for another platform for adding perpheral support that I can use as lead? |
The only other Cortex-M platform we have is STM32, so something basic like the recent DAC driver comes to mind: #420 You can in general just hack the STM32 drivers by The GPIO and peripheral data comes from here. |
Unfortunately since this is a Cortex-M0, you don't have the ITM, otherwise you could've used |
FYI: Fixed the docs upload and the SAMD doxypress is here: https://doc.modm.io/develop/api/samd21j18a-mz/ |
just a start so we can comment. Still wrapping my head around the python-template stuff.
Fixes #189.
Update 2020-04-27: @salkinium took over this PR, see #194 (comment)