cpu/saml1x: add support for SAML10 and SAML11 MCUs (Cortex-M23)#10653
Conversation
|
Very nice! Thanks. I'll review and test it in 2019 :) |
There was a problem hiding this comment.
I could test this PR on saml11-xpro and confirm that it's working.
Unfortunately, my impression is that there is too much code duplication, at least between the saml10-xpro and saml11-xpro boards. I would recommend to directly introduce a boards/common/saml1x common implementation: the timer and uart configuration are the same, the LEDs and buttons are the same, the features provided are the same, etc. The only difference I could see is the used LED0_ON in board_init in one board but not in the other (which is maybe be a leftover).
Regarding the duplication of code at cpu level, I would suggest to directly rename sam0_common to samx_common and depends on it: it will contain the peripheral implementation for sam0 and sam23 (we can keep sam3 appart). And then as you said, sam23 will have support for a lot of peripherals.
To me, this won't be a big effort and it is worth doing right now. I can help if you want.
| @@ -0,0 +1,9 @@ | |||
| # Put defined MCU peripherals here (in alphabetical order) | |||
| FEATURES_PROVIDED += periph_gpio periph_gpio_irq | |||
There was a problem hiding this comment.
This is not needed and can be provided at CPU levels (several PRs were recently merged in that direction)
There was a problem hiding this comment.
I'll remove it. This is a leftover because this PR was started some times before this change was merged.
|
@aabadie Thanks for the review.
In this case, I'll rework this PR but it'll take some time.
Since you're pretty busy with the release management I don't think you should afford such effort. I'll rework all SAM0 to support SAML1x MCUs. |
739a0d5 to
0ea1763
Compare
|
@aabadie I've forced-push the branch. |
aabadie
left a comment
There was a problem hiding this comment.
Thanks for updating this PR @dylad !
I just reviewed/tried (saml11-xpro) it again and found some problems:
gpio_params.his missing butsaul_gpiois included with thesaul_defaultmodule- the gpio driver is broken with interrupts
- I found the saml21 and saml1x peripheral implementations very close. I won't ask you to factorize in this PR though, but I see room for improvement here.
tests/periph_rtcandtests/periph_rttdoesn't work: the first one is stuck and doesn't print anything, the second one doesn't print "many hellos". Maybe just remove for now the support for these periphs ?tests/periph_flashpagedoesn't build, it needs to be adapted.
I haven't test I2C and SPI but others I tested (cpuid, timer, adc) work.
There are other minor stuff see below.
| @@ -0,0 +1,3 @@ | |||
| ifneq (,$(filter saul_default,$(USEMODULE))) | |||
| USEMODULE += saul_gpio | |||
| endif No newline at end of file | |||
| MODULE = board | ||
| DIRS = $(RIOTBOARD)/common/saml1x | ||
|
|
||
| include $(RIOTBASE)/Makefile.base No newline at end of file |
| @@ -0,0 +1,9 @@ | |||
| FEATURES_PROVIDED += periph_adc | |||
There was a problem hiding this comment.
It would make more sense to move these provided features to the common boards. They are the same for saml11-xpro.
| @@ -99,7 +99,11 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg) | |||
| if ((rx_cb) && (uart_config[uart].rx_pin != GPIO_UNDEF)) { | |||
| uart_ctx[uart].rx_cb = rx_cb; | |||
| uart_ctx[uart].arg = arg; | |||
| #if defined (CPU_FAM_SAML10) || defined (CPU_FAM_SAML11) | |||
There was a problem hiding this comment.
| #if defined (CPU_FAM_SAML10) || defined (CPU_FAM_SAML11) | |
| #if defined (CPU_SAML1X) |
| # (file triggers compiler bug. see #5775) | ||
| SRC_NOLTO += vectors.c | ||
|
|
||
| include $(RIOTBASE)/Makefile.base |
| @@ -0,0 +1 @@ | |||
| -include $(RIOTCPU)/sam0_common/Makefile.features | |||
| @@ -0,0 +1 @@ | |||
| include $(RIOTMAKE)/periph.mk | |||
| #endif | ||
|
|
||
| #endif /* PERIPH_CPU_H */ | ||
| /** @} */ |
There was a problem hiding this comment.
newline, and maybe in other places (I won't check all of them)
| @@ -0,0 +1,3 @@ | |||
| ifneq (,$(filter saul_default,$(USEMODULE))) | |||
| USEMODULE += saul_gpio | |||
There was a problem hiding this comment.
The gpio_params.h is missing in the include directory. Maybe a mistake when factorizing the code ? It doesn't build examples/default
On which board ? L10 or L11 ?
Yes, this should be factorize (later). I had not idea how to reuse SAML21 drivers without adding another dependency. IMHO, the best way to do is merge timer, rtc and rtt driver to sam0_common. I'll work on this later I swear.
I'll fix.
I probably miss this driver.
I'll fix. |
0ea1763 to
23dcca3
Compare
|
@aabadie I'm sorry I had to rebased the branch to the current master to include some fix to flashpage for SAM0 but It does work yet on SAML10/SAML11. I'll investigate further but I'm not an expert.
I didn't squash, so you can have a look at the changes introduce by the new commits. |
aabadie
left a comment
There was a problem hiding this comment.
I retested with saml11-xpro and still found small things with the saul gpio, see below.
Also the tests/buttons doesn't work. Maybe the exti array needs an update (haven't checked the datasheet). Or there is something else with the peripheral driver ?
I'm running some tests on samr30-xpro (saml21 based) to check everything is ok.
| { | ||
| .name = "LED(orange)", | ||
| .pin = LED0_PIN, | ||
| .mode = GPIO_OUT |
There was a problem hiding this comment.
For me saml11-xpro, the LED and buttons are inverted.
| .mode = GPIO_OUT | |
| .mode = GPIO_OUT, | |
| .flags = (SAUL_GPIO_INVERTED | SAUL_GPIO_INIT_CLEAR) |
| { | ||
| .name = "Button(SW0)", | ||
| .pin = BTN0_PIN, | ||
| .mode = BTN0_MODE |
There was a problem hiding this comment.
| .mode = BTN0_MODE | |
| .mode = BTN0_MODE, | |
| .flags = SAUL_GPIO_INVERTED |
|
@dylad, I tested your last commit and it fixes the Just in case, for rebase/squash ease, you may want to split the commit in 2, one for saul, one for periph gpio. |
|
@aabadie Thanks for the SAUL tips, it is now fixed.
I forget something important for this |
Sure. |
|
Now that #10558, you need to rebase this PR. I'll do a full pass with all test applications to verify saml11-xpro before merging this PR. |
Is there a way to easily disable flashpage driver for SAML1X (which depend on sam0_common) ? |
I tested it and it was working, so there's no need to disable it. |
Really ? I'll triple-check that tonight. |
|
@aabadie I can confirm that driver_flashpage is broken right now for SAML11 only. If I cannot fix it in time I suggest to disable it. |
1e10266 to
1b4ce7c
Compare
|
Removed #10558 commits and rebased. |
This is strange, I tried |
Yes, the test_last command, ran from shell, fails. |
|
Ok, I'm not with the board right now so I can't re-test, will do tomorrow. I checked the automatic test code and it calls also |
|
Not proud of it but I found a possible workaround for my weird unittests bug. see lastest commit. |
| } | ||
|
|
||
| #ifdef CPU_SAML1X | ||
| void isr_eic0(void) |
There was a problem hiding this comment.
I would do this differently do avoid all this code duplication:
#ifdef CPU_SAML1X
void isr_eic0(void)
{
isr_eic();
}
[...]
void isr_eic3(void)
{
isr_eic();
}
void isr_eic_other(void)
{
isr_eic();
}
#endif /* SAML1X */
void isr_eic(void)
{
for (unsigned i = 0; i < NUMOF_IRQS; i++) {
if (_EIC->INTFLAG.reg & (1 << i)) {
_EIC->INTFLAG.reg = (1 << i);
gpio_config[i].cb(gpio_config[i].arg);
}
}
cortexm_isr_end();
}This is untested but I think it should work.
| @@ -92,19 +92,6 @@ void i2c_init(i2c_t dev) | |||
|
|
|||
| /* I2C using CLK GEN 0 */ | |||
| sercom_set_gen(bus(dev),i2c_config[dev].gclk_src); | |||
| #if defined(CPU_FAM_SAML21) || defined(CPU_FAM_SAMR30) | |||
There was a problem hiding this comment.
This seems unrelated. Is there a good reason to remove this part ?
There was a problem hiding this comment.
Oh right I remember now.
In fact I removed this part on purpose because this is pointless. Sercom slow clock is used only by some SMBus features like timeout. But we don't use them at all, so no need for this clock (and it saves some power).
There was a problem hiding this comment.
It is unclear to me what this code is about. Are you sure it's strictly not required ? What if someone wants to use the slow clock ?
There was a problem hiding this comment.
This code setup the SERCOM_GCLK_SLOW clock for the SERCOM your are using. (which is completely unrelated to the SERCOM_GCLK)
According to, SAML21 datasheet, the SERCOM_GLCK_SLOW is used for :
Two generic clocks ared used by SERCOM, GCLK_SERCOMx_CORE and
GCLK_SERCOM_SLOW.
The core clock (GCLK_SERCOMx_CORE) can clock the I 2 C when working as a master. The slow clock
(GCLK_SERCOM_SLOW) is required only for certain functions, e.g. SMBus timing. These clocks must
be configured and enabled in the Generic Clock Controller (GCLK) before using the I 2 C.
Those SMBus features can be active in the CTRLA register for each SERCOM. We're not using them in RIOT codebase.
See chapter 34.5.3 of SAML21 datasheet.
The SERCOM_SLOW clock is NOT used by UART nor SPI.
There was a problem hiding this comment.
I know it's annoying but I think this change should be in it's own PR because it's not only related to saml1x. In any case, there is no need for this PR to depend on it IIUC.
There was a problem hiding this comment.
I reapplied this piece of code. (And I will remove it as soon as this PR is merged ;) )
|
I have 2 remaining code comments, and I think they will be my last ones. I also re-ran the magic Python script and got no failure this time (except the 2 ones that we already know to be unrelated to this PR). |
|
comments answered/addressed. |
Add SAML10/SAML11 support through SAM0 because hardware IP are the same so reuse to avoid duplication
Disable optimization for this function only with CPU_SAML1X MCUs due to an internal crosscompiler bug
19406f1 to
7afacf9
Compare
|
The branch was squashed and the CI is now all green. Let's go. Thanks again for the good work and your perseverance @dylad ! |
|
great! |
|
What I'm missing in the merge is a precise description where the vendor files came from. Is a copy from ASF? Then I want to see which version ASF and whether it was a verbatim copy, and if not, then describe what was changed. Now that the merge is still fresh we should add the information before it is too late. The place to document is Notice the same can be said of #9437. In that PR the file |
|
@keestux When I started to write this PR, Microchip didn't include SAML10/SAML11 into ASF. It seems this is still the same today. (ASF 3.45). |
|
@dylad OK, I see. In that case we need to write down the version of these atpacks. I'll take a look and will come up with a (small) PR. Thanks for the URL, that helped. That said, URLs of Atmel are moving targets (to put it mildly). |
|
See #10914 |
Contribution description
This PR adds a very basic support for our first Cortex-M23 MCUs, SAML10 and SAML11 so people can start to play with it. These chips are the same except that SAML11 add security stuff (ARM TrustZone, non-secure+secure registers,...)
In the current state, only GPIOs, timer and UART work.SAML10/SAML11 IP peripherals are really close to SAML21. But I don't know if these MCUs should re-use stuff within sam0_common since they are cortex-m23 based...So right now, I copied GPIOs, timer , uart SAML21 drivers and make the required changes to use them but this can be optimized. (now or later). In fact, we can re-use all sam0 drivers with these MCUs but it will take much more time to fully test it. We can stay as it now and optimize later or we can do it now but I was hoping to see this PR merged for the incoming release.
Regarding MPU support, I intentionally prevent from using this feature on Cortex-M23 because armv8 introduces several changes and I need more time to rework and test this feature. I (or someone with more MPU knowledge) will do it later.
Testing procedure
run make BOARD=saml10-xpro -C [test_you_want]
or make BOARD=saml11-xpro -C [test_you_want]
EDBG will be used to flash the board.
Issues/PRs references
This PR is based on top of #10558
see also #10570 for EDBG update which supports these MCUs.