diff --git a/esp32/Makefile b/esp32/Makefile index 616720ccd9..742dae3c04 100644 --- a/esp32/Makefile +++ b/esp32/Makefile @@ -14,7 +14,7 @@ ifeq ($(wildcard boards/$(BOARD)/.),) $(error Invalid BOARD specified) endif -IDF_HASH=d072c55 +IDF_HASH=6ec081c TARGET ?= boot_app diff --git a/esp32/PyJTAG/Readme.md b/esp32/PyJTAG/Readme.md index cb44c9e89b..415fd342eb 100644 --- a/esp32/PyJTAG/Readme.md +++ b/esp32/PyJTAG/Readme.md @@ -80,6 +80,17 @@ It can be advisable to use the `gdb` from the latest xtensa toolchain, even if a If `gdb` does not reach the `Thread 1 hit Temporary breakpoint ...` line, close and reopen `gdb`. + +## Versions +There are two generations of PyJTAG boards: + +1) First generation with green PCB has three blocks of switches. (Make sure SAFE_BOOT_SW is off.) +2) Second generation with black PCB and two blocks of switches. + +Both generation boards can be equipped with pogo pins that connect to the bottom of the development board and allow LTE debugging. There can either be pins that connect to a GPy or pins that conenct to a FiPy. + +To reach the modem UART connect to `/dev/ttyUSB1`. + ## Extra A few more details are here: https://pycomiot.atlassian.net/wiki/spaces/FIR/pages/966295564/Usage+of+PyJTAG diff --git a/esp32/fatfs/src/drivers/sflash_diskio.c b/esp32/fatfs/src/drivers/sflash_diskio.c index 6e20352a68..421fb98a79 100644 --- a/esp32/fatfs/src/drivers/sflash_diskio.c +++ b/esp32/fatfs/src/drivers/sflash_diskio.c @@ -54,7 +54,7 @@ DRESULT sflash_disk_init (void) { sflash_start_address = SFLASH_START_ADDR_4MB; sflash_fs_sector_count = SFLASH_FS_SECTOR_COUNT_4MB; } - sflash_block_cache = (uint8_t *)heap_caps_malloc(SFLASH_BLOCK_SIZE, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + sflash_block_cache = (uint8_t *)malloc(SFLASH_BLOCK_SIZE); sflash_prev_block_addr = UINT32_MAX; sflash_cache_is_dirty = false; sflash_init_done = true; diff --git a/esp32/frozen/Pybytes/_pybytes.py b/esp32/frozen/Pybytes/_pybytes.py index ba191c21db..4251baa2c6 100644 --- a/esp32/frozen/Pybytes/_pybytes.py +++ b/esp32/frozen/Pybytes/_pybytes.py @@ -273,16 +273,13 @@ def connect(self): self.enable_terminal() # CHECK PYMESH FIRMWARE VERSION - try: - if hasattr(os.uname(),'pymesh'): - try: - from pybytes_pymesh_config import PybytesPymeshConfig - except: - from _pybytes_pymesh_config import PybytesPymeshConfig - self.__pymesh = PybytesPymeshConfig(self) - self.__pymesh.pymesh_init() - except Exception as e: - print("Exception: {}".format(e)) + if hasattr(os.uname(), 'pymesh'): + try: + from pybytes_pymesh_config import PybytesPymeshConfig + except: + from _pybytes_pymesh_config import PybytesPymeshConfig + self.__pymesh = PybytesPymeshConfig(self) + self.__pymesh.pymesh_init() else: print('ERROR! Could not connect to Pybytes!') diff --git a/esp32/frozen/Pybytes/_pybytes_constants.py b/esp32/frozen/Pybytes/_pybytes_constants.py index 8b68cffa9c..bd2117fef5 100644 --- a/esp32/frozen/Pybytes/_pybytes_constants.py +++ b/esp32/frozen/Pybytes/_pybytes_constants.py @@ -96,6 +96,7 @@ class constants: __FCOTA_COMMAND_FILE_UPDATE = 0x02 __FCOTA_PING = 0x03 __FCOTA_COMMAND_FILE_DELETE = 0x04 + __FCOTA_COMMAND_FILE_UPDATE_NO_RESET = 0x05 __DEVICE_TYPE_WIPY = 0x00 __DEVICE_TYPE_LOPY = 0x01 diff --git a/esp32/frozen/Pybytes/_pybytes_protocol.py b/esp32/frozen/Pybytes/_pybytes_protocol.py index 484b242add..385d8c6f9c 100644 --- a/esp32/frozen/Pybytes/_pybytes_protocol.py +++ b/esp32/frozen/Pybytes/_pybytes_protocol.py @@ -276,6 +276,23 @@ def __process_recv_message(self, message): else: self.send_fcota_ping("file update failed!") + elif (command == constants.__FCOTA_COMMAND_FILE_UPDATE_NO_RESET): + bodyString = body[1:len(body)].decode() + splittedBody = bodyString.split(',') + if (len(splittedBody) >= 2): + path = splittedBody[0] + print_debug(2, path[len(path)-7:len(path)]) + if (path[len(path)-7:len(path)] != '.pymakr'): + self.send_fcota_ping('updating file...') + newContent = bodyString[len(path)+1:len(body)] + if (self.__FCOTA.update_file_content(path, newContent) is True): # noqa + size = self.__FCOTA.get_file_size(path) + self.send_fcota_file(newContent, path, size) + else: + self.send_fcota_ping('file update failed!') + else: + self.send_fcota_ping("file update failed!") + elif (command == constants.__FCOTA_PING): self.send_fcota_ping('') diff --git a/esp32/frozen/Pybytes/_pybytes_pymesh_config.py b/esp32/frozen/Pybytes/_pybytes_pymesh_config.py index aa1d6586ab..699e16c11e 100644 --- a/esp32/frozen/Pybytes/_pybytes_pymesh_config.py +++ b/esp32/frozen/Pybytes/_pybytes_pymesh_config.py @@ -150,7 +150,7 @@ def write_config(self, wmac, file='/flash/pymesh_config.json', pymeshSettings={} "ble_api": False, "ble_name_prefix": "Device-{}".format(wmac), "br_prio": 0, - "br_ena": False, + "br_ena": customSettings["br_ena"], "autostart": True } diff --git a/esp32/ftp/ftp.c b/esp32/ftp/ftp.c index bb673e173b..6c551614bc 100644 --- a/esp32/ftp/ftp.c +++ b/esp32/ftp/ftp.c @@ -338,7 +338,7 @@ STATIC FRESULT f_readdir_helper(ftp_dir_t *dp, ftp_fileinfo_t *fno ) { if(length_of_relative_path > 1) { path_length++; } - char* file_relative_path = m_malloc(path_length); + char* file_relative_path = malloc(path_length); // Copy the current working directory (relative path) memcpy(file_relative_path, path_relative, length_of_relative_path); @@ -359,7 +359,7 @@ STATIC FRESULT f_readdir_helper(ftp_dir_t *dp, ftp_fileinfo_t *fno ) { fno->u.fpinfo_lfs.timestamp.ftime = 0; } - m_free(file_relative_path); + free(file_relative_path); } xSemaphoreGive(littlefs->mutex); @@ -614,10 +614,10 @@ static void ftp_return_to_previous_path (char *pwd, char *dir); ******************************************************************************/ void ftp_init (void) { // allocate memory for the data buffer, and the file system structs (from the RTOS heap) - ftp_data.dBuffer = heap_caps_malloc(FTP_BUFFER_SIZE, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); - ftp_path = heap_caps_malloc(FTP_MAX_PARAM_SIZE, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); - ftp_scratch_buffer = heap_caps_malloc(FTP_MAX_PARAM_SIZE, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); - ftp_cmd_buffer = heap_caps_malloc(FTP_MAX_PARAM_SIZE + FTP_CMD_SIZE_MAX, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + ftp_data.dBuffer = malloc(FTP_BUFFER_SIZE); + ftp_path = malloc(FTP_MAX_PARAM_SIZE); + ftp_scratch_buffer = malloc(FTP_MAX_PARAM_SIZE); + ftp_cmd_buffer = malloc(FTP_MAX_PARAM_SIZE + FTP_CMD_SIZE_MAX); SOCKETFIFO_Init (&ftp_socketfifo, (void *)ftp_fifoelements, FTP_SOCKETFIFO_ELEMENTS_MAX); ftp_data.c_sd = -1; ftp_data.d_sd = -1; @@ -933,7 +933,7 @@ static void ftp_send_reply (uint32_t status, char *message) { strcat ((char *)ftp_cmd_buffer, "\r\n"); fifoelement.sd = &ftp_data.c_sd; fifoelement.datasize = strlen((char *)ftp_cmd_buffer); - fifoelement.data = pvPortMalloc(fifoelement.datasize); + fifoelement.data = malloc(fifoelement.datasize); if (status == 221) { fifoelement.closesockets = E_FTP_CLOSE_CMD_AND_DATA; } else if (status == 426 || status == 451 || status == 550) { @@ -945,7 +945,7 @@ static void ftp_send_reply (uint32_t status, char *message) { if (fifoelement.data) { memcpy (fifoelement.data, ftp_cmd_buffer, fifoelement.datasize); if (!SOCKETFIFO_Push (&fifoelement)) { - vPortFree(fifoelement.data); + free(fifoelement.data); } } } @@ -979,13 +979,13 @@ static void ftp_send_from_fifo (void) { ftp_close_filesystem_on_error(); } if (fifoelement.freedata) { - vPortFree(fifoelement.data); + free(fifoelement.data); } } } else { // socket closed, remove it from the queue SOCKETFIFO_Pop (&fifoelement); if (fifoelement.freedata) { - vPortFree(fifoelement.data); + free(fifoelement.data); } } } else if (ftp_data.state == E_FTP_STE_END_TRANSFER && (ftp_data.d_sd > 0)) { diff --git a/esp32/littlefs/lfs_util.h b/esp32/littlefs/lfs_util.h index 6c1c8ebe82..801ac80eda 100644 --- a/esp32/littlefs/lfs_util.h +++ b/esp32/littlefs/lfs_util.h @@ -21,7 +21,6 @@ #include "py/mpconfig.h" #include "py/misc.h" -#include "py/gc.h" // System includes #include @@ -204,7 +203,7 @@ uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size); // Note, memory must be 64-bit aligned static inline void *lfs_malloc(size_t size) { #ifndef LFS_NO_MALLOC - return gc_alloc(size, false); + return malloc(size); #else return NULL; #endif @@ -213,7 +212,7 @@ static inline void *lfs_malloc(size_t size) { // Deallocate memory, only used if buffers are not provided to littlefs static inline void lfs_free(void *p) { #ifndef LFS_NO_MALLOC - m_free(p); + free(p); #endif } diff --git a/esp32/littlefs/vfs_littlefs.c b/esp32/littlefs/vfs_littlefs.c index 1cb8c8ece2..f56ee84caa 100644 --- a/esp32/littlefs/vfs_littlefs.c +++ b/esp32/littlefs/vfs_littlefs.c @@ -4,7 +4,6 @@ #include #include "py/runtime.h" #include "py/mperrno.h" -#include "py/gc.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs.h" #include "vfs_littlefs.h" @@ -18,14 +17,14 @@ int lfs_statvfs_count(void *p, lfs_block_t b) return 0; } -// After this function m_free() must be called on the returned address after usage!! +// After this function free() must be called on the returned address after usage!! const char* concat_with_cwd(vfs_lfs_struct_t* littlefs, const char* path) { char* path_out = NULL; if (path[0] == '/') /* Absolute path */ { - path_out = (char*)gc_alloc(strlen(path) + 1, false); // Count the \0 too + path_out = (char*)malloc(strlen(path) + 1); // Count the \0 too if(path_out != NULL) { strcpy(path_out, path); @@ -33,7 +32,7 @@ const char* concat_with_cwd(vfs_lfs_struct_t* littlefs, const char* path) } else { - path_out = (char*)gc_alloc(strlen(littlefs->cwd) + 1 + strlen(path) + 1, false); + path_out = (char*)malloc(strlen(littlefs->cwd) + 1 + strlen(path) + 1); if(path_out != NULL) { strcpy(path_out, littlefs->cwd); @@ -130,9 +129,8 @@ static int change_cwd(vfs_lfs_struct_t* littlefs, const char* path_in) } else if(is_valid_directory(littlefs, new_path)) { - m_free(littlefs->cwd); + free(littlefs->cwd); littlefs->cwd = (char*)new_path; - MP_STATE_PORT(lfs_cwd) = littlefs->cwd; res = LFS_ERR_OK; } @@ -354,12 +352,12 @@ void littlefs_prepare_attributes(struct lfs_file_config *cfg) { // Currently we only have 1 attribute cfg->attr_count = 1; - cfg->attrs = m_malloc(cfg->attr_count * sizeof(struct lfs_attr)); + cfg->attrs = malloc(cfg->attr_count * sizeof(struct lfs_attr)); // Set attribute for storing the timestamp cfg->attrs[0].size = sizeof(lfs_timestamp_attribute_t); cfg->attrs[0].type = LFS_ATTRIBUTE_TIMESTAMP; - cfg->attrs[0].buffer = m_malloc(sizeof(lfs_timestamp_attribute_t)); + cfg->attrs[0].buffer = malloc(sizeof(lfs_timestamp_attribute_t)); } @@ -367,8 +365,8 @@ void littlefs_free_up_attributes(struct lfs_file_config *cfg) { cfg->attr_count = 0; // Currently we only have 1 attribute for timestamp - m_free(cfg->attrs[0].buffer); - m_free(cfg->attrs); + free(cfg->attrs[0].buffer); + free(cfg->attrs); } @@ -479,18 +477,15 @@ STATIC mp_obj_t littlefs_vfs_ilistdir_func(size_t n_args, const mp_obj_t *args) iter->is_str = is_str_type; xSemaphoreTake(self->fs.littlefs.mutex, portMAX_DELAY); - const char* path = concat_with_cwd(&self->fs.littlefs, path_in); - if(path == NULL) - { + const char *path = concat_with_cwd(&self->fs.littlefs, path_in); + if (path == NULL) { res = LFS_ERR_NOMEM; - } - else - { + } else { res = lfs_dir_open(&self->fs.littlefs.lfs, &iter->dir, path); } xSemaphoreGive(self->fs.littlefs.mutex); - m_free((void*)path); + free((void*)path); if (res != LFS_ERR_OK) { mp_raise_OSError(littleFsErrorToErrno(res)); @@ -507,21 +502,18 @@ STATIC mp_obj_t littlefs_vfs_mkdir(mp_obj_t vfs_in, mp_obj_t path_param) { const char *path_in = mp_obj_str_get_str(path_param); xSemaphoreTake(self->fs.littlefs.mutex, portMAX_DELAY); - const char* path = concat_with_cwd(&self->fs.littlefs, path_in); - if(path == NULL) - { + const char *path = concat_with_cwd(&self->fs.littlefs, path_in); + if (path == NULL) { res = LFS_ERR_NOMEM; - } - else - { + } else { res = lfs_mkdir(&self->fs.littlefs.lfs, path); - if(res == LFS_ERR_OK) { + if (res == LFS_ERR_OK) { littlefs_update_timestamp(&self->fs.littlefs.lfs, path); } } xSemaphoreGive(self->fs.littlefs.mutex); - m_free((void*)path); + free((void*)path); if (res != LFS_ERR_OK) { mp_raise_OSError(littleFsErrorToErrno(res)); @@ -539,18 +531,15 @@ STATIC mp_obj_t littlefs_vfs_remove(mp_obj_t vfs_in, mp_obj_t path_param) { const char *path_in = mp_obj_str_get_str(path_param); xSemaphoreTake(self->fs.littlefs.mutex, portMAX_DELAY); - const char* path = concat_with_cwd(&self->fs.littlefs, path_in); - if(path == NULL) - { + const char *path = concat_with_cwd(&self->fs.littlefs, path_in); + if (path == NULL) { res = LFS_ERR_NOMEM; - } - else - { + } else { res = lfs_remove(&self->fs.littlefs.lfs, path); } xSemaphoreGive(self->fs.littlefs.mutex); - m_free((void*)path); + free((void*)path); if (res != LFS_ERR_OK) { mp_raise_OSError(littleFsErrorToErrno(res)); @@ -569,21 +558,18 @@ STATIC mp_obj_t littlefs_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_param_in, mp_ const char *path_out = mp_obj_str_get_str(path_param_out); xSemaphoreTake(self->fs.littlefs.mutex, portMAX_DELAY); - const char* old_path = concat_with_cwd(&self->fs.littlefs, path_in); - const char* new_path = concat_with_cwd(&self->fs.littlefs, path_out); + const char *old_path = concat_with_cwd(&self->fs.littlefs, path_in); + const char *new_path = concat_with_cwd(&self->fs.littlefs, path_out); - if(old_path == NULL || new_path == NULL) - { + if (old_path == NULL || new_path == NULL) { res = LFS_ERR_NOMEM; - } - else - { + } else { res = lfs_rename(&self->fs.littlefs.lfs, old_path, new_path); } xSemaphoreGive(self->fs.littlefs.mutex); - m_free((void*)old_path); - m_free((void*)new_path); + free((void*)old_path); + free((void*)new_path); if (res != LFS_ERR_OK) { mp_raise_OSError(littleFsErrorToErrno(res)); @@ -634,13 +620,10 @@ STATIC mp_obj_t littlefs_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_param) { xSemaphoreTake(self->fs.littlefs.mutex, portMAX_DELAY); - const char* path = concat_with_cwd(&self->fs.littlefs, path_in); - if(path == NULL) - { + const char *path = concat_with_cwd(&self->fs.littlefs, path_in); + if (path == NULL) { res = LFS_ERR_NOMEM; - } - else if (path[0] == 0 || (path[0] == '/' && path[1] == 0)) - { + } else if (path[0] == 0 || (path[0] == '/' && path[1] == 0)) { // stat root directory fno.size = 0; fno.type = LFS_TYPE_DIR; @@ -650,7 +633,7 @@ STATIC mp_obj_t littlefs_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_param) { xSemaphoreGive(self->fs.littlefs.mutex); - m_free((void*)path); + free((void*)path); if (res < LFS_ERR_OK) { mp_raise_OSError(littleFsErrorToErrno(res)); @@ -686,9 +669,9 @@ STATIC mp_obj_t littlefs_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_param) { else { t->items[6] = mp_obj_new_int_from_uint(0); // st_size } - t->items[7] = MP_OBJ_NEW_SMALL_INT(seconds); // st_atime - t->items[8] = MP_OBJ_NEW_SMALL_INT(seconds); // st_mtime - t->items[9] = MP_OBJ_NEW_SMALL_INT(seconds); // st_ctime + t->items[7] = mp_obj_new_int_from_uint(seconds); // st_atime + t->items[8] = mp_obj_new_int_from_uint(seconds); // st_mtime + t->items[9] = mp_obj_new_int_from_uint(seconds); // st_ctime return MP_OBJ_FROM_PTR(t); } diff --git a/esp32/littlefs/vfs_littlefs_file.c b/esp32/littlefs/vfs_littlefs_file.c index e16e45df9d..aa7a90edb5 100644 --- a/esp32/littlefs/vfs_littlefs_file.c +++ b/esp32/littlefs/vfs_littlefs_file.c @@ -171,7 +171,7 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar int res = littlefs_open_common_helper(&vfs->fs.littlefs.lfs, fname, &o->fp, mode, &o->cfg, &o->timestamp_update); xSemaphoreGive(vfs->fs.littlefs.mutex); - m_free((void*)fname); + free((void*)fname); if (res < LFS_ERR_OK) { m_del_obj(pyb_file_obj_t, o); mp_raise_OSError(littleFsErrorToErrno(res)); diff --git a/esp32/lte/lteppp.c b/esp32/lte/lteppp.c index a7daec96fe..43c46904a5 100644 --- a/esp32/lte/lteppp.c +++ b/esp32/lte/lteppp.c @@ -159,7 +159,7 @@ void lteppp_init(void) { lteppp_connstatus = LTE_PPP_IDLE; #ifdef LTE_DEBUG_BUFF - lteppp_log.log = heap_caps_malloc(LTE_LOG_BUFF_SIZE, MALLOC_CAP_SPIRAM); + lteppp_log.log = malloc(LTE_LOG_BUFF_SIZE); #endif } diff --git a/esp32/main.c b/esp32/main.c index 0250906317..0d64729b67 100644 --- a/esp32/main.c +++ b/esp32/main.c @@ -149,7 +149,7 @@ void app_main(void) { micropy_lpwan_dio_pin_num = 23; micropy_lpwan_dio_pin = &pin_GPIO23; - mpTaskStack = heap_caps_malloc(MICROPY_TASK_STACK_SIZE_PSRAM, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + mpTaskStack = malloc(MICROPY_TASK_STACK_SIZE_PSRAM); // create the MicroPython task mpTaskHandle = @@ -172,7 +172,7 @@ void app_main(void) { micropy_lpwan_dio_pin_num = 23; micropy_lpwan_dio_pin = &pin_GPIO23; - mpTaskStack = heap_caps_malloc(MICROPY_TASK_STACK_SIZE, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + mpTaskStack = malloc(MICROPY_TASK_STACK_SIZE); // create the MicroPython task mpTaskHandle = diff --git a/esp32/mods/machrmt.c b/esp32/mods/machrmt.c index 20e4197016..880f64b803 100644 --- a/esp32/mods/machrmt.c +++ b/esp32/mods/machrmt.c @@ -365,7 +365,7 @@ STATIC mp_obj_t mach_rmt_pulses_send(mp_uint_t n_args, const mp_obj_t *pos_args, /* An rmt_item32_t can contain 2 bits, calculate the number of the necessary objects needed to store the input data */ mp_uint_t items_to_send_count = (data_length / 2) + (data_length % 2); - rmt_item32_t* items_to_send = (rmt_item32_t*)m_malloc(items_to_send_count * sizeof(rmt_item32_t)); + rmt_item32_t* items_to_send = (rmt_item32_t*)malloc(items_to_send_count * sizeof(rmt_item32_t)); for(mp_uint_t i = 0, j = 0; i < items_to_send_count; i++, j++) { items_to_send[i].level0 = mp_obj_get_int(data_ptr[j]); @@ -396,7 +396,7 @@ STATIC mp_obj_t mach_rmt_pulses_send(mp_uint_t n_args, const mp_obj_t *pos_args, esp_err_t retval = rmt_write_items(self->config.channel, items_to_send, items_to_send_count, wait_tx_done); MP_THREAD_GIL_ENTER(); - m_free(items_to_send); + free(items_to_send); if (retval != ESP_OK) { nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Could not send data!")); diff --git a/esp32/mods/machtimer_alarm.c b/esp32/mods/machtimer_alarm.c index 1415f539be..4bf444fcb4 100644 --- a/esp32/mods/machtimer_alarm.c +++ b/esp32/mods/machtimer_alarm.c @@ -8,7 +8,6 @@ #include "py/mpconfig.h" #include "py/nlr.h" #include "py/runtime.h" -#include "py/gc.h" #include "py/mperrno.h" #include "util/mpirq.h" @@ -56,7 +55,7 @@ void mach_timer_alarm_preinit(void) { void mach_timer_alarm_init_heap(void) { alarm_heap.count = 0; - MP_STATE_PORT(mp_alarm_heap) = gc_alloc(ALARM_HEAP_MAX_ELEMENTS * sizeof(mp_obj_alarm_t *), false); + MP_STATE_PORT(mp_alarm_heap) = m_malloc(ALARM_HEAP_MAX_ELEMENTS * sizeof(mp_obj_alarm_t *)); alarm_heap.data = MP_STATE_PORT(mp_alarm_heap); if (alarm_heap.data == NULL) { mp_printf(&mp_plat_print, "FATAL ERROR: not enough memory for the alarms heap\n"); diff --git a/esp32/mods/modbt.c b/esp32/mods/modbt.c index 984d289dbb..2b720d69ab 100644 --- a/esp32/mods/modbt.c +++ b/esp32/mods/modbt.c @@ -500,7 +500,7 @@ static void remove_all_bonded_devices(void) { int dev_num = esp_ble_get_bond_device_num(); - esp_ble_bond_dev_t *dev_list = heap_caps_malloc(sizeof(esp_ble_bond_dev_t) * dev_num, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + esp_ble_bond_dev_t *dev_list = malloc(sizeof(esp_ble_bond_dev_t) * dev_num); esp_ble_get_bond_device_list(&dev_num, dev_list); for (int i = 0; i < dev_num; i++) { esp_ble_remove_bond_device(dev_list[i].bd_addr); @@ -801,8 +801,8 @@ STATIC void gatts_char_callback_handler(void *arg) { tuple[1] = mp_const_none; if(((char_cbk_arg_t*)arg)->data_length > 0) { tuple[1] = mp_obj_new_bytes(((char_cbk_arg_t*)arg)->data, ((char_cbk_arg_t*)arg)->data_length); - heap_caps_free(((char_cbk_arg_t*)arg)->data); - heap_caps_free((char_cbk_arg_t*)arg); + free(((char_cbk_arg_t*)arg)->data); + free((char_cbk_arg_t*)arg); } mp_obj_t r_value = mp_call_function_2(chr->handler, chr->handler_arg, mp_obj_new_tuple(2, tuple)); @@ -865,7 +865,7 @@ static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_ char_obj->read_request = true; char_obj->trans_id = p->read.trans_id; - char_cbk_arg_t *cbk_arg = heap_caps_malloc(sizeof(char_cbk_arg_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + char_cbk_arg_t *cbk_arg = malloc(sizeof(char_cbk_arg_t)); cbk_arg->chr = char_obj; cbk_arg->event = MOD_BT_GATTS_READ_EVT; @@ -900,12 +900,12 @@ static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_ char_obj->events |= MOD_BT_GATTS_WRITE_EVT; if (char_obj->trigger & MOD_BT_GATTS_WRITE_EVT) { - char_cbk_arg_t *cbk_arg = heap_caps_malloc(sizeof(char_cbk_arg_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + char_cbk_arg_t *cbk_arg = malloc(sizeof(char_cbk_arg_t)); cbk_arg->chr = char_obj; cbk_arg->event = MOD_BT_GATTS_WRITE_EVT; cbk_arg->data_length = write_len; - cbk_arg->data = heap_caps_malloc(cbk_arg->data_length, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + cbk_arg->data = malloc(cbk_arg->data_length); memcpy(cbk_arg->data, p->write.value, cbk_arg->data_length); mp_irq_queue_interrupt_non_ISR(gatts_char_callback_handler, cbk_arg); @@ -918,7 +918,7 @@ static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_ char_obj->events |= MOD_BT_GATTS_SUBSCRIBE_EVT; if (char_obj->trigger & MOD_BT_GATTS_SUBSCRIBE_EVT) { - char_cbk_arg_t *cbk_arg = heap_caps_malloc(sizeof(char_cbk_arg_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + char_cbk_arg_t *cbk_arg = malloc(sizeof(char_cbk_arg_t)); cbk_arg->chr = char_obj; cbk_arg->event = MOD_BT_GATTS_SUBSCRIBE_EVT; @@ -2344,7 +2344,7 @@ STATIC mp_obj_t bt_srv_characteristics(mp_obj_t self_in) { &attr_count); if (attr_count > 0) { - esp_gattc_char_elem_t *char_elems = (esp_gattc_char_elem_t *)heap_caps_malloc(sizeof(esp_gattc_char_elem_t) * attr_count, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + esp_gattc_char_elem_t *char_elems = (esp_gattc_char_elem_t *)malloc(sizeof(esp_gattc_char_elem_t) * attr_count); if (!char_elems) { mp_raise_OSError(MP_ENOMEM); } else { @@ -2585,7 +2585,7 @@ STATIC mp_obj_t bt_char_callback(mp_uint_t n_args, const mp_obj_t *pos_args, mp_ self->characteristic.char_handle, &attr_count); if (attr_count > 0) { - esp_gattc_descr_elem_t *descr_elems = (esp_gattc_descr_elem_t *)heap_caps_malloc(sizeof(esp_gattc_descr_elem_t) * attr_count, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + esp_gattc_descr_elem_t *descr_elems = (esp_gattc_descr_elem_t *)malloc(sizeof(esp_gattc_descr_elem_t) * attr_count); if (!descr_elems) { mp_raise_OSError(MP_ENOMEM); } else { diff --git a/esp32/mods/modcoap.c b/esp32/mods/modcoap.c index cdf4922568..cae166d61d 100644 --- a/esp32/mods/modcoap.c +++ b/esp32/mods/modcoap.c @@ -11,7 +11,6 @@ #include "py/mpconfig.h" #include "py/obj.h" #include "py/runtime.h" -#include "py/gc.h" #include "coap.h" #include "coap_list.h" @@ -1235,7 +1234,7 @@ STATIC mp_obj_t mod_coap_send_request(mp_uint_t n_args, const mp_obj_t *pos_args // Split up the URI-PATH into more segments if needed //TODO: allocate the proper length size_t length = 300; - unsigned char* path = m_malloc(length); + unsigned char* path = malloc(length); int segments = coap_split_path(coap_uri.path.s, coap_uri.path.length, path, &length); // Insert the segments as separate URI-Path options @@ -1249,7 +1248,7 @@ STATIC mp_obj_t mod_coap_send_request(mp_uint_t n_args, const mp_obj_t *pos_args } - m_free(path); + free(path); // Put Content Format option if given if(content_format != -1) { diff --git a/esp32/mods/modmdns.c b/esp32/mods/modmdns.c index 5b1c8ebed6..bb0814d220 100644 --- a/esp32/mods/modmdns.c +++ b/esp32/mods/modmdns.c @@ -168,7 +168,7 @@ STATIC mp_obj_t mod_mdns_add_service(mp_uint_t n_args, const mp_obj_t *pos_args, mp_obj_t* items; mp_obj_tuple_get(args[3].u_obj, &length_total, &items); - service_txt = m_malloc(length_total * sizeof(mdns_txt_item_t)); + service_txt = malloc(length_total * sizeof(mdns_txt_item_t)); for(int i = 0; i < length_total; i++) { size_t length_elem = 0; @@ -186,6 +186,7 @@ STATIC mp_obj_t mod_mdns_add_service(mp_uint_t n_args, const mp_obj_t *pos_args, } esp_err_t ret = mdns_service_add(NULL, service_type, proto, port, service_txt, length_total); + free(service_txt); if(ret != ESP_OK) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_RuntimeError, "Service could not be added, error code: %d", ret)); } @@ -295,7 +296,13 @@ STATIC mp_obj_t mod_mdns_query(mp_uint_t n_args, const mp_obj_t *pos_args, mp_ma tuple[1] = mp_obj_new_str(result->txt[i].value, strlen(result->txt[i].value)); mp_obj_list_append(query_obj->txt, mp_obj_new_tuple(2, tuple)); } - query_obj->addr = netutils_format_ipv4_addr((uint8_t *)&result->addr->addr.u_addr.ip4.addr, NETUTILS_BIG); + + if (result->addr) { + query_obj->addr = netutils_format_ipv4_addr((uint8_t *)&result->addr->addr.u_addr.ip4.addr, NETUTILS_BIG); + } else { + u32_t zero_ip = 0; + query_obj->addr = netutils_format_ipv4_addr((uint8_t *)&zero_ip, NETUTILS_BIG); + } mp_obj_list_append(queries_list, query_obj); diff --git a/esp32/mods/modpycom.c b/esp32/mods/modpycom.c index 477abc2e17..c56d47c05b 100644 --- a/esp32/mods/modpycom.c +++ b/esp32/mods/modpycom.c @@ -302,16 +302,15 @@ STATIC mp_obj_t mod_pycom_nvs_get (mp_uint_t n_args, const mp_obj_t *args) { else { esp_err = nvs_get_str(pycom_nvs_handle, key, NULL, &value); if(esp_err == ESP_OK) { - char* value_string = (char*)m_malloc(value); + char* value_string = (char*)malloc(value); esp_err = nvs_get_str(pycom_nvs_handle, key, value_string, &value); if(esp_err == ESP_OK) { //do not count the terminating \0 ret = mp_obj_new_str(value_string, value-1); - m_free(value_string); } - m_free(value_string); + free(value_string); } } @@ -422,7 +421,7 @@ STATIC mp_obj_t mod_pycom_wifi_ssid_sta (mp_uint_t n_args, const mp_obj_t *args) else{/*Nothing*/} } else { - uint8_t * ssid = (uint8_t *)m_malloc(33); + uint8_t * ssid = (uint8_t *)malloc(33); mp_obj_t ssid_obj; if(config_get_wifi_sta_ssid(ssid)) { @@ -432,7 +431,7 @@ STATIC mp_obj_t mod_pycom_wifi_ssid_sta (mp_uint_t n_args, const mp_obj_t *args) { ssid_obj = mp_const_none; } - m_free(ssid); + free(ssid); return ssid_obj; } return mp_const_none; @@ -451,7 +450,7 @@ STATIC mp_obj_t mod_pycom_wifi_pwd_sta (mp_uint_t n_args, const mp_obj_t *args) } else{/*Nothing*/} } else { - uint8_t * pwd = (uint8_t *)m_malloc(65); + uint8_t * pwd = (uint8_t *)malloc(65); mp_obj_t pwd_obj; if(config_get_wifi_sta_pwd(pwd)) { @@ -461,7 +460,7 @@ STATIC mp_obj_t mod_pycom_wifi_pwd_sta (mp_uint_t n_args, const mp_obj_t *args) { pwd_obj = mp_const_none; } - m_free(pwd); + free(pwd); return pwd_obj; } return mp_const_none; @@ -480,7 +479,7 @@ STATIC mp_obj_t mod_pycom_wifi_ssid_ap (mp_uint_t n_args, const mp_obj_t *args) } else{/*Nothing*/} } else { - uint8_t * ssid = (uint8_t *)m_malloc(33); + uint8_t * ssid = (uint8_t *)malloc(33); mp_obj_t ssid_obj; if(config_get_wifi_ap_ssid(ssid)) { @@ -490,7 +489,7 @@ STATIC mp_obj_t mod_pycom_wifi_ssid_ap (mp_uint_t n_args, const mp_obj_t *args) { ssid_obj = mp_const_none; } - m_free(ssid); + free(ssid); return ssid_obj; } return mp_const_none; @@ -509,7 +508,7 @@ STATIC mp_obj_t mod_pycom_wifi_pwd_ap (mp_uint_t n_args, const mp_obj_t *args) { } else{/*Nothing*/} } else { - uint8_t * pwd = (uint8_t *)m_malloc(65); + uint8_t * pwd = (uint8_t *)malloc(65); mp_obj_t pwd_obj; if(config_get_wifi_ap_pwd(pwd)) { @@ -519,7 +518,7 @@ STATIC mp_obj_t mod_pycom_wifi_pwd_ap (mp_uint_t n_args, const mp_obj_t *args) { { pwd_obj = mp_const_none; } - m_free(pwd); + free(pwd); return pwd_obj; } return mp_const_none; diff --git a/esp32/mods/moducrypto.c b/esp32/mods/moducrypto.c index bdd7704f9c..f6340b8998 100644 --- a/esp32/mods/moducrypto.c +++ b/esp32/mods/moducrypto.c @@ -324,7 +324,7 @@ STATIC mp_obj_t mod_crypt_generate_rsa_signature(mp_uint_t n_args, const mp_obj_ nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_RuntimeError, "Message Digest operation failed, error code: %d", rc)); } - unsigned char *signature = m_malloc(5000); + unsigned char *signature = malloc(5000); size_t signature_length; rc = mbedtls_pk_sign(&pk_context, MBEDTLS_MD_SHA256, digest, sizeof(digest), signature, &signature_length, mbedtls_ctr_drbg_random, &ctr_drbg); @@ -335,7 +335,7 @@ STATIC mp_obj_t mod_crypt_generate_rsa_signature(mp_uint_t n_args, const mp_obj_ mp_obj_t ret_signature = mp_obj_new_bytes((const byte*)signature, signature_length); mbedtls_pk_free(&pk_context); - m_free((char*)signature); + free((char*)signature); return ret_signature; } @@ -382,7 +382,7 @@ STATIC mp_obj_t mod_crypt_rsa_encrypt(mp_uint_t n_args, const mp_obj_t *pos_args strlen(pers)); size_t output_len = message.len + 256; - unsigned char *output = m_malloc(output_len); + unsigned char *output = malloc(output_len); size_t output_actual_length = 0; rc = mbedtls_pk_encrypt(&pk_context, @@ -401,7 +401,7 @@ STATIC mp_obj_t mod_crypt_rsa_encrypt(mp_uint_t n_args, const mp_obj_t *pos_args mp_obj_t ret_output = mp_obj_new_bytes((const byte*)output, output_actual_length); mbedtls_pk_free(&pk_context); - m_free((char*)output); + free((char*)output); return ret_output; } @@ -448,7 +448,7 @@ STATIC mp_obj_t mod_crypt_rsa_decrypt(mp_uint_t n_args, const mp_obj_t *pos_args strlen(pers)); size_t output_len = message.len + 256; - unsigned char *output = m_malloc(output_len); + unsigned char *output = malloc(output_len); size_t output_actual_length = 0; rc = mbedtls_pk_decrypt(&pk_context, @@ -467,7 +467,7 @@ STATIC mp_obj_t mod_crypt_rsa_decrypt(mp_uint_t n_args, const mp_obj_t *pos_args mp_obj_t ret_output = mp_obj_new_bytes((const byte*)output, output_actual_length); mbedtls_pk_free(&pk_context); - m_free((char*)output); + free((char*)output); return ret_output; } diff --git a/esp32/mods/moduqueue.c b/esp32/mods/moduqueue.c index 64b01f78aa..0a5aa10bdd 100644 --- a/esp32/mods/moduqueue.c +++ b/esp32/mods/moduqueue.c @@ -45,7 +45,7 @@ STATIC mp_obj_t mod_uqueue_queue(mp_uint_t n_args, const mp_obj_t *pos_args, mp_ mp_obj_queue_t *queue = m_new_obj_with_finaliser(mp_obj_queue_t); // allocate the queue storage and the queue buffer - queue->buffer = heap_caps_malloc(sizeof(StaticQueue_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + queue->buffer = malloc(sizeof(StaticQueue_t)); if (NULL == queue->buffer) { nlr_raise(mp_obj_new_exception_msg(&mp_type_MemoryError, "no memory available to create the queue")); } diff --git a/esp32/mods/modussl.c b/esp32/mods/modussl.c index 78227c1039..9e1dbe9a02 100644 --- a/esp32/mods/modussl.c +++ b/esp32/mods/modussl.c @@ -168,7 +168,7 @@ static int32_t mod_ssl_setup_socket (mp_obj_ssl_socket_t *ssl_sock, const mbedtl mbedtls_ssl_set_bio(&ssl_sock->ssl, &ssl_sock->context_fd, mbedtls_net_send, NULL, mbedtls_net_recv_timeout); - // printf("Performing the SSL/TLS handshake...\n"); + //printf("Performing the SSL/TLS handshake...\n"); int count = 0; while ((ret = mbedtls_ssl_handshake(&ssl_sock->ssl)) != 0) { @@ -182,13 +182,21 @@ static int32_t mod_ssl_setup_socket (mp_obj_ssl_socket_t *ssl_sock, const mbedtl } } - // printf("Verifying peer X.509 certificate...\n"); - if ((ret = mbedtls_ssl_get_verify_result(&ssl_sock->ssl)) != 0) { - /* In real life, we probably want to close connection if ret != 0 */ - // printf("Failed to verify peer certificate!\n"); + //printf("Verifying peer X.509 certificate...\n"); + ret = mbedtls_ssl_get_verify_result(&ssl_sock->ssl); + if (ret == 0) { + //printf("Certificate verified.\n"); + return 0; + } + // If no verification is needed the mbedtls_ssl_get_verify_result() returns with MBEDTLS_X509_BADCERT_SKIP_VERIFY + else if((ssl_verify == MBEDTLS_SSL_VERIFY_NONE) && (ret == MBEDTLS_X509_BADCERT_SKIP_VERIFY)) { + //printf("Certification validation skipped.\n"); + return 0; + } + else { + /* In real life, we probably want to close connection in this case */ + //printf("Failed to verify peer certificate!\n"); return -1; - } else { - // printf("Certificate verified.\n"); } } diff --git a/esp32/mods/modwlan.c b/esp32/mods/modwlan.c index 8d3567cd75..64a0ecc321 100644 --- a/esp32/mods/modwlan.c +++ b/esp32/mods/modwlan.c @@ -1444,7 +1444,7 @@ STATIC mp_obj_t wlan_scan(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t * esp_wifi_scan_get_ap_num(&ap_num); // get the number of scanned APs if (ap_num > 0) { - ap_record_buffer = pvPortMalloc(ap_num * sizeof(wifi_ap_record_t)); + ap_record_buffer = malloc(ap_num * sizeof(wifi_ap_record_t)); if (ap_record_buffer == NULL) { mp_raise_OSError(MP_ENOMEM); } @@ -1464,7 +1464,7 @@ STATIC mp_obj_t wlan_scan(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t * mp_obj_list_append(nets, mp_obj_new_attrtuple(wlan_scan_info_fields, 5, tuple)); } } - vPortFree(ap_record_buffer); + free(ap_record_buffer); } return nets; @@ -1971,6 +1971,40 @@ STATIC mp_obj_t wlan_ap_sta_list (mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_ap_sta_list_obj, wlan_ap_sta_list); +STATIC mp_obj_t wlan_ap_tcpip_sta_list (mp_obj_t self_in) { + STATIC const qstr wlan_sta_ifo_fields[] = { + MP_QSTR_mac, MP_QSTR_IP + }; + uint8_t index; + wifi_sta_list_t wifi_sta_list; + esp_wifi_ap_get_sta_list(&wifi_sta_list); + tcpip_adapter_sta_list_t sta_list; + wlan_obj_t * self = self_in; + + mp_obj_t sta_out_list = mp_obj_new_list(0, NULL); + /* Check if AP mode is enabled */ + if (self->mode == WIFI_MODE_AP || self->mode == WIFI_MODE_APSTA) { + tcpip_adapter_get_sta_list(&wifi_sta_list, &sta_list); + + mp_obj_t tuple[2]; + for(index = 0; index < MAX_AP_CONNECTED_STA && index < sta_list.num; index++) + { + tuple[0] = mp_obj_new_bytes((const byte *)sta_list.sta[index].mac, 6); + tuple[1] = netutils_format_ipv4_addr((uint8_t *)&sta_list.sta[index].ip.addr, NETUTILS_BIG); + + /*insert tuple */ + mp_obj_list_append(sta_out_list, mp_obj_new_attrtuple(wlan_sta_ifo_fields, 2, tuple)); + } + } + else + { + nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_request_not_possible)); + } + + return sta_out_list; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_ap_tcpip_sta_list_obj, wlan_ap_tcpip_sta_list); + STATIC mp_obj_t wlan_joined_ap_info (mp_obj_t self_in) { STATIC const qstr wlan_sta_ifo_fields[] = { @@ -2654,6 +2688,7 @@ STATIC const mp_map_elem_t wlan_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_antenna), (mp_obj_t)&wlan_antenna_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_mac), (mp_obj_t)&wlan_mac_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_ap_sta_list), (mp_obj_t)&wlan_ap_sta_list_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_ap_tcpip_sta_list), (mp_obj_t)&wlan_ap_tcpip_sta_list_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_max_tx_power), (mp_obj_t)&wlan_max_tx_power_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_country), (mp_obj_t)&wlan_country_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_joined_ap_info), (mp_obj_t)&wlan_joined_ap_info_obj }, diff --git a/esp32/mpconfigport.h b/esp32/mpconfigport.h index 51a30b2e05..9870415bd2 100644 --- a/esp32/mpconfigport.h +++ b/esp32/mpconfigport.h @@ -250,7 +250,6 @@ extern const struct _mp_obj_module_t mp_module_uqueue; mp_obj_list_t btc_conn_list; \ mp_obj_list_t bts_srv_list; \ mp_obj_list_t bts_attr_list; \ - char* lfs_cwd; \ mp_obj_t coap_ptr; \ // we need to provide a declaration/definition of alloca() diff --git a/esp32/mptask.c b/esp32/mptask.c index 9ae359dc7d..77bc0d58f4 100644 --- a/esp32/mptask.c +++ b/esp32/mptask.c @@ -174,12 +174,12 @@ void TASK_Micropython (void *pvParameters) { if (esp32_get_chip_rev() > 0) { gc_pool_size = GC_POOL_SIZE_BYTES_PSRAM; - gc_pool_upy = heap_caps_malloc(GC_POOL_SIZE_BYTES_PSRAM, MALLOC_CAP_SPIRAM); } else { gc_pool_size = GC_POOL_SIZE_BYTES; - gc_pool_upy = heap_caps_malloc(GC_POOL_SIZE_BYTES, MALLOC_CAP_INTERNAL); } + gc_pool_upy = malloc(gc_pool_size); + if (NULL == gc_pool_upy) { printf("GC pool malloc failed!\n"); for ( ; ; ); @@ -534,11 +534,10 @@ STATIC void mptask_init_sflash_filesystem_littlefs(void) { MP_STATE_PORT(vfs_cur) = vfs; //Initialize the current working directory (cwd) - vfs_littlefs->fs.littlefs.cwd = (char*)m_malloc(2); + vfs_littlefs->fs.littlefs.cwd = (char*)malloc(2); vfs_littlefs->fs.littlefs.cwd[0] = '/'; vfs_littlefs->fs.littlefs.cwd[1] = '\0'; - MP_STATE_PORT(lfs_cwd) = vfs_littlefs->fs.littlefs.cwd; vfs_littlefs->fs.littlefs.mutex = xSemaphoreCreateMutex(); xSemaphoreTake(vfs_littlefs->fs.littlefs.mutex, portMAX_DELAY); diff --git a/esp32/mpthreadport.c b/esp32/mpthreadport.c index 276c2cd5aa..de383be612 100644 --- a/esp32/mpthreadport.c +++ b/esp32/mpthreadport.c @@ -171,15 +171,15 @@ void mp_thread_create_ex(void *(*entry)(void*), void *arg, size_t *stack_size, i // allocate TCB, stack and linked-list node (must be outside thread_mutex lock) if (mp_chip_revision > 0) { // for revision 1 devices we allocate from the internal memory of the malloc heap - tcb = heap_caps_malloc(sizeof(StaticTask_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + tcb = malloc(sizeof(StaticTask_t)); if (!tcb) { goto memory_error; } - stack = heap_caps_malloc(*stack_size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + stack = malloc(*stack_size); if (!stack) { goto memory_error; } - th = heap_caps_malloc(sizeof(thread_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + th = malloc(sizeof(thread_t)); if (!th) { goto memory_error; } @@ -280,6 +280,7 @@ void vPortCleanUpTCB (void *tcb) { mp_obj_thread_lock_t *mp_thread_new_thread_lock(void) { mp_obj_thread_lock_t *self = m_new_obj(mp_obj_thread_lock_t); + self->mutex = gc_alloc(sizeof(mp_thread_mutex_t), false); if (NULL == self->mutex) { nlr_raise(mp_obj_new_exception_msg(&mp_type_MemoryError, "can't create lock")); diff --git a/esp32/pycom_config.h b/esp32/pycom_config.h index f3e691b2f5..9c23f5ae17 100644 --- a/esp32/pycom_config.h +++ b/esp32/pycom_config.h @@ -11,7 +11,16 @@ #define PYCOM_CONFIG_H_ #include "py/mpconfig.h" +#include +/** + * pycom_config_block_t is written and read directly to the config partition + * (see ./esp32/lib/partitions_xMB.csv) + * When adding attributes to this config block, be sure to only add them *after* + * all existing attributes. + * + * the _Static_assert()'s below enforce that the memory layout doesn't change + */ /****************************************************************************** DEFINE CONSTANTS @@ -29,6 +38,7 @@ typedef struct { uint8_t sigfox_public_key[16]; uint8_t lora_region; } pycom_lpwan_config_t; +_Static_assert(sizeof(pycom_lpwan_config_t) == 53, "pycom_lpwan_config_t should have a size of 53 bytes"); typedef struct { uint8_t wifi_on_boot :1; @@ -37,16 +47,19 @@ typedef struct { uint8_t wifi_auth :3; uint8_t wifi_antenna :1; } pycom_wifi_config_t; +_Static_assert(sizeof(pycom_wifi_config_t) == 1, "pycom_wifi_config_t should have a size of 1 bytes"); typedef struct { uint8_t wifi_ssid[33]; uint8_t wifi_pwd[65]; } pycom_wifi_sta_config_t; +_Static_assert(sizeof(pycom_wifi_sta_config_t) == 98, "pycom_wifi_sta_config_t should have a size of 98 bytes"); typedef struct { uint8_t wifi_ssid[33]; uint8_t wifi_pwd[65]; } pycom_wifi_ap_config_t; +_Static_assert(sizeof(pycom_wifi_ap_config_t) == 98, "pycom_wifi_ap_config_t should have a size of 98 bytes"); typedef struct { uint8_t heartbeat_on_boot :1; @@ -54,6 +67,7 @@ typedef struct { uint8_t rgb_safeboot_color[3]; uint8_t rgb_heartbeat_color[3]; } pycom_rgbled_config_t; +_Static_assert(sizeof(pycom_rgbled_config_t) == 10, "pycom_rgbled_config_t should have a size of 10 bytes"); typedef struct { uint8_t device_token[40]; @@ -65,6 +79,7 @@ typedef struct { uint8_t auto_start; uint8_t reserved[11]; } pycom_pybytes_config_t; +_Static_assert(sizeof(pycom_pybytes_config_t) == 348, "pycom_pybytes_config_t should have a size of 348 bytes"); typedef struct { uint8_t sw_version[12]; @@ -72,15 +87,18 @@ typedef struct { uint8_t boot_partition; uint8_t hw_type; } pycom_config_t; +_Static_assert(sizeof(pycom_config_t) == 15, "pycom_config_t should have a size of 15 bytes"); typedef struct { - uint8_t wdt_on_boot; + uint8_t wdt_on_boot; // 1byte + 3bytes padding uint32_t wdt_on_boot_timeout; } pycom_wdt_config_t; +_Static_assert(sizeof(pycom_wdt_config_t) == 8, "pycom_wdt_config_t should have a size of 8 bytes"); typedef struct { uint8_t lte_modem_en_on_boot; } pycom_lte_config_t; +_Static_assert(sizeof(pycom_lte_config_t) == 1, "pycom_lte_config_t should have a size of 1 bytes"); typedef struct { uint8_t carrier[129]; @@ -90,20 +108,23 @@ typedef struct { uint8_t band; uint8_t reset; } pycom_pybytes_lte_config_t; - -typedef struct { - pycom_lpwan_config_t lpwan_config; - pycom_wifi_config_t wifi_config; - pycom_wifi_sta_config_t wifi_sta_config; - pycom_rgbled_config_t rgbled_config; - pycom_pybytes_config_t pybytes_config; - pycom_wdt_config_t wdt_config; - pycom_lte_config_t lte_config; - pycom_config_t pycom_config; - pycom_wifi_ap_config_t wifi_ap_config; - pycom_pybytes_lte_config_t pycom_pybytes_lte_config; - uint8_t pycom_reserved[112]; -} pycom_config_block_t; +// pycom_pybytes_lte_config_t is the last used member of pycom_config_block_t, so no _Static_assert(sizeof()) needed + +typedef struct { // size + pycom_lpwan_config_t lpwan_config; // 53 + pycom_wifi_config_t wifi_config; // 1 + pycom_wifi_sta_config_t wifi_sta_config; // 98 + pycom_rgbled_config_t rgbled_config; // 10 + pycom_pybytes_config_t pybytes_config; // 348 + uint8_t pycom_unused[2]; // 2 since wdt_config has 4byte-alignment, there are currently two bytes of padding before it + pycom_wdt_config_t wdt_config; // 8 since wdt_config contains a uint32_t, it has 4byte-alignment + pycom_lte_config_t lte_config; // 1 + pycom_config_t pycom_config; // 15 + pycom_wifi_ap_config_t wifi_ap_config; // 98 + pycom_pybytes_lte_config_t pycom_pybytes_lte_config; // 278 + uint8_t pycom_reserved[112]; // 112 +} pycom_config_block_t; // 1024 +_Static_assert(sizeof(pycom_config_block_t) == 1024, "pycom_config_block_t should have a size of 1024 bytes"); // partition is 4Kb, I think multiples of 1Kb <= 4Kb are ok typedef enum { diff --git a/esp32/pycom_version.h b/esp32/pycom_version.h index e3cd562a1c..78e655b766 100644 --- a/esp32/pycom_version.h +++ b/esp32/pycom_version.h @@ -10,14 +10,14 @@ #ifndef VERSION_H_ #define VERSION_H_ -#define SW_VERSION_NUMBER "1.20.2.rc7" +#define SW_VERSION_NUMBER "1.20.2.rc9" #define LORAWAN_VERSION_NUMBER "1.0.2" #define SIGFOX_VERSION_NUMBER "1.0.1" #if (VARIANT == PYBYTES) -#define PYBYTES_VERSION_NUMBER "1.4.0" +#define PYBYTES_VERSION_NUMBER "1.5.0" #endif #endif /* VERSION_H_ */ diff --git a/esp32/sigfox/README b/esp32/sigfox/README index 1da6e7dbd6..80418deb3d 100644 --- a/esp32/sigfox/README +++ b/esp32/sigfox/README @@ -6,7 +6,7 @@ There are three prebuilt libraries for SIPY, LOPY4, and FIPY. git clone -b sigfox git@github.com:pycom/pyupython.git src cd src -git checkout ba89a617 +git checkout 9a5e7a9b cd ../.. make BOARD=LOPY4 TARGET=sigfox make BOARD=FIPY TARGET=sigfox diff --git a/esp32/telnet/telnet.c b/esp32/telnet/telnet.c index 1df927a47b..91972ecdfe 100644 --- a/esp32/telnet/telnet.c +++ b/esp32/telnet/telnet.c @@ -154,7 +154,7 @@ static void telnet_reset_buffer (void); ******************************************************************************/ void telnet_init (void) { // allocate memory for the receive buffer (from the RTOS heap) - telnet_data.rxBuffer = heap_caps_malloc(TELNET_RX_BUFFER_SIZE, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + telnet_data.rxBuffer = malloc(TELNET_RX_BUFFER_SIZE); telnet_data.state = E_TELNET_STE_DISABLED; } diff --git a/esp32/util/socketfifo.c b/esp32/util/socketfifo.c index 70c1e18def..58169799b1 100644 --- a/esp32/util/socketfifo.c +++ b/esp32/util/socketfifo.c @@ -62,7 +62,7 @@ void SOCKETFIFO_Flush (void) { SocketFifoElement_t element; while (SOCKETFIFO_Pop(&element)) { if (element.freedata) { - vPortFree(element.data); + free(element.data); } } } diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 9776f60aa9..f7cb095cbd 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -365,9 +365,9 @@ STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) { t->items[4] = MP_OBJ_NEW_SMALL_INT(0); // st_uid t->items[5] = MP_OBJ_NEW_SMALL_INT(0); // st_gid t->items[6] = mp_obj_new_int_from_uint(fno.fsize); // st_size - t->items[7] = MP_OBJ_NEW_SMALL_INT(seconds); // st_atime - t->items[8] = MP_OBJ_NEW_SMALL_INT(seconds); // st_mtime - t->items[9] = MP_OBJ_NEW_SMALL_INT(seconds); // st_ctime + t->items[7] = mp_obj_new_int_from_uint(seconds); // st_atime + t->items[8] = mp_obj_new_int_from_uint(seconds); // st_mtime + t->items[9] = mp_obj_new_int_from_uint(seconds); // st_ctime return MP_OBJ_FROM_PTR(t); }