Skip to content

Commit

Permalink
cpu/msp430: rework MSP430 x1xx periph drivers
Browse files Browse the repository at this point in the history
Move common code for USART (shared SPI / UART peripheral) to its
own file and allow sharing the USART peripheral to provide both
UART and SPI in round-robin fashion.

Note: Sharing an USART used as UART requires cooperation from the app:
- If the UART is used in TX-only mode (no RX callback), the driver
  will release the USART while not sending
- If the UART is used to also receive, the application needs to power
  the UART down while not expecting something to send. An
  `spi_acquire()` will be blocked while the UART is powered up.
  • Loading branch information
maribu committed Dec 6, 2023
1 parent 9e7e8a9 commit 5660ffd
Show file tree
Hide file tree
Showing 9 changed files with 716 additions and 198 deletions.
34 changes: 20 additions & 14 deletions boards/msb-430/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern "C" {
* @brief Clock configuration
*/
static const msp430_clock_params_t clock_params = {
.target_dco_frequency = 7372800U,
.target_dco_frequency = MHZ(8),
.lfxt1_frequency = 32768,
.main_clock_source = MAIN_CLOCK_SOURCE_DCOCLK,
.submain_clock_source = SUBMAIN_CLOCK_SOURCE_DCOCLK,
Expand Down Expand Up @@ -72,25 +72,31 @@ static const timer_conf_t timer_conf[] = {
* @name UART configuration
* @{
*/
#define UART_NUMOF (1U)

#define UART_BASE (&USART_1)
#define UART_SFR (&USART_1_SFR)
#define UART_IE_RX_BIT (1 << 4)
#define UART_IE_TX_BIT (1 << 5)
#define UART_ME_BITS (0x30)
#define UART_PORT (&PORT_3)
#define UART_RX_PIN (1 << 6)
#define UART_TX_PIN (1 << 7)
#define UART_RX_ISR (USART1RX_VECTOR)
#define UART_TX_ISR (USART1TX_VECTOR)
static const uart_conf_t uart_config[] = {
{
.uart = &usart1_as_uart,
},
};

#define UART0_RX_ISR (USART1RX_VECTOR)
#define UART0_TX_ISR (USART1TX_VECTOR)

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

/**
* @name SPI configuration
* @{
*/
#define SPI_NUMOF (1U)
static const spi_conf_t spi_config[] = {
{
/* beware of resource conflict with UART */
.spi = &usart1_as_spi,
},
};

#define SPI_NUMOF ARRAY_SIZE(spi_config)
/** @} */

/* SPI configuration */
#define SPI_BASE (&USART_1)
Expand Down
36 changes: 15 additions & 21 deletions boards/msb-430h/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,35 +71,29 @@ static const timer_conf_t timer_conf[] = {
* @name UART configuration
* @{
*/
#define UART_NUMOF (1U)
static const uart_conf_t uart_config[] = {
{
.uart = &usart1_as_uart,
},
};

#define UART0_RX_ISR (USART1RX_VECTOR)
#define UART0_TX_ISR (USART1TX_VECTOR)

#define UART_BASE (&USART_1)
#define UART_SFR (&USART_1_SFR)
#define UART_IE_RX_BIT (1 << 4)
#define UART_IE_TX_BIT (1 << 5)
#define UART_ME_BITS (0x30)
#define UART_PORT (&PORT_3)
#define UART_RX_PIN (1 << 6)
#define UART_TX_PIN (1 << 7)
#define UART_RX_ISR (USART1RX_VECTOR)
#define UART_TX_ISR (USART1TX_VECTOR)
#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

/**
* @name SPI configuration
* @{
*/
#define SPI_NUMOF (1U)
static const spi_conf_t spi_config[] = {
{
.spi = &usart0_as_spi,
},
};

/* SPI configuration */
#define SPI_BASE (&USART_0)
#define SPI_SFR (&USART_0_SFR)
#define SPI_IE_RX_BIT (1 << 6)
#define SPI_IE_TX_BIT (1 << 7)
#define SPI_ME_BIT (1 << 6)
#define SPI_PIN_MISO GPIO_PIN(P3, 2)
#define SPI_PIN_MOSI GPIO_PIN(P3, 1)
#define SPI_PIN_CLK GPIO_PIN(P3, 3)
#define SPI_NUMOF ARRAY_SIZE(spi_config)
/** @} */

#ifdef __cplusplus
Expand Down
36 changes: 15 additions & 21 deletions boards/olimex-msp430-h1611/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,35 +71,29 @@ static const timer_conf_t timer_conf[] = {
* @name UART configuration
* @{
*/
#define UART_NUMOF (1U)
static const uart_conf_t uart_config[] = {
{
.uart = &usart1_as_uart,
},
};

#define UART0_RX_ISR (USART1RX_VECTOR)
#define UART0_TX_ISR (USART1TX_VECTOR)

#define UART_BASE (&USART_1)
#define UART_SFR (&USART_1_SFR)
#define UART_IE_RX_BIT (1 << 4)
#define UART_IE_TX_BIT (1 << 5)
#define UART_ME_BITS (0x30)
#define UART_PORT (&PORT_3)
#define UART_RX_PIN (1 << 6)
#define UART_TX_PIN (1 << 7)
#define UART_RX_ISR (USART1RX_VECTOR)
#define UART_TX_ISR (USART1TX_VECTOR)
#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

/**
* @name SPI configuration
* @{
*/
#define SPI_NUMOF (1U)
static const spi_conf_t spi_config[] = {
{
.spi = &usart0_as_spi,
},
};

/* SPI configuration */
#define SPI_BASE (&USART_0)
#define SPI_SFR (&USART_0_SFR)
#define SPI_IE_RX_BIT (1 << 6)
#define SPI_IE_TX_BIT (1 << 7)
#define SPI_ME_BIT (1 << 6)
#define SPI_PIN_MISO GPIO_PIN(P3, 2)
#define SPI_PIN_MOSI GPIO_PIN(P3, 1)
#define SPI_PIN_CLK GPIO_PIN(P3, 3)
#define SPI_NUMOF ARRAY_SIZE(spi_config)
/** @} */

#ifdef __cplusplus
Expand Down
35 changes: 15 additions & 20 deletions boards/telosb/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,34 +71,29 @@ static const timer_conf_t timer_conf[] = {
* @name UART configuration
* @{
*/
#define UART_NUMOF (1U)
static const uart_conf_t uart_config[] = {
{
.uart = &usart1_as_uart,
},
};

#define UART0_RX_ISR (USART1RX_VECTOR)
#define UART0_TX_ISR (USART1TX_VECTOR)

#define UART_BASE (&USART_1)
#define UART_SFR (&USART_1_SFR)
#define UART_IE_RX_BIT (1 << 4)
#define UART_IE_TX_BIT (1 << 5)
#define UART_ME_BITS (0x30)
#define UART_PORT (&PORT_3)
#define UART_RX_PIN (1 << 6)
#define UART_TX_PIN (1 << 7)
#define UART_RX_ISR (USART1RX_VECTOR)
#define UART_TX_ISR (USART1TX_VECTOR)
#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

/**
* @name SPI configuration
* @{
*/
#define SPI_NUMOF (1U)
static const spi_conf_t spi_config[] = {
{
.spi = &usart0_as_spi,
},
};

#define SPI_BASE (&USART_0)
#define SPI_SFR (&USART_0_SFR)
#define SPI_IE_RX_BIT (1 << 6)
#define SPI_IE_TX_BIT (1 << 7)
#define SPI_ME_BIT (1 << 6)
#define SPI_PIN_MISO GPIO_PIN(P3, 2)
#define SPI_PIN_MOSI GPIO_PIN(P3, 1)
#define SPI_PIN_CLK GPIO_PIN(P3, 3)
#define SPI_NUMOF ARRAY_SIZE(spi_config)
/** @} */

#ifdef __cplusplus
Expand Down
Loading

0 comments on commit 5660ffd

Please sign in to comment.