Skip to content

Commit

Permalink
cpu/sam0_common: implement SERCOM time-sharing
Browse files Browse the repository at this point in the history
This adds a `periph_sercom` feature and implementation which
`periph_i2c`, `periph_uart`, and `periph_spi` are implemented on top.
This allows for sharing a single SERCOM instance to provide multiple
serial interfaces (in round-robin time-sharing fashion).

Note: In practice, a SERCOM can often not be shared if it needs to
      provide an UART.

Background:

While code using the I2C/SPI APIs is already optimized to share the
peripheral with `i2c_acquire()`/`spi_acquire()` and
`i2c_release()`/`spi_release()`, UARTs are typically not shared and most
users will not call `uart_poweron()` and `uart_poweroff()` to only have
the SERCOM in UART mode when actually needed. Worse: For many use cases
(such as stdin), the UART will need to be constantly running, as
receiving data happens asynchronously at unpredictable points in time.
  • Loading branch information
maribu committed Nov 26, 2024
1 parent 1f624ad commit c672afd
Show file tree
Hide file tree
Showing 45 changed files with 1,016 additions and 813 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,6 @@ static const uart_conf_t uart_config[] = {
},
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom0_2
#define UART_0_ISR_TX isr_sercom0_0
#define UART_1_ISR isr_sercom4_2
#define UART_1_ISR_TX isr_sercom4_0
#define UART_2_ISR isr_sercom1_2
#define UART_2_ISR_TX isr_sercom1_0

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
4 changes: 0 additions & 4 deletions boards/adafruit-itsybitsy-m4/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ static const uart_conf_t uart_config[] = {
},
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom3_2
#define UART_0_ISR_TX isr_sercom3_0

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
4 changes: 0 additions & 4 deletions boards/adafruit-metro-m4-express/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,6 @@ static const uart_conf_t uart_config[] = {
},
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom3_2
#define UART_0_ISR_TX isr_sercom3_0

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
4 changes: 0 additions & 4 deletions boards/adafruit-pybadge/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ static const uart_conf_t uart_config[] = {
}
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom5_2
#define UART_0_ISR_TX isr_sercom5_0

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
4 changes: 0 additions & 4 deletions boards/arduino-mkrwan1300/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ static const uart_conf_t uart_config[] = {
},
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom5
#define UART_1_ISR isr_sercom4

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
3 changes: 0 additions & 3 deletions boards/arduino-nano-33-iot/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ static const uart_conf_t uart_config[] = {
}
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom5

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
3 changes: 0 additions & 3 deletions boards/common/arduino-mkr/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ static const uart_conf_t uart_config[] = {
}
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom5

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
4 changes: 0 additions & 4 deletions boards/common/arduino-zero/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@ static const uart_conf_t uart_config[] = {
}
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom5
#define UART_1_ISR isr_sercom0

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
6 changes: 0 additions & 6 deletions boards/common/saml1x/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@ static const uart_conf_t uart_config[] = {
}
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom2_2
#define UART_0_ISR_TX isr_sercom2_0
#define UART_1_ISR isr_sercom1_2
#define UART_1_ISR_TX isr_sercom1_0

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
3 changes: 0 additions & 3 deletions boards/feather-m0/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ static const uart_conf_t uart_config[] = {
}
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom0

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
3 changes: 0 additions & 3 deletions boards/samd10-xmini/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ static const uart_conf_t uart_config[] = {
},
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom0

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
5 changes: 0 additions & 5 deletions boards/samd20-xpro/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,6 @@ static const uart_conf_t uart_config[] = {
},
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom3
#define UART_1_ISR isr_sercom4
#define UART_2_ISR isr_sercom0

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
5 changes: 0 additions & 5 deletions boards/samd21-xpro/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,6 @@ static const uart_conf_t uart_config[] = {
}
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom3
#define UART_1_ISR isr_sercom4
#define UART_2_ISR isr_sercom5

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
13 changes: 0 additions & 13 deletions boards/same54-xpro/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,6 @@ static const uart_conf_t uart_config[] = {
}
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom2_2
#define UART_0_ISR_TX isr_sercom2_0

#define UART_1_ISR isr_sercom0_2
#define UART_1_ISR_TX isr_sercom0_0

#define UART_2_ISR isr_sercom5_2
#define UART_2_ISR_TX isr_sercom5_0

#define UART_3_ISR isr_sercom1_2
#define UART_3_ISR_TX isr_sercom1_0

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
5 changes: 0 additions & 5 deletions boards/saml21-xpro/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ static const uart_conf_t uart_config[] = {
}
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom3
#define UART_1_ISR isr_sercom4
#define UART_2_ISR isr_sercom1

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
4 changes: 0 additions & 4 deletions boards/samr21-xpro/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,6 @@ static const uart_conf_t uart_config[] = {
}
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom0
#define UART_1_ISR isr_sercom5

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
3 changes: 0 additions & 3 deletions boards/samr30-xpro/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ static const uart_conf_t uart_config[] = {
}
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom0

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
4 changes: 0 additions & 4 deletions boards/samr34-xpro/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ static const uart_conf_t uart_config[] = {
}
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom0
#define UART_1_ISR isr_sercom3

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
3 changes: 0 additions & 3 deletions boards/seeeduino_xiao/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ static const uart_conf_t uart_config[] = {
}
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom4

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
4 changes: 0 additions & 4 deletions boards/sensebox_samd21/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ static const uart_conf_t uart_config[] = {
}
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom3
#define UART_1_ISR isr_sercom4

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
4 changes: 0 additions & 4 deletions boards/serpente/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ static const uart_conf_t uart_config[] = {
}
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom2
#define UART_1_ISR isr_sercom0

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
6 changes: 0 additions & 6 deletions boards/sodaq-autonomo/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ static const uart_conf_t uart_config[] = {
},
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom0
#define UART_1_ISR isr_sercom5
#define UART_2_ISR isr_sercom4
#define UART_3_ISR isr_sercom1

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
5 changes: 0 additions & 5 deletions boards/sodaq-explorer/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ static const uart_conf_t uart_config[] = {
},
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom5
#define UART_1_ISR isr_sercom4
#define UART_2_ISR isr_sercom0

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
4 changes: 0 additions & 4 deletions boards/sodaq-one/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ static const uart_conf_t uart_config[] = {
},
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom5
#define UART_1_ISR isr_sercom2

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
4 changes: 0 additions & 4 deletions boards/sodaq-sara-aff/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ static const uart_conf_t uart_config[] = {
},
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom5
#define UART_1_ISR isr_sercom0

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
4 changes: 0 additions & 4 deletions boards/sodaq-sara-sff/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ static const uart_conf_t uart_config[] = {
},
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom5
#define UART_1_ISR isr_sercom2

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
3 changes: 0 additions & 3 deletions boards/yarm/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ static const uart_conf_t uart_config[] = {
}
};

/* interrupt function name mapping */
#define UART_0_ISR isr_sercom3

#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

Expand Down
1 change: 1 addition & 0 deletions bootloaders/riotboot_serial/Makefile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ BOARD_INSUFFICIENT_MEMORY := \
frdm-kw41z \
pba-d-01-kw2x \
phynode-kw41z \
samr21-xpro \
usb-kw41z \
#
4 changes: 1 addition & 3 deletions cpu/cortexm_common/include/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@
#ifndef CPU_H
#define CPU_H

#include <stdio.h>

#include "irq.h"
#include "sched.h"
#include "thread.h"
#include "cpu_conf.h"
#include "cpu_conf.h" /* IWYU pragma: export */

#ifdef __cplusplus
extern "C" {
Expand Down
5 changes: 5 additions & 0 deletions cpu/sam0_common/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ ifneq (,$(filter periph_spi,$(USEMODULE)))
USEMODULE += periph_spi_gpio_mode
endif

ifneq (,$(filter periph_spi periph_uart periph_i2c,$(USEMODULE)))
FEATURES_REQUIRED += periph_sercom
USEMODULE += bitfield
endif

ifneq (,$(filter periph_sdmmc,$(USEMODULE)))
USEMODULE += sdmmc_sdhc
endif
Expand Down
1 change: 1 addition & 0 deletions cpu/sam0_common/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ FEATURES_PROVIDED += periph_sdmmc_auto_cmd12
FEATURES_PROVIDED += periph_sdmmc_hs
FEATURES_PROVIDED += periph_sdmmc_mmc
FEATURES_PROVIDED += periph_sdmmc_sdhc
FEATURES_PROVIDED += periph_sercom
FEATURES_PROVIDED += periph_spi_reconfigure
FEATURES_PROVIDED += periph_spi_gpio_mode
FEATURES_PROVIDED += periph_spi_reconfigure
Expand Down
Loading

0 comments on commit c672afd

Please sign in to comment.