Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 44b21d6

Browse files
committed
Update to development release 1.19.0.b3
esp32/core: Add support for FatFS & LittleFS esp32/mods: Enabled wifi/bt after light sleep wakeup esp32/mods/pycom: Add bootmgr() function to control application partition, filesystem type and safeboot esp32/mods: added blutooth client re-connection after wakeup from light sleep + Server advertisments resume after light sleep wakeup esp32/mods: feature to recover wifi connectivity after light sleep wakeup esp32/mods/modbt: Remov unnecessary Api esp32/ftp: Fix a bug were files are listed twice through FTP on LFS esp32/sdkconfig.h: updated after IDF new version update
1 parent 7ec4c0a commit 44b21d6

25 files changed

+639
-87
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ By default the firmware is built for the WIPY2:
109109
$ make
110110
$ make flash
111111

112+
You can force the firmware to use LittleFS (the default is FatFS if not configured via pycom.bootmgr() or firmware updater):
113+
114+
$ cd esp32
115+
$ make clean
116+
$ make FS=LFS
117+
$ make flash
118+
119+
112120
By default, both bootloader and application are built. To build them separately:
113121

114122
$ cd esp32

drivers/sx127x/sx1272/sx1272.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is derived from the MicroPython project, http://micropython.org/
33
*
4-
* Copyright (c) 2016, Pycom Limited and its licensors.
4+
* Copyright (c) 2018, Pycom Limited and its licensors.
55
*
66
* This software is licensed under the GNU GPL version 3 or any later version,
77
* with permitted additional terms. For more information see the Pycom Licence

drivers/sx127x/sx1276/sx1276.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is derived from the MicroPython project, http://micropython.org/
33
*
4-
* Copyright (c) 2016, Pycom Limited and its licensors.
4+
* Copyright (c) 2018, Pycom Limited and its licensors.
55
*
66
* This software is licensed under the GNU GPL version 3 or any later version,
77
* with permitted additional terms. For more information see the Pycom Licence

esp32/application.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,12 @@ CFLAGS += $(APP_INC) -DMICROPY_NLR_SETJMP=1 -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_
333333
CFLAGS_SIGFOX += $(APP_INC) -DMICROPY_NLR_SETJMP=1 -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' -DHAVE_CONFIG_H -DESP_PLATFORM
334334
CFLAGS += -DREGION_AS923 -DREGION_AU915 -DREGION_EU868 -DREGION_US915
335335

336+
# Give the possibility to use LittleFs on /flash, otherwise FatFs is used
337+
FS ?= ""
338+
ifeq ($(FS), LFS)
339+
CFLAGS += -DFS_USE_LITTLEFS
340+
endif
341+
336342
# add the application archive, this order is very important
337343
APP_LIBS = -Wl,--start-group $(LIBS) $(BUILD)/application.a -Wl,--end-group -Wl,-EL
338344

esp32/bootloader/bootloader.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ static void print_flash_info(const esp_image_header_t* phdr)
745745

746746
static void vddsdio_configure()
747747
{
748-
#if CONFIG_BOOTLOADER_VDDSDIO_BOOST
748+
#if CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V
749749
rtc_vddsdio_config_t cfg = rtc_vddsdio_get_config();
750750
if (cfg.enable == 1 && cfg.tieh == 0) { // VDDSDIO regulator is enabled @ 1.8V
751751
cfg.drefh = 3;
@@ -755,7 +755,7 @@ static void vddsdio_configure()
755755
rtc_vddsdio_set_config(cfg);
756756
ets_delay_us(10); // wait for regulator to become stable
757757
}
758-
#endif // CONFIG_BOOTLOADER_VDDSDIO_BOOST
758+
#endif // CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V
759759
}
760760

761761

esp32/ftp/ftp.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151

5252
#include "machrtc.h"
5353

54+
#include "mptask.h"
55+
5456
/******************************************************************************
5557
DEFINE PRIVATE CONSTANTS
5658
******************************************************************************/
@@ -1419,8 +1421,16 @@ static ftp_result_t ftp_list_dir (char *list, uint32_t maxlistsize, uint32_t *li
14191421
result = E_FTP_RESULT_OK;
14201422
break; /* Break on error or end of dp */
14211423
}
1422-
if (fno.u.fpinfo_lfs.name[0] == '.' && fno.u.fpinfo_lfs.name[1] == 0) continue; /* Ignore . entry */
1423-
if (fno.u.fpinfo_lfs.name[0] == '.' && fno.u.fpinfo_lfs.name[1] == '.' && fno.u.fpinfo_lfs.name[2] == 0) continue; /* Ignore .. entry */
1424+
if (fno.u.fpinfo_lfs.name[0] == '.' && fno.u.fpinfo_lfs.name[1] == 0)
1425+
{
1426+
ftp_last_dir_idx++;
1427+
continue; /* Ignore . entry, but need to count it as LittleFs does not filter it out opposed to FatFs */
1428+
}
1429+
if (fno.u.fpinfo_lfs.name[0] == '.' && fno.u.fpinfo_lfs.name[1] == '.' && fno.u.fpinfo_lfs.name[2] == 0)
1430+
{
1431+
ftp_last_dir_idx++;
1432+
continue; /* Ignore .. entry, but need to count it as LittleFs does not filter it out opposed to FatFs */
1433+
}
14241434
}
14251435
else
14261436
{

esp32/littlefs/vfs_littlefs.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,19 +168,6 @@ static int parse_and_append_to_cwd(vfs_lfs_struct_t* littlefs, const char* path_
168168
return LFS_ERR_OK;
169169
}
170170

171-
bool isLittleFs(const TCHAR *path)
172-
{
173-
const char *flash = "/flash";
174-
175-
if(strncmp(flash, path, sizeof(flash)-1) == 0)
176-
{
177-
return true;
178-
}
179-
else
180-
{
181-
return false;
182-
}
183-
}
184171

185172
// this table converts from FRESULT to POSIX errno
186173
byte littleFsErrorToErrno(enum lfs_error littleFsError)

esp32/littlefs/vfs_littlefs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ typedef struct vfs_lfs_struct_s
1414
SemaphoreHandle_t mutex; // Needs to be created
1515
}vfs_lfs_struct_t;
1616

