Skip to content

Commit 72f27ce

Browse files
authored
Merge pull request #15458 from MultiTechSystems/xdot-max32670
Add target support for XDOT_MAX32670
2 parents 7c7d20d + 4ba13f1 commit 72f27ce

File tree

5 files changed

+401
-0
lines changed

5 files changed

+401
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
add_library(mbed-xdot-max32670 INTERFACE)
2+
3+
target_include_directories(mbed-xdot-max32670
4+
INTERFACE
5+
.
6+
)
7+
8+
target_link_libraries(mbed-xdot-max32670
9+
INTERFACE
10+
mbed-max32670
11+
)
12+
13+
target_sources(mbed-xdot-max32670
14+
INTERFACE
15+
SystemInit.c
16+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*******************************************************************************
2+
* Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
18+
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
* OTHER DEALINGS IN THE SOFTWARE.
21+
*
22+
* Except as contained in this notice, the name of Maxim Integrated
23+
* Products, Inc. shall not be used except as stated in the Maxim Integrated
24+
* Products, Inc. Branding Policy.
25+
*
26+
* The mere transfer of this software does not imply any licenses
27+
* of trade secrets, proprietary technology, copyrights, patents,
28+
* trademarks, maskwork rights, or any other form of intellectual
29+
* property whatsoever. Maxim Integrated Products, Inc. retains all
30+
* ownership rights.
31+
*******************************************************************************
32+
*/
33+
34+
#ifndef MBED_PERIPHERALNAMES_H
35+
#define MBED_PERIPHERALNAMES_H
36+
37+
#include "cmsis.h"
38+
39+
#ifdef __cplusplus
40+
extern "C" {
41+
#endif
42+
43+
typedef enum {
44+
UART_0 = MXC_BASE_UART0,
45+
UART_1 = MXC_BASE_UART1,
46+
UART_2 = MXC_BASE_UART2,
47+
UART_3 = MXC_BASE_UART3,
48+
#if defined(MBED_CONF_TARGET_STDIO_UART)
49+
STDIO_UART = MBED_CONF_TARGET_STDIO_UART,
50+
#else
51+
STDIO_UART = UART_0,
52+
#endif
53+
} UARTName;
54+
55+
typedef enum {
56+
I2C_0 = MXC_BASE_I2C0,
57+
I2C_1 = MXC_BASE_I2C1,
58+
I2C_2 = MXC_BASE_I2C2,
59+
} I2CName;
60+
61+
typedef enum {
62+
SPI_0 = MXC_BASE_SPI0,
63+
SPI_1 = MXC_BASE_SPI1,
64+
SPI_2 = MXC_BASE_SPI2,
65+
} SPIName;
66+
67+
68+
#ifdef __cplusplus
69+
}
70+
#endif
71+
72+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2022 Maxim Integrated Products, Inc., All Rights Reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
18+
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
* OTHER DEALINGS IN THE SOFTWARE.
21+
*
22+
* Except as contained in this notice, the name of Maxim Integrated
23+
* Products, Inc. shall not be used except as stated in the Maxim Integrated
24+
* Products, Inc. Branding Policy.
25+
*
26+
* The mere transfer of this software does not imply any licenses
27+
* of trade secrets, proprietary technology, copyrights, patents,
28+
* trademarks, maskwork rights, or any other form of intellectual
29+
* property whatsoever. Maxim Integrated Products, Inc. retains all
30+
* ownership rights.
31+
*******************************************************************************
32+
*/
33+
34+
/* MBED TARGET LIST: MAX32670EVKIT */
35+
36+
#ifndef MBED_PINNAMES_H
37+
#define MBED_PINNAMES_H
38+
39+
#include "cmsis.h"
40+
#include "gpio_regs.h"
41+
42+
#ifdef __cplusplus
43+
extern "C" {
44+
#endif
45+
46+
typedef enum {
47+
PIN_INPUT = 0,
48+
PIN_OUTPUT = 1
49+
} PinDirection;
50+
51+
#define PORT_SHIFT 12
52+
53+
#define PINNAME_TO_PORT(name) ((unsigned int)(name) >> PORT_SHIFT)
54+
#define PINNAME_TO_PIN(name) ((unsigned int)(name) & ~(0xFFFFFFFF << PORT_SHIFT))
55+
#define NOT_CONNECTED (int)0xFFFFFFFF
56+
57+
typedef enum {
58+
// Port 0
59+
P0_0 = (0 << PORT_SHIFT),
60+
P0_1, P0_2, P0_3, P0_4, P0_5, P0_6, P0_7, P0_8, P0_9, P0_10, P0_11, P0_12, P0_13, P0_14, P0_15,
61+
P0_16, P0_17, P0_18, P0_19, P0_20, P0_21, P0_22, P0_23,P0_24, P0_25, P0_26, P0_27, P0_28, P0_29, P0_30, P0_31,
62+
63+
// Port 1
64+
P1_0 = (1 << PORT_SHIFT),
65+
P1_1, P1_2, P1_3, P1_4, P1_5, P1_6, P1_7, P1_8, P1_9, P1_10, P1_11, P1_12, P1_13, P1_14, P1_15,
66+
P1_16, P1_17, P1_18, P1_19, P1_20, P1_21, P1_22, P1_23,P1_24, P1_25, P1_26, P1_27, P1_28, P1_29, P1_30, P1_31,
67+
68+
// USB bridge connected UART pins
69+
#if defined(MBED_CONF_TARGET_STDIO_UART_TX)
70+
CONSOLE_TX = MBED_CONF_TARGET_STDIO_UART_TX,
71+
#else
72+
CONSOLE_TX = P0_29,
73+
#endif // MBED_CONF_TARGET_STDIO_UART_TX
74+
75+
#if defined(MBED_CONF_TARGET_STDIO_UART_RX)
76+
CONSOLE_RX = MBED_CONF_TARGET_STDIO_UART_RX,
77+
#else
78+
CONSOLE_RX = P0_28,
79+
#endif // MBED_CONF_TARGET_STDIO_UART_RX
80+
81+
STDIO_UART_TX = CONSOLE_TX,
82+
STDIO_UART_RX = CONSOLE_RX,
83+
84+
// ----- Start of xDot external pin definitions -----
85+
WAKE = P0_19,
86+
GPIO0 = P0_30,
87+
GPIO1 = P0_27,
88+
GPIO2 = P0_26,
89+
GPIO3 = P0_25,
90+
91+
// AT command port UART
92+
UART_RX = P0_8,
93+
UART_TX = P0_9,
94+
UART_CTS = P0_10,
95+
UART_RTS = P0_11,
96+
97+
UART0_RX = UART_RX,
98+
UART0_TX = UART_TX,
99+
UART0_CTS = UART_CTS,
100+
UART0_RTS = UART_RTS,
101+
102+
// debug UART
103+
UART1_RX = P0_28,
104+
UART1_TX = P0_29,
105+
106+
// SwD
107+
SWDIO = P0_0,
108+
SWCLK = P0_1,
109+
110+
// I2C
111+
I2C1_SCL = P0_12,
112+
I2C1_SDA = P0_13,
113+
114+
// SPI
115+
SPI0_SCK = P0_4,
116+
SPI0_MOSI = P0_3,
117+
SPI0_MISO = P0_2,
118+
SPI0_SS = P0_5,
119+
// ----- End of xDot external pin definitions -----
120+
121+
// ----- Start of xDot dedicated internal pins. -----
122+
MEM_PWR_EN = P0_24, // Power to EEPROM, Flash & Secure element
123+
FLASH_CS = P0_23,
124+
125+
// EEPROM and SE I2C
126+
I2C0_SCL = P0_6,
127+
I2C0_SDA = P0_7,
128+
SE_SDA = I2C0_SDA,
129+
SE_SCL = I2C0_SCL,
130+
131+
// SX1262
132+
SPI1_SCK = P0_16,
133+
SPI1_MOSI = P0_15,
134+
SPI1_MISO = P0_14,
135+
SPI1_SS = P0_17,
136+
LORA_MISO = SPI1_MISO,
137+
LORA_MOSI = SPI1_MOSI,
138+
LORA_SCK = SPI1_SCK,
139+
LORA_NSS = SPI1_SS,
140+
141+
LORA_RESET = P0_20,
142+
LORA_BUSY = P0_21,
143+
LORA_DIO1 = P0_22,
144+
145+
RF_SW_CTRL = P0_18, // RF switch, active high
146+
// ----- End of xDot dedicated internal pins. -----
147+
148+
// ----- Start of aliases for MAX32670 serial_api.c -----
149+
// The xDot does not use these serial UARTs or the serial_api
150+
// code. These pins are used on the xDot as detailed above.
151+
UART0B_RX = P0_24,
152+
UART0B_TX = P0_25,
153+
154+
UART1B_RX = P0_2,
155+
UART1B_TX = P0_3,
156+
157+
UART2B_RX = P0_14,
158+
UART2B_TX = P0_15,
159+
// ----- end of aliases for MAX32670 serial_api.c -----
160+
161+
// Not connected
162+
NC = NOT_CONNECTED
163+
} PinName;
164+
165+
#define LED1 P0_30
166+
#define I2C_SCL I2C1_SCL
167+
#define I2C_SDA I2C1_SDA
168+
#define SPI_MISO SPI0_MISO
169+
#define SPI_MOSI SPI0_MOSI
170+
#define SPI_SCK SPI0_SCK
171+
#define SPI_NSS SPI0_SS
172+
173+
typedef enum {
174+
PullNone = 0,
175+
PullUp = 1,
176+
PullDown = 2,
177+
PullDefault = PullUp
178+
} PinMode;
179+
180+
typedef enum {
181+
LED_ON = 0,
182+
LED_OFF = 1
183+
} LedStates;
184+
185+
#ifdef __cplusplus
186+
}
187+
#endif
188+
189+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/* mbed Microcontroller Library
2+
*******************************************************************************
3+
* Copyright (c) 2023, MultiTech Systems
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice,
10+
* this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
* 3. Neither the name of MultiTech nor the names of its contributors
15+
* may be used to endorse or promote products derived from this software
16+
* without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*******************************************************************************
29+
*/
30+
31+
#include <string.h>
32+
#include <stdio.h>
33+
#include <stdlib.h>
34+
#include "max32670.h"
35+
#include "gcr_regs.h"
36+
#include "mxc_sys.h"
37+
#include "pwrseq_regs.h"
38+
39+
#define XDOT_ERFO_FREQ 24000000 // Change to 24000000 for xDot 1.5 Rev A
40+
41+
void SystemCoreClockUpdateXdot(void)
42+
{
43+
uint32_t base_freq, div, clk_src;
44+
45+
// Get the clock source and frequency
46+
clk_src = (MXC_GCR->clkctrl & MXC_F_GCR_CLKCTRL_SYSCLK_SEL);
47+
switch (clk_src)
48+
{
49+
case MXC_S_GCR_CLKCTRL_SYSCLK_SEL_EXTCLK:
50+
base_freq = EXTCLK_FREQ;
51+
break;
52+
case MXC_S_GCR_CLKCTRL_SYSCLK_SEL_ERFO:
53+
base_freq = XDOT_ERFO_FREQ;
54+
break;
55+
case MXC_S_GCR_CLKCTRL_SYSCLK_SEL_INRO:
56+
base_freq = INRO_FREQ;
57+
break;
58+
case MXC_S_GCR_CLKCTRL_SYSCLK_SEL_IPO:
59+
base_freq = IPO_FREQ;
60+
break;
61+
case MXC_S_GCR_CLKCTRL_SYSCLK_SEL_IBRO:
62+
base_freq = IBRO_FREQ;
63+
break;
64+
case MXC_S_GCR_CLKCTRL_SYSCLK_SEL_ERTCO:
65+
base_freq = ERTCO_FREQ;
66+
break;
67+
default:
68+
// Codes 001 and 111 are reserved.
69+
// This code should never execute, however, initialize to safe value.
70+
base_freq = HIRC_FREQ;
71+
break;
72+
}
73+
// Get the clock divider
74+
if (clk_src == MXC_S_GCR_CLKCTRL_SYSCLK_SEL_IPO)
75+
{
76+
base_freq = base_freq >> ((MXC_GCR->clkctrl & MXC_F_GCR_CLKCTRL_IPO_DIV)>> MXC_F_GCR_CLKCTRL_IPO_DIV_POS);
77+
}
78+
div = (MXC_GCR->clkctrl & MXC_F_GCR_CLKCTRL_SYSCLK_DIV) >> MXC_F_GCR_CLKCTRL_SYSCLK_DIV_POS;
79+
80+
SystemCoreClock = base_freq >> div;
81+
}
82+
83+
int PreInit(void)
84+
{
85+
return 0;
86+
}
87+
88+
void SystemInit(void)
89+
{
90+
/* Make sure interrupts are enabled. */
91+
__enable_irq();
92+
93+
#if (__FPU_PRESENT == 1)
94+
/* Enable FPU on Cortex-M4, which occupies coprocessor slots 10 & 11 */
95+
/* Grant full access, per "Table B3-24 CPACR bit assignments". */
96+
/* DDI0403D "ARMv7-M Architecture Reference Manual" */
97+
SCB->CPACR |= SCB_CPACR_CP10_Msk | SCB_CPACR_CP11_Msk;
98+
__DSB();
99+
__ISB();
100+
#endif
101+
102+
MXC_PWRSEQ->lpcn &= ~(1 << 31); // Ensure ERTCO is on
103+
104+
MXC_SYS_Clock_Select(MXC_SYS_CLOCK_IPO);
105+
SystemCoreClockUpdateXdot();
106+
107+
// Increase drive strength of I2C_SE bus and Mem Pwr En.
108+
// Note: Mem Pwr En doesn't help, higher drive strength on se i2c pins seems to though
109+
MXC_GPIO0->ds0 |= (1 << 6) | (1 << 7) | (1 << 24);
110+
MXC_GPIO0->ds1 |= (1 << 6) | (1 << 7) | (1 << 24);
111+
112+
MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_GPIO0);
113+
MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_GPIO1);
114+
}

0 commit comments

Comments
 (0)