Skip to content

Commit 4418f02

Browse files
committed
Updated GSM module
1 parent 9046907 commit 4418f02

File tree

10 files changed

+107
-66
lines changed

10 files changed

+107
-66
lines changed

firmware/MaixPy.bin

0 Bytes
Binary file not shown.

firmware/MaixPy.kfpkg

-247 Bytes
Binary file not shown.

firmware/MaixPy_firmware.zip

603 Bytes
Binary file not shown.

firmware/MaixPy_sqlite.bin

0 Bytes
Binary file not shown.

firmware/MaixPy_sqlite.kfpkg

685 Bytes
Binary file not shown.

k210-freertos/BUILD.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ TOOLCHAIN_ARCHIVE_NAME="kendryte-toolchain_v2a.tar.xz"
55

66
VERBOSE=""
77
J_OPTION=""
8+
CREATE_DUMP=""
89

910
# Get arguments
1011
POSITIONAL_ARGS=()
@@ -21,6 +22,10 @@ do
2122
-V|--VERBOSE)
2223
VERBOSE="yesyes"
2324
shift # past argument
25+
;;
26+
-d|--dump)
27+
CREATE_DUMP="yes"
28+
shift # past argument
2429
;;
2530
*) # unknown option
2631
arg_opt="$1"
@@ -178,7 +183,10 @@ END_ADDRESS=$(( ${ALLIGNED_SIZE} + 2147483648 ))
178183
mv MaixPy.bin MaixPy.bin.bkp
179184
../kendryte-toolchain/bin/riscv64-unknown-elf-objcopy --output-format=binary --file-alignment 4096 --gap-fill 0xFF --pad-to ${END_ADDRESS} MaixPy MaixPy.bin
180185

181-
#../kendryte-toolchain/bin/riscv64-unknown-elf-objdump -S --disassemble MaixPy > MaixPy.dump
186+
if [ "${CREATE_DUMP}" == "yes" ]; then
187+
echo "===[ Exporting objdump ]==="
188+
../kendryte-toolchain/bin/riscv64-unknown-elf-objdump -S --disassemble MaixPy > MaixPy.dump
189+
fi
182190

183191
# =========================================
184192
# === Create kfpkg package ================

k210-freertos/mpy_support/mpconfigport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
#define MICROPY_HW_BOARD_NAME "Sipeed_board"
4242
#define MICROPY_HW_MCU_NAME "Kendryte-K210"
4343
#define MICROPY_PY_SYS_PLATFORM "K210/FreeRTOS"
44-
#define MICROPY_PY_LOBO_VERSION "1.11.7"
45-
#define MICROPY_PY_LOBO_VERSION_NUM (0x011107)
44+
#define MICROPY_PY_LOBO_VERSION "1.11.8"
45+
#define MICROPY_PY_LOBO_VERSION_NUM (0x011108)
4646

4747
#define MICROPY_PY_USE_LOG_COLORS (1)
4848

k210-freertos/mpy_support/standard_lib/gsm/at_util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ mp_obj_t mpy_atCmd(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args
730730
// Execute multiple at commands
731731
//------------------------------------------------------------------
732732
if (strstr(tag, "WIFI")) res = wifi_at_Commands(&at_commands, NULL);
733-
else res = gsm_at_Commands(&at_commands);
733+
else res = gsm_at_Commands(&at_commands, NULL);
734734
//------------------------------------------------------------------
735735

736736
if (res > 0) {

k210-freertos/mpy_support/standard_lib/gsm/libGSM.c

Lines changed: 90 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static uint32_t pppos_rx_count = 0;
7373
static uint32_t pppos_tx_count = 0;
7474

7575
int gsm_uart_baudrate = 115200;
76-
bool gsm_debug = true;
76+
bool gsm_debug = false;
7777
int gsm_uart_num = -1;
7878
at_responses_t gsm_at_responses = { 0 };
7979
at_command_t gsm_at_command = { 0 };
@@ -89,6 +89,7 @@ static uint8_t ppp_status = ATDEV_STATEFIRSTINIT;
8989
static uint32_t gsm_ppp_ip = 0;
9090
static uint32_t gsm_ppp_netmask = 0;
9191
static uint32_t gsm_ppp_gw = 0;
92+
static time_t ntp_got_time = 0;
9293

9394
static char gsm_connect_string[32] = "ATDT*99***1#\r\n"; // "AT+CGDATA=\"PPP\",1\r\n"
9495
const char *GSM_PPP_TAG = "[GSM_PPPOS]";
@@ -225,18 +226,6 @@ extern handle_t mp_rtc_rtc0;
225226

226227
static void *ntp_time_cb = NULL;
227228

228-
//==========================
229-
int setNTP_cb(void *cb_func)
230-
{
231-
if (mpy_uarts[gsm_uart_num].uart_mutex == NULL) return 0;
232-
if (xSemaphoreTake(mpy_uarts[gsm_uart_num].uart_mutex, PPPOSMUTEX_TIMEOUT) == pdTRUE) {
233-
ntp_time_cb = cb_func;
234-
xSemaphoreGive(mpy_uarts[gsm_uart_num].uart_mutex);
235-
}
236-
return 1;
237-
}
238-
239-
240229
//==============================================
241230
// Function used by SNTP to synchronize the time
242231
//==============================================
@@ -246,15 +235,7 @@ void set_rtc_time_from_seconds(time_t seconds)
246235
tm_info = gmtime(&seconds);
247236
//rtc_set_datetime(mp_rtc_rtc0, tm_info); // set RTC time
248237
_set_sys_time(tm_info, 0);
249-
if (gsm_debug) {
250-
LOGM("[NTP]", "Time synchronized from NTP (%ld)", seconds);
251-
}
252-
int taken = pdFALSE;
253-
if (mpy_uarts[gsm_uart_num].uart_mutex) taken = xSemaphoreTake(mpy_uarts[gsm_uart_num].uart_mutex, PPPOSMUTEX_TIMEOUT);
254-
if ((taken) && (ntp_time_cb)) {
255-
mp_sched_schedule((mp_obj_t)ntp_time_cb, mp_obj_new_int(seconds));
256-
}
257-
if (taken) xSemaphoreGive(mpy_uarts[gsm_uart_num].uart_mutex);
238+
ntp_got_time = seconds;
258239
if (sntp_enabled()) {
259240
sntp_stop();
260241
}
@@ -515,7 +496,7 @@ static void checkSMS()
515496
gsm_debug = false;
516497
sms_timer = mp_hal_ticks_ms() + SMS_check_interval;
517498
SMS_indexes indexes;
518-
int nmsg = checkMessages(SMS_LIST_NEW, 0, NULL, &indexes, SMS_SORT_NONE);
499+
int nmsg = checkMessages(SMS_LIST_NEW, 0, NULL, &indexes, SMS_SORT_ASC);
519500
if (nmsg > 0) {
520501
if (nmsg > 100) nmsg = 100;
521502
// Create a tuple containing SMS indexes
@@ -548,8 +529,8 @@ static int _task_idle()
548529
}
549530

550531
gstat = do_pppos_connect;
551-
checkSMS();
552532
xSemaphoreGive(mpy_uarts[gsm_uart_num].uart_mutex);
533+
checkSMS();
553534
}
554535
net_active_interfaces &= ~ACTIVE_INTERFACE_GSM;
555536
return gstat;
@@ -567,6 +548,11 @@ static void _handle_pppos_data(char *data)
567548
vTaskDelay(5 / portTICK_PERIOD_MS);
568549
do_check = true;
569550
}
551+
if (ntp_got_time > 0) {
552+
if (gsm_debug) LOGM(GSM_PPP_TAG, "NTP time synchronized (%lu)", ntp_got_time);
553+
if (ntp_time_cb) mp_sched_schedule((mp_obj_t)ntp_time_cb, mp_obj_new_int(ntp_got_time));
554+
ntp_got_time = 0;
555+
}
570556