17-
extern bool isLittleFs(const TCHAR *path);
1817
extern byte littleFsErrorToErrno(enum lfs_error littleFsError);
1918
extern FRESULT lfsErrorToFatFsError(int lfs_error);
2019
extern int fatFsModetoLittleFsMode(int FatFsMode);

esp32/mods/modbt.c

Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ static esp_ble_adv_params_t bt_adv_params = {
226226
.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
227227
};
228228

229+
static bool mod_bt_is_deinit;
230+
static bool mod_bt_is_conn_restore_available;
231+
229232
/******************************************************************************
230233
DECLARE PRIVATE FUNCTIONS
231234
******************************************************************************/
@@ -237,6 +240,9 @@ static void close_connection(int32_t conn_id);
237240
STATIC void bluetooth_callback_handler(void *arg);
238241
STATIC void gattc_char_callback_handler(void *arg);
239242
STATIC void gatts_char_callback_handler(void *arg);
243+
static mp_obj_t modbt_start_scan(mp_obj_t timeout);
244+
static mp_obj_t modbt_conn_disconnect(mp_obj_t self_in);
245+
static mp_obj_t modbt_connect(mp_obj_t addr);
240246

241247
/******************************************************************************
242248
DEFINE PUBLIC FUNCTIONS
@@ -263,6 +269,69 @@ void modbt_init0(void) {
263269
mp_obj_list_init((mp_obj_t)&MP_STATE_PORT(bts_attr_list), 0);
264270

265271
esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT);
272+
273+
mod_bt_is_deinit = false;
274+
mod_bt_is_conn_restore_available = false;
275+
}
276+
277+
void bt_resume(bool reconnect)
278+
{
279+
if(mod_bt_is_deinit && !bt_obj.init)
280+
{
281+
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
282+
esp_bt_controller_init(&bt_cfg);
283+
284+
esp_bt_controller_enable(ESP_BT_MODE_BLE);
285+
286+
if (ESP_OK != esp_bluedroid_init()) {
287+
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Bluetooth init failed"));
288+
}
289+
if (ESP_OK != esp_bluedroid_enable()) {
290+
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Bluetooth enable failed"));
291+
}
292+
293+
esp_ble_gattc_app_register(MOD_BT_CLIENT_APP_ID);
294+
esp_ble_gatts_app_register(MOD_BT_SERVER_APP_ID);
295+
296+
esp_ble_gatt_set_local_mtu(200);
297+
298+
bt_connection_obj_t *connection_obj = NULL;
299+
300+
if(MP_STATE_PORT(btc_conn_list).len > 0)
301+
{
302+
/* Get the Last gattc connection obj before sleep */
303+
connection_obj = ((bt_connection_obj_t *)(MP_STATE_PORT(btc_conn_list).items[MP_STATE_PORT(btc_conn_list).len - 1]));
304+
}
305+
306+
if (reconnect)
307+
{
308+
/* Check if there was a gattc connection Active before sleep */
309+
if (connection_obj != NULL) {
310+
if (connection_obj->conn_id >= 0) {
311+
/* Enable Scan */
312+
modbt_start_scan(MP_OBJ_NEW_SMALL_INT(-1));
313+
mp_hal_delay_ms(50);
314+
while(!bt_obj.scanning){
315+
/* Wait for scanning to start */
316+
}
317+
/* re-connect to Last Connection */
318+
mp_obj_list_remove((void *)&MP_STATE_PORT(btc_conn_list), connection_obj);
319+
mp_obj_list_append((void *)&MP_STATE_PORT(btc_conn_list), modbt_connect(mp_obj_new_bytes((const byte *)connection_obj->srv_bda, 6)));
320+
321+
mod_bt_is_conn_restore_available = true;
322+
}
323+
}
324+
325+
/* See if there was an averstisment active before Sleep */
326+
if(bt_obj.advertising)
327+
{
328+
esp_ble_gap_start_advertising(&bt_adv_params);
329+
}
330+
}
331+
332+
bt_obj.init = true;
333+
mod_bt_is_deinit = false;
334+
}
266335
}
267336

