Skip to content
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

Add support for the Sillicon Labs Thunderboard Sense (updated) #7929

Merged
merged 4 commits into from
Nov 14, 2017

Conversation

basilfx
Copy link
Member

@basilfx basilfx commented Nov 1, 2017

So here is my fourth attempt of adding EFM32 to RIOT-OS. I choose to open a new PR, since a lot has changed since my last attempt (#5652). It is a similar PR to #5652 and #4824 and the comments of PR #4722 still apply.

This PR adds support for the Thunderboard Sense (SLTB001A) by Silicon Labs. It's still a vendor-library supported version, but this time this vendor library is added as an external package. It's split up in four commits, and this is as small as I can get it.

Most drivers have been implemented. The best example to check out is one with SAUL enabled, since drivers for the Si7021 and BMP280 are available (it does depend on #7921 for the time being).

  • Board description: here
  • Benchmarks: here

@basilfx basilfx added Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: new feature The issue requests / The PR implemements a new feature for RIOT labels Nov 1, 2017
@basilfx
Copy link
Member Author

basilfx commented Nov 1, 2017

To address some of the previous comments:

the emlib files need to be excluded from doxygen

The emlib files are now a package, the other vendor files are in the vendor/ folder now. Usage to emlib is limited to peripheral drivers and board files only.

the license header of the emlib files needs to be included into the license patterns

The emlib files are now a package.

for the peripheral drivers (except SPI and I2C for now): remove the #ifdef xx_NUMOF guards around the file, since the peripheral remodeling these are not longer needed

Turns out that this is still needed until selective compilation of peripherals is included (cannot find PR number this quick).

all vendor supplied headers should be moved to a vendor include (sub)dir as we did for all other CPUs. This helps to separate things and also tells doxygen not to look at them

Done.

I think it would be much better to provide the emlib as a pkg. As it seems, SiLabs provides it in their official github (https://github.com/SiliconLabs/Gecko_SDK/tree/master/platform/emlib/src), so this should be easy to do

Done, but using my own mirror, since Silicon Labs is not updating their repository anymore.

@basilfx
Copy link
Member Author

basilfx commented Nov 1, 2017

So, this PR is the start of fixing #1123. If this PR gets merged, I will open additional PR's to add support for the following boards (I own most of them):

Optionally (will replace existing one):

In total, I can add support for 715 additional MCUs (34 families). That is excluding devices with less than 4kb of flash and 8kb of memory.

@kaspar030
Copy link
Contributor

Would you mind rebaseing this to #7241? I hope to be able to merge it today...

@basilfx
Copy link
Member Author

basilfx commented Nov 2, 2017

@kaspar030 Yeah sure, I'll adapt this PR after #7241 gets merged.

@haukepetersen
Copy link
Contributor

Awesome, and thanks for sticking with this, despite the trouble I might have caused you :-)

Will review the PR now. Already tested it (with #7921 being merged) and it works like a charm...

Copy link
Contributor

@haukepetersen haukepetersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Some remarks (of which some are probably subjective and debatable..).

{
.name = "Button 1",
.pin = PB0_PIN,
.mode = GPIO_IN_PU
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could add .flags = SAUL_GPIO_INVERTED here to reflect active low circuit of the buttons...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks for de addition.

@@ -0,0 +1,19 @@
# Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += periph_adc
FEATURES_PROVIDED += periph_cpuid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you adapt the list of features to the changes introduced in #7880?

So move all features that don't depend on any board specific configuration (e.g. cpuid) to the (possibly shared) CPU's makefile.features, which then needs to be included from this file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only moved periph_cpuid.

#include "periph/gpio.h"
#include "periph/i2c.h"

#if BMP280_ENABLED || CCS811_ENABLED || ICM_20648_ENABLED || SI1133_ENABLED || SI7021_ENABLED || SI7210A_ENABLED || RGB_LED1_ENABLED || RGB_LED2_ENABLED || RGB_LED3_ENABLED || RGB_LED4_ENABLED
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line seems to slightly exceed the 80 char line length... :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed :-)

#if BMP280_ENABLED || CCS811_ENABLED || ICM_20648_ENABLED || SI1133_ENABLED || SI7021_ENABLED || SI7210A_ENABLED || RGB_LED1_ENABLED || RGB_LED2_ENABLED || RGB_LED3_ENABLED || RGB_LED4_ENABLED
static inline void board_usleep(uint32_t delay)
{
delay = (delay * 1000) / (1000 / (SystemCoreClock / 1000 / 1000));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delay = (delay * (SystemCoreClock / 1000000))?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, divide this value by 2, as the loop takes two instructions (nop and inc and compare)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I have it now:

MHz / 1000 / 1000 -> instructions per usec -> multiply by delay to get number of instructions to skip, divided by two (compare and inc).

#ifndef BMP280_ENABLED
#define BMP280_ENABLED (1)
#endif
#define BMP280_I2C (0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here and below: this should better be I2C_DEV(0)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


# enable memory protection unit
USEMODULE += mpu_stack_guard
USEMODULE += pm_layered
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't pm_layered be included from efm32_common?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the STM32F1/F2/F4 it is also on per-CPU base. Any preference?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The STMs do this on a per-CPU base, as we simply didn't touch all of the CPUs, yet. In the end this will be done in stm32_common. So as I also see all EFM32 CPUs use that module, I would put the usemodule define there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

export CPU_ARCH = cortex-m4
export CPU_FAM = efr32mg1p

# enable memory protection unit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for enabling memory protection as default for this CPU? Shouldn't this be something that is enabled by the user?

Copy link
Member Author

@basilfx basilfx Nov 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove it from here (I think I found it a good idea to enable it by default back then).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to remove it. This again a matter of expectation: CPUs should only include what their implementation really needs. Everything else should be up to external modules/applications to define.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,3 @@
MODULE = periph

include $(RIOTBASE)/Makefile.base
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably best to wait for #7241 and adapt before merging.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet included, but will do once merged.

WEAK_DEFAULT void isr_fpueh(void);

/* interrupt vector table */
ISR_VECTOR(1) const isr_t vector_cpu[CPU_IRQ_NUMOF] = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to use the indexed notation here, e.g.

    [ 0] = isr_em, ...
    [ 2] = isr_wdog0, ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -0,0 +1,11 @@
PKG_NAME=emlib
PKG_URL=https://github.com/basilfx/emlib
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wondering: as we use your fork of the emlib, couldn't we simply apply the patches directly to your fork and skip them in RIOT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine. I'll rename it, remove the patches and fix the URL.

@basilfx
Copy link
Member Author

basilfx commented Nov 5, 2017

Thanks @haukepetersen for the review. I have fixed almost all feedback, and improved a few other things:

  • Added hwrng (not supported by sltb001a, but by newer boards such as the slstk3402a).
  • Documentation fixes.
  • Tooling fixes.

I think #7241 is the only thing remaining, if you agree :-)

ifneq (,$(filter saul_default,$(USEMODULE)))
USEMODULE += saul_gpio
USEMODULE += bmp280
USEMODULE += si70xx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once #7296 is merged, here you can use the exact reference of the sensor (si7021 I think)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And included :-)

@haukepetersen
Copy link
Contributor

Nice. #7241 is on its way, I expect it to be merged today.

@basilfx
Copy link
Member Author

basilfx commented Nov 6, 2017

Support for #7241 added and some other fixes have been pushed.

There is one problem remaining: due to #7241, rtc.c is compiled when needed, but for some generations, I have rtc_gemstone.c. Since the SLTB001A is a Gemstone CPU, RTC will not work anymore.

What is the best way to fix this? (cc @kaspar030)?

(I see a similar case for kinetis_common/periph/hwrng_rngb.c, but I do not understand how this exception is compiled into RIOT-OS.)

Other than that, it should be ready.

@kaspar030
Copy link
Contributor

What is the best way to fix this? (cc @kaspar030)?

One way would be to have a different file for each rtc implementation, and then make "periph_rtc" depend on the right one (e.g., "periph_rtc_gemstone").
A good place for that dependency would probably be in cpu/$(CPU)/Makefile.dep.

(I see a similar case for kinetis_common/periph/hwrng_rngb.c, but I do not understand how this exception is compiled into RIOT-OS.)

hwrng_rngb is currently unused...

# setup serial terminal
include $(RIOTMAKE)/tools/serial.inc.mk

# include board dependencies
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this here, the file is included by the main Makefile.dep

endif

# i2c is required for environmental sensors
USEMODULE += periph_i2c
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sensors should specify their dependencies themselves, in drivers/Makefile.dep.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The board itself needs i2c for enabling the sensors (there is an additional chip on that board that is used as a GPIO expander).

I'll change the comment to reflect that situation.

Copy link
Contributor

@haukepetersen haukepetersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just this one thing and @kaspar030's last comment, then I think we should be ready to go!

#include "em_cmu.h"
#include "em_rtc.h"

#if defined(RTC_COUNT) && RTC_COUNT > 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these guards should be dropped now, as the RTC is only build if the feature is provided by the board/cpu, which again should only be the case if a valud RTC configuration is present...

#include "em_timer_utils.h"

/* guard file in case no PWM device was specified */
#ifdef PWM_NUMOF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need anymore, as this file is only build if a pwm feature is defined.

--> please check also all other periph implementation files for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@basilfx
Copy link
Member Author

basilfx commented Nov 12, 2017

I've updated + rebased this PR. All comments should be fixed.

I also implemented a flashpage driver. New benchmarks/compile results here.

@basilfx basilfx added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Nov 12, 2017
@basilfx basilfx force-pushed the feature/thunderboard_v2 branch 2 times, most recently from a847d4b to d60204c Compare November 12, 2017 13:55
@basilfx
Copy link
Member Author

basilfx commented Nov 12, 2017

It's finally green 😎

Last few commits include whitespace removal and Doxygen fixes.

If permitted, I'll squash it down into the first four commits.

Copy link
Contributor

@haukepetersen haukepetersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now! -> ACK

please squash

@basilfx
Copy link
Member Author

basilfx commented Nov 13, 2017

Squashed! And it's green!

I'll add the Wiki page after this is merged.

@basilfx basilfx dismissed kaspar030’s stale review November 13, 2017 15:38

Changes have been incorporated and @haukepetersen already approved.

@basilfx
Copy link
Member Author

basilfx commented Nov 13, 2017

Reworded 102d85b because it's the efr32mg1p instead of efm32mg1p. Very sloppy of me!

No other changes besides a rebase.

@basilfx basilfx merged commit df3389b into RIOT-OS:master Nov 14, 2017
@haukepetersen
Copy link
Contributor

Excellent! Well done and thanks for all the work you put in!

@aabadie aabadie added this to the Release 2018.01 milestone Jan 18, 2018
@basilfx basilfx deleted the feature/thunderboard_v2 branch January 9, 2020 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants