Skip to content

Commit

Permalink
Merge pull request #14057 from bergzand/pr/nrf52/dma_spi
Browse files Browse the repository at this point in the history
nrf52: Implement EasyDMA-based SPI peripheral implemenation
  • Loading branch information
benpicco authored May 18, 2020
2 parents 87403c7 + e76ee57 commit 9f707bf
Show file tree
Hide file tree
Showing 19 changed files with 513 additions and 36 deletions.
5 changes: 3 additions & 2 deletions boards/acd52832/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ extern "C" {
*/
static const spi_conf_t spi_config[] = {
{
.dev = NRF_SPI0,
.dev = NRF_SPIM0,
.sclk = 4,
.mosi = 3,
.miso = 13
.miso = 13,
.ppi = 0
}
};

Expand Down
4 changes: 2 additions & 2 deletions boards/adafruit-clue/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ static const i2c_conf_t i2c_config[] = {
*/
static const spi_conf_t spi_config[] = {
{ /* External connectors */
.dev = NRF_SPI0,
.dev = NRF_SPIM0,
.sclk = GPIO_PIN(0, 23), /* D13 */
.mosi = GPIO_PIN(0, 21), /* D15 */
.miso = GPIO_PIN(0, 22), /* D14 */
},
{ /* TFT LCD screen */
.dev = NRF_SPI1,
.dev = NRF_SPIM1,
.sclk = GPIO_PIN(0, 14),
.mosi = GPIO_PIN(0, 15),
.miso = GPIO_PIN(0, 0),
Expand Down
2 changes: 1 addition & 1 deletion boards/arduino-nano-33-ble/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static const i2c_conf_t i2c_config[] = {
*/
static const spi_conf_t spi_config[] = {
{
.dev = NRF_SPI0,
.dev = NRF_SPIM0,
.sclk = GPIO_PIN(0, 13),
.mosi = GPIO_PIN(1, 1),
.miso = GPIO_PIN(1, 8),
Expand Down
5 changes: 4 additions & 1 deletion boards/common/nrf52/include/cfg_spi_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ extern "C" {
*/
static const spi_conf_t spi_config[] = {
{
.dev = NRF_SPI0,
.dev = NRF_SPIM0,
.sclk = GPIO_PIN(0, 15),
.mosi = GPIO_PIN(0, 13),
.miso = GPIO_PIN(0, 14),
#ifdef ERRATA_SPI_SINGLE_BYTE_WORKAROUND
.ppi = 0,
#endif
}
};

Expand Down
4 changes: 2 additions & 2 deletions boards/common/particle-mesh/include/periph_conf_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ extern "C" {
*/
static const spi_conf_t spi_config[] = {
{
.dev = NRF_SPI0,
.dev = NRF_SPIM0,
.sclk = 15,
.mosi = 13,
.miso = 14
.miso = 14,
}
};

Expand Down
4 changes: 2 additions & 2 deletions boards/feather-nrf52840/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ static const uart_conf_t uart_config[] = {
*/
static const spi_conf_t spi_config[] = {
{
.dev = NRF_SPI0,
.dev = NRF_SPIM0,
.sclk = 14,
.mosi = 13,
.miso = 15
.miso = 15,
}
};

Expand Down
4 changes: 2 additions & 2 deletions boards/nrf52840dk/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ extern "C" {
*/
static const spi_conf_t spi_config[] = {
{
.dev = NRF_SPI0,
.dev = NRF_SPIM0,
.sclk = GPIO_PIN(1, 15),
.mosi = GPIO_PIN(1, 13),
.miso = GPIO_PIN(1, 14),
},
{
.dev = NRF_SPI1,
.dev = NRF_SPIM1,
.sclk = GPIO_PIN(0, 19),
.mosi = GPIO_PIN(0, 20),
.miso = GPIO_PIN(0, 21),
Expand Down
3 changes: 2 additions & 1 deletion boards/nrf52dk/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ extern "C" {
*/
static const spi_conf_t spi_config[] = {
{
.dev = NRF_SPI0,
.dev = NRF_SPIM0,
.sclk = GPIO_PIN(0, 25),
.mosi = GPIO_PIN(0, 23),
.miso = GPIO_PIN(0, 24),
.ppi = 0,
}
};
#define SPI_NUMOF ARRAY_SIZE(spi_config)
Expand Down
3 changes: 2 additions & 1 deletion boards/pinetime/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ extern "C" {
*/
static const spi_conf_t spi_config[] = {
{
.dev = NRF_SPI0,
.dev = NRF_SPIM0,
.sclk = GPIO_PIN(0, 2),
.mosi = GPIO_PIN(0, 3),
.miso = GPIO_PIN(0, 4),
.ppi = 0,
}
};

Expand Down
2 changes: 1 addition & 1 deletion boards/reel/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static const uart_conf_t uart_config[] = {
*/
static const spi_conf_t spi_config[] = {
{
.dev = NRF_SPI0,
.dev = NRF_SPIM0,
.sclk = GPIO_PIN(0, 19),
.mosi = GPIO_PIN(0, 20),
.miso = GPIO_PIN(0, 21),
Expand Down
3 changes: 2 additions & 1 deletion boards/ruuvitag/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ extern "C" {
*/
static const spi_conf_t spi_config[] = {
{
.dev = NRF_SPI0,
.dev = NRF_SPIM0,
.sclk = 29,
.mosi = 25,
.miso = 28,
.ppi = 0,
}
};

Expand Down
10 changes: 10 additions & 0 deletions cpu/nrf51/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ typedef struct {
i2c_speed_t speed; /**< bus speed */
} i2c_conf_t;

/**
* @brief SPI configuration values
*/
typedef struct {
NRF_SPI_Type *dev; /**< SPI device used */
gpio_t sclk; /**< CLK pin */
gpio_t mosi; /**< MOSI pin */
gpio_t miso; /**< MISO pin */
} spi_conf_t;

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 1 addition & 5 deletions cpu/nrf5x_common/periph/spi.c → cpu/nrf51/periph/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

/**
* @ingroup cpu_nrf5x_common
* @ingroup cpu_nrf51
* @ingroup drivers_periph_spi
* @{
*
Expand Down Expand Up @@ -64,10 +64,8 @@ int spi_acquire(spi_t bus, spi_cs_t cs, spi_mode_t mode, spi_clk_t clk)
(void) cs;

mutex_lock(&locks[bus]);
#ifdef CPU_FAM_NRF51
/* power on the bus (NRF51 only) */
dev(bus)->POWER = 1;
#endif
/* configure bus */
dev(bus)->CONFIG = mode;
dev(bus)->FREQUENCY = clk;
Expand All @@ -81,9 +79,7 @@ void spi_release(spi_t bus)
{
/* power off everything */
dev(bus)->ENABLE = 0;
#ifdef CPU_FAM_NRF51
dev(bus)->POWER = 0;
#endif
mutex_unlock(&locks[bus]);
}

Expand Down
7 changes: 7 additions & 0 deletions cpu/nrf52/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@ ifneq (,$(filter nrf802154,$(USEMODULE)))
USEMODULE += netdev_ieee802154
endif

# The nrf52832 requires gpio IRQ with SPI to work around errata 58
ifneq (,$(filter nrf52832xxaa,$(CPU_MODEL)))
ifneq (,$(filter periph_spi,$(USEMODULE)))
FEATURES_REQUIRED += periph_gpio_irq
endif
endif

include $(RIOTCPU)/nrf5x_common/Makefile.dep
include $(RIOTCPU)/cortexm_common/Makefile.dep
56 changes: 56 additions & 0 deletions cpu/nrf52/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
extern "C" {
#endif

/**
* @brief Enable the workaround for the SPI single byte transmit errata (No.
* 58 on the nrf52832)
*/
#ifdef CPU_MODEL_NRF52832XXAA
#define ERRATA_SPI_SINGLE_BYTE_WORKAROUND (1)
#endif

/**
* @brief System core clock speed, fixed to 64MHz for all NRF52x CPUs
*/
Expand Down Expand Up @@ -54,6 +62,14 @@ extern "C" {
*/
#define ADC_NUMOF (9U)

/**
* @brief SPI temporary buffer size for storing const data in RAM before
* initiating DMA transfer
*/
#ifndef CONFIG_SPI_MBUF_SIZE
#define CONFIG_SPI_MBUF_SIZE 64
#endif

/**
* @brief nRF52 specific naming of ADC lines (for convenience)
*/
Expand Down Expand Up @@ -180,6 +196,46 @@ typedef struct {
} uart_conf_t;
#endif

/**
* @brief SPI configuration values
*/
typedef struct {
NRF_SPIM_Type *dev; /**< SPI device used */
gpio_t sclk; /**< CLK pin */
gpio_t mosi; /**< MOSI pin */
gpio_t miso; /**< MISO pin */
#if ERRATA_SPI_SINGLE_BYTE_WORKAROUND
uint8_t ppi; /**< PPI channel */
#endif
} spi_conf_t;


/**
* @brief Common SPI/I2C interrupt callback
*
* @param arg Opaque context pointer
*/
typedef void (*spi_twi_irq_cb_t)(void *arg);

/**
* @brief Reqister a SPI IRQ handler for a shared I2C/SPI irq vector
*
* @param bus bus to register the IRQ handler on
* @param cb callback to call on IRQ
* @param arg Argument to pass to the handler
*/
void spi_twi_irq_register_spi(NRF_SPIM_Type *bus,
spi_twi_irq_cb_t cb, void *arg);

/**
* @brief Reqister a I2C IRQ handler for a shared I2C/SPI irq vector
*
* @param bus bus to register the IRQ handler on
* @param cb callback to call on IRQ
* @param arg Argument to pass to the handler
*/
void spi_twi_irq_register_i2c(NRF_TWIM_Type *bus,
spi_twi_irq_cb_t cb, void *arg);
#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit 9f707bf

Please sign in to comment.