268337
/******************************************************************************
@@ -282,7 +351,8 @@ static esp_ble_scan_params_t ble_scan_params = {
282351
static void close_connection (int32_t conn_id) {
283352
for (mp_uint_t i = 0; i < MP_STATE_PORT(btc_conn_list).len; i++) {
284353
bt_connection_obj_t *connection_obj = ((bt_connection_obj_t *)(MP_STATE_PORT(btc_conn_list).items[i]));
285-
if (connection_obj->conn_id == conn_id) {
354+
/* Only reset Conn Id if it is a normal disconnect not module de-init to mark conn obj to be restored */
355+
if (connection_obj->conn_id == conn_id && (!mod_bt_is_deinit)) {
286356
connection_obj->conn_id = -1;
287357
mp_obj_list_remove((void *)&MP_STATE_PORT(btc_conn_list), connection_obj);
288358
}
@@ -461,6 +531,7 @@ static void gattc_events_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc
461531
// intentional fall through
462532
case ESP_GATTC_CLOSE_EVT:
463533
close_connection(p_data->close.conn_id);
534+
bt_obj.busy = false;
464535
break;
465536
default:
466537
break;
@@ -765,10 +836,23 @@ mp_obj_t bt_deinit(mp_obj_t self_in) {
765836
esp_ble_gap_stop_scanning();
766837
bt_obj.scanning = false;
767838
}
839+
/* Indicate module is de-initializing */
840+
mod_bt_is_deinit = true;
841+
842+
bt_connection_obj_t *connection_obj;
843+
844+
for (mp_uint_t i = 0; i < MP_STATE_PORT(btc_conn_list).len; i++)
845+
{
846+
// loop through the connections
847+
connection_obj = ((bt_connection_obj_t *)(MP_STATE_PORT(btc_conn_list).items[i]));
848+
//close connections
849+
modbt_conn_disconnect(connection_obj);
850+
}
768851
esp_bluedroid_disable();
769852
esp_bluedroid_deinit();
770853
esp_bt_controller_disable();
771854
bt_obj.init = false;
855+
mod_bt_is_conn_restore_available = false;
772856
}
773857
return mp_const_none;
774858
}
@@ -795,6 +879,11 @@ STATIC mp_obj_t bt_start_scan(mp_obj_t self_in, mp_obj_t timeout) {
795879
}
796880
STATIC MP_DEFINE_CONST_FUN_OBJ_2(bt_start_scan_obj, bt_start_scan);
797881

882+
static mp_obj_t modbt_start_scan(mp_obj_t timeout)
883+
{
884+
return bt_start_scan(NULL, timeout);
885+
}
886+
798887
STATIC mp_obj_t bt_isscanning(mp_obj_t self_in) {
799888
if (bt_obj.scanning) {
800889
return mp_const_true;
@@ -990,6 +1079,11 @@ STATIC mp_obj_t bt_connect(mp_obj_t self_in, mp_obj_t addr) {
9901079
}
9911080
STATIC MP_DEFINE_CONST_FUN_OBJ_2(bt_connect_obj, bt_connect);
9921081

1082+
static mp_obj_t modbt_connect(mp_obj_t addr)
1083+
{
1084+
return bt_connect(NULL, addr);
1085+
}
1086+
9931087
STATIC mp_obj_t bt_set_advertisement (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
9941088
static const mp_arg_t allowed_args[] = {
9951089
{ MP_QSTR_name, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
@@ -1510,12 +1604,21 @@ STATIC mp_obj_t bt_conn_disconnect(mp_obj_t self_in) {
15101604
if (self->conn_id >= 0) {
15111605
esp_ble_gattc_close(bt_obj.gattc_if, self->conn_id);
15121606
esp_ble_gap_disconnect(self->srv_bda);
1513-
self->conn_id = -1;
1607+
/* Only reset Conn Id if it is a normal disconnect not module de-init to mark conn obj to be restored */
1608+
if(!mod_bt_is_deinit)
1609+
{
1610+
self->conn_id = -1;
1611+
}
15141612
}
15151613
return mp_const_none;
15161614
}
15171615
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bt_conn_disconnect_obj, bt_conn_disconnect);
15181616

1617+
static mp_obj_t modbt_conn_disconnect(mp_obj_t self_in)
1618+
{
1619+
return bt_conn_disconnect(self_in);
1620+
}
1621+
15191622
STATIC mp_obj_t bt_conn_services (mp_obj_t self_in) {
15201623
bt_connection_obj_t *self = self_in;
15211624
bt_event_result_t bt_event;

esp32/mods/modbt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
******************************************************************************/
2828
extern void modbt_init0(void);
2929
extern mp_obj_t bt_deinit(mp_obj_t self_in);
30-
30+
extern void bt_resume(bool reconnect);
3131
#endif // MODBT_H_

0 commit comments

Comments
 (0)