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 Silabs EFR32MG12P device and Thunderboard Sense 2 #9042

Merged
merged 3 commits into from
Oct 31, 2018

Conversation

diegosueiro
Copy link
Contributor

This PR adds the support for Silabs EFR32MG-SLTB004A (Thunderboard Sense 2) board in Zephyr.

It adds the Gecko SDK for EFR32MG12P devices into the ext/hal for Silabs, introduces leuart and i2c drivers for Gecko Devices and a sample application to read Relative Humidity and Temperature from Silabs
SI7021 chip via I2C interface.

This PR depends on #8930 (first 3 commits) and as soon as it gets merged I will update this one to remove the redundant commits.

@diegosueiro diegosueiro changed the title Thunderboard sense 2 Add support for Silabs EFR32MG device and Thunderboard Sense 2 Jul 20, 2018
@diegosueiro
Copy link
Contributor Author

Ping @chrta .

@diegosueiro diegosueiro changed the title Add support for Silabs EFR32MG device and Thunderboard Sense 2 Add support for Silabs EFR32MG12P device and Thunderboard Sense 2 Jul 20, 2018
@chrta
Copy link
Collaborator

chrta commented Jul 20, 2018

Are the emlib and the other gecko sdk files are still on 5.1.2, but the efm32mg files are from gecko sdk 5.5.0? Does this work? Or should we first update the gecko sdk to 5.5.0 for all already merged silabs boards?

@codecov-io
Copy link

codecov-io commented Jul 20, 2018

Codecov Report

Merging #9042 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #9042   +/-   ##
======================================
  Coverage    53.3%   53.3%           
======================================
  Files         215     215           
  Lines       25908   25908           
  Branches     5711    5711           
======================================
  Hits        13810   13810           
  Misses       9777    9777           
  Partials     2321    2321

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a19ae13...bddc8d7. Read the comment docs.

@diegosueiro
Copy link
Contributor Author

@chrta ,

It is working without any issues. If you compare the CMSIS headers between these versions you will see that it is more about adding defines and declarations.

The idea is to update the Gecko SDK in the near future.

.. _efr32mg_sltb004a:

EFR32MG-SLTB004A
###############
Copy link
Contributor

Choose a reason for hiding this comment

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

The title underline must be at least as long as the title above it, so add one more #

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed.

- One bi-color LED and two push buttons
- Power enable signals for fine grained power-control
- On-board SEGGER J-Link debugger for easy programming and debugging, which
includes a USB virtual COM port
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 should be indented to the O on the previous line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed.

- On-board SEGGER J-Link debugger for easy programming and debugging, which
includes a USB virtual COM port
- Mini Simplicity connector for access to energy profiling and advanced wireless
network debugging
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, indent the line to the M

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed.


The default configuration can be found in the defconfig file:

``boards/arm/efr32mg_sltb004a/efr32mg_sltb004a_defconfig``
Copy link
Contributor

Choose a reason for hiding this comment

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

delete the blank line and indent:

The default configuration can be found in the defconfig file:
``boards/arm/efr32mg_sltb004a/efr32mg_sltb004a_defconfig``.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed.

@diegosueiro diegosueiro force-pushed the thunderboard_sense_2 branch 2 times, most recently from e92f489 to 187026b Compare July 24, 2018 05:21
Copy link
Contributor

@dbkinder dbkinder left a comment

Choose a reason for hiding this comment

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

+1 for docs, thanks.

@diegosueiro
Copy link
Contributor Author

@galak and @MaureenHelm ,

Any feedbacks?

@galak galak added area: ARM ARM (32-bit) Architecture area: Boards EXT Has change or related to ext/ (obsolete) labels Sep 12, 2018
Copy link
Collaborator

@galak galak left a comment

Choose a reason for hiding this comment

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

Number of dts related comments.

config SOC_SERIES_EFR32MG12P
bool "EFR32MG12P Series MCU"
select CPU_CORTEX_M4
select CPU_HAS_FPU
Copy link
Collaborator

