Skip to content

Commit 513f581

Browse files
authored
Merge pull request #15012 from felser/MTS_DRAGONFLY_L496VG
Add platform MTS_DRAGONFLY_L496VG
2 parents 3377f08 + 4b27aef commit 513f581

File tree

10 files changed

+1061
-1
lines changed

10 files changed

+1061
-1
lines changed

hal/tests/TESTS/mbed_hal/qspi/flash_configs/flash_configs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
#undef QSPI_CMD_WRITE_DPI
4747
#undef QSPI_CMD_WRITE_QPI
4848

49+
#elif defined(TARGET_MTS_DRAGONFLY_L496VG)
50+
#include "MT25Q_config.h"
51+
4952
#elif defined(TARGET_NRF52840)
5053
#if TARGET_EP_AGORA
5154
#include "NORDIC/EP_AGORA/flash_config.h"

platform/mbed_lib.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
},
165165
"UNO_91H": {
166166
"stdio-baud-rate": 115200
167-
},
167+
},
168168
"DISCO_L475VG_IOT01A": {
169169
"crash-capture-enabled": true,
170170
"fatal-error-auto-reboot-enabled": true

targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L496xG/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
add_subdirectory(TARGET_DISCO_L496AG EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_MTS_DRAGONFLY_L496VG EXCLUDE_FROM_ALL)
56
add_subdirectory(TARGET_NUCLEO_L496ZG EXCLUDE_FROM_ALL)
67

78
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2021 ARM Limited. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
add_library(mbed-mts-dragonfly-l496vg INTERFACE)
5+
6+
target_sources(mbed-mts-dragonfly-l496vg
7+
INTERFACE
8+
ONBOARD_QUECTEL_EG25.cpp
9+
PeripheralPins.c
10+
TargetInit.c
11+
)
12+
13+
target_include_directories(mbed-mts-dragonfly-l496vg
14+
INTERFACE
15+
.
16+
)
17+
18+
target_link_libraries(mbed-mts-dragonfly-l496vg INTERFACE mbed-stm32l496xg)
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2018 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#if MBED_CONF_NSAPI_PRESENT
19+
20+
#include "QUECTEL_EC2X.h"
21+
#include "ONBOARD_QUECTEL_EG25.h"
22+
#include "gpio_api.h"
23+
#include "platform/mbed_thread.h"
24+
#include "PinNames.h"
25+
#include "drivers/BufferedSerial.h"
26+
#include "CellularLog.h"
27+
#include "mbed_wait_api.h"
28+
29+
using namespace mbed;
30+
31+
ONBOARD_QUECTEL_EG25::ONBOARD_QUECTEL_EG25(FileHandle *fh, PinName pwr, bool active_high, PinName rst) : QUECTEL_EC2X(fh, pwr, active_high, rst)
32+
{
33+
initialized = 0;
34+
ls = new DigitalOut(LS_LED);
35+
net_status = new InterruptIn(NET_STATUS);
36+
}
37+
38+
nsapi_error_t ONBOARD_QUECTEL_EG25::hard_power_on()
39+
{
40+
onboard_modem_init();
41+
return NSAPI_ERROR_OK;
42+
}
43+
44+
nsapi_error_t ONBOARD_QUECTEL_EG25::hard_power_off()
45+
{
46+
onboard_modem_deinit();
47+
return NSAPI_ERROR_OK;
48+
}
49+
50+
nsapi_error_t ONBOARD_QUECTEL_EG25::soft_power_on()
51+
{
52+
// See base function description. This function is for power on but reset too.
53+
onboard_modem_power_down();
54+
onboard_modem_power_up();
55+
return NSAPI_ERROR_OK;
56+
}
57+
58+
nsapi_error_t ONBOARD_QUECTEL_EG25::soft_power_off()
59+
{
60+
onboard_modem_power_down();
61+
return NSAPI_ERROR_OK;
62+
}
63+
64+
CellularDevice *CellularDevice::get_target_default_instance()
65+
{
66+
static BufferedSerial serial(MDMTXD, MDMRXD, 115200);
67+
#if DEVICE_SERIAL_FC
68+
if (MDMRTS != NC && MDMCTS != NC) {
69+
tr_debug("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS);
70+
serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
71+
}
72+
#endif
73+
static ONBOARD_QUECTEL_EG25 device(&serial, MDMPWRON, 0, MDMRST);
74+
return &device;
75+
}
76+
77+
void ONBOARD_QUECTEL_EG25::press_power_button(int time_us)
78+
{
79+
gpio_t gpio;
80+
gpio_init_inout(&gpio, MDMPWRON, PIN_OUTPUT, OpenDrainNoPull, 0);
81+
wait_us(time_us);
82+
gpio_init_inout(&gpio, MDMPWRON, PIN_INPUT, PullNone, 1);
83+
}
84+
85+
void ONBOARD_QUECTEL_EG25::onboard_modem_init()
86+
{
87+
// PWRKEY/RADIO_ONOFF = output open drain
88+
// RADIO_PWR = Enables the regulator. High = on. Has pulldown on board.
89+
// RADIO_RESET/MDMRST = Reset the radio. Open drain or float.
90+
// RADIO_STATUS/STATUS = input with pull up. Gets driven low when radio is on.
91+
92+
gpio_t gpio;
93+
// Enable radio power regulator and buffer, configure RESET_N and PWR_ON.
94+
gpio_init_inout(&gpio, RADIO_PWR, PIN_OUTPUT, PushPullNoPull, 1);
95+
gpio_init_inout(&gpio, BUF_EN, PIN_OUTPUT, OpenDrainNoPull, 0);
96+
// MDMRST and MDMPWRON get driven low via open drain.
97+
gpio_init_inout(&gpio, MDMRST, PIN_INPUT, PullNone, 1);
98+
gpio_init_inout(&gpio, MDMPWRON, PIN_INPUT, PullNone, 1);
99+
gpio_init_in_ex(&gpio, RADIO_STATUS, PullUp);
100+
// Quectel hardware design guide recommends >= 30ms from powered until
101+
// PWRKEY(MDMPWRON) is pulled low.
102+
wait_us(40000);
103+
initialized = 1;
104+
}
105+
106+
void ONBOARD_QUECTEL_EG25::onboard_modem_deinit()
107+
{
108+
// Make sure to power down before removing power!
109+
onboard_modem_power_down();
110+
gpio_t gpio;
111+
112+
// Set all to inputs no pull. Let pull resistors do their thing. Allows
113+
// for lowest power draw. Disable radio power regulator and buffer.
114+
gpio_init_inout(&gpio, MDMRST, PIN_INPUT, PullNone, 1);
115+
gpio_init_inout(&gpio, MDMPWRON, PIN_INPUT, PullNone, 1);
116+
gpio_init_inout(&gpio, BUF_EN, PIN_INPUT, PullNone, 1);
117+
gpio_init_inout(&gpio, RADIO_PWR, PIN_INPUT, PullNone, 0);
118+
initialized = 0;
119+
}
120+
121+
void ONBOARD_QUECTEL_EG25::link_status()
122+
{
123+
ls->write(net_status->read());
124+
}
125+
126+
void ONBOARD_QUECTEL_EG25::onboard_modem_power_up()
127+
{
128+
// NET_STATUS = input. InterruptIn make LS LED follow.
129+
// LS_LED = output. Follow NET_STATUS.
130+
net_status->rise(callback(this,&ONBOARD_QUECTEL_EG25::link_status));
131+
net_status->fall(callback(this,&ONBOARD_QUECTEL_EG25::link_status));
132+
133+
// Make sure the radio is initialized so it can be powered on.
134+
if (!initialized){
135+
onboard_modem_init();
136+
}
137+
138+
gpio_t status;
139+
gpio_init_in_ex(&status, RADIO_STATUS, PullUp);
140+
141+
int radio_off = gpio_read(&status);
142+
// If radio is on, do nothing.
143+
if (!radio_off) {
144+
return;
145+
}
146+
147+
// Activate PWRKEY at least 500ms to turn on.
148+
press_power_button(550000);
149+
150+
// Wait 10s for status to go low before retrying.
151+
uint8_t timeout = 10;
152+
do {
153+
thread_sleep_for(1000);
154+
radio_off = gpio_read(&status);
155+
if(!timeout--){
156+
press_power_button(550000);
157+
timeout = 10;
158+
}
159+
} while (radio_off);
160+
161+
_at.lock();
162+
163+
_at.set_at_timeout(15000);
164+
_at.resp_start();
165+
_at.set_stop_tag("RDY");
166+
bool rdy = _at.consume_to_stop_tag();
167+
_at.set_stop_tag(OK);
168+
169+
_at.unlock();
170+
if (rdy) {
171+
tr_debug("Radio outputted RDY");
172+
} else {
173+
tr_debug("Radio did not output RDY within 15s.");
174+
}
175+
}
176+
177+
void ONBOARD_QUECTEL_EG25::onboard_modem_power_down()
178+
{
179+
gpio_t status;
180+
gpio_init_in_ex(&status, RADIO_STATUS, PullUp);
181+
// Need volatile so status check is not optimized out.
182+
volatile int radio_off = gpio_read(&status);
183+
// Do nothing if it's already off.
184+
if (radio_off) {
185+
return;
186+
}
187+
188+
// Make sure the I/O are properly initialized.
189+
if (!initialized){
190+
onboard_modem_init();
191+
}
192+
193+
do {
194+
// Activate PWRKEY for at least 650ms to turn off.
195+
press_power_button(680000);
196+
// Wait 40s for status to go high before resetting.
197+
uint8_t timeout = 40;
198+
do {
199+
thread_sleep_for(1000);
200+
radio_off = gpio_read(&status);
201+
} while (!radio_off && timeout);
202+
203+
if (radio_off) {
204+
break;
205+
}
206+
else {
207+
onboard_modem_reset();
208+
}
209+
}
210+
while (!radio_off);
211+
}
212+
213+
void ONBOARD_QUECTEL_EG25::onboard_modem_reset()
214+
{
215+
gpio_t gpio;
216+
gpio_init_inout(&gpio, MDMRST, PIN_OUTPUT, OpenDrainNoPull, 0);
217+
thread_sleep_for(500);
218+
gpio_init_inout(&gpio, MDMRST, PIN_INPUT, PullNone, 1);
219+
thread_sleep_for(100);
220+
}
221+
222+
#endif // MBED_CONF_NSAPI_PRESENT
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2018 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef ONBOARD_QUECTEL_EG25_H
19+
#define ONBOARD_QUECTEL_EG25_H
20+
21+
#include "QUECTEL_EC2X.h"
22+
23+
namespace mbed {
24+
25+
class ONBOARD_QUECTEL_EG25 : public QUECTEL_EC2X {
26+
public:
27+
ONBOARD_QUECTEL_EG25(FileHandle *fh, PinName pwr, bool active_high, PinName rst);
28+
29+
virtual nsapi_error_t hard_power_on();
30+
virtual nsapi_error_t hard_power_off();
31+
virtual nsapi_error_t soft_power_on();
32+
virtual nsapi_error_t soft_power_off();
33+
34+
private:
35+
uint8_t initialized;
36+
DigitalOut* ls;
37+
InterruptIn* net_status;
38+
void link_status();
39+
void press_power_button(int time_ms);
40+
void onboard_modem_init();
41+
void onboard_modem_deinit();
42+
void onboard_modem_power_up();
43+
void onboard_modem_power_down();
44+
void onboard_modem_reset();
45+
};
46+
47+
} // namespace mbed
48+
49+
#endif // ONBOARD_QUECTEL_EG25_H

0 commit comments

Comments
 (0)