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

drivers: spi: gecko: Add new driver for SPI communication via EUSART #77353

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions boards/sparkfun/thing_plus_matter_mgm240p/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ static int sparkfun_thing_plus_mgm240p_init_clocks(void)
#endif
#if defined(_CMU_EM01GRPBCLKCTRL_MASK)
CMU_ClockSelectSet(cmuClock_EM01GRPBCLK, cmuSelect_HFRCODPLL);
#endif
#if defined(_CMU_EM01GRPCCLKCTRL_MASK)
CMU_ClockSelectSet(cmuClock_EM01GRPCCLK, cmuSelect_HFRCODPLL);
#endif
CMU_ClockSelectSet(cmuClock_EM23GRPACLK, cmuSelect_LFRCO);
CMU_ClockSelectSet(cmuClock_EM4GRPACLK, cmuSelect_LFRCO);
Expand Down
10 changes: 5 additions & 5 deletions boards/sparkfun/thing_plus_matter_mgm240p/doc/index.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. _sparkfun_thing_plus_mgm240p:

SPARKFUN THING PLUS MATTER
SparkFun Thing Plus Matter
###########################

Overview
Expand All @@ -15,7 +15,7 @@ ARM Cortex®-M33F processor with excellent low power capabilities.
:align: center
:alt: MGM240P Sparkfun Think Plus Matter

xG24-MGM240P (image courtesy of Sparkfun)
MGM240P Sparkfun Think Plus Matter (image courtesy of Sparkfun)

Hardware
********
Expand Down Expand Up @@ -81,7 +81,7 @@ means Pin number 2 on PORTA, as used in the board's datasheets and manuals.
+-------+-------------+-------------------------------------+

The default configuration can be found in
:zephyr_file:`boards/silabs/sparkfun_thing_plus_mgm240p/sparkfun_thing_plus_mgm240p_defconfig`
:zephyr_file:`boards/silabs/sparkfun_thing_plus_matter_mgm240p/sparkfun_thing_plus_matter_mgm240p_defconfig`

System Clock
============
Expand Down Expand Up @@ -128,7 +128,7 @@ terminal session:

.. code-block:: console

Hello World! _sparkfun_thing_plus_mgm240p
Hello World! _sparkfun_thing_plus_matter_mgm240p

Bluetooth
=========
Expand All @@ -146,7 +146,7 @@ this example.

.. zephyr-app-commands::
:zephyr-app: samples/bluetooth/observer
:board: sparkfun_thing_plus_mgm240p
:board: sparkfun_thing_plus_matter_mgm240p
:goals: build

.. _EFR32MG24 Website:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
};
};

eusart1_default: eusart1_default {
group1 {
psels = <GECKO_PSEL(SPI_SCK, C, 2)>,
<GECKO_PSEL(SPI_MISO, C, 3)>,
<GECKO_PSEL(SPI_MOSI, C, 6)>,
<GECKO_PSEL(SPI_CSN, A, 7)>;
};
};

i2c0_default: i2c0_default {
group1 {
psels = <GECKO_PSEL(I2C_SDA, B, 3)>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

aliases {
led0 = &blue_led;
spi0 = &eusart1;
watchdog0 = &wdog0;
};

Expand Down Expand Up @@ -53,6 +54,18 @@
pinctrl-names = "default";
status = "okay";
};

&eusart1 {
Terezvent marked this conversation as resolved.
Show resolved Hide resolved
compatible = "silabs,gecko-spi-eusart";

#address-cells = <1>;
#size-cells = <0>;
pinctrl-0 = <&eusart1_default>;
pinctrl-names = "default";

status = "okay";
};

&i2c0 {
pinctrl-0 = <&i2c0_default>;
pinctrl-names = "default";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ supported:
- uart
- spi
- watchdog
- clock_control
testing:
ignore_tags:
- net
Expand Down
55 changes: 53 additions & 2 deletions drivers/pinctrl/pinctrl_gecko.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintp
(void)base;
#endif /*USART_COUNT > 1*/

#ifdef CONFIG_SPI_GECKO_EUSART
EUSART_TypeDef *ebase = (EUSART_TypeDef *)reg;
int eusart_num = EUSART_NUM(ebase);
#endif

#endif

#ifdef CONFIG_I2C_GECKO
Expand Down Expand Up @@ -171,7 +176,53 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintp
#endif /* CONFIG_SOC_FAMILY_SILABS_S1 */
#endif /* CONFIG_UART_GECKO */

#ifdef CONFIG_SPI_GECKO
#ifdef CONFIG_SPI_GECKO_EUSART
case GECKO_FUN_SPI_SCK:
pin_config.mode = gpioModePushPull;
pin_config.out = 1;
GPIO->EUSARTROUTE[eusart_num].SCLKROUTE =
(pin_config.port << _GPIO_EUSART_SCLKROUTE_PORT_SHIFT) |
(pin_config.pin << _GPIO_EUSART_SCLKROUTE_PIN_SHIFT);
GPIO->EUSARTROUTE[eusart_num].ROUTEEN |= GPIO_EUSART_ROUTEEN_SCLKPEN;
GPIO_PinModeSet(pin_config.port, pin_config.pin, pin_config.mode,
pin_config.out);
break;

case GECKO_FUN_SPI_CSN:
pin_config.mode = gpioModePushPull;
pin_config.out = 1;
GPIO->EUSARTROUTE[eusart_num].CSROUTE =
(pin_config.port << _GPIO_EUSART_CSROUTE_PORT_SHIFT) |
(pin_config.pin << _GPIO_EUSART_CSROUTE_PIN_SHIFT);
GPIO->EUSARTROUTE[eusart_num].ROUTEEN |= GPIO_EUSART_ROUTEEN_CSPEN;
GPIO_PinModeSet(pin_config.port, pin_config.pin, pin_config.mode,
pin_config.out);
break;

case GECKO_FUN_SPI_MOSI:
pin_config.mode = gpioModePushPull;
pin_config.out = 1;
GPIO->EUSARTROUTE[eusart_num].TXROUTE =
(pin_config.port << _GPIO_EUSART_TXROUTE_PORT_SHIFT) |
(pin_config.pin << _GPIO_EUSART_TXROUTE_PIN_SHIFT);
GPIO->EUSARTROUTE[eusart_num].ROUTEEN |= GPIO_EUSART_ROUTEEN_TXPEN;
GPIO_PinModeSet(pin_config.port, pin_config.pin, pin_config.mode,
pin_config.out);
break;

case GECKO_FUN_SPI_MISO:
pin_config.mode = gpioModeInput;
pin_config.out = 1;
GPIO->EUSARTROUTE[eusart_num].RXROUTE =
(pin_config.port << _GPIO_EUSART_RXROUTE_PORT_SHIFT) |
(pin_config.pin << _GPIO_EUSART_RXROUTE_PIN_SHIFT);
GPIO->EUSARTROUTE[EUSART_NUM(EUSART1)].ROUTEEN |= GPIO_EUSART_ROUTEEN_RXPEN;
GPIO_PinModeSet(pin_config.port, pin_config.pin, pin_config.mode,
pin_config.out);
break;
#endif /*CONFIG_SPI_GECKO_EUSART*/

#ifdef CONFIG_SPI_GECKO_USART
#ifdef CONFIG_SOC_FAMILY_SILABS_S1
case GECKO_FUN_SPIM_SCK:
pin_config.mode = gpioModePushPull;
Expand Down Expand Up @@ -287,7 +338,7 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintp
pin_config.out);
break;
#endif /* CONFIG_SOC_FAMILY_SILABS_S1 */
#endif /* CONFIG_SPI_GECKO */
#endif /* CONFIG_SPI_GECKO_USART */

#ifdef CONFIG_I2C_GECKO
case GECKO_FUN_I2C_SDA:
Expand Down
3 changes: 2 additions & 1 deletion drivers/spi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ zephyr_library_sources_ifdef(CONFIG_SPI_LITEX spi_litex.c)
zephyr_library_sources_ifdef(CONFIG_SPI_LITEX_LITESPI spi_litex_litespi.c)
zephyr_library_sources_ifdef(CONFIG_SPI_OC_SIMPLE spi_oc_simple.c)
zephyr_library_sources_ifdef(CONFIG_SPI_XEC_QMSPI spi_xec_qmspi.c)
zephyr_library_sources_ifdef(CONFIG_SPI_GECKO spi_gecko.c)
zephyr_library_sources_ifdef(CONFIG_SPI_GECKO_USART spi_gecko_usart.c)
zephyr_library_sources_ifdef(CONFIG_SPI_GECKO_EUSART spi_gecko_eusart.c)
zephyr_library_sources_ifdef(CONFIG_SPI_XLNX_AXI_QUADSPI spi_xlnx_axi_quadspi.c)
zephyr_library_sources_ifdef(CONFIG_ESP32_SPIM spi_esp32_spim.c)
zephyr_library_sources_ifdef(CONFIG_SPI_TEST spi_test.c)
Expand Down
4 changes: 3 additions & 1 deletion drivers/spi/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ source "drivers/spi/Kconfig.oc_simple"

source "drivers/spi/Kconfig.xec_qmspi"

source "drivers/spi/Kconfig.gecko"
source "drivers/spi/Kconfig.gecko_usart"

source "drivers/spi/Kconfig.gecko_eusart"

source "drivers/spi/Kconfig.xlnx"

Expand Down
13 changes: 13 additions & 0 deletions drivers/spi/Kconfig.gecko_eusart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Gecko SPI configuration option

# Copyright (c) 2024 Daikin Comfort Technologies North America, Inc.
# SPDX-License-Identifier: Apache-2.0

config SPI_GECKO_EUSART
bool "Gecko EUSART SPI controller driver"
default y
depends on DT_HAS_SILABS_GECKO_SPI_EUSART_ENABLED
depends on GPIO
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
depends on GPIO
select GPIO

select SOC_GECKO_EUSART
help
Enable the EUSART SPI peripherals on Gecko
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright (c) 2019 Christian Taedcke <[email protected]>
# SPDX-License-Identifier: Apache-2.0

config SPI_GECKO
config SPI_GECKO_USART
bool "Gecko SPI controller driver"
default y
depends on DT_HAS_SILABS_GECKO_SPI_USART_ENABLED
Expand Down
Loading
Loading