Skip to content

Commit 88099be

Browse files
committed
Add extra I2C options for MAX32690 non-TQFN packages
Also reformatted pinmaps for SPI/I2C/UART on MAX32690 Signed-off-by: Brandon Hurst <[email protected]>
1 parent 32c6b3e commit 88099be

File tree

3 files changed

+53
-23
lines changed

3 files changed

+53
-23
lines changed

ports/analog/peripherals/max32690/max32_i2c.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,44 @@
1313
#include "py/runtime.h"
1414
#include "py/mperrno.h"
1515

16+
17+
/* Note: The MAX32690 assigns the same alternate function to multiple sets
18+
* of pins. The drivers will enable both sets so that either can be used.
19+
* Users should ensure the unused set is left unconnected.
20+
*
21+
* See MAX32690 Rev A2 Errata #16:
22+
* https://www.analog.com/media/en/technical-documentation/data-sheets/max32690_a2_errata_rev2.pdf
23+
*
24+
* Additionally, note that the TQFN package does not expose some of the duplicate pins. For this package,
25+
* enabling the un-routed GPIOs has been shown to cause initialization issues with the I2C block.
26+
* To work around this, "MAX32690GTK_PACKAGE_TQFN" can be defined by the build system. The recommend place
27+
* to do it is in the "board.mk" file of the BSP. This will prevent the inaccessible pins from being configured.
28+
*/
29+
1630
const mxc_gpio_cfg_t i2c_maps[NUM_I2C] = {
31+
// I2C0
32+
{ MXC_GPIO2, (MXC_GPIO_PIN_7 | MXC_GPIO_PIN_8), MXC_GPIO_FUNC_ALT1,
33+
MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 };
34+
// I2C1
35+
{ MXC_GPIO0, (MXC_GPIO_PIN_11 | MXC_GPIO_PIN_12), MXC_GPIO_FUNC_ALT1,
36+
MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 };
37+
// I2C2
38+
{ MXC_GPIO1, (MXC_GPIO_PIN_7 | MXC_GPIO_PIN_8), MXC_GPIO_FUNC_ALT3,
39+
MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH, MXC_GPIO_DRVSTR_0 };,
40+
};
41+
#ifndef MAX32690GTK_PACKAGE_TQFN
42+
const mxc_gpio_cfg_t i2c_maps_extra[NUM_I2C] = {
1743
// I2C0A
1844
{ MXC_GPIO0, (MXC_GPIO_PIN_30 | MXC_GPIO_PIN_31), MXC_GPIO_FUNC_ALT1,
1945
MXC_GPIO_PAD_PULL_UP, MXC_GPIO_VSSEL_VDDIOH, MXC_GPIO_DRVSTR_0 },
2046
// I2C1A
2147
{ MXC_GPIO2, (MXC_GPIO_PIN_17 | MXC_GPIO_PIN_18), MXC_GPIO_FUNC_ALT1,
2248
MXC_GPIO_PAD_PULL_UP, MXC_GPIO_VSSEL_VDDIOH, MXC_GPIO_DRVSTR_0 },
49+
// I2C2C
50+
{ MXC_GPIO0, (MXC_GPIO_PIN_13 | MXC_GPIO_PIN_14), MXC_GPIO_FUNC_ALT3,
51+
MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 };,
2352
};
53+
#endif
2454

