A number of small ESP32S2 fixes:

* Fix flash writes that don't end on a sector boundary. Fixes #2944
* Fix enum incompatibility with IDF.
* Fix printf output so it goes out debug UART.
* Increase stack size to 8k.
* Fix sleep of less than a tick so it doesn't crash.
This commit is contained in:
Scott Shawcroft 2020-05-28 15:43:55 -07:00
parent a9419b5d46
commit 796373b8be
No known key found for this signature in database
GPG Key ID: 9349BC7E64B1921E
12 changed files with 22 additions and 15 deletions

View File

@ -134,7 +134,7 @@ else
endif endif
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) ifeq ($(CHIP_FAMILY), samd21)
CFLAGS += \ 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 LIBS := -lgcc -lc
# Use toolchain libm if we're not using our own. # Use toolchain libm if we're not using our own.

View File

@ -110,7 +110,7 @@ endif
CFLAGS += $(INC) -Werror -Wall -mlongcalls -std=gnu11 -Wl,--gc-sections $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT) 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 \ LDFLAGS += -L$(BUILD)/esp-idf/esp-idf/esp32s2 \
-Tesp32s2_out.ld \ -Tesp32s2_out.ld \
-L$(BUILD)/esp-idf/esp-idf/esp32s2/ld \ -L$(BUILD)/esp-idf/esp-idf/esp32s2/ld \

View File

@ -32,6 +32,7 @@
#define MICROPY_NLR_THUMB (0) #define MICROPY_NLR_THUMB (0)
#define MICROPY_PY_UJSON (0) #define MICROPY_PY_UJSON (0)
#define MICROPY_USE_INTERNAL_PRINTF (0)
#include "py/circuitpy_mpconfig.h" #include "py/circuitpy_mpconfig.h"

View File

@ -259,7 +259,7 @@ CONFIG_ESP32S2_RTC_CLK_CAL_CYCLES=576
CONFIG_ESP_ERR_TO_NAME_LOOKUP=y CONFIG_ESP_ERR_TO_NAME_LOOKUP=y
CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=32 CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=32
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2304 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_IPC_TASK_STACK_SIZE=1024
CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048 CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048
CONFIG_ESP_CONSOLE_UART_DEFAULT=y CONFIG_ESP_CONSOLE_UART_DEFAULT=y

View File

@ -100,18 +100,20 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32
_cache_lba = sector_offset; _cache_lba = sector_offset;
} }
for (uint8_t b = block_offset; b < blocks_per_sector; b++) { 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, memcpy(_cache + b * FILESYSTEM_BLOCK_SIZE,
src + block * FILESYSTEM_BLOCK_SIZE, src + block * FILESYSTEM_BLOCK_SIZE,
FILESYSTEM_BLOCK_SIZE); FILESYSTEM_BLOCK_SIZE);
block++; block++;
} }
result = esp_partition_erase_range(_partition, sector_offset, SECTOR_SIZE); result = esp_partition_erase_range(_partition, sector_offset, SECTOR_SIZE);
ESP_EARLY_LOGW(TAG, "erase %d", result);
result = esp_partition_write(_partition, result = esp_partition_write(_partition,
sector_offset, sector_offset,
_cache, _cache,
SECTOR_SIZE); SECTOR_SIZE);
ESP_EARLY_LOGW(TAG, "write %d", result);
} }
return 0; // success return 0; // success

View File

@ -152,6 +152,9 @@ void port_sleep_until_interrupt(void) {
// FreeRTOS delay here maybe. // FreeRTOS delay here maybe.
// Light sleep shuts down BLE and wifi. // Light sleep shuts down BLE and wifi.
// esp_light_sleep_start() // esp_light_sleep_start()
if (sleep_time_duration == 0) {
return;
}
vTaskDelayUntil(&sleep_time_set, sleep_time_duration); vTaskDelayUntil(&sleep_time_set, sleep_time_duration);
} }

View File

@ -83,14 +83,14 @@ else
### CFLAGS += -flto ### CFLAGS += -flto
endif 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 # TODO: check this
CFLAGS += -D__START=main -DFOMU CFLAGS += -D__START=main -DFOMU
LD_FILE := boards/$(BOARD)/$(BOARD)-spi.ld 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 LIBS := -lgcc -lc

View File

@ -90,7 +90,7 @@ else
#CFLAGS += -flto -flto-partition=none #CFLAGS += -flto -flto-partition=none
endif 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 # TODO: add these when -Werror is applied
# Disable some warnings, as do most ports. NXP SDK causes undef, tinyusb causes cast-align # 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, 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 LIBS := -lgcc -lc -lnosys -lm
# Use toolchain libm if we're not using our own. # Use toolchain libm if we're not using our own.

View File

@ -93,7 +93,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)
# Undo some warnings. # Undo some warnings.
# nrfx uses undefined preprocessor variables quite casually, so we can't do warning checks for these. # nrfx uses undefined preprocessor variables quite casually, so we can't do warning checks for these.
@ -114,7 +114,7 @@ CFLAGS += \
# TODO: check this # TODO: check this
CFLAGS += -D__START=main 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 LIBS := -lgcc -lc
LDFLAGS += -mthumb -mcpu=cortex-m4 LDFLAGS += -mthumb -mcpu=cortex-m4

View File

@ -94,7 +94,7 @@ endif
# MCU Series is defined by the HAL package and doesn't need to be specified here # 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) 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. # Undo some warnings.
# STM32 HAL uses undefined preprocessor variables, shadowed variables, casts that change alignment reqs # STM32 HAL uses undefined preprocessor variables, shadowed variables, casts that change alignment reqs
@ -136,7 +136,7 @@ ifndef BOOTLOADER_OFFSET
BOOTLOADER_OFFSET := 0x8000000 BOOTLOADER_OFFSET := 0x8000000
endif 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 LIBS := -lgcc -lc
# Use toolchain libm if we're not using our own. # Use toolchain libm if we're not using our own.

View File

@ -48,7 +48,6 @@ BASE_CFLAGS = \
-D__$(CHIP_VARIANT)__ \ -D__$(CHIP_VARIANT)__ \
-ffunction-sections \ -ffunction-sections \
-fdata-sections \ -fdata-sections \
-fshort-enums \
-DCIRCUITPY_SOFTWARE_SAFE_MODE=0x0ADABEEF \ -DCIRCUITPY_SOFTWARE_SAFE_MODE=0x0ADABEEF \
-DCIRCUITPY_CANARY_WORD=0xADAF00 \ -DCIRCUITPY_CANARY_WORD=0xADAF00 \
-DCIRCUITPY_SAFE_RESTART_WORD=0xDEADBEEF \ -DCIRCUITPY_SAFE_RESTART_WORD=0xDEADBEEF \

View File

@ -121,7 +121,9 @@
#define MICROPY_REPL_EVENT_DRIVEN (0) #define MICROPY_REPL_EVENT_DRIVEN (0)
#define MICROPY_STACK_CHECK (1) #define MICROPY_STACK_CHECK (1)
#define MICROPY_STREAMS_NON_BLOCK (1) #define MICROPY_STREAMS_NON_BLOCK (1)
#ifndef MICROPY_USE_INTERNAL_PRINTF
#define MICROPY_USE_INTERNAL_PRINTF (1) #define MICROPY_USE_INTERNAL_PRINTF (1)
#endif
// fatfs configuration used in ffconf.h // fatfs configuration used in ffconf.h
// //