Skip to content

Commit 00c53ea

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 aaeee4d commit 00c53ea

File tree

3 files changed

+74
-8
lines changed

3 files changed

+74
-8
lines changed

ports/analog/Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,9 @@ INC += \
8888
-I$(PERIPH_SRC)/TMR \
8989
-I$(PERIPH_SRC)/RTC \
9090
-I$(PERIPH_SRC)/UART \
91-
<<<<<<< HEAD
92-
-I$(PERIPH_SRC)/TRNG
93-
=======
94-
-I$(PERIPH_SRC)/I2C
95-
>>>>>>> edf069d0e7 (Add BUSIO.I2C and MAX32690 I2C structure)
91+
-I$(PERIPH_SRC)/TRNG \
92+
-I$(PERIPH_SRC)/I2C \
93+
-I$(PERIPH_SRC)/SPI
9694

9795
INC += -I$(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/GCC
9896

@@ -129,16 +127,18 @@ SRC_MAX32 += \
129127
$(PERIPH_SRC)/TRNG/trng_revb.c \
130128
$(PERIPH_SRC)/TRNG/trng_$(DIE_TYPE).c
131129
$(PERIPH_SRC)/I2C/i2c_$(DIE_TYPE).c \
132-
$(PERIPH_SRC)/I2C/i2c_reva.c
130+
$(PERIPH_SRC)/I2C/i2c_reva.c \
131+
$(PERIPH_SRC)/SPI/spi_$(DIE_TYPE).c \
132+
$(PERIPH_SRC)/SPI/spi_reva1.c
133133

134134
SRC_C += $(SRC_MAX32) \
135135
boards/$(BOARD)/board.c \
136136
boards/$(BOARD)/pins.c \
137137
peripherals/$(MCU_VARIANT_LOWER)/pins.c \
138138
peripherals/$(MCU_VARIANT_LOWER)/gpios.c \
139139
peripherals/$(MCU_VARIANT_LOWER)/max32_uart.c \
140-
peripherals/$(MCU_VARIANT_LOWER)/max32_i2c.c
141-
140+
peripherals/$(MCU_VARIANT_LOWER)/max32_i2c.c \
141+
peripherals/$(MCU_VARIANT_LOWER)/max32_spi.c
142142

143143
# *******************************************************************************
144144
### 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)