Skip to content

Commit 6d59673

Browse files
committed
cellular - BG96 - auto enable flow control and lower baud rate if defined
1 parent 6d8e683 commit 6d59673

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include "QUECTEL/BG96/QUECTEL_BG96_CellularNetwork.h"
2020
#include "QUECTEL/BG96/QUECTEL_BG96_CellularStack.h"
2121

22+
#include "CellularUtil.h"
23+
#include "UARTSerial.h"
24+
#include "CellularLog.h"
25+
2226
using namespace mbed;
2327
using namespace events;
2428

@@ -56,3 +60,50 @@ CellularNetwork *QUECTEL_BG96::open_network(FileHandle *fh)
5660
}
5761
return _network;
5862
}
63+
64+
nsapi_error_t QUECTEL_BG96::init_module(FileHandle *fh) {
65+
ATHandler *atHandler = get_at_handler(fh);
66+
if (atHandler) {
67+
bool didAccessAt = false;
68+
//enable flow control if required
69+
#if defined (MDMRTS) && defined (MDMCTS)
70+
if (!didAccessAt) atHandler->lock();
71+
didAccessAt = true;
72+
73+
atHandler->cmd_start("AT+IFC=2,2");
74+
atHandler->cmd_stop();
75+
atHandler->resp_start();
76+
atHandler->resp_stop();
77+
if (atHandler->get_last_error() == NSAPI_ERROR_OK) {
78+
tr_info("Cellular device - enabled flow control.");
79+
} else {
80+
tr_warn("Cellular device - failed to enable flow control.");
81+
}
82+
#endif
83+
84+
//set target baud rate
85+
#if defined(MDM_TARGET_BAUD_RATE)
86+
if (!didAccessAt) atHandler->lock();
87+
didAccessAt = true;
88+
89+
atHandler->cmd_start("AT+IPR=" CELLULAR_STRINGIFY(MDM_TARGET_BAUD_RATE));
90+
atHandler->cmd_stop();
91+
atHandler->resp_start();
92+
atHandler->resp_stop();
93+
if (atHandler->get_last_error() == NSAPI_ERROR_OK) {
94+
//update uart baud rate
95+
((UARTSerial*)atHandler->get_file_handle())->set_baud(MDM_TARGET_BAUD_RATE);
96+
97+
tr_info("Cellular device - set baud rate (" CELLULAR_STRINGIFY(MDM_TARGET_BAUD_RATE) ").");
98+
} else {
99+
tr_warn("Cellular device - failed to set baud rate (" CELLULAR_STRINGIFY(MDM_TARGET_BAUD_RATE) ").");
100+
}
101+
#endif
102+
103+
if (didAccessAt) {
104+
return atHandler->unlock_return_error();
105+
}
106+
}
107+
108+
return NSAPI_ERROR_OK;
109+
}

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class QUECTEL_BG96 : public AT_CellularDevice {
3333

3434
public: // NetworkInterface
3535
void handle_urc(FileHandle *fh);
36+
virtual nsapi_error_t init_module(FileHandle *fh);
3637
};
3738
} // namespace mbed
3839
#endif // QUECTEL_BG96_H_

0 commit comments

Comments
 (0)