diff --git a/tools/esptool.py b/tools/esptool.py index e311634f3e03f9b7745d548d8ef3b986eace3b44..6327cc86443168f5f79436aab09cd8fb9691b724 100755 --- a/tools/esptool.py +++ b/tools/esptool.py @@ -30,7 +30,7 @@ import base64 import zlib import shlex -__version__ = "2.0-beta1" +__version__ = "2.0-beta2" MAX_UINT32 = 0xffffffff MAX_UINT24 = 0xffffff @@ -281,6 +281,62 @@ class ESPLoader(object): for i in range(7): self.command() + def _connect_attempt(self, mode='default_reset', esp32r0_delay=False): + """ A single connection attempt, with esp32r0 workaround options """ + # esp32r0_delay is a workaround for bugs with the most common auto reset + # circuit and Windows, if the EN pin on the dev board does not have + # enough capacitance. + # + # Newer dev boards shouldn't have this problem (higher value capacitor + # on the EN pin), and ESP32 revision 1 can't use this workaround as it + # relies on a silicon bug. + # + # Details: https://github.com/espressif/esptool/issues/136 + last_error = None + + # issue reset-to-bootloader: + # RTS = either CH_PD/EN or nRESET (both active low = chip in reset + # DTR = GPIO0 (active low = boot to flasher) + # + # DTR & RTS are active low signals, + # ie True = pin @ 0V, False = pin @ VCC. + if mode != 'no_reset': + self._port.setDTR(False) # IO0=HIGH + self._port.setRTS(True) # EN=LOW, chip in reset + time.sleep(0.1) + if esp32r0_delay: + # Some chips are more likely to trigger the esp32r0 + # watchdog reset silicon bug if they're held with EN=LOW + # for a longer period + time.sleep(1.2) + self._port.setDTR(True) # IO0=LOW + self._port.setRTS(False) # EN=HIGH, chip out of reset + if esp32r0_delay: + # Sleep longer after reset. + # This workaround only works on revision 0 ESP32 chips, + # it exploits a silicon bug spurious watchdog reset. + time.sleep(0.4) # allow watchdog reset to occur + time.sleep(0.05) + self._port.setDTR(False) # IO0=HIGH, done + + self._port.timeout = 0.1 + for _ in range(5): + try: + self.flush_input() + self._port.flushOutput() + self.sync() + self._port.timeout = 5 + return None + except FatalError as e: + if esp32r0_delay: + print('_', end='') + else: + print('.', end='') + sys.stdout.flush() + time.sleep(0.05) + last_error = e + return last_error + def connect(self, mode='default_reset'): """ Try connecting repeatedly until successful, or giving up """ print('Connecting...', end='') @@ -289,44 +345,12 @@ class ESPLoader(object): try: for _ in range(10): - # issue reset-to-bootloader: - # RTS = either CH_PD/EN or nRESET (both active low = chip in reset - # DTR = GPIO0 (active low = boot to flasher) - # - # DTR & RTS are active low signals, - # ie True = pin @ 0V, False = pin @ VCC. - if mode != 'no_reset': - self._port.setDTR(False) # IO0=HIGH - self._port.setRTS(True) # EN=LOW, chip in reset - time.sleep(0.05) - self._port.setDTR(True) # IO0=LOW - self._port.setRTS(False) # EN=HIGH, chip out of reset - if mode == 'esp32r0': - # this is a workaround for a bug with the most - # common auto reset circuit and Windows, if the EN - # pin on the dev board does not have enough - # capacitance. This workaround only works on - # revision 0 ESP32 chips, it exploits a silicon - # bug spurious watchdog reset. - # - # Details: https://github.com/espressif/esptool/issues/136 - time.sleep(0.4) # allow watchdog reset to occur - time.sleep(0.05) - self._port.setDTR(False) # IO0=HIGH, done - - self._port.timeout = 0.1 - for _ in range(4): - try: - self.flush_input() - self._port.flushOutput() - self.sync() - self._port.timeout = 5 - return - except FatalError as e: - print('.', end='') - sys.stdout.flush() - time.sleep(0.05) - last_error = e + last_error = self._connect_attempt(mode=mode, esp32r0_delay=False) + if last_error is None: + return + last_error = self._connect_attempt(mode=mode, esp32r0_delay=True) + if last_error is None: + return finally: print('') # end 'Connecting...' line raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error)) @@ -653,8 +677,7 @@ class ESPLoader(object): if data_bits == 0: self.write_reg(SPI_W0_REG, 0) # clear data register before we read it else: - if len(data) % 4 != 0: # pad to 32-bit multiple - data += b'\0' * (4 - (len(data) % 4)) + data = pad_to(data, 4, b'\00') # pad to 32-bit multiple words = struct.unpack("I" * (len(data) // 4), data) next_reg = SPI_W0_REG for word in words: @@ -901,11 +924,11 @@ class ESP32ROM(ESPLoader): def read_mac(self): """ Read MAC from EFUSE region """ - words = [self.read_efuse(1), self.read_efuse(2)] + words = [self.read_efuse(2), self.read_efuse(1)] bitstring = struct.pack(">II", *words) - bitstring = bitstring[:6] # trim 2 byte CRC + bitstring = bitstring[2:8] # trim the 2 byte CRC try: - return tuple(ord(b) for b in bitstring) # trim 2 byte CRC + return tuple(ord(b) for b in bitstring) except TypeError: # Python 3, bitstring elements are already bytes return tuple(bitstring) @@ -964,10 +987,7 @@ class ImageSegment(object): def __init__(self, addr, data, file_offs=None): self.addr = addr # pad all ImageSegments to at least 4 bytes length - pad_mod = len(data) % 4 - if pad_mod != 0: - data += b"\x00" * (4 - pad_mod) - self.data = data + self.data = pad_to(data, 4, b'\x00') self.file_offs = file_offs self.include_in_checksum = True @@ -1210,15 +1230,13 @@ class ESP32FirmwareImage(BaseFirmwareImage): self.flash_mode = 0 self.flash_size_freq = 0 self.version = 1 - self.encrypt_flag = False if load_file is not None: segments = self.load_common_header(load_file, ESPLoader.ESP_IMAGE_MAGIC) additional_header = list(struct.unpack("B" * 16, load_file.read(16))) - self.encrypt_flag = (additional_header[0] == 0x01) - # check remaining 14 bytes are unused - if additional_header[2:] != [0] * 14: + # check these bytes are unused + if additional_header != [0] * 16: print("WARNING: ESP32 image header contains unknown flags. Possibly this image is from a newer version of esptool.py") for _ in range(segments): @@ -1241,9 +1259,9 @@ class ESP32FirmwareImage(BaseFirmwareImage): with open(filename, 'wb') as f: self.write_common_header(f, self.segments) - f.write(b'\x01' if self.encrypt_flag else b'\x00') - # remaining 15 bytes of header are unused - f.write(b'\x00' * 15) + # first 4 bytes of header are read by ROM bootloader for SPI + # config, but currently unused + f.write(b'\x00' * 16) checksum = ESPLoader.ESP_CHECKSUM_MAGIC last_addr = None @@ -1464,6 +1482,14 @@ def unhexify(hs): return s +def pad_to(data, alignment, pad_character=b'\xFF'): + """ Pad to the next alignment boundary """ + pad_mod = len(data) % alignment + if pad_mod != 0: + data += pad_character * (alignment - pad_mod) + return data + + class FatalError(RuntimeError): """ Wrapper class for runtime errors that aren't caused by internal bugs, but by @@ -1590,7 +1616,7 @@ def write_flash(esp, args): for address, argfile in args.addr_filename: if args.no_stub: print('Erasing flash...') - image = argfile.read() + image = pad_to(argfile.read(), 4) image = _update_image_flash_params(esp, address, flash_params, image) calcmd5 = hashlib.md5(image).hexdigest() uncsize = len(image) @@ -1689,10 +1715,6 @@ def elf2image(args): print("Creating image for ESP8266...") args.chip == 'esp8266' - if args.chip != 'esp32': - if args.set_encrypt_flag: - raise FatalError("--encrypt-flag only applies to ESP32 images") - if args.chip == 'esp32': image = ESP32FirmwareImage() elif args.version == '1': # ESP8266 @@ -1704,7 +1726,6 @@ def elf2image(args): image.flash_mode = {'qio':0, 'qout':1, 'dio':2, 'dout': 3}[args.flash_mode] image.flash_size_freq = image.ROM_LOADER.FLASH_SIZES[args.flash_size] image.flash_size_freq += {'40m':0, '26m':1, '20m':2, '80m': 0xf}[args.flash_freq] - image.encrypt_flag = args.set_encrypt_flag if args.output is None: args.output = image.default_output_name(args.input) @@ -1776,7 +1797,7 @@ def _verify_flash(esp, args): flash_params = _get_flash_params(esp, args) for address, argfile in args.addr_filename: - image = argfile.read() + image = pad_to(argfile.read(), 4) argfile.seek(0) # rewind in case we need it again image = _update_image_flash_params(esp, address, flash_params, image) @@ -1853,7 +1874,7 @@ def main(): parser.add_argument( '--before', help='What to do before connecting to the chip', - choices=['default_reset', 'no_reset', 'esp32r0'], + choices=['default_reset', 'no_reset'], default=os.environ.get('ESPTOOL_BEFORE', 'default_reset')) parser.add_argument( @@ -1946,7 +1967,6 @@ def main(): parser_elf2image.add_argument('input', help='Input ELF file') parser_elf2image.add_argument('--output', '-o', help='Output filename prefix (for version 1 image), or filename (for version 2 single image)', type=str) parser_elf2image.add_argument('--version', '-e', help='Output image version', choices=['1','2'], default='1') - parser_elf2image.add_argument('--set-encrypt-flag', help='Flag image to be encrypted by bootloader after flashing.', action="store_true") add_spi_flash_subparsers(parser_elf2image) @@ -2152,6 +2172,19 @@ class AddrFilenamePairAction(argparse.Action): except IndexError: raise argparse.ArgumentError(self,'Must be pairs of an address and the binary filename to write there') pairs.append((address, argfile)) + + # Sort the addresses and check for overlapping + end = 0 + for address, argfile in sorted(pairs): + argfile.seek(0,2) # seek to end + size = argfile.tell() + argfile.seek(0) + sector_start = address & ~(ESPLoader.FLASH_SECTOR_SIZE - 1) + sector_end = ((address + size + ESPLoader.FLASH_SECTOR_SIZE - 1) & ~(ESPLoader.FLASH_SECTOR_SIZE - 1)) - 1 + if sector_start < end: + message = 'Detected overlap at address: 0x%x for file: %s' % (address, argfile.name) + raise argparse.ArgumentError(self, message) + end = sector_end setattr(namespace, self.dest, pairs) diff --git a/tools/sdk/bin/bootloader.bin b/tools/sdk/bin/bootloader.bin index 5e30a0843e3afb8a4e7a5ab5ffeefe8c9c92230d..52aff86707dec5787f9c24b22ca65cc1079cb3da 100644 Binary files a/tools/sdk/bin/bootloader.bin and b/tools/sdk/bin/bootloader.bin differ diff --git a/tools/sdk/include/app_update/esp_ota_ops.h b/tools/sdk/include/app_update/esp_ota_ops.h index fe3307763f39a9117a9b0f333421f3675f5ea5b5..33c03030aa025602265655654d77bbe1dd4c64f9 100755 --- a/tools/sdk/include/app_update/esp_ota_ops.h +++ b/tools/sdk/include/app_update/esp_ota_ops.h @@ -27,57 +27,76 @@ extern "C" { #endif -#define OTA_SIZE_UNKNOWN 0xffffffff +#define OTA_SIZE_UNKNOWN 0xffffffff /*!< Used for esp_ota_begin() if new image size is unknown */ -#define ESP_ERR_OTA_BASE 0x1500 /*!< base error code for ota_ops api */ -#define ESP_ERR_OTA_PARTITION_CONFLICT (ESP_ERR_OTA_BASE + 0x01) /*!< want to write or erase current running partition */ -#define ESP_ERR_OTA_SELECT_INFO_INVALID (ESP_ERR_OTA_BASE + 0x02) /*!< ota data partition info is error */ -#define ESP_ERR_OTA_VALIDATE_FAILED (ESP_ERR_OTA_BASE + 0x03) /*!< validate ota image failed */ +#define ESP_ERR_OTA_BASE 0x1500 /*!< Base error code for ota_ops api */ +#define ESP_ERR_OTA_PARTITION_CONFLICT (ESP_ERR_OTA_BASE + 0x01) /*!< Error if request was to write or erase the current running partition */ +#define ESP_ERR_OTA_SELECT_INFO_INVALID (ESP_ERR_OTA_BASE + 0x02) /*!< Error if OTA data partition contains invalid content */ +#define ESP_ERR_OTA_VALIDATE_FAILED (ESP_ERR_OTA_BASE + 0x03) /*!< Error if OTA app image is invalid */ /** - * @brief Opaque handle for application update obtained from app_ops. + * @brief Opaque handle for an application OTA update + * + * esp_ota_begin() returns a handle which is then used for subsequent + * calls to esp_ota_write() and esp_ota_end(). */ typedef uint32_t esp_ota_handle_t; /** - * @brief format input partition in flash to 0xFF as input image size, - * if unkown image size ,pass 0x0 or 0xFFFFFFFF, it will erase all the - * partition ,Otherwise, erase the required range - * - * @param partition Pointer to partition structure which need to be updated - * Must be non-NULL. - * @param image_size size of image need to be updated - * @param out_handle handle which should be used for esp_ota_write or esp_ota_end call - - * @return: - * - ESP_OK: if format ota image OK - * - ESP_ERR_OTA_PARTITION_CONFLICT: operate current running bin - * - ESP_ERR_OTA_SELECT_INFO_INVALID: ota bin select info invalid + * @brief Commence an OTA update writing to the specified partition. + + * The specified partition is erased to the specified image size. + * + * If image size is not yet known, pass OTA_SIZE_UNKNOWN which will + * cause the entire partition to be erased. + * + * On success, this function allocates memory that remains in use + * until esp_ota_end() is called with the returned handle. + * + * @param partition Pointer to info for partition which will receive the OTA update. Required. + * @param image_size Size of new OTA app image. Partition will be erased in order to receive this size of image. If 0 or OTA_SIZE_UNKNOWN, the entire partition is erased. + * @param out_handle On success, returns a handle which should be used for subsequent esp_ota_write() and esp_ota_end() calls. + + * @return + * - ESP_OK: OTA operation commenced successfully. + * - ESP_ERR_INVALID_ARG: partition or out_handle arguments were NULL, or partition doesn't point to an OTA app partition. + * - ESP_ERR_NO_MEM: Cannot allocate memory for OTA operation. + * - ESP_ERR_OTA_PARTITION_CONFLICT: Partition holds the currently running firmware, cannot update in place. + * - ESP_ERR_NOT_FOUND: Partition argument not found in partition table. + * - ESP_ERR_OTA_SELECT_INFO_INVALID: The OTA data partition contains invalid data. + * - ESP_ERR_INVALID_SIZE: Partition doesn't fit in configured flash size. + * - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash write failed. */ esp_err_t esp_ota_begin(const esp_partition_t* partition, size_t image_size, esp_ota_handle_t* out_handle); /** - * @brief Write data to input input partition + * @brief Write OTA update data to partition + * + * This function can be called multiple times as + * data is received during the OTA operation. Data is written + * sequentially to the partition. * - * @param handle Handle obtained from esp_ota_begin - * @param data Pointer to data write to flash - * @param size data size of recieved data + * @param handle Handle obtained from esp_ota_begin + * @param data Data buffer to write + * @param size Size of data buffer in bytes. * - * @return: - * - ESP_OK: if write flash data OK - * - ESP_ERR_OTA_PARTITION_CONFLICT: operate current running bin - * - ESP_ERR_OTA_SELECT_INFO_INVALID: ota bin select info invalid + * @return + * - ESP_OK: Data was written to flash successfully. + * - ESP_ERR_INVALID_ARG: handle is invalid. + * - ESP_ERR_OTA_VALIDATE_FAILED: First byte of image contains invalid app image magic byte. + * - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash write failed. + * - ESP_ERR_OTA_SELECT_INFO_INVALID: OTA data partition has invalid contents */ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void* data, size_t size); - + /** - * @brief Finish the update and validate written data + * @brief Finish OTA update and validate newly written app image. * - * @param handle Handle obtained from esp_ota_begin. + * @param handle Handle obtained from esp_ota_begin(). * * @note After calling esp_ota_end(), the handle is no longer valid and any memory associated with it is freed (regardless of result). * - * @return: + * @return * - ESP_OK: Newly written OTA app image is valid. * - ESP_ERR_NOT_FOUND: OTA handle was not found. * - ESP_ERR_INVALID_ARG: Handle was never written to. @@ -87,27 +106,61 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void* data, size_t size); esp_err_t esp_ota_end(esp_ota_handle_t handle); /** - * @brief Set next boot partition, call system_restart() will switch to run it + * @brief Configure OTA data for a new boot partition * - * @note if you want switch to run a bin file - * has never been checked before,please validate it's signature firstly + * @note If this function returns ESP_OK, calling esp_restart() will boot the newly configured app partition. * - * @param partition Pointer to partition structure which need to boot + * @param partition Pointer to info for partition containing app image to boot. * - * @return: - * - ESP_OK: if set next boot partition OK - * - ESP_ERR_OTA_SELECT_INFO_INVALID: ota bin select info invalid + * @return + * - ESP_OK: OTA data updated, next reboot will use specified partition. + * - ESP_ERR_INVALID_ARG: partition argument was NULL or didn't point to a valid OTA partition of type "app". + * - ESP_ERR_OTA_VALIDATE_FAILED: Partition contained invalid app image. Also returned if secure boot is enabled and signature validation failed. + * - ESP_ERR_NOT_FOUND: OTA data partition not found. + * - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash erase or write failed. */ esp_err_t esp_ota_set_boot_partition(const esp_partition_t* partition); /** - * @brief Get partition info of current running image - * - * @return pointer to esp_partition_t structure, or NULL if no partition is found or - * operate flash failed,This pointer is valid for the lifetime of the application. + * @brief Get partition info of currently configured boot app + * + * If esp_ota_set_boot_partition() has been called, the partition which was set by that function will be returned. + * + * If esp_ota_set_boot_partition() has not been called, the result is + * equivalent to esp_ota_get_running_partition(). + * + * @return Pointer to info for partition structure, or NULL if no partition is found or flash read operation failed. Returned pointer is valid for the lifetime of the application. */ const esp_partition_t* esp_ota_get_boot_partition(void); + +/** + * @brief Get partition info of currently running app + * + * This function is different to esp_ota_get_boot_partition() in that + * it ignores any change of selected boot partition caused by + * esp_ota_set_boot_partition(). Only the app whose code is currently + * running will have its partition information returned. + * + * @return Pointer to info for partition structure, or NULL if no partition is found or flash read operation failed. Returned pointer is valid for the lifetime of the application. + */ +const esp_partition_t* esp_ota_get_running_partition(void); + + +/** + * @brief Return the next OTA app partition which should be written with a new firmware. + * + * Call this function to find an OTA app partition which can be passed to esp_ota_begin(). + * + * Finds next partition round-robin, starting from the current running partition. + * + * @param start_from If set, treat this partition info as describing the current running partition. Can be NULL, in which case esp_ota_get_running_partition() is used to find the currently running partition. The result of this function is never the same as this argument. + * + * @return Pointer to info for partition which should be updated next. NULL result indicates invalid OTA data partition, or that no eligible OTA app slot partition was found. + * + */ +const esp_partition_t* esp_ota_get_next_update_partition(const esp_partition_t *start_from); + #ifdef __cplusplus } #endif diff --git a/tools/sdk/include/bluedroid/bta_api.h b/tools/sdk/include/bluedroid/bta_api.h index 1b97dc4fc6fe7e15365cac120974a5f4c223cc82..8e4b927aa400c5ef3845adf9cdb83c10dde11d7a 100644 --- a/tools/sdk/include/bluedroid/bta_api.h +++ b/tools/sdk/include/bluedroid/bta_api.h @@ -400,6 +400,8 @@ typedef struct { typedef void (tBTA_SET_ADV_DATA_CMPL_CBACK) (tBTA_STATUS status); +typedef void (tBTA_START_ADV_CMPL_CBACK) (tBTA_STATUS status); + /* advertising channel map */ #define BTA_BLE_ADV_CHNL_37 BTM_BLE_ADV_CHNL_37 #define BTA_BLE_ADV_CHNL_38 BTM_BLE_ADV_CHNL_38 @@ -1095,6 +1097,8 @@ typedef void (tBTA_BLE_SCAN_SETUP_CBACK) (tBTA_BLE_BATCH_SCAN_EVT evt, tBTA_DM_BLE_REF_VALUE ref_value, tBTA_STATUS status); +typedef void (tBTA_START_SCAN_CMPL_CBACK) (tBTA_STATUS status); + typedef void (tBTA_BLE_TRACK_ADV_CMPL_CBACK)(int action, tBTA_STATUS status, tBTA_DM_BLE_PF_AVBL_SPACE avbl_space, tBTA_DM_BLE_REF_VALUE ref_value); @@ -1891,7 +1895,7 @@ extern void BTA_DmSetBleAdvParams (UINT16 adv_int_min, UINT16 adv_int_max, extern void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max, UINT8 adv_type, tBLE_ADDR_TYPE addr_type_own, tBTM_BLE_ADV_CHNL_MAP chnl_map, tBTM_BLE_AFP adv_fil_pol, - tBLE_BD_ADDR *p_dir_bda); + tBLE_BD_ADDR *p_dir_bda, tBTA_START_ADV_CMPL_CBACK p_start_adv_cb); /******************************************************************************* @@ -1997,7 +2001,8 @@ extern void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport, ** *******************************************************************************/ extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration, - tBTA_DM_SEARCH_CBACK *p_results_cb); + tBTA_DM_SEARCH_CBACK *p_results_cb, + tBTA_START_SCAN_CMPL_CBACK *p_start_scan_cb); extern void BTA_DmBleStopAdvertising(void); diff --git a/tools/sdk/include/bluedroid/esp_gap_ble_api.h b/tools/sdk/include/bluedroid/esp_gap_ble_api.h index 64aff1fb1afadc71581f8e5c318600c23dbdbb9b..8b5882d270a61922e38de045b73df10ef75e5ad8 100644 --- a/tools/sdk/include/bluedroid/esp_gap_ble_api.h +++ b/tools/sdk/include/bluedroid/esp_gap_ble_api.h @@ -46,6 +46,8 @@ typedef enum { ESP_GAP_BLE_SCAN_RESULT_EVT, /*!< When one scan result ready, the event comes each time */ ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT, /*!< When raw advertising data set complete, the event comes */ ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT, /*!< When raw advertising data set complete, the event comes */ + ESP_GAP_BLE_ADV_START_COMPLETE_EVT, /*!< When start advertising complete, the event comes */ + ESP_GAP_BLE_SCAN_START_COMPLETE_EVT, /*!< When start scan complete, the event comes */ } esp_gap_ble_cb_event_t; /// Advertising data maximum length @@ -284,6 +286,18 @@ typedef union { struct ble_scan_rsp_data_raw_cmpl_evt_param { esp_bt_status_t status; /*!< Indicate the set raw advertising data operation success status */ } scan_rsp_data_raw_cmpl; /*!< Event parameter of ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT */ + /** + * @brief ESP_GAP_BLE_ADV_START_COMPLETE_EVT + */ + struct ble_adv_start_cmpl_evt_param { + esp_bt_status_t status; /*!< Indicate advertising start operation success status */ + } adv_start_cmpl; /*!< Event parameter of ESP_GAP_BLE_ADV_START_COMPLETE_EVT */ + /** + * @brief ESP_GAP_BLE_SCAN_START_COMPLETE_EVT + */ + struct ble_scan_start_cmpl_evt_param { + esp_bt_status_t status; /*!< Indicate scan start operation success status */ + } scan_start_cmpl; /*!< Event parameter of ESP_GAP_BLE_SCAN_START_COMPLETE_EVT */ } esp_ble_gap_cb_param_t; /** diff --git a/tools/sdk/include/bluedroid/thread.h b/tools/sdk/include/bluedroid/thread.h index 61e9487eaf5cdbed01b40cbf2206d622a3dfeb9f..01df95388952bcb665f987e1ba39a79133dcb12d 100644 --- a/tools/sdk/include/bluedroid/thread.h +++ b/tools/sdk/include/bluedroid/thread.h @@ -20,7 +20,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/queue.h" #include "freertos/task.h" - +#include "esp_task.h" #include "bt_defs.h" #define portBASE_TYPE int @@ -43,25 +43,25 @@ enum { SIG_BTIF_WORK = 0xff }; -#define HCI_HOST_TASK_STACK_SIZE 1500 -#define HCI_HOST_TASK_PRIO (configMAX_PRIORITIES - 2) -#define HCI_HOST_TASK_NAME "hciHostT" -#define HCI_HOST_QUEUE_NUM 40 +#define HCI_HOST_TASK_STACK_SIZE (2048 + BT_TASK_EXTRA_STACK_SIZE) +#define HCI_HOST_TASK_PRIO (configMAX_PRIORITIES - 2) +#define HCI_HOST_TASK_NAME "hciHostT" +#define HCI_HOST_QUEUE_NUM 40 -#define HCI_H4_TASK_STACK_SIZE 1500 -#define HCI_H4_TASK_PRIO (configMAX_PRIORITIES - 3) -#define HCI_H4_TASK_NAME "hciH4T" -#define HCI_H4_QUEUE_NUM 60 +#define HCI_H4_TASK_STACK_SIZE (2048 + BT_TASK_EXTRA_STACK_SIZE) +#define HCI_H4_TASK_PRIO (configMAX_PRIORITIES - 3) +#define HCI_H4_TASK_NAME "hciH4T" +#define HCI_H4_QUEUE_NUM 60 -#define BTU_TASK_STACK_SIZE 4096 -#define BTU_TASK_PRIO (configMAX_PRIORITIES - 4) -#define BTU_TASK_NAME "btuT" -#define BTU_QUEUE_NUM 50 +#define BTU_TASK_STACK_SIZE (3584 + BT_TASK_EXTRA_STACK_SIZE) +#define BTU_TASK_PRIO (configMAX_PRIORITIES - 4) +#define BTU_TASK_NAME "btuT" +#define BTU_QUEUE_NUM 50 -#define BTC_TASK_STACK_SIZE CONFIG_BTC_TASK_STACK_SIZE //by menuconfig -#define BTC_TASK_NAME "btcT" -#define BTC_TASK_PRIO (configMAX_PRIORITIES - 5) -#define BTC_TASK_QUEUE_NUM 20 +#define BTC_TASK_STACK_SIZE (CONFIG_BTC_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) //by menuconfig +#define BTC_TASK_NAME "btcT" +#define BTC_TASK_PRIO (configMAX_PRIORITIES - 5) +#define BTC_TASK_QUEUE_NUM 20 void btu_task_post(uint32_t sig); void hci_host_task_post(void); diff --git a/tools/sdk/include/config/sdkconfig.h b/tools/sdk/include/config/sdkconfig.h index d1d2e277670e701854da6ee765840f6932a11f51..3c18e6b3407af101956e4faa0fe8723402dadc14 100644 --- a/tools/sdk/include/config/sdkconfig.h +++ b/tools/sdk/include/config/sdkconfig.h @@ -7,7 +7,9 @@ #define CONFIG_ESP32_PHY_MAX_TX_POWER 20 #define CONFIG_PHY_ENABLED 1 #define CONFIG_TRACEMEM_RESERVE_DRAM 0x0 +#define CONFIG_FREERTOS_MAX_TASK_NAME_LEN 16 #define CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE 1 +#define CONFIG_FOUR_MAC_ADDRESS_FROM_EFUSE 1 #define CONFIG_ESPTOOLPY_FLASHSIZE_4MB 1 #define CONFIG_ESPTOOLPY_FLASHFREQ "80m" #define CONFIG_NEWLIB_STDOUT_ADDCR 1 @@ -18,6 +20,7 @@ #define CONFIG_INT_WDT 1 #define CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL 1 #define CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS 1 +#define CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM 10 #define CONFIG_BT_RESERVE_DRAM 0x10000 #define CONFIG_LOG_BOOTLOADER_LEVEL_ERROR 1 #define CONFIG_CONSOLE_UART_BAUDRATE 115200 @@ -28,6 +31,7 @@ #define CONFIG_INT_WDT_CHECK_CPU1 1 #define CONFIG_ESPTOOLPY_AFTER_RESET 1 #define CONFIG_TOOLPREFIX "xtensa-esp32-elf-" +#define CONFIG_ESP32_WIFI_AMPDU_ENABLED 1 #define CONFIG_CONSOLE_UART_NUM 0 #define CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC 1 #define CONFIG_LWIP_THREAD_LOCAL_STORAGE_INDEX 0 @@ -46,10 +50,11 @@ #define CONFIG_BTC_TASK_STACK_SIZE 2048 #define CONFIG_ESPTOOLPY_BEFORE "default_reset" #define CONFIG_LOG_DEFAULT_LEVEL 1 +#define CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM 0 #define CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER 20 +#define CONFIG_ESP32_WIFI_NVS_ENABLED 1 #define CONFIG_ULP_COPROC_ENABLED 1 #define CONFIG_DMA_RX_BUF_NUM 10 -#define CONFIG_ESPTOOLPY_FLASHMODE_DIO 1 #define CONFIG_TCP_SYNMAXRTX 6 #define CONFIG_PYTHON "python" #define CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1 1 @@ -57,12 +62,15 @@ #define CONFIG_PARTITION_TABLE_FILENAME "partitions_singleapp.csv" #define CONFIG_LWIP_DHCP_MAX_NTP_SERVERS 1 #define CONFIG_PARTITION_TABLE_SINGLE_APP 1 +#define CONFIG_NUMBER_OF_MAC_ADDRESS_GENERATED_FROM_EFUSE 4 #define CONFIG_WIFI_ENABLED 1 +#define CONFIG_FLASHMODE_QIO 1 #define CONFIG_ESPTOOLPY_FLASHFREQ_80M 1 #define CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE 2048 #define CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY 0 #define CONFIG_PHY_DATA_OFFSET 0xf000 #define CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET 0x10000 +#define CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM 32 #define CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ 240 #define CONFIG_MBEDTLS_HARDWARE_AES 1 #define CONFIG_FREERTOS_HZ 1000 @@ -88,7 +96,6 @@ #define CONFIG_OPENSSL_ASSERT_DO_NOTHING 1 #define CONFIG_OPTIMIZATION_LEVEL_DEBUG 1 #define CONFIG_SYSTEM_EVENT_QUEUE_SIZE 32 -#define CONFIG_ESP32_WIFI_RX_BUFFER_NUM 25 #define CONFIG_ESPTOOLPY_BAUD_921600B 1 #define CONFIG_APP_OFFSET 0x10000 #define CONFIG_MEMMAP_SMP 1 diff --git a/tools/sdk/include/driver/driver/sdmmc_host.h b/tools/sdk/include/driver/driver/sdmmc_host.h index 0f56c266a84324f12dee153c79ebfed00b1ccb4a..dc3e9ef6bf997a2f30226c13218dae73bbf3d25a 100644 --- a/tools/sdk/include/driver/driver/sdmmc_host.h +++ b/tools/sdk/include/driver/driver/sdmmc_host.h @@ -50,10 +50,12 @@ extern "C" { typedef struct { gpio_num_t gpio_cd; ///< GPIO number of card detect signal gpio_num_t gpio_wp; ///< GPIO number of write protect signal + uint8_t width; ///< Bus width used by the slot (might be less than the max width supported) } sdmmc_slot_config_t; #define SDMMC_SLOT_NO_CD ((gpio_num_t) -1) ///< indicates that card detect line is not used #define SDMMC_SLOT_NO_WP ((gpio_num_t) -1) ///< indicates that write protect line is not used +#define SDMMC_SLOT_WIDTH_DEFAULT 0 ///< use the default width for the slot (8 for slot 0, 4 for slot 1) /** * Macro defining default configuration of SDMMC host slot @@ -61,6 +63,7 @@ typedef struct { #define SDMMC_SLOT_CONFIG_DEFAULT() {\ .gpio_cd = SDMMC_SLOT_NO_CD, \ .gpio_wp = SDMMC_SLOT_NO_WP, \ + .width = SDMMC_SLOT_WIDTH_DEFAULT, \ } /** diff --git a/tools/sdk/include/driver/driver/uart.h b/tools/sdk/include/driver/driver/uart.h index 23635df27d65f40b19df0402eedb92f3228146d7..748735c5da7240bb42f36d30410d3a710a383506 100644 --- a/tools/sdk/include/driver/driver/uart.h +++ b/tools/sdk/include/driver/driver/uart.h @@ -478,7 +478,8 @@ esp_err_t uart_intr_config(uart_port_t uart_num, const uart_intr_config_t *intr_ * @param uart_queue UART event queue handle (out param). On success, a new queue handle is written here to provide * access to UART events. If set to NULL, driver will not use an event queue. * @param intr_alloc_flags Flags used to allocate the interrupt. One or multiple (ORred) - * ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info. + * ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info. Do not set ESP_INTR_FLAG_IRAM here + * (the driver's ISR handler is not located in IRAM) * * @return * - ESP_OK Success diff --git a/tools/sdk/include/esp32/esp_deep_sleep.h b/tools/sdk/include/esp32/esp_deep_sleep.h index aba74b30da42651ed13ef512078b063826254a95..61d3642b506530735b75ba6ec997281f5fc43c96 100644 --- a/tools/sdk/include/esp32/esp_deep_sleep.h +++ b/tools/sdk/include/esp32/esp_deep_sleep.h @@ -17,6 +17,7 @@ #include #include "esp_err.h" #include "driver/gpio.h" +#include "driver/touch_pad.h" #ifdef __cplusplus extern "C" { @@ -50,12 +51,28 @@ typedef enum { ESP_PD_OPTION_AUTO //!< Keep power domain enabled in deep sleep, if it is needed by one of the wakeup options. Otherwise power it down. } esp_deep_sleep_pd_option_t; +/** + * @brief Deep sleep wakeup cause + */ +typedef enum { + ESP_DEEP_SLEEP_WAKEUP_UNDEFINED, //! Wakeup was not caused by deep sleep + ESP_DEEP_SLEEP_WAKEUP_EXT0, //! Wakeup caused by external signal using RTC_IO + ESP_DEEP_SLEEP_WAKEUP_EXT1, //! Wakeup caused by external signal using RTC_CNTL + ESP_DEEP_SLEEP_WAKEUP_TIMER, //! Wakeup caused by timer + ESP_DEEP_SLEEP_WAKEUP_TOUCHPAD, //! Wakeup caused by touchpad + ESP_DEEP_SLEEP_WAKEUP_ULP, //! Wakeup caused by ULP program +} esp_deep_sleep_wakeup_cause_t; + /** * @brief Enable wakeup by ULP coprocessor + * @note In revisions 0 and 1 of the ESP32, ULP wakeup source + * can not be used when RTC_PERIPH power domain is forced + * to be powered on (ESP_PD_OPTION_ON) or when ext0 wakeup + * source is used. * @return * - ESP_OK on success - * - ESP_ERR_INVALID_STATE if ULP co-processor is not enabled. + * - ESP_ERR_INVALID_STATE if ULP co-processor is not enabled or if wakeup triggers conflict */ esp_err_t esp_deep_sleep_enable_ulp_wakeup(); @@ -68,6 +85,29 @@ esp_err_t esp_deep_sleep_enable_ulp_wakeup(); */ esp_err_t esp_deep_sleep_enable_timer_wakeup(uint64_t time_in_us); +/** + * @brief Enable wakeup by touch sensor + * + * @note In revisions 0 and 1 of the ESP32, touch wakeup source + * can not be used when RTC_PERIPH power domain is forced + * to be powered on (ESP_PD_OPTION_ON) or when ext0 wakeup + * source is used. + * + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_STATE if wakeup triggers conflict + */ +esp_err_t esp_deep_sleep_enable_touchpad_wakeup(); + +/** + * @brief Get the touch pad which caused wakeup + * + * If wakeup was caused by another source, this function will return TOUCH_PAD_MAX; + * + * @return touch pad which caused wakeup + */ +touch_pad_t esp_deep_sleep_get_touchpad_wakeup_status(); + /** * @brief Enable wakeup using a pin * @@ -81,6 +121,9 @@ esp_err_t esp_deep_sleep_enable_timer_wakeup(uint64_t time_in_us); * configured in esp_deep_sleep_start, immediately before * entering deep sleep. * + * @note In revisions 0 and 1 of the ESP32, ext0 wakeup source + * can not be used together with touch or ULP wakeup sources. + * * @param gpio_num GPIO number used as wakeup source. Only GPIOs which are have RTC * functionality can be used: 0,2,4,12-15,25-27,32-39. * @param level input level which will trigger wakeup (0=low, 1=high) @@ -88,6 +131,7 @@ esp_err_t esp_deep_sleep_enable_timer_wakeup(uint64_t time_in_us); * - ESP_OK on success * - ESP_ERR_INVALID_ARG if the selected GPIO is not an RTC GPIO, * or the mode is invalid + * - ESP_ERR_INVALID_STATE if wakeup triggers conflict */ esp_err_t esp_deep_sleep_enable_ext0_wakeup(gpio_num_t gpio_num, int level); @@ -188,6 +232,15 @@ void esp_deep_sleep(uint64_t time_in_us) __attribute__((noreturn)); */ void system_deep_sleep(uint64_t time_in_us) __attribute__((noreturn, deprecated)); + +/** + * @brief Get the source which caused deep sleep wakeup + * + * @return wakeup cause, or ESP_DEEP_SLEEP_WAKEUP_UNDEFINED if reset reason is other than deep sleep reset. + */ +esp_deep_sleep_wakeup_cause_t esp_deep_sleep_get_wakeup_cause(); + + /** * @brief Default stub to run on wake from deep sleep. * diff --git a/tools/sdk/include/esp32/esp_err.h b/tools/sdk/include/esp32/esp_err.h index b6a1e8b42152b3649729569979061cd836def7a8..c7beafd37563b08c7291ede1dd85d0bac1e0a9d7 100644 --- a/tools/sdk/include/esp32/esp_err.h +++ b/tools/sdk/include/esp32/esp_err.h @@ -11,10 +11,10 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#ifndef __ESP_ERR_H__ -#define __ESP_ERR_H__ +#pragma once #include +#include #include #ifdef __cplusplus @@ -40,15 +40,38 @@ typedef int32_t esp_err_t; #define ESP_ERR_WIFI_BASE 0x3000 /*!< Starting number of WiFi error codes */ +void _esp_error_check_failed(esp_err_t rc, const char *file, int line, const char *function, const char *expression) __attribute__((noreturn)); + +#ifndef __ASSERT_FUNC +/* This won't happen on IDF, which defines __ASSERT_FUNC in assert.h, but it does happen when building on the host which + uses /usr/include/assert.h or equivalent. +*/ +#ifdef __ASSERT_FUNCTION +#define __ASSERT_FUNC __ASSERT_FUNCTION /* used in glibc assert.h */ +#else +#define __ASSERT_FUNC "??" +#endif +#endif + /** * Macro which can be used to check the error code, * and terminate the program in case the code is not ESP_OK. - * Prints the failed statement to serial output. + * Prints the error code, error location, and the failed statement to serial output. + * + * Disabled if assertions are disabled. */ -#define ESP_ERROR_CHECK(x) do { esp_err_t rc = (x); if (rc != ESP_OK) { assert(0 && #x);} } while(0); +#ifdef NDEBUG +#define ESP_ERROR_CHECK(x) do { (x); } while (0) +#else +#define ESP_ERROR_CHECK(x) do { \ + esp_err_t rc = (x); \ + if (rc != ESP_OK) { \ + _esp_error_check_failed(rc, __FILE__, __LINE__, \ + __ASSERT_FUNC, #x); \ + } \ + } while(0); +#endif #ifdef __cplusplus } #endif - -#endif /* __ESP_ERR_H__ */ diff --git a/tools/sdk/include/esp32/esp_system.h b/tools/sdk/include/esp32/esp_system.h index 30701761ad293a02e142cdfa2c5ca564343dddad..9a88743b8069ba31392f6a3ede9dadbb9266c30f 100644 --- a/tools/sdk/include/esp32/esp_system.h +++ b/tools/sdk/include/esp32/esp_system.h @@ -24,6 +24,17 @@ extern "C" { #endif +typedef enum { + ESP_MAC_WIFI_STA, + ESP_MAC_WIFI_SOFTAP, + ESP_MAC_BT, + ESP_MAC_ETH, +} esp_mac_type_t; + +#define TWO_MAC_ADDRESS_FROM_EFUSE 2 +#define FOUR_MAC_ADDRESS_FROM_EFUSE 4 +#define NUM_MAC_ADDRESS_FROM_EFUSE CONFIG_NUMBER_OF_MAC_ADDRESS_GENERATED_FROM_EFUSE + /** * @attention application don't need to call this function anymore. It do nothing and will * be removed in future version. @@ -115,6 +126,47 @@ esp_err_t esp_efuse_read_mac(uint8_t* mac); */ esp_err_t system_efuse_read_mac(uint8_t mac[6]) __attribute__ ((deprecated)); +/** + * @brief Read hardware MAC address and set MAC address of the interface. + * + * This function first reads hardware MAC address from efuse. Then set the MAC address of the interface + * including wifi station, wifi softap, bluetooth and ethernet. + * + * @param mac MAC address of the interface, length: 6 bytes. + * @param type type of MAC address, 0:wifi station, 1:wifi softap, 2:bluetooth, 3:ethernet. + * + * @return ESP_OK on success + */ +esp_err_t esp_read_mac(uint8_t* mac, esp_mac_type_t type); + +/** + * @brief Derive MAC address. + * + * This function derives a local MAC address from an universal MAC address. + * Addresses can either be universally administered addresses or locally administered addresses. + * A universally administered address is uniquely assigned to a device by its manufacturer. + * The first three octets (in transmission order) identify the organization that issued the identifier + * and are known as the Organizationally Unique Identifier (OUI).[4] The remainder of the address + * (three octets for MAC-48 and EUI-48 or five for EUI-64) are assigned by that organization in nearly + * any manner they please, subject to the constraint of uniqueness. A locally administered address is + * assigned to a device by a network administrator, overriding the burned-in address. + * Universally administered and locally administered addresses are distinguished by setting + * the second-least-significant bit of the first octet of the address. This bit is also referred to + * as the U/L bit, short for Universal/Local, which identifies how the address is administered. + * If the bit is 0, the address is universally administered. If it is 1, the address is locally administered. + * In the example address 06-00-00-00-00-00 the first octet is 06 (hex), the binary form of which is 00000110, + * where the second-least-significant bit is 1. Therefore, it is a locally administered address.[7] Consequently, + * this bit is 0 in all OUIs. + * In ESP32, universal MAC address is generated from the hardware MAC address in efuse. + * Local MAC address is derived from the universal MAC address. + * + * @param dst_mac Derived local MAC address, length: 6 bytes. + * @param src_mac Source universal MAC address, length: 6 bytes. + * + * @return ESP_OK on success + */ +esp_err_t esp_derive_mac(uint8_t* dst_mac, const uint8_t* src_mac); + /** * Get SDK version * diff --git a/tools/sdk/include/esp32/esp_task.h b/tools/sdk/include/esp32/esp_task.h index bb028bf48582635a3cd8590bf840df49ee6e95c5..bd263626495fa72ec9ad387749ff9b6273bbf53b 100644 --- a/tools/sdk/include/esp32/esp_task.h +++ b/tools/sdk/include/esp32/esp_task.h @@ -31,22 +31,16 @@ #define ESP_TASK_PRIO_MAX (configMAX_PRIORITIES) #define ESP_TASK_PRIO_MIN (0) -/* Wifi library task */ -#define ESP_TASKD_WATCHDOG_PRIO (ESP_TASK_PRIO_MAX - 1) -#define ESP_TASKD_WATCHDOG_STACK 2048 -#define ESP_TASK_WPA2_PRIO (ESP_TASK_PRIO_MAX - 1) -#define ESP_TASK_WPA2_STACK 2048 -#define ESP_TASKD_WIFI_PRIO (ESP_TASK_PRIO_MAX - 2) -#define ESP_TASKD_WIFI_STACK 8196 -#define ESP_TASKD_WIFI_TIMER_PRIO (ESP_TASK_PRIO_MAX - 3) -#define ESP_TASKD_WIFI_TIMER_STACK 2048 -#define ESP_TASK_WPS_PRIO (ESP_TASK_PRIO_MIN + 2) -#define ESP_TASK_WPS_STACK 2048 - /* Bt contoller Task */ /* controller */ #define ESP_TASK_BT_CONTROLLER_PRIO (ESP_TASK_PRIO_MAX - 1) -#define ESP_TASK_BT_CONTROLLER_STACK 4096 +#ifdef CONFIG_NEWLIB_NANO_FORMAT +#define BT_TASK_EXTRA_STACK_SIZE (0) +#else +#define BT_TASK_EXTRA_STACK_SIZE (512) +#endif +#define ESP_TASK_BT_CONTROLLER_STACK (3584 + BT_TASK_EXTRA_STACK_SIZE) + /* idf task */ #define ESP_TASKD_EVENT_PRIO (ESP_TASK_PRIO_MAX - 5) diff --git a/tools/sdk/include/esp32/esp_wifi.h b/tools/sdk/include/esp32/esp_wifi.h index 0f7e2996e8bb09644b23fc6715a8875984672a77..2312bc08a207c9c246f21fca4e0af364422c767b 100755 --- a/tools/sdk/include/esp32/esp_wifi.h +++ b/tools/sdk/include/esp32/esp_wifi.h @@ -94,14 +94,45 @@ extern "C" { * @brief WiFi stack configuration parameters passed to esp_wifi_init call. */ typedef struct { - system_event_handler_t event_handler; /**< WiFi event handler */ - uint32_t rx_buf_num; /**< WiFi RX buffer number */ + system_event_handler_t event_handler; /**< WiFi event handler */ + int static_rx_buf_num; /**< WiFi static RX buffer number */ + int dynamic_rx_buf_num; /**< WiFi dynamic RX buffer number */ + int dynamic_tx_buf_num; /**< WiFi dynamic TX buffer number */ + int ampdu_enable; /**< WiFi AMPDU feature enable flag */ + int nvs_enable; /**< WiFi NVS flash enable flag */ + int nano_enable; /**< Nano option for printf/scan family enable flag */ + int magic; /**< WiFi init magic number, it should be the last field */ } wifi_init_config_t; +#if CONFIG_ESP32_WIFI_AMPDU_ENABLED +#define WIFI_AMPDU_ENABLED 1 +#else +#define WIFI_AMPDU_ENABLED 0 +#endif + +#if CONFIG_ESP32_WIFI_NVS_ENABLED +#define WIFI_NVS_ENABLED 1 +#else +#define WIFI_NVS_ENABLED 0 +#endif + +#if CONFIG_NEWLIB_NANO_FORMAT +#define WIFI_NANO_FORMAT_ENABLED 1 +#else +#define WIFI_NANO_FORMAT_ENABLED 0 +#endif + +#define WIFI_INIT_CONFIG_MAGIC 0x1F2F3F4F #ifdef CONFIG_WIFI_ENABLED #define WIFI_INIT_CONFIG_DEFAULT() { \ .event_handler = &esp_event_send, \ - .rx_buf_num = CONFIG_ESP32_WIFI_RX_BUFFER_NUM, \ + .static_rx_buf_num = CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM,\ + .dynamic_rx_buf_num = CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM,\ + .dynamic_tx_buf_num = CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM,\ + .ampdu_enable = WIFI_AMPDU_ENABLED,\ + .nvs_enable = WIFI_NVS_ENABLED,\ + .nano_enable = WIFI_NANO_FORMAT_ENABLED,\ + .magic = WIFI_INIT_CONFIG_MAGIC\ }; #else #define WIFI_INIT_CONFIG_DEFAULT #error Wifi is disabled in config, WIFI_INIT_CONFIG_DEFAULT will not work @@ -113,8 +144,11 @@ typedef struct { * WiFi NVS structure etc, this WiFi also start WiFi task * * @attention 1. This API must be called before all other WiFi API can be called - * @attention 2. event_handler field in cfg should be set to a valid event handler function. - * In most cases, use the WIFI_INIT_CONFIG_DEFAULT macro which sets esp_event_send(). + * @attention 2. Always use WIFI_INIT_CONFIG_DEFAULT macro to init the config to default values, this can + * guarantee all the fields got correct value when more fields are added into wifi_init_config_t + * in future release. If you want to set your owner initial values, overwrite the default values + * which are set by WIFI_INIT_CONFIG_DEFAULT, please be notified that the field 'magic' of + * wifi_init_config_t should always be WIFI_INIT_CONFIG_MAGIC! * * @param config provide WiFi init configuration * @@ -422,6 +456,7 @@ esp_err_t esp_wifi_get_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t *bw); * @brief Set primary/secondary channel of ESP32 * * @attention 1. This is a special API for sniffer + * @attention 2. This API should be called after esp_wifi_start() or esp_wifi_set_promiscuous() * * @param primary for HT20, primary is the channel number, for HT40, primary is the primary channel * @param second for HT20, second is ignored, for HT40, second is the second channel diff --git a/tools/sdk/include/esp32/rom/spi_flash.h b/tools/sdk/include/esp32/rom/spi_flash.h index 44098475d6adfeb19d76e0b4dfbe50c46f65aeeb..a9d617e7541b91c9f0959a448f829d11427b6a88 100644 --- a/tools/sdk/include/esp32/rom/spi_flash.h +++ b/tools/sdk/include/esp32/rom/spi_flash.h @@ -504,12 +504,25 @@ void SPI_Write_Encrypt_Disable(void); * @param uint32_t len : Length to write, should be 32 bytes aligned. * * @return SPI_FLASH_RESULT_OK : Data written successfully. - * SPI_FLASH_RESULT_ERR : Encrypto write error. + * SPI_FLASH_RESULT_ERR : Encryption write error. * SPI_FLASH_RESULT_TIMEOUT : Encrypto write timeout. */ SpiFlashOpResult SPI_Encrypt_Write(uint32_t flash_addr, uint32_t *data, uint32_t len); +/** @brief Wait until SPI flash write operation is complete + * + * @note Please do not call this function in SDK. + * + * Reads the Write In Progress bit of the SPI flash status register, + * repeats until this bit is zero (indicating write complete). + * + * @return SPI_FLASH_RESULT_OK : Write is complete + * SPI_FLASH_RESULT_ERR : Error while reading status. + */ +SpiFlashOpResult SPI_Wait_Idle(SpiFlashChip *spi); + + /** @brief Global SpiFlashChip structure used by ROM functions * */ diff --git a/tools/sdk/include/esp32/soc/cpu.h b/tools/sdk/include/esp32/soc/cpu.h index 2e0ac7de8029e01031e546bef998755f9f6c76b1..7e1301345b30fcf8f493f1b51f802732262f0cd7 100644 --- a/tools/sdk/include/esp32/soc/cpu.h +++ b/tools/sdk/include/esp32/soc/cpu.h @@ -36,16 +36,6 @@ static inline void *get_sp() return sp; } -/* Return true if the CPU is in an interrupt context - (PS.UM == 0) -*/ -static inline bool cpu_in_interrupt_context(void) -{ - uint32_t ps; - RSR(PS, ps); - return (ps & PS_UM) == 0; -} - /* Functions to set page attributes for Region Protection option in the CPU. * See Xtensa ISA Reference manual for explanation of arguments (section 4.6.3.2). */ diff --git a/tools/sdk/include/esp32/soc/dport_reg.h b/tools/sdk/include/esp32/soc/dport_reg.h index ef231e316ed4f73f49b07443434ab207b3a035d9..141b05b4a502cf91539a18b75cedc7b1d269c89e 100644 --- a/tools/sdk/include/esp32/soc/dport_reg.h +++ b/tools/sdk/include/esp32/soc/dport_reg.h @@ -1035,11 +1035,27 @@ #define DPORT_WIFI_CLK_EN_V 0xFFFFFFFF #define DPORT_WIFI_CLK_EN_S 0 +/* Mask for all Wifi clock bits - 0, 1, 2, 3, 6, 7, 8, 9, 10, 15 */ +#define DPORT_WIFI_CLK_WIFI_EN 0x000007cf +#define DPORT_WIFI_CLK_WIFI_EN_M ((DPORT_WIFI_CLK_WIFI_EN_V)<<(DPORT_WIFI_CLK_WIFI_EN_S)) +#define DPORT_WIFI_CLK_WIFI_EN_V 0x1FF +#define DPORT_WIFI_CLK_WIFI_EN_S 0 +/* Mask for all Bluetooth clock bits - 11, 16, 17 */ +#define DPORT_WIFI_CLK_BT_EN 0x61 +#define DPORT_WIFI_CLK_BT_EN_M ((DPORT_WIFI_CLK_BT_EN_V)<<(DPORT_WIFI_CLK_BT_EN_S)) +#define DPORT_WIFI_CLK_BT_EN_V 0x61 +#define DPORT_WIFI_CLK_BT_EN_S 11 +/* Remaining single bit clock masks */ +#define DPORT_WIFI_CLK_SDIOSLAVE_EN BIT(4) +#define DPORT_WIFI_CLK_SDIO_HOST_EN BIT(13) +#define DPORT_WIFI_CLK_EMAC_EN BIT(14) +#define DPORT_WIFI_CLK_RNG_EN BIT(15) + #define DPORT_CORE_RST_EN_REG (DR_REG_DPORT_BASE + 0x0D0) /* DPORT_CORE_RST : R/W ;bitpos:[31:0] ;default: 32'h0 ; */ /*description: */ -#define DPROT_RW_BTLP_RST (BIT(10)) -#define DPROT_RW_BTMAC_RST (BIT(9)) +#define DPORT_RW_BTLP_RST (BIT(10)) +#define DPORT_RW_BTMAC_RST (BIT(9)) #define DPORT_MACPWR_RST (BIT(8)) #define DPORT_EMAC_RST (BIT(7)) #define DPORT_SDIO_HOST_RST (BIT(6)) diff --git a/tools/sdk/include/esp32/soc/io_mux_reg.h b/tools/sdk/include/esp32/soc/io_mux_reg.h index de8fe7ec99477cd211c68478bebf8f0647f3900f..459a97009cdebe6f52c750406afa4b24aa704412 100644 --- a/tools/sdk/include/esp32/soc/io_mux_reg.h +++ b/tools/sdk/include/esp32/soc/io_mux_reg.h @@ -88,7 +88,7 @@ static inline void __attribute__ ((deprecated)) PIN_PULLDWN_EN(uint32_t PIN_NAME #define FUNC_GPIO0_GPIO0_0 0 #define PERIPHS_IO_MUX_U0TXD_U (DR_REG_IO_MUX_BASE +0x88) -#define FUNC_U0TXD_EMAC_RXD2 3 +#define FUNC_U0TXD_EMAC_RXD2 5 #define FUNC_U0TXD_GPIO1 2 #define FUNC_U0TXD_CLK_OUT3 1 #define FUNC_U0TXD_U0TXD 0 @@ -181,7 +181,7 @@ static inline void __attribute__ ((deprecated)) PIN_PULLDWN_EN(uint32_t PIN_NAME #define PERIPHS_IO_MUX_MTMS_U (DR_REG_IO_MUX_BASE +0x30) #define FUNC_MTMS_EMAC_TXD2 5 #define FUNC_MTMS_SD_CLK 4 -#define FUNC_MTMS_HS2_CLk 3 +#define FUNC_MTMS_HS2_CLK 3 #define FUNC_MTMS_GPIO14 2 #define FUNC_MTMS_HSPICLK 1 #define FUNC_MTMS_MTMS 0 diff --git a/tools/sdk/include/esp32/soc/rtc_cntl_reg.h b/tools/sdk/include/esp32/soc/rtc_cntl_reg.h index d99cec1864315fef62b281821d8e9d4e41a7f702..40d65f21f69a0891083dd1959e2008b29a13ad3f 100644 --- a/tools/sdk/include/esp32/soc/rtc_cntl_reg.h +++ b/tools/sdk/include/esp32/soc/rtc_cntl_reg.h @@ -240,7 +240,7 @@ #define RTC_CNTL_TIME_VALID_S 30 /* frequency of RTC slow clock, Hz */ -#define RTC_CTNL_SLOWCLK_FREQ 150000 +#define RTC_CNTL_SLOWCLK_FREQ 150000 #define RTC_CNTL_TIME0_REG (DR_REG_RTCCNTL_BASE + 0x10) /* RTC_CNTL_TIME_LO : RO ;bitpos:[31:0] ;default: 32'h0 ; */ diff --git a/tools/sdk/include/freertos/freertos/FreeRTOSConfig.h b/tools/sdk/include/freertos/freertos/FreeRTOSConfig.h index 9deb9f4b5e463a6c2598436baf7f6ff7bbc7bea4..4f403303983ab60032ec2c66cece268711ee4868 100644 --- a/tools/sdk/include/freertos/freertos/FreeRTOSConfig.h +++ b/tools/sdk/include/freertos/freertos/FreeRTOSConfig.h @@ -187,7 +187,7 @@ #define configAPPLICATION_ALLOCATED_HEAP 1 #define configTOTAL_HEAP_SIZE (&_heap_end - &_heap_start)//( ( size_t ) (64 * 1024) ) -#define configMAX_TASK_NAME_LEN ( 16 ) +#define configMAX_TASK_NAME_LEN ( CONFIG_FREERTOS_MAX_TASK_NAME_LEN ) #define configUSE_TRACE_FACILITY 0 /* Used by vTaskList in main.c */ #define configUSE_STATS_FORMATTING_FUNCTIONS 0 /* Used by vTaskList in main.c */ #define configUSE_TRACE_FACILITY_2 0 /* Provided by Xtensa port patch */ diff --git a/tools/sdk/include/freertos/freertos/portable.h b/tools/sdk/include/freertos/freertos/portable.h index 0c10ac36eb3116406bb710285aa598d1c2cc7f12..e46ec17fb6141d61f6c85c77074b077ea6d42240 100644 --- a/tools/sdk/include/freertos/freertos/portable.h +++ b/tools/sdk/include/freertos/freertos/portable.h @@ -194,6 +194,12 @@ void vPortYieldOtherCore( BaseType_t coreid) PRIVILEGED_FUNCTION; */ void vPortSetStackWatchpoint( void* pxStackStart ); +/* + * Returns true if the current core is in ISR context; low prio ISR, med prio ISR or timer tick ISR. High prio ISRs + * aren't detected here, but they normally cannot call C code, so that should not be an issue anyway. + */ +BaseType_t xPortInIsrContext(); + /* * The structures and methods of manipulating the MPU are contained within the * port layer. diff --git a/tools/sdk/include/lwip/lwip/dhcp.h b/tools/sdk/include/lwip/lwip/dhcp.h index c3a057ac0ff3e5b88601ea9fddf84a93f4e1b078..f282c8ab49c03fd6f426681ac019d7d57867a780 100755 --- a/tools/sdk/include/lwip/lwip/dhcp.h +++ b/tools/sdk/include/lwip/lwip/dhcp.h @@ -45,7 +45,7 @@ extern "C" { #endif /** period (in seconds) of the application calling dhcp_coarse_tmr() */ -#define DHCP_COARSE_TIMER_SECS 60 +#define DHCP_COARSE_TIMER_SECS 1 /** period (in milliseconds) of the application calling dhcp_coarse_tmr() */ #define DHCP_COARSE_TIMER_MSECS (DHCP_COARSE_TIMER_SECS * 1000UL) /** period (in milliseconds) of the application calling dhcp_fine_tmr() */ @@ -76,12 +76,12 @@ struct dhcp struct dhcp_msg *msg_out; /* outgoing msg */ u16_t options_out_len; /* outgoing msg options length */ u16_t request_timeout; /* #ticks with period DHCP_FINE_TIMER_SECS for request timeout */ - u16_t t1_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for renewal time */ - u16_t t2_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for rebind time */ - u16_t t1_renew_time; /* #ticks with period DHCP_COARSE_TIMER_SECS until next renew try */ - u16_t t2_rebind_time; /* #ticks with period DHCP_COARSE_TIMER_SECS until next rebind try */ - u16_t lease_used; /* #ticks with period DHCP_COARSE_TIMER_SECS since last received DHCP ack */ - u16_t t0_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for lease time */ + u32_t t1_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for renewal time */ + u32_t t2_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for rebind time */ + u32_t t1_renew_time; /* #ticks with period DHCP_COARSE_TIMER_SECS until next renew try */ + u32_t t2_rebind_time; /* #ticks with period DHCP_COARSE_TIMER_SECS until next rebind try */ + u32_t lease_used; /* #ticks with period DHCP_COARSE_TIMER_SECS since last received DHCP ack */ + u32_t t0_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for lease time */ ip_addr_t server_ip_addr; /* dhcp server address that offered this lease (ip_addr_t because passed to UDP) */ ip4_addr_t offered_ip_addr; ip4_addr_t offered_sn_mask; diff --git a/tools/sdk/include/lwip/lwip/netif.h b/tools/sdk/include/lwip/lwip/netif.h index 34e6d4489784c347652149ea170d51b6aac0da5f..13cbb798e06b6c9d468d4c9382290ff73de1f3ae 100755 --- a/tools/sdk/include/lwip/lwip/netif.h +++ b/tools/sdk/include/lwip/lwip/netif.h @@ -330,6 +330,10 @@ struct netif { u16_t loop_cnt_current; #endif /* LWIP_LOOPBACK_MAX_PBUFS */ #endif /* ENABLE_LOOPBACK */ + +#if ESP_LWIP + void (*l2_buffer_free_notify)(void *user_buf); /* Allows LWIP to notify driver when a L2-supplied pbuf can be freed */ +#endif }; #if LWIP_CHECKSUM_CTRL_PER_NETIF diff --git a/tools/sdk/include/lwip/lwip/pbuf.h b/tools/sdk/include/lwip/lwip/pbuf.h index d84aabaf81430cf27f88576ff522ef93c6db100f..42146f6fc46e130117a49a576b1c337fc5d8dabc 100755 --- a/tools/sdk/include/lwip/lwip/pbuf.h +++ b/tools/sdk/include/lwip/lwip/pbuf.h @@ -105,12 +105,6 @@ typedef enum { /** indicates this pbuf includes a TCP FIN flag */ #define PBUF_FLAG_TCP_FIN 0x20U -#if ESP_LWIP -#define PBUF_USER_FLAG_OWNER_NULL 0 -#define PBUF_USER_FLAG_OWNER_WIFI 1 -#define PBUF_USER_FLAG_OWNER_ETH 2 -#endif - struct pbuf { /** next pbuf in singly linked pbuf chain */ struct pbuf *next; @@ -142,10 +136,10 @@ struct pbuf { * the stack itself, or pbuf->next pointers from a chain. */ u16_t ref; - + #if ESP_LWIP - void *user_buf; - u8_t user_flag; + struct netif *l2_owner; + void *l2_buf; #endif }; diff --git a/tools/sdk/include/lwip/lwipopts.h b/tools/sdk/include/lwip/lwipopts.h index dc82649479dbeaf645e775ae678b3d2b3c84d6e3..60d7ecf212030b86c480c7f91f380782af2c3550 100644 --- a/tools/sdk/include/lwip/lwipopts.h +++ b/tools/sdk/include/lwip/lwipopts.h @@ -602,6 +602,7 @@ #define ESP_LIGHT_SLEEP 1 #define ESP_L2_TO_L3_COPY CONFIG_L2_TO_L3_COPY #define ESP_CNT_DEBUG 0 +#define ESP_DHCP_TIMER 1 #define TCP_WND_DEFAULT (4*TCP_MSS) #define TCP_SND_BUF_DEFAULT (2*TCP_MSS) diff --git a/tools/sdk/include/lwip/port/lwipopts.h b/tools/sdk/include/lwip/port/lwipopts.h index dc82649479dbeaf645e775ae678b3d2b3c84d6e3..60d7ecf212030b86c480c7f91f380782af2c3550 100644 --- a/tools/sdk/include/lwip/port/lwipopts.h +++ b/tools/sdk/include/lwip/port/lwipopts.h @@ -602,6 +602,7 @@ #define ESP_LIGHT_SLEEP 1 #define ESP_L2_TO_L3_COPY CONFIG_L2_TO_L3_COPY #define ESP_CNT_DEBUG 0 +#define ESP_DHCP_TIMER 1 #define TCP_WND_DEFAULT (4*TCP_MSS) #define TCP_SND_BUF_DEFAULT (2*TCP_MSS) diff --git a/tools/sdk/include/mbedtls/mbedtls/ssl.h b/tools/sdk/include/mbedtls/mbedtls/ssl.h index 82c07607f51298f7a6c3b9c014042ce4ad546064..7e1a17c8136ad680edd0cb560cf7ab7ca54e8e53 100644 --- a/tools/sdk/include/mbedtls/mbedtls/ssl.h +++ b/tools/sdk/include/mbedtls/mbedtls/ssl.h @@ -29,6 +29,7 @@ #include MBEDTLS_CONFIG_FILE #endif +#include "platform.h" #include "bignum.h" #include "ecp.h" diff --git a/tools/sdk/include/spi_flash/esp_partition.h b/tools/sdk/include/spi_flash/esp_partition.h index 28f8551dcb624adbf718fad1da8cb2f52322be9c..f3d5a424af21f0398e85f741de78a3206b0d701a 100644 --- a/tools/sdk/include/spi_flash/esp_partition.h +++ b/tools/sdk/include/spi_flash/esp_partition.h @@ -63,7 +63,7 @@ typedef enum { ESP_PARTITION_SUBTYPE_APP_OTA_13 = ESP_PARTITION_SUBTYPE_APP_OTA_MIN + 13,//!< OTA partition 13 ESP_PARTITION_SUBTYPE_APP_OTA_14 = ESP_PARTITION_SUBTYPE_APP_OTA_MIN + 14,//!< OTA partition 14 ESP_PARTITION_SUBTYPE_APP_OTA_15 = ESP_PARTITION_SUBTYPE_APP_OTA_MIN + 15,//!< OTA partition 15 - ESP_PARTITION_SUBTYPE_APP_OTA_MAX = 15, //!< Max subtype of OTA partition + ESP_PARTITION_SUBTYPE_APP_OTA_MAX = ESP_PARTITION_SUBTYPE_APP_OTA_MIN + 16,//!< Max subtype of OTA partition ESP_PARTITION_SUBTYPE_APP_TEST = 0x20, //!< Test application partition ESP_PARTITION_SUBTYPE_DATA_OTA = 0x00, //!< OTA selection partition @@ -165,6 +165,26 @@ esp_partition_iterator_t esp_partition_next(esp_partition_iterator_t iterator); */ void esp_partition_iterator_release(esp_partition_iterator_t iterator); +/** + * @brief Verify partition data + * + * Given a pointer to partition data, verify this partition exists in the partition table (all fields match.) + * + * This function is also useful to take partition data which may be in a RAM buffer and convert it to a pointer to the + * permanent partition data stored in flash. + * + * Pointers returned from this function can be compared directly to the address of any pointer returned from + * esp_partition_get(), as a test for equality. + * + * @param partition Pointer to partition data to verify. Must be non-NULL. All fields of this structure must match the + * partition table entry in flash for this function to return a successful match. + * + * @return + * - If partition not found, returns NULL. + * - If found, returns a pointer to the esp_partition_t structure in flash. This pointer is always valid for the lifetime of the application. + */ +const esp_partition_t *esp_partition_verify(const esp_partition_t *partition); + /** * @brief Read data from the partition * diff --git a/tools/sdk/include/spi_flash/esp_spi_flash.h b/tools/sdk/include/spi_flash/esp_spi_flash.h index 060d598ec0f2beab067f62ccba0982e463a13260..00797b8df25ff4c1ee6e8ecd12e9775f1f0a63f1 100644 --- a/tools/sdk/include/spi_flash/esp_spi_flash.h +++ b/tools/sdk/include/spi_flash/esp_spi_flash.h @@ -197,6 +197,48 @@ void spi_flash_munmap(spi_flash_mmap_handle_t handle); */ void spi_flash_mmap_dump(); + +#define SPI_FLASH_CACHE2PHYS_FAIL UINT32_MAX /*