Skip to content

Commit 6967949

Browse files
committed
Add hardware mapping for BUSIO.SPI for MAX32690
Currently coupled a bit to APARD32690-SL board. Will refactor after testing BUSIO.SPI Signed-off-by: Brandon-Hurst <[email protected]>
1 parent edf069d commit 6967949

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

ports/analog/Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ INC += \
8787
-I$(PERIPH_SRC)/TMR \
8888
-I$(PERIPH_SRC)/RTC \
8989
-I$(PERIPH_SRC)/UART \
90-
-I$(PERIPH_SRC)/I2C
90+
-I$(PERIPH_SRC)/I2C \
91+
-I$(PERIPH_SRC)/SPI
9192

9293
INC += -I$(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/GCC
9394

@@ -122,16 +123,18 @@ SRC_MAX32 += \
122123
$(PERIPH_SRC)/UART/uart_$(DIE_TYPE).c \
123124
$(PERIPH_SRC)/UART/uart_revb.c \
124125
$(PERIPH_SRC)/I2C/i2c_$(DIE_TYPE).c \
125-
$(PERIPH_SRC)/I2C/i2c_reva.c
126+
$(PERIPH_SRC)/I2C/i2c_reva.c \
127+
$(PERIPH_SRC)/SPI/spi_$(DIE_TYPE).c \
128+
$(PERIPH_SRC)/SPI/spi_reva1.c
126129

127130
SRC_C += $(SRC_MAX32) \
128131
boards/$(BOARD)/board.c \
129132
boards/$(BOARD)/pins.c \
130133
peripherals/$(MCU_VARIANT_LOWER)/pins.c \
131134
peripherals/$(MCU_VARIANT_LOWER)/gpios.c \
132135
peripherals/$(MCU_VARIANT_LOWER)/max32_uart.c \
133-
peripherals/$(MCU_VARIANT_LOWER)/max32_i2c.c
134-
136+
peripherals/$(MCU_VARIANT_LOWER)/max32_i2c.c \
137+
peripherals/$(MCU_VARIANT_LOWER)/max32_spi.c
135138

136139
# *******************************************************************************
137140
### Compiler & Linker Flags ###
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc.
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "peripherals/pins.h"
8+
9+
#include "common-hal/busio/SPI.h"
10+
#include "max32_spi.h"
11+
#include "max32690.h"
12+
13+
#include "py/runtime.h"
14+
#include "py/mperrno.h"
15+
16+
// TODO Decouple from APARD board
17+
const mxc_gpio_cfg_t spi_maps[NUM_SPI] = {
18+
// DUMMY entry for SPI0 (not on APARD board)
19+
{ MXC_GPIO0, 0xFFFFFFFF, 0, 0, 0, 0},
20+
21+
// SPI1A
22+
{ MXC_GPIO1, (MXC_GPIO_PIN_23 | MXC_GPIO_PIN_26 | MXC_GPIO_PIN_28 | MXC_GPIO_PIN_29),
23+
MXC_GPIO_FUNC_ALT1, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
24+
// SPI2A
25+
{ MXC_GPIO2, (MXC_GPIO_PIN_2 | MXC_GPIO_PIN_3 | MXC_GPIO_PIN_4 | MXC_GPIO_PIN_5),
26+
MXC_GPIO_FUNC_ALT1, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
27+
// SPI3A
28+
{ MXC_GPIO0, (MXC_GPIO_PIN_16 | MXC_GPIO_PIN_19 | MXC_GPIO_PIN_20 | MXC_GPIO_PIN_21),
29+
MXC_GPIO_FUNC_ALT1, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
30+
// SPI4A
31+
{ MXC_GPIO1, (MXC_GPIO_PIN_0 | MXC_GPIO_PIN_1 | MXC_GPIO_PIN_2 | MXC_GPIO_PIN_3),
32+
MXC_GPIO_FUNC_ALT1, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
33+
};
34+
35+
int pinsToSpi(const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso,
36+
const mcu_pin_obj_t *sck, const mcu_pin_obj_t *cs) {
37+
for (int i = 0; i < NUM_SPI; i++) {
38+
if ((spi_maps[i].port == (MXC_GPIO_GET_GPIO(mosi->port)))
39+
&& (spi_maps[i].mask == ((cs->mask) | (mosi->mask) | (miso->mask) | (sck->mask)))) {
40+
return i;
41+
}
42+
}
43+
mp_raise_RuntimeError_varg(MP_ERROR_TEXT("ERR: Unable to find an SPI matching pins... \
44+
\nMOSI: port %d mask %d\nMISO: port %d mask %d\n \
45+
\nSCK: port %d mask %d\nCS: port %d mask%d\n"),
46+
mosi->port, mosi->mask, miso->port, miso->mask,
47+
sck->port, sck->mask, cs->port, cs->mask);
48+
return -1;
49+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc.
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#pragma once
8+
9+
#include "spi_regs.h"
10+
#include "mxc_sys.h"
11+
#include "spi.h"
12+
#include "peripherals/pins.h"
13+
14+
#define NUM_SPI 5
15+
16+
int pinsToSpi(const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso,
17+
const mcu_pin_obj_t *sck, const mcu_pin_obj_t *cs);

0 commit comments

Comments
 (0)