summaryrefslogtreecommitdiff
path: root/ports
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2020-05-29 10:16:24 -0700
committerScott Shawcroft <scott@tannewt.org>2020-05-29 10:16:24 -0700
commit2fd7a43f2f5b2bafad6bfed68b6c0a00688ece9b (patch)
tree8b2be430407cfed9b860875a30f4bab4da7c853c /ports
parent198f9579f3b3120caf8d292b303ff2a070c74053 (diff)
parent7ea95457eeb67fcaccfa911a4d979fa642262da5 (diff)
Merge remote-tracking branch 'adafruit/master' into wdt-nrf
Diffstat (limited to 'ports')
-rw-r--r--ports/atmel-samd/Makefile4
-rw-r--r--ports/esp32s2/Makefile2
m---------ports/esp32s2/esp-idf0
-rw-r--r--ports/esp32s2/mpconfigport.h1
-rw-r--r--ports/esp32s2/mphalport.c20
-rw-r--r--ports/esp32s2/sdkconfig.defaults2
-rw-r--r--ports/esp32s2/supervisor/internal_flash.c6
-rw-r--r--ports/esp32s2/supervisor/port.c3
-rw-r--r--ports/esp32s2/supervisor/usb.c13
-rw-r--r--ports/esp32s2/tools/decode_backtrace.py23
-rw-r--r--ports/litex/Makefile4
-rw-r--r--ports/mimxrt10xx/Makefile4
-rwxr-xr-xports/nrf/Makefile4
-rwxr-xr-xports/stm/Makefile4
14 files changed, 74 insertions, 16 deletions
diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile
index 8a5c3309f..d0ab65e6b 100644
--- a/ports/atmel-samd/Makefile
+++ b/ports/atmel-samd/Makefile
@@ -134,7 +134,7 @@ else
endif
endif
-CFLAGS += $(INC) -Wall -Werror -std=gnu11 -nostdlib $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT)
+CFLAGS += $(INC) -Wall -Werror -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT)
ifeq ($(CHIP_FAMILY), samd21)
CFLAGS += \
@@ -157,7 +157,7 @@ endif
-LDFLAGS = $(CFLAGS) -nostartfiles -fshort-enums -Wl,-nostdlib -Wl,-T,$(GENERATED_LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
+LDFLAGS = $(CFLAGS) -nostartfiles -Wl,-nostdlib -Wl,-T,$(GENERATED_LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
LIBS := -lgcc -lc
# Use toolchain libm if we're not using our own.
diff --git a/ports/esp32s2/Makefile b/ports/esp32s2/Makefile
index 1104c5289..5ad5c2f1d 100644
--- a/ports/esp32s2/Makefile
+++ b/ports/esp32s2/Makefile
@@ -110,7 +110,7 @@ endif
CFLAGS += $(INC) -Werror -Wall -mlongcalls -std=gnu11 -Wl,--gc-sections $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT)
-LDFLAGS = $(CFLAGS) -fshort-enums -Wl,-nostdlib -Wl,-Map=$@.map -Wl,-cref
+LDFLAGS = $(CFLAGS) -Wl,-nostdlib -Wl,-Map=$@.map -Wl,-cref
LDFLAGS += -L$(BUILD)/esp-idf/esp-idf/esp32s2 \
-Tesp32s2_out.ld \
-L$(BUILD)/esp-idf/esp-idf/esp32s2/ld \
diff --git a/ports/esp32s2/esp-idf b/ports/esp32s2/esp-idf
-Subproject 0daf6e0e41f95d22d193d08941a00df9525bc40
+Subproject 7aae7f034bab68d2dd6aaa763924c91eb697d87
diff --git a/ports/esp32s2/mpconfigport.h b/ports/esp32s2/mpconfigport.h
index c307d4791..d340bb480 100644
--- a/ports/esp32s2/mpconfigport.h
+++ b/ports/esp32s2/mpconfigport.h
@@ -32,6 +32,7 @@
#define MICROPY_NLR_THUMB (0)
#define MICROPY_PY_UJSON (0)
+#define MICROPY_USE_INTERNAL_PRINTF (0)
#include "py/circuitpy_mpconfig.h"
diff --git a/ports/esp32s2/mphalport.c b/ports/esp32s2/mphalport.c
index 772b61c9e..da5258b0e 100644
--- a/ports/esp32s2/mphalport.c
+++ b/ports/esp32s2/mphalport.c
@@ -37,6 +37,24 @@ void mp_hal_delay_us(mp_uint_t delay) {
mp_hal_delay_ms(delay / 1000);
}
-mp_uint_t cpu_get_regs_and_sp(mp_uint_t *regs) {
+// This is provided by the esp-idf/components/xtensa/esp32s2/libhal.a binary
+// blob.
+extern void xthal_window_spill(void);
+
+mp_uint_t cpu_get_regs_and_sp(mp_uint_t *regs, uint8_t reg_count) {
+ // xtensa has more registers than an instruction can address. The 16 that
+ // can be addressed are called the "window". When a function is called or
+ // returns the window rotates. This allows for more efficient function calls
+ // because ram doesn't need to be used. It's only used if the window wraps
+ // around onto itself. At that point values are "spilled" to empty spots in
+ // the stack that were set aside. When the window rotates back around (on
+ // function return), the values are restored into the register from ram.
+
+ // So, in order to read the values in the stack scan we must make sure all
+ // of the register values we care about have been spilled to RAM. Luckily,
+ // there is a HAL call to do it. There is a bit of a race condition here
+ // because the register value could change after it's been restored but that
+ // is unlikely to happen with a heap pointer while we do a GC.
+ xthal_window_spill();
return (mp_uint_t) __builtin_frame_address(0);
}
diff --git a/ports/esp32s2/sdkconfig.defaults b/ports/esp32s2/sdkconfig.defaults
index f7deb53fb..958e1852e 100644
--- a/ports/esp32s2/sdkconfig.defaults
+++ b/ports/esp32s2/sdkconfig.defaults
@@ -259,7 +259,7 @@ CONFIG_ESP32S2_RTC_CLK_CAL_CYCLES=576
CONFIG_ESP_ERR_TO_NAME_LOOKUP=y
CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=32
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2304
-CONFIG_ESP_MAIN_TASK_STACK_SIZE=3584
+CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192
CONFIG_ESP_IPC_TASK_STACK_SIZE=1024
CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048
CONFIG_ESP_CONSOLE_UART_DEFAULT=y
diff --git a/ports/esp32s2/supervisor/internal_flash.c b/ports/esp32s2/supervisor/internal_flash.c
index aab7e587a..ef216c4b1 100644
--- a/ports/esp32s2/supervisor/internal_flash.c
+++ b/ports/esp32s2/supervisor/internal_flash.c
@@ -100,18 +100,20 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32
_cache_lba = sector_offset;
}
for (uint8_t b = block_offset; b < blocks_per_sector; b++) {
+ // Stop copying after the last block.
+ if (block >= num_blocks) {
+ break;
+ }
memcpy(_cache + b * FILESYSTEM_BLOCK_SIZE,
src + block * FILESYSTEM_BLOCK_SIZE,
FILESYSTEM_BLOCK_SIZE);
block++;
}
result = esp_partition_erase_range(_partition, sector_offset, SECTOR_SIZE);
- ESP_EARLY_LOGW(TAG, "erase %d", result);
result = esp_partition_write(_partition,
sector_offset,
_cache,
SECTOR_SIZE);
- ESP_EARLY_LOGW(TAG, "write %d", result);
}
return 0; // success
diff --git a/ports/esp32s2/supervisor/port.c b/ports/esp32s2/supervisor/port.c
index 9e83e5778..4c42f11af 100644
--- a/ports/esp32s2/supervisor/port.c
+++ b/ports/esp32s2/supervisor/port.c
@@ -152,6 +152,9 @@ void port_sleep_until_interrupt(void) {
// FreeRTOS delay here maybe.
// Light sleep shuts down BLE and wifi.
// esp_light_sleep_start()
+ if (sleep_time_duration == 0) {
+ return;
+ }
vTaskDelayUntil(&sleep_time_set, sleep_time_duration);
}
diff --git a/ports/esp32s2/supervisor/usb.c b/ports/esp32s2/supervisor/usb.c
index 7c508485e..8bba84015 100644
--- a/ports/esp32s2/supervisor/usb.c
+++ b/ports/esp32s2/supervisor/usb.c
@@ -29,6 +29,11 @@
#include "lib/utils/interrupt_char.h"
#include "lib/mp-readline/readline.h"
+#include "esp-idf/components/soc/soc/esp32s2/include/soc/usb_periph.h"
+#include "esp-idf/components/driver/include/driver/periph_ctrl.h"
+#include "esp-idf/components/driver/include/driver/gpio.h"
+#include "esp-idf/components/esp_rom/include/esp32s2/rom/gpio.h"
+
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
@@ -64,16 +69,22 @@ void usb_device_task(void* param)
}
void init_usb_hardware(void) {
+ periph_module_reset(PERIPH_USB_MODULE);
+ periph_module_enable(PERIPH_USB_MODULE);
usb_hal_context_t hal = {
.use_external_phy = false // use built-in PHY
};
usb_hal_init(&hal);
+ // Initialize the pin drive strength.
+ gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3);
+ gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3);
+
(void) xTaskCreateStatic(usb_device_task,
"usbd",
USBD_STACK_SIZE,
NULL,
- configMAX_PRIORITIES-1,
+ 5,
usb_device_stack,
&usb_device_taskdef);
}
diff --git a/ports/esp32s2/tools/decode_backtrace.py b/ports/esp32s2/tools/decode_backtrace.py
new file mode 100644
index 000000000..3f078895a
--- /dev/null
+++ b/ports/esp32s2/tools/decode_backtrace.py
@@ -0,0 +1,23 @@
+"""Simple script that translates "Backtrace:" lines from the ESP output to files
+ and line numbers.
+
+ Run with: python3 tools/decode_backtrace.py <board>
+
+ Enter the backtrace line at the "? " prompt. CTRL-C to exit the script.
+ """
+
+import subprocess
+import sys
+
+board = sys.argv[1]
+print(board)
+
+while True:
+ addresses = input("? ")
+ if addresses.startswith("Backtrace:"):
+ addresses = addresses[len("Backtrace:"):]
+ addresses = addresses.strip().split()
+ addresses = [address.split(":")[0] for address in addresses]
+ print('got', addresses)
+ subprocess.run(["xtensa-esp32s2-elf-addr2line",
+ "-e", "build-{}/firmware.elf".format(board)] + addresses)
diff --git a/ports/litex/Makefile b/ports/litex/Makefile
index 596eaf2bb..d75a4da28 100644
--- a/ports/litex/Makefile
+++ b/ports/litex/Makefile
@@ -83,14 +83,14 @@ else
### CFLAGS += -flto
endif
-CFLAGS += $(INC) -Werror -Wall -std=gnu11 -nostdlib $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT)
+CFLAGS += $(INC) -Werror -Wall -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT)
# TODO: check this
CFLAGS += -D__START=main -DFOMU
LD_FILE := boards/$(BOARD)/$(BOARD)-spi.ld
-LDFLAGS = $(CFLAGS) -fshort-enums -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs -Wl,-melf32lriscv
+LDFLAGS = $(CFLAGS) -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs -Wl,-melf32lriscv
LIBS := -lgcc -lc
diff --git a/ports/mimxrt10xx/Makefile b/ports/mimxrt10xx/Makefile
index 922978ac2..78cab0188 100644
--- a/ports/mimxrt10xx/Makefile
+++ b/ports/mimxrt10xx/Makefile
@@ -90,7 +90,7 @@ else
#CFLAGS += -flto -flto-partition=none
endif
-CFLAGS += $(INC) -ggdb -Wall -Wno-cast-align -std=gnu11 -nostdlib $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT)
+CFLAGS += $(INC) -ggdb -Wall -Wno-cast-align -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT)
# TODO: add these when -Werror is applied
# Disable some warnings, as do most ports. NXP SDK causes undef, tinyusb causes cast-align
@@ -112,7 +112,7 @@ LD_FILES = $(wildcard boards/$(BOARD)/*.ld) $(addprefix linking/, flash/$(FLASH)
LD_SCRIPT_FLAG := -Wl,-T,
-LDFLAGS = $(CFLAGS) -nostartfiles -fshort-enums -Wl,-nostdlib $(addprefix $(LD_SCRIPT_FLAG), $(LD_FILES)) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
+LDFLAGS = $(CFLAGS) -nostartfiles -Wl,-nostdlib $(addprefix $(LD_SCRIPT_FLAG), $(LD_FILES)) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
LIBS := -lgcc -lc -lnosys -lm
# Use toolchain libm if we're not using our own.
diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile
index e5931af5e..5b81fa9a7 100755
--- a/ports/nrf/Makefile
+++ b/ports/nrf/Makefile
@@ -93,7 +93,7 @@ else
endif
-CFLAGS += $(INC) -Wall -Werror -std=gnu11 -nostdlib $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT)
+CFLAGS += $(INC) -Wall -Werror -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT)
# Undo some warnings.
# nrfx uses undefined preprocessor variables quite casually, so we can't do warning checks for these.
@@ -114,7 +114,7 @@ CFLAGS += \
# TODO: check this
CFLAGS += -D__START=main
-LDFLAGS = $(CFLAGS) -nostartfiles -fshort-enums -Wl,-nostdlib -Wl,-T,$(GENERATED_LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
+LDFLAGS = $(CFLAGS) -nostartfiles -Wl,-nostdlib -Wl,-T,$(GENERATED_LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
LIBS := -lgcc -lc
LDFLAGS += -mthumb -mcpu=cortex-m4
diff --git a/ports/stm/Makefile b/ports/stm/Makefile
index b667990bd..bd69d6fd7 100755
--- a/ports/stm/Makefile
+++ b/ports/stm/Makefile
@@ -94,7 +94,7 @@ endif
# MCU Series is defined by the HAL package and doesn't need to be specified here
C_DEFS = -D$(MCU_PACKAGE) -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -D$(MCU_VARIANT)
-CFLAGS += $(INC) -Werror -Wall -std=gnu11 $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT) -nostdlib -nostartfiles
+CFLAGS += $(INC) -Werror -Wall -std=gnu11 -fshort-enums $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT) -nostdlib -nostartfiles
# Undo some warnings.
# STM32 HAL uses undefined preprocessor variables, shadowed variables, casts that change alignment reqs
@@ -136,7 +136,7 @@ ifndef BOOTLOADER_OFFSET
BOOTLOADER_OFFSET := 0x8000000
endif
-LDFLAGS = $(CFLAGS) -fshort-enums -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-T,$(LD_COMMON) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
+LDFLAGS = $(CFLAGS) -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-T,$(LD_COMMON) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
LIBS := -lgcc -lc
# Use toolchain libm if we're not using our own.