571557
if (do_check) {
572558
//if (xSemaphoreTake(mpy_uarts[gsm_uart_num].uart_mutex, PPPOSMUTEX_TIMEOUT) == pdTRUE) {
@@ -1065,7 +1051,7 @@ int gsm_ppposInit(int tx, int rx, int rts, int cts, int bdr, char *user, char *p
10651051
strncpy(GSM_APN, apn, PPP_MAX_NAME_LEN);
10661052

10671053
if (!tcpip_adapter_initialized) {
1068-
LOGM(GSM_PPP_TAG,"Network init (from GSM module)");
1054+
if (gsm_debug) LOGM(GSM_PPP_TAG,"Network init (from GSM module)");
10691055
network_init();
10701056
tcpip_adapter_initialized = true;
10711057
}
@@ -1305,8 +1291,8 @@ static bool is_OnLine()
13051291
return ret;
13061292
}
13071293

1308-
//---------------------------------------
1309-
time_t sms_time(char * msg_time, int *tz)
1294+
//-------------------------------------------------
1295+
static time_t sms_time(char * msg_time, int *tzone)
13101296
{
13111297
if (strlen(msg_time) >= 20) {
13121298
// Convert message time to time structure
@@ -1319,7 +1305,7 @@ time_t sms_time(char * msg_time, int *tz)
13191305
tm.tm_year = yy+100;
13201306
tm.tm_mon = mn-1;
13211307
tm.tm_mday = dd;
1322-
if (tz) tz = tz/4; // time zone info
1308+
if (tzone) *tzone = tz/4; // time zone info
13231309
return mktime(&tm); // Linux time
13241310
}
13251311
return 0;
@@ -1439,6 +1425,9 @@ static int getSMSindex(char *msgstart, time_t *msgtime)
14391425
//-------------------------------------------------------------------------------------------------
14401426
int checkMessages(uint8_t rd_status, int sms_idx, SMS_Msg *msg, SMS_indexes *indexes, uint8_t sort)
14411427
{
1428+
char cmd[32] = {0};
1429+
char *list_change = "";
1430+
if (msg == NULL) list_change = ",1";
14421431
char *rbuffer = pvPortMalloc(1024);
14431432
if (rbuffer == NULL) {
14441433
if (gsm_debug) {
@@ -1449,36 +1438,61 @@ int checkMessages(uint8_t rd_status, int sms_idx, SMS_Msg *msg, SMS_indexes *ind
14491438
memset(rbuffer, 0, 1024);
14501439

14511440
// ** Send command to GSM and get the response
1452-
char *cmd = SMS_LIST_ALL_STR;
1453-
if (rd_status == SMS_LIST_NEW) cmd = SMS_LIST_NEW_STR;
1454-
else if (rd_status == SMS_LIST_OLD) cmd = SMS_LIST_OLD_STR;
1441+
if (rd_status == SMS_LIST_NEW) sprintf(cmd, "%s%s\r\n", SMS_LIST_NEW_STR, list_change);
1442+
else if (rd_status == SMS_LIST_OLD) sprintf(cmd, "%s%s\r\n", SMS_LIST_OLD_STR, list_change);
1443+
else sprintf(cmd, "%s%s\r\n", SMS_LIST_ALL_STR, list_change);
14551444

14561445
// Read all messages to buffer
1446+
at_responses_t at_responses1;
1447+
memset(&at_responses1, 0, sizeof(at_responses_t));
1448+
at_responses1.nresp = 2;
1449+
at_responses1.resp[0] = AT_OK_Str;
1450+
at_responses1.resp[1] = AT_Error_Str;
1451+
14571452
memset(&gsm_at_responses, 0, sizeof(at_responses_t));
1458-
memset(&gsm_at_command, 0, sizeof(at_command_t));
14591453
gsm_at_responses.nresp = 2;
1460-
gsm_at_responses.resp[0] = "\r\n\r\nOK";
1454+
gsm_at_responses.resp[0] = "\r\n\r\nOK\r\n"; // wait for end of messages list
14611455
gsm_at_responses.resp[1] = AT_Error_Str;
1462-
gsm_at_command.cmd = cmd;
1463-
gsm_at_command.cmdSize = strlen(cmd);
1464-
gsm_at_command.responses = &gsm_at_responses;
1465-
gsm_at_command.timeout = 4000;
1466-
gsm_at_command.at_uart_num = gsm_uart_num;
1467-
gsm_at_command.dbg = gsm_debug;
1468-
gsm_at_command.respbSize = 1024;
1469-
gsm_at_command.respbuff = rbuffer;
1470-
gsm_at_command.flush = true;
1456+
1457+
at_commands_t at_commands;
1458+
memset(&at_commands, 0, sizeof(at_commands_t));
1459+
at_commands.ncmd = 2;
1460+
at_commands.at_uart_num = gsm_uart_num;
1461+
at_commands.dbg = gsm_debug;
1462+
at_commands.expect_resp[0] = 1;
1463+
at_commands.expect_resp[1] = 1;
1464+
1465+
at_commands.commands[0].cmd = "AT+CMGF=1\r\n";
1466+
at_commands.commands[0].cmdSize = -1;
1467+
at_commands.commands[0].responses = &at_responses1;
1468+
at_commands.commands[0].timeout = 100;
1469+
at_commands.commands[0].at_uart_num = gsm_uart_num;
1470+
at_commands.commands[0].dbg = gsm_debug;
1471+
at_commands.commands[0].flush = true;
1472+
1473+
at_commands.commands[1].cmd = cmd;
1474+
at_commands.commands[1].cmdSize = strlen(cmd);
1475+
at_commands.commands[1].responses = &gsm_at_responses;
1476+
at_commands.commands[1].timeout = 2000;
1477+
at_commands.commands[1].at_uart_num = gsm_uart_num;
1478+
at_commands.commands[1].dbg = gsm_debug;
1479+
at_commands.commands[1].respbSize = 1024;
1480+
at_commands.commands[1].respbuff = rbuffer;
1481+
at_commands.commands[1].flush = true;
14711482

14721483
int buflen = 0;
1484+
int res, n_proc = 0;
1485+
int msgidx = 0;
1486+
time_t msgtime = 0;
14731487

14741488
// Execute command
1475-
int res = gsm_at_Cmd(&gsm_at_command);
1489+
res = gsm_at_Commands(&at_commands, &n_proc);
14761490

1477-
if (res == 1) buflen = strlen(gsm_at_command.respbuff);
1491+
if ((n_proc == 2) && (res == 1)) buflen = strlen(at_commands.commands[1].respbuff);
14781492

14791493
if (indexes !=NULL) memset(indexes, 0, sizeof(SMS_indexes));
14801494
// The buffer may have been expanded
1481-
rbuffer = gsm_at_command.respbuff;
1495+
rbuffer = at_commands.commands[1].respbuff;
14821496

14831497
// Parse the response
14841498
int nmsg = 0;
@@ -1498,13 +1512,15 @@ int checkMessages(uint8_t rd_status, int sms_idx, SMS_Msg *msg, SMS_indexes *ind
14981512
}
14991513
}
15001514
if ((msgstart) && (msgend_h) && (msgend_t)) {
1501-
// We have at least one the whole message in the buffer
1515+
// We have at least one whole message in the buffer
15021516
nmsg++;
1517+
msgidx = getSMSindex(msgstart+7, &msgtime);
15031518
if ((indexes !=NULL) && (nmsg < SMS_MAX_MESSAGES)) {
15041519
// Only save message index and time
1505-
indexes->idx[nmsg-1] = getSMSindex(msgstart+7, &indexes->time[nmsg-1]);
1520+
indexes->idx[nmsg-1] = msgidx;
1521+
indexes->time[nmsg-1] = msgtime;
15061522
}
1507-
if ((sms_idx == (nmsg-1)) && (msg != NULL)) {
1523+
if ((sms_idx == msgidx) && (msg != NULL)) {
15081524
// Get the message text if requested, save message info and text
15091525
getSMS(msgstart+7, msg, 1);
15101526
idx_found = 1;
@@ -1608,7 +1624,7 @@ int smsSend(char *smsnum, char *msg)
16081624
at_commands.commands[1].dbg = gsm_debug;
16091625
at_commands.commands[1].flush = true;
16101626

1611-
res = gsm_at_Commands(&at_commands);
1627+
res = gsm_at_Commands(&at_commands, NULL);
16121628
if (res != 1) {
16131629
// Try to recover
16141630
at_uart_write(gsm_uart_num, (uint8_t *)"\x1B", 1);
@@ -1715,25 +1731,43 @@ bool gsm_set_baudrate(int bdr, bool perm)
17151731
}
17161732

17171733

1734+
//==========================
1735+
int setNTP_cb(void *cb_func)
1736+
{
1737+
int stat = ppposStatus(NULL, NULL, NULL);
1738+
int taken = pdFALSE;
1739+
if ((stat != ATDEV_STATEFIRSTINIT) && (mpy_uarts[gsm_uart_num].uart_mutex != NULL))
1740+
taken = xSemaphoreTake(mpy_uarts[gsm_uart_num].uart_mutex, PPPOSMUTEX_TIMEOUT*5);
1741+
1742+
ntp_time_cb = cb_func;
1743+
1744+
if (taken) xSemaphoreGive(mpy_uarts[gsm_uart_num].uart_mutex);
1745+
return 1;
1746+
}
1747+
17181748
//=============================================
17191749
int setSMS_cb(void *cb_func, uint32_t interval)
17201750
{
1721-
if (mpy_uarts[gsm_uart_num].uart_mutex == NULL) return 0;
1722-
if (xSemaphoreTake(mpy_uarts[gsm_uart_num].uart_mutex, PPPOSMUTEX_TIMEOUT*5) != pdTRUE) return 0;
1751+
int stat = ppposStatus(NULL, NULL, NULL);
1752+
int taken = pdFALSE;
1753+
if ((stat != ATDEV_STATEFIRSTINIT) && (mpy_uarts[gsm_uart_num].uart_mutex != NULL))
1754+
taken = xSemaphoreTake(mpy_uarts[gsm_uart_num].uart_mutex, PPPOSMUTEX_TIMEOUT*5);
17231755

17241756
new_SMS_cb = cb_func;
17251757
SMS_check_interval = interval;
17261758
sms_timer = mp_hal_ticks_ms() + SMS_check_interval;
1759+
doCheckSMS = 1;
17271760

1728-
xSemaphoreGive(mpy_uarts[gsm_uart_num].uart_mutex);
1761+
if (taken) xSemaphoreGive(mpy_uarts[gsm_uart_num].uart_mutex);
17291762
return 1;
17301763
}
17311764

17321765
//=========================
17331766
void gsm_setDebug(bool dbg)
17341767
{
1768+
int stat = ppposStatus(NULL, NULL, NULL);
17351769
int taken = pdFALSE;
1736-
if (mpy_uarts[gsm_uart_num].uart_mutex != NULL) taken = xSemaphoreTake(mpy_uarts[gsm_uart_num].uart_mutex, PPPOSMUTEX_TIMEOUT);
1770+
if ((stat != ATDEV_STATEFIRSTINIT) && (mpy_uarts[gsm_uart_num].uart_mutex != NULL)) taken = xSemaphoreTake(mpy_uarts[gsm_uart_num].uart_mutex, PPPOSMUTEX_TIMEOUT);
17371771
gsm_debug = dbg;
17381772
if (taken) xSemaphoreGive(mpy_uarts[gsm_uart_num].uart_mutex);
17391773
}
@@ -1755,8 +1789,8 @@ int gsm_at_Cmd(at_command_t *command)
17551789
return res;
17561790
}
17571791

1758-
//==========================================
1759-
int gsm_at_Commands(at_commands_t *commands)
1792+
//==========================================================
1793+
int gsm_at_Commands(at_commands_t *commands, int *processed)
17601794
{
17611795
if (ppposStatus(NULL, NULL, NULL) != ATDEV_STATEIDLE) return 0;
17621796

@@ -1766,8 +1800,7 @@ int gsm_at_Commands(at_commands_t *commands)
17661800
}
17671801
return 0;
17681802
}
1769-
int n_proc = 0;
1770-
int res = at_Commands(commands, &n_proc);
1803+
int res = at_Commands(commands, processed);
17711804
xSemaphoreGive(mpy_uarts[gsm_uart_num].uart_mutex);
17721805

17731806
return res;

k210-freertos/mpy_support/standard_lib/include/libGSM.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
#define SMS_LIST_ALL 0
4343
#define SMS_LIST_NEW 1
4444
#define SMS_LIST_OLD 2
45-
#define SMS_LIST_ALL_STR "AT+CMGL=\"ALL\"\r\n"
46-
#define SMS_LIST_NEW_STR "AT+CMGL=\"REC UNREAD\"\r\n"
47-
#define SMS_LIST_OLD_STR "AT+CMGL=\"REC READ\"\r\n"
45+
#define SMS_LIST_ALL_STR "AT+CMGL=\"ALL\""
46+
#define SMS_LIST_NEW_STR "AT+CMGL=\"REC UNREAD\""
47+
#define SMS_LIST_OLD_STR "AT+CMGL=\"REC READ\""
4848

4949
#define SMS_MAX_MESSAGES 64
5050

@@ -157,8 +157,8 @@ void gsm_setDebug(bool dbg);
157157
//====================================
158158
int gsm_at_Cmd(at_command_t *command);
159159

160-
//===========================================
161-
int gsm_at_Commands(at_commands_t *commands);
160+
//===========================================================
161+
int gsm_at_Commands(at_commands_t *commands, int *processed);
162162

163163
//========================================
164164
bool gsm_set_baudrate(int bdr, bool perm);

0 commit comments

Comments
 (0)