Skip to content

Commit 6bf147b

Browse files
RobMeadesadbridge
authored andcommitted
Platform support for OnboardCellular modem and u-blox cellular interface drivers. This change allows the u-blox C027 and C030 boards to use both the mbed-os OnboardCellular modem driver and the u-blox cellular interface drivers (which support both PPP and AT data modes).
1 parent e2d2a33 commit 6bf147b

File tree

10 files changed

+216
-29
lines changed

10 files changed

+216
-29
lines changed

targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ublox_low_level_api.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ void ublox_mdm_init(void)
4646
while ((us_ticker_read() - start) < 50000);
4747
}
4848

49+
// For forwards compatibility
50+
void ublox_mdm_power_on(int usb)
51+
{
52+
ublox_mdm_powerOn(usb);
53+
}
54+
4955
void ublox_mdm_powerOn(int usb)
5056
{
5157
gpio_t gpio;
@@ -61,6 +67,12 @@ void ublox_mdm_powerOn(int usb)
6167
}
6268
}
6369

70+
// For forwards compatibility
71+
void ublox_mdm_power_off()
72+
{
73+
ublox_mdm_powerOff();
74+
}
75+
6476
void ublox_mdm_powerOff(void)
6577
{
6678
gpio_t gpio;

targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ublox_low_level_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ extern "C" {
2222

2323
void ublox_mdm_init(void);
2424

25+
void ublox_mdm_power_on(int usb);
2526
void ublox_mdm_powerOn(int usb);
2627

28+
void ublox_mdm_power_off(void);
2729
void ublox_mdm_powerOff(void);
2830

2931
void ublox_gps_powerOn(void);

targets/TARGET_NXP/TARGET_LPC176X/objects.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ struct spi_s {
7171
LPC_SSP_TypeDef *spi;
7272
};
7373

74-
struct modem_s {
75-
uint32_t state;
76-
};
77-
7874
#ifdef __cplusplus
7975
}
8076
#endif

targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/PeripheralPins.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ const PinMap PinMap_UART_RX[] = {
101101
{NC, NC, 0}
102102
};
103103

104+
const PinMap PinMap_UART_RTS[] = {
105+
{PA_12, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
106+
{PD_4, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
107+
{NC, NC, 0}
108+
};
109+
110+
const PinMap PinMap_UART_CTS[] = {
111+
{PA_11, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
112+
{PD_3, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
113+
{NC, NC, 0}
114+
};
115+
104116
//*** SPI ***
105117

106118
const PinMap PinMap_SPI_MOSI[] = {

targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/PinNames.h

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,34 @@ typedef enum {
6969
// Not connected
7070
NC = -1,
7171

72+
// Power
73+
PWR3V3 = PE_0, // 3.3V rail for the Arduino interface,
74+
// user LEDs and GNSS power, should be
75+
// set to open drain output
76+
77+
// GNSS
78+
GNSSEN = PA_15, // VCC_IO to GNSS, should be set to push-pull, no pull-up, output
7279
GNSSTXD = PC_6,
7380
GNSSRXD = PC_7,
74-
// Control
75-
GNSSRST = PC_10, // Reset (input to GPS, active low)
76-
GNSSPWR = PE_0, // 2.8V rail, should be set to open drain output
77-
GNSSEN = PA_15, // VCC_IO to GNSS, should be set to push-pull, no pull-up, output
78-
// u-blox LISA/SARA cellular modem
79-
// http://www.u-blox.com/wireless-modules.html
80-
// -----------------------------------------------------------
81-
// UART (LISA/SARA = DCE)
82-
MDMTXD = PD_5, // Transmit Data
83-
MDMRXD = PD_6, // Receive Data
84-
MDMCTS = PD_3, // Clear to Send
85-
MDMRTS = PD_4, // Request to Send (set high or use handshake)
86-
MDMDCD = NC, // DCD line not connecetd
8781

88-
// USB
89-
// Control
90-
MDMEN = PC_2, // Supply Control (high = enabled)
91-
MDMPWRON = PE_14, //
92-
MDMGPIO2 = PD_1, //
93-
MDMGPIO3 = PB_4, //
94-
MDMRST = PB_5, // Reset (active low, set as open drain!)
82+
// Cellular modem (a DCE)
83+
MDMPWRON = PE_14, // Power (active high)
84+
MDMRST = PB_5, // Reset (active low)
85+
MDMTXD = PD_5, // Transmit Data
86+
MDMRXD = PD_6, // Receive Data
87+
MDMCTS = PD_3, // Clear to Send
88+
MDMRTS = PD_4, // Request to Send
89+
MDMDCD = NC, // DCD line not connected
90+
MDMDSR = NC, // DSR line not connected
91+
MDMDTR = NC, // DTR line not connected
92+
MDMRI = NC, // RI line not connected
93+
MDMGPIO2 = PD_1, //
94+
MDMGPIO3 = PB_4, //
95+
MDMCURRENTSENSE = PC_2,
96+
97+
// SD card
98+
SDPWRON = PE_10, // Set to high to power on the SD card
99+
SDCSEL = PD_7, // SPI chip select for on-board SD card
95100

96101
// Board Pins
97102
// A0-A5
@@ -126,6 +131,20 @@ typedef enum {
126131
LED_RED = LED1,
127132
SW0 = PC_13, // Switch-0
128133

134+
// Arduino header I2C
135+
I2C_SDA = D14,
136+
I2C_SCL = D15,
137+
138+
// On-board I2C
139+
I2C_SDA_B = PC_9,
140+
I2C_SCL_B = PA_8,
141+
142+
// SPI
143+
SPI_MOSI = D11,
144+
SPI_MISO = D12,
145+
SPI_CLK = D13,
146+
SPI_NSS = D10,
147+
129148
// ST-Link
130149
USBRX = PA_10,
131150
USBTX = PA_9,
@@ -134,8 +153,13 @@ typedef enum {
134153
NTRST = PB_4,
135154
} PinName;
136155

137-
#define GNSSBAUD 9600 // Default GNSS Baud Rate
138-
#define MDMBAUD 115200 // Default Modem Baud Rate
156+
#define ACTIVE_HIGH_POLARITY 1
157+
#define ACTIVE_LOW_POLARITY 0
158+
159+
#define MDM_PIN_POLARITY ACTIVE_LOW_POLARITY
160+
161+
// The default GNSS baud rate is set in targets.json
162+
// The default modem baud rate is set in the mbed_lib.json file under features/cellular/TARGET_UBLOX_MODEM_GENERIC/ubox_modem_driver
139163

140164
#ifdef __cplusplus
141165
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#if MBED_CONF_NSAPI_PRESENT
18+
19+
#include "onboard_modem_api.h"
20+
#include "gpio_api.h"
21+
#include "platform/mbed_wait_api.h"
22+
#include "PinNames.h"
23+
24+
#if MODEM_ON_BOARD
25+
26+
// Note microseconds not milliseconds
27+
static void press_power_button(int time_us)
28+
{
29+
gpio_t gpio;
30+
31+
gpio_init_out_ex(&gpio, MDMPWRON, 0);
32+
wait_us(time_us);
33+
gpio_write(&gpio, 1);
34+
}
35+
36+
void onboard_modem_init()
37+
{
38+
gpio_t gpio;
39+
40+
// Take us out of reset
41+
gpio_init_out_ex(&gpio, MDMRST, 1);
42+
}
43+
44+
void onboard_modem_deinit()
45+
{
46+
gpio_t gpio;
47+
48+
// Back into reset
49+
gpio_init_out_ex(&gpio, MDMRST, 0);
50+
}
51+
52+
void onboard_modem_power_up()
53+
{
54+
/* keep the power line low for 50 microseconds */
55+
press_power_button(50);
56+
/* give modem a little time to respond */
57+
wait_ms(100);
58+
}
59+
60+
void onboard_modem_power_down()
61+
{
62+
/* keep the power line low for 1 second */
63+
press_power_button(1000000);
64+
}
65+
66+
#endif //MODEM_ON_BOARD
67+
#endif //MBED_CONF_NSAPI_PRESENT

targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/system_stm32f4xx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
*/
7979

8080

81+
#include "ublox_low_level_api.h"
8182
#include "stm32f4xx.h"
8283

8384
#if !defined (HSE_VALUE)
@@ -220,6 +221,7 @@ void SystemInit(void)
220221
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
221222
#endif
222223

224+
ublox_board_init();
223225
}
224226

225227
/**
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2006-2013 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "ublox_low_level_api.h"
17+
18+
#include <stdbool.h>
19+
#include "gpio_api.h"
20+
21+
void ublox_board_init(void) {
22+
gpio_t gpio;
23+
24+
// Enable power to 3V3
25+
gpio_init_inout(&gpio, PWR3V3, PIN_OUTPUT, OpenDrain, 1);
26+
27+
// start with modem disabled
28+
gpio_init_out_ex(&gpio, MDMRST, 0);
29+
gpio_init_out_ex(&gpio, MDMPWRON, 0);
30+
gpio_init_out_ex(&gpio, MDMRTS, 0);
31+
gpio_init_in_ex(&gpio, MDMCURRENTSENSE, PullNone);
32+
33+
// start with GNSS disabled
34+
gpio_init_inout(&gpio, GNSSEN, PIN_OUTPUT, PushPullNoPull, 0);
35+
36+
// power on SD card
37+
gpio_init_out_ex(&gpio, SDPWRON, 1);
38+
39+
// led should be off
40+
gpio_init_out_ex(&gpio, LED1, 1);
41+
gpio_init_out_ex(&gpio, LED2, 1);
42+
gpio_init_out_ex(&gpio, LED3, 1);
43+
gpio_init_out_ex(&gpio, LED4, 1);
44+
}
45+
46+
// End Of File
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef UBLOX_LOW_LEVEL_API_H
2+
#define UBLOX_LOW_LEVEL_API_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
void ublox_board_init(void);
9+
10+
#ifdef __cplusplus
11+
}
12+
#endif
13+
14+
#endif // UBLOX_LOW_LEVEL_H

targets/targets.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259
"supported_form_factors": ["ARDUINO"],
260260
"core": "Cortex-M3",
261261
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "GCC_CR", "IAR"],
262-
"extra_labels": ["NXP", "LPC176X", "FLASH_CMSIS_ALGO", "UBLOX_MODEM_GENERIC"],
262+
"extra_labels": ["NXP", "LPC176X", "FLASH_CMSIS_ALGO"],
263263
"config": {
264264
"modem_is_on_board": {
265265
"help": "Value: Tells the build system that the modem is on-board as oppose to a plug-in shield/module.",
@@ -1452,9 +1452,21 @@
14521452
"default_toolchain": "ARM",
14531453
"supported_toolchains": ["GCC_ARM", "ARM", "IAR"],
14541454
"extra_labels": ["STM", "STM32F4", "STM32F437", "STM32F437VG", "STM32F437xx", "STM32F437xG"],
1455-
"macros": ["TRANSACTION_QUEUE_SIZE_SPI=2", "RTC_LSI=1", "HSE_VALUE=12000000"],
1455+
"config": {
1456+
"modem_is_on_board": {
1457+
"help": "Value: Tells the build system that the modem is on-board as oppose to a plug-in shield/module.",
1458+
"value": 1,
1459+
"macro_name": "MODEM_ON_BOARD"
1460+
},
1461+
"modem_data_connection_type": {
1462+
"help": "Value: Defines how the modem is wired up to the MCU, e.g., data connection can be a UART or USB and so forth.",
1463+
"value": 1,
1464+
"macro_name": "MODEM_ON_BOARD_UART"
1465+
}
1466+
},
1467+
"macros": ["TRANSACTION_QUEUE_SIZE_SPI=2", "RTC_LSI=1", "HSE_VALUE=12000000", "GNSSBAUD=9600"],
14561468
"inherits": ["Target"],
1457-
"device_has": ["ANALOGIN", "ANALOGOUT", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SERIAL", "SLEEP", "RTC", "SPI", "SPISLAVE", "STDIO_MESSAGES", "TRNG"],
1469+
"device_has": ["ANALOGIN", "ANALOGOUT", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SERIAL", "SERIAL_FC", "SLEEP", "RTC", "SPI", "SPISLAVE", "STDIO_MESSAGES", "TRNG"],
14581470
"features": ["LWIP"],
14591471
"public": false,
14601472
"device_name": "STM32F437VG"

0 commit comments

Comments
 (0)