2555
int pinsToI2c(const mcu_pin_obj_t *sda, const mcu_pin_obj_t *scl) {
2656
for (int i = 0; i < NUM_I2C; i++) {
@@ -29,6 +59,17 @@ int pinsToI2c(const mcu_pin_obj_t *sda, const mcu_pin_obj_t *scl) {
2959
return i;
3060
}
3161
}
62+
63+
// Additional for loop to cover alternate potential I2C maps
64+
#ifndef MAX32690GTK_PACKAGE_TQFN
65+
for (int i = 0; i < NUM_I2C; i++) {
66+
if ((i2c_maps_extra[i].port == (MXC_GPIO_GET_GPIO(sda->port)))
67+
&& (i2c_maps_extra[i].mask == ((sda->mask) | (scl->mask)))) {
68+
return i;
69+
}
70+
}
71+
#endif
72+
3273
mp_raise_RuntimeError_varg(MP_ERROR_TEXT("ERR: Unable to find an I2C matching pins...\nSCL: port %d mask %d\nSDA: port %d mask %d\n"),
3374
sda->port, sda->mask, scl->port, scl->mask);
3475
return -1;

ports/analog/peripherals/max32690/max32_spi.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,20 @@
1313
#include "py/runtime.h"
1414
#include "py/mperrno.h"
1515

16-
// TODO Decouple from APARD board
1716
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
17+
// SPI0
18+
{ MXC_GPIO2, (MXC_GPIO_PIN_27 | MXC_GPIO_PIN_28 | MXC_GPIO_PIN_29),
19+
MXC_GPIO_FUNC_ALT2, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 };
20+
// SPI1
2221
{ MXC_GPIO1, (MXC_GPIO_PIN_26 | MXC_GPIO_PIN_28 | MXC_GPIO_PIN_29),
2322
MXC_GPIO_FUNC_ALT1, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
24-
// SPI2A
23+
// SPI2
2524
{ MXC_GPIO2, (MXC_GPIO_PIN_2 | MXC_GPIO_PIN_3 | MXC_GPIO_PIN_4),
2625
MXC_GPIO_FUNC_ALT1, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
27-
// SPI3A
26+
// SPI3
2827
{ MXC_GPIO0, (MXC_GPIO_PIN_16 | MXC_GPIO_PIN_20 | MXC_GPIO_PIN_21),
2928
MXC_GPIO_FUNC_ALT1, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
30-
// SPI4A
29+
// SPI4
3130
{ MXC_GPIO1, (MXC_GPIO_PIN_1 | MXC_GPIO_PIN_2 | MXC_GPIO_PIN_3),
3231
MXC_GPIO_FUNC_ALT1, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
3332
};

ports/analog/peripherals/max32690/max32_uart.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,19 @@
1313
#include "py/runtime.h"
1414
#include "py/mperrno.h"
1515

16-
// FIXME: Remove upon test!
17-
// mxc_uart_regs_t max32_uarts[NUM_UARTS] = {
18-
// MXC_UART0,
19-
// MXC_UART1,
20-
// MXC_UART2,
21-
// MXC_UART3,
22-
// };
23-
2416
const mxc_gpio_cfg_t uart_maps[NUM_UARTS] = {
2517
{ MXC_GPIO2, (MXC_GPIO_PIN_11 | MXC_GPIO_PIN_12), MXC_GPIO_FUNC_ALT1,
2618
MXC_GPIO_PAD_WEAK_PULL_UP, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
2719
{ MXC_GPIO2, (MXC_GPIO_PIN_14 | MXC_GPIO_PIN_16), MXC_GPIO_FUNC_ALT1,
2820
MXC_GPIO_PAD_WEAK_PULL_UP, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
29-
{ MXC_GPIO1, (MXC_GPIO_PIN_9 | MXC_GPIO_PIN_10),
30-
MXC_GPIO_FUNC_ALT1, MXC_GPIO_PAD_WEAK_PULL_UP,
31-
MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
32-
{ MXC_GPIO3, (MXC_GPIO_PIN_0 | MXC_GPIO_PIN_1),
33-
MXC_GPIO_FUNC_ALT2, MXC_GPIO_PAD_WEAK_PULL_UP,
34-
MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }
21+
{ MXC_GPIO1, (MXC_GPIO_PIN_9 | MXC_GPIO_PIN_10), MXC_GPIO_FUNC_ALT1,
22+
MXC_GPIO_PAD_WEAK_PULL_UP, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 },
23+
{ MXC_GPIO3, (MXC_GPIO_PIN_0 | MXC_GPIO_PIN_1), MXC_GPIO_FUNC_ALT2,
24+
MXC_GPIO_PAD_WEAK_PULL_UP, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }
3525
};
3626

3727
int pinsToUart(const mcu_pin_obj_t *rx, const mcu_pin_obj_t *tx) {
38-
for (int i = 0; i < NUM_UARTS; i++) {
28+
for (int i = 0; i < uart_entries; i++) {
3929
if ((uart_maps[i].port == (MXC_GPIO_GET_GPIO(tx->port)))
4030
&& (uart_maps[i].mask == ((tx->mask) | (rx->mask)))) {
4131
return i;

0 commit comments

Comments
 (0)