samd21 firmware codebase improvement

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
opal
 
Posts: 27
Joined: Wed Nov 29, 2017 12:05 pm

samd21 firmware codebase improvement

Post by opal »

Hello dear circuitpython maintainers,

When building CP for SAMD21 I have noticed a duplicated directories with config files that differ in meaning but almost identical content wise (sometimes to the line number).

I mean:/home/vagrant/source/circuitpython-bb/ports/atmel-samd/asf4/samd21/config and
/home/vagrant/source/circuitpython-bb/ports/atmel-samd/asf4_conf/samd21

It is confusing when full-text searching the sources and all the time test compilation attempt is needed to figure out which setting will be considered for compilation.

Experimentally I have figured out that /home/vagrant/source/circuitpython-bb/ports/atmel-samd/asf4/samd21/config could be thrown away.

So, if you take for example RTC clock source definition and full-text search for CONF_GCLK_RTC_SRC (used later on for RTC initialization in common-hal/rtc/RTC.c ) you get:

Code: Select all

asf4_conf/samd21/peripheral_clk_config.h:323:#ifndef CONF_GCLK_RTC_SRC
asf4_conf/samd21/peripheral_clk_config.h:324:#define CONF_GCLK_RTC_SRC GCLK_CLKCTRL_GEN_GCLK2_Val
asf4_conf/samd51/peripheral_clk_config.h:591:#ifndef CONF_GCLK_RTC_SRC
asf4_conf/samd51/peripheral_clk_config.h:592:#define CONF_GCLK_RTC_SRC RTC_CLOCK_SOURCE
asf4/samd21/config_/peripheral_clk_config.h:323:#ifndef CONF_GCLK_RTC_SRC
asf4/samd21/config_/peripheral_clk_config.h:324:#define CONF_GCLK_RTC_SRC GCLK_CLKCTRL_GEN_GCLK0_Val
asf4/samd51/config/peripheral_clk_config.h:591:#ifndef CONF_GCLK_RTC_SRC
asf4/samd51/config/peripheral_clk_config.h:592:#define CONF_GCLK_RTC_SRC RTC_CLOCK_SOURCE
So, some 10 min of "mutual exclusion deduction" ;) is all the time needed, just to figure out which of all these is actually the init value.

I don't mention the samd51 stuff blended in here - that is a sad story on its own and separate discussion topic.

So, how I usually figure out what the right value is: I ignore samd51 stuff, which leaves us with

Code: Select all

asf4_conf/samd21/peripheral_clk_config.h:323:#ifndef CONF_GCLK_RTC_SRC
asf4_conf/samd21/peripheral_clk_config.h:324:#define CONF_GCLK_RTC_SRC GCLK_CLKCTRL_GEN_GCLK2_Val
asf4/samd21/config_/peripheral_clk_config.h:323:#ifndef CONF_GCLK_RTC_SRC
asf4/samd21/config_/peripheral_clk_config.h:324:#define CONF_GCLK_RTC_SRC GCLK_CLKCTRL_GEN_GCLK0_Val
Then I put some non-compilable garbage in front of the define in question and see if the compiler complains. One could check the Makefile -I directories, but will have to test anyways, so why not doing that directly.

That is how I navigate through all the settings. This exercise tires me and makes my customer impatient :)

Another advantage of getting read of that duplicated stuff is making it a bit easier for the version control. Less code for pushing/pulling changes all the time. Not a game changer, I agree, but still.

Would that be possible to remove /home/vagrant/source/circuitpython-bb/ports/atmel-samd/asf4/samd21/config from the source tree in the next release?

Unless there is a reason that stuff is in. I would be curious to know every consideration about the firmware source tree in general and code settings - in particular.

Regards

User avatar
tannewt
 
Posts: 3304
Joined: Thu Oct 06, 2016 8:48 pm

Re: samd21 firmware codebase improvement

Post by tannewt »

The config files within asf4/ are there because they are produced by Atmel Start. leaving them makes updating that code easier. We will eventually remove asf4 and asf4_conf because we are using asf4 less and less.

For example, clocks are now initialized without ASF here: https://github.com/adafruit/samd-periph ... cks.c#L167

(Its a submodule pulled into CircuitPython.)

User avatar
opal
 
Posts: 27
Joined: Wed Nov 29, 2017 12:05 pm

Re: samd21 firmware codebase improvement

Post by opal »

I was more confused not by the asf itself but rather by the duplicates of asf-sepcific configs. Makes it difficult to follow.

I can understand where these configs come from, but why are they duplicated - i don't get.

Same applies to samd51 code. Why mixing samd21 ans samd51 if you have board separation build scripts in place. There is no way you will need both of code variants in one project. Sure samd21 and samd51 overlap a lot. Why then not keeping the overlapping part common and have two separate firmware libs for 21 and 51? In the end you will specify the BOARD env. var. for building the firmware - that is where the decision is made which code to take, not these confusing #ifdefs everywhere.

About the clock initialization without asf4 (in your answer above) - what is the value if it does not use asf, if these functions will be anyways called by the code that does use asf: https://github.com/adafruit/circuitpyth ... sor/port.c

Just some thoughts. No rush answering them. I just got interested in design decisions while working/struggling with that code.

Regards

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”