Choose a reason for hiding this comment

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

duplicated in config SOC_EFR32MG12P

@@ -6,7 +6,7 @@
#

menuconfig UART_GECKO
bool "Gecko uart driver"
bool "Gecko UART/USART driver"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you merge this with the rework of the driver patch.


#define CONFIG_UART_GECKO_0_BAUD_RATE SILABS_EFM32_USART_4000C000_CURRENT_SPEED
#define CONFIG_UART_GECKO_0_IRQ_PRI SILABS_EFM32_USART_4000C000_IRQ_0_PRIORITY
#define USART_0_RX_IRQ SILABS_GECKO_USART_4000C000_IRQ_0
Copy link
Collaborator

Choose a reason for hiding this comment

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

We've used CONFIG_ to prefix such defines. Want to keep this consistent with other DTS support for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm trying to keep the consistency with the define names automatically generated by the alias. I can check if I can do something in the devicetree yaml to have these defines automatically generated without needing a fixup.
Doesn't look nice to me to have in the driver a mixture between defines with and without CONFIG_ prefix.
I even sent an email to the mailing list about cleaning up these fixups and make usage of the aliases. Have you seen it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@galak,

I got rid of these fixups by adding the "interrupt-names" for the uarts nodes.

@@ -18,13 +18,13 @@

#ifdef CONFIG_SOC_PART_NUMBER_EFR32FG1P133F256GM48
#ifdef CONFIG_USART_GECKO_0
#if (CONFIG_USART_GECKO_0_GPIO_LOC == 0)
#if (USART_0_LOC == 0)
#define PIN_USART0_TXD {gpioPortA, 0, gpioModePushPull, 1}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why can't these just be:

`
#define PIN_USART0_TXD {gpioPortA, 0 + CONFIG_USART_0_LOC, gpioModePushPull, 1}
#define PIN_USART0_RXD {gpioPortA, 1 + CONFIG_USART_0_LOC, gpioModeInput, 1}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@galak,

The "loc" property is not directly related to the pin number.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, ignore my comments on loc. However we should rename to location.

#error ("Serial Driver for Gecko MCUs not implemented for this location index")
#elif (CONFIG_USART_GECKO_1_GPIO_LOC == 1)
#elif (USART_1_LOC == 1)
#define PIN_USART1_TXD {gpioPortF, 10, gpioModePushPull, 1}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar comment as above.

@@ -20,5 +24,6 @@

&uart0 {
current-speed = <115200>;
loc = <1>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should have this be tx-pin and rx-pin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean we need to have a loc (location) property for the tx-pin and rx-pin separately?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm thinking we should, it would be consistent with what the NRF SoC is doing in dts for the pins for rx & tx.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking at the manual, and maybe loc makes sense. I was tracing the code and came to soc_gpio_configure/GPIO_PinModeSet. So I'm confused about what location means for which pins are used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The loc is used to instruct which pin (ball) is going to be used. As a consequence, we need to pass which port will be used and the alternate configuration (location). Take a look at the section "6.7 Alternate Functionality Overview" in this document:
https://www.silabs.com/documents/public/data-sheets/efr32fg1-datasheet.pdf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@galak,

What do you say?

Take a look at the function uart_gecko_init_pins in drivers/serial/uart_gecko.c file to understand how the "loc" property is used. If you want we can slipt the loc for rx and tx because they can be eventually different.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For the EFM32WG (and all the older EFM32 i think), there is only one loc per U(S)ART, see e.g. https://www.silabs.com/documents/public/reference-manuals/EFM32WG-RM.pdf chapter 17.5.22 USARTn_ROUTE - I/O Routing Register.

This should be considered (one loc per peripheral vs. one loc per pin in a peripheral), if the driver implementation is changed.

dts/bindings/serial/silabs,gecko-uart.yaml Outdated Show resolved Hide resolved
@@ -27,4 +27,10 @@ properties:
category: required
description: required interrupts
generation: define

loc:
Copy link
Collaborator

Choose a reason for hiding this comment

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

should be rx-pin & tx-pin.

dts/bindings/serial/silabs,gecko-leuart.yaml Outdated Show resolved Hide resolved
@galak galak added area: I2C area: UART Universal Asynchronous Receiver-Transmitter labels Sep 12, 2018
@galak galak added the platform: Silabs Silicon Labs label Sep 12, 2018
@diegosueiro
Copy link
Contributor Author

diegosueiro commented Sep 16, 2018

@galak ,

Comments addressed.
Note that this PR has a dependency on PR #8930 and as soon as it gets merged I'll rebase this one.

@diegosueiro
Copy link
Contributor Author

@galak,

I'm not sure how to solve the merging conflicts in the Shippable testing environment.

@chrta
Copy link
Collaborator

chrta commented Sep 16, 2018

@galak,

I'm not sure how to solve the merging conflicts in the Shippable testing environment.

You have to rebase your branch on the current master. Because the soc files moved to another directory, you have to change a few things (board dts file, create soc dtsi file, change path to drivers is board cmake file etc).

@diegosueiro
Copy link
Contributor Author

@chrta,

I already rebased and I'm using the new SoC path.
The test failures are not related to this.

@chrta
Copy link
Collaborator

chrta commented Sep 16, 2018

@diegosueiro Your SoC commit 10045194958167858bf93db5c74b8405501d32fe is still based on an older master branch, e.g. there is no file dts/arm/silabs/mem.h any more.

@diegosueiro
Copy link
Contributor Author

@chrta,

You are right. I missed the 912b4a2 commit.
I'll rebase and push again.

@galak
Copy link
Collaborator

galak commented Oct 19, 2018

@pfalcon can you review the uart driver.

@galak
Copy link
Collaborator

galak commented Oct 19, 2018

I opened up PR #10728 to merge the base SoC support. The board code needs a little updating (for moving gpio info into device tree). Also would like to get a little more review on the uart/i2c drivers.

Copy link
Collaborator

@galak galak left a comment

Choose a reason for hiding this comment

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

Seems like the I2C driver doesn't use interrupts, so we should remove the code associated w/setting up interrupts and the isr handler.

@@ -52,4 +52,4 @@ config USART_GECKO_3
Enable support for Gecko USART3 port in the driver. Say y here if you
want to use USART3 device.

endif # UART_GECKO
endif # UART_GECKO
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this commit doing anything now? (drivers: Add more uart instances for Silabs Devices)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is showing as outdated. I think this is gone after I rebased it the master instead of the PR that was changing this file.

}


static void i2c_gecko_isr(void *arg)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why have isr code at all if it doesn't do anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll remove that after getting the others reviews.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I found the problem. I forgot to drop 2 commits when rebasing this PR against the master.
I'll rebase it dropping these two commits and remove the i2c interrupt function.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, I've merged the base SoC support, and add a few minor comments on the board code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done



/* Push button PB0 (SW0) */
#define PB0_GPIO_NAME CONFIG_GPIO_GECKO_PORTD_NAME
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move the button and LED into device tree out of board.h

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


if LEUART_GECKO

config LEUART_GECKO_0
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, but is that we still don't have means to deal with that in device tree?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm following the same pattern for drivers/serial/Kconfig.gecko

{
LEUART_TypeDef *base = DEV_BASE(dev);

LEUART_Tx(base, c);
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 suggest to add comment here that the blocking until a char can be sent happens in LEUART_Tx(). (Because majority of our drivers have explicit busy-wait loop in poll_out; so, the above looks confusing.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment.

LEUART_TypeDef *base = DEV_BASE(dev);
u32_t flags = LEUART_IntGet(base);

LEUART_IntClear(base, LEUART_IF_TXC);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you clear interrupt here? This function is supposed to be side effect free.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

Copy link
Contributor

@pfalcon pfalcon left a comment

Choose a reason for hiding this comment

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

(Github glitches today, let's see if my comments were recorded.)

Some questions/suggestions.

Copy link
Contributor

@pfalcon pfalcon left a comment

Choose a reason for hiding this comment

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

Just a note.

static void leuart_gecko_irq_tx_enable(struct device *dev)
{
LEUART_TypeDef *base = DEV_BASE(dev);
u32_t mask = LEUART_IEN_TXBL | LEUART_IEN_TXC;
Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding that this enables both "fifo has empty space" and "transmission complete" interrupts. Just a note that many other drivers don't enable "transmission complete" IRQ, because it's not really much useful.

Again, this is just a note of difference to other drivers. (If someone later would need to investigate any issues and path which led to them.
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just followed the same pattern for drivers/serial/uart_gecko.c driver.

@pfalcon
Copy link
Contributor

pfalcon commented Oct 23, 2018

@pfalcon can you review the uart driver.

Well, I tried. If there's something to guaranteedly change, is to add more comments ;-).

Otherwise, it's prompted me to prepare #10761 , because docs there still leave much to be desired (i.e. were partially updated previously).

@diegosueiro : Did you try to run samples/subsys/console/echo with this driver? That would a litmus test whether this driver does everything "good enough" or "not good enough". Please be sure to also test clipboard-pasting of reasonable amount of data into the sample (at least CONFIG_CONSOLE_GETCHAR_BUFSIZE should go without any char loss, but on many boards I tried many more than that can go w/o loss, let's say at least 2x).

Adds the Low Energy UART shim serial driver for Silabs Gecko Devices.

Signed-off-by: Diego Sueiro <diego.sueiro@gmail.com>
Adds the I2C shim driver for Silabs Gecko Devices.

Signed-off-by: Diego Sueiro <diego.sueiro@gmail.com>
@diegosueiro
Copy link
Contributor Author

@pfalcon

@diegosueiro : Did you try to run samples/subsys/console/echo with this driver? That would a litmus test whether this driver does everything "good enough" or "not good enough". Please be sure to also test clipboard-pasting of reasonable amount of data into the sample (at least CONFIG_CONSOLE_GETCHAR_BUFSIZE should go without any char loss, but on many boards I tried many more than that can go w/o loss, let's say at least 2x).

I tested as you suggested and it is working fine.

@pfalcon
Copy link
Contributor

pfalcon commented Oct 30, 2018

I tested as you suggested and it is working fine.

Great! Let me approve from my side.

Copy link
Contributor

@pfalcon pfalcon left a comment

Choose a reason for hiding this comment

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

+1 for UART driver.


#include <init.h>

static int efr32mg_sltb004a_init(struct device *dev)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this doesn't do anything, why do we need it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

#endif

/* Environment Sensors Enable Pin */
#define ENV_SENSE_ENABLE_NAME CONFIG_GPIO_GECKO_PORTF_NAME
Copy link
Collaborator

Choose a reason for hiding this comment

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

where is this used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one I used for testing an i2c sensor in the board to validate the i2c driver.
I'll remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

@galak galak left a comment

Choose a reason for hiding this comment

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

do we need board.c and some defines in board.h don't seem to be used.

The EFR32™ Mighty Gecko Starter Kit EFR32MG-SLTB004A (a.k.a
Thunderboard Sense 2) contains a MCU from the EFR32MG12P family built
on ARM® Cortex®-M4F processor with low power capabilities.

There is an On-Board J-Link Debugger that presents a virtual COM port
for general purpose application serial data transfer with this
interface and a Mass Storage for firmware flashing.

Signed-off-by: Diego Sueiro <diego.sueiro@gmail.com>
@galak galak merged commit 5540016 into zephyrproject-rtos:master Oct 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ARM ARM (32-bit) Architecture area: Boards area: I2C area: UART Universal Asynchronous Receiver-Transmitter EXT Has change or related to ext/ (obsolete) platform: Silabs Silicon Labs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants