Skip to content

Commit d98151a

Browse files
authored
Merge pull request #2972 from tannewt/esp32s2_fixes1
A number of small ESP32S2 fixes
2 parents b901def + 796373b commit d98151a

File tree

14 files changed

+35
-17
lines changed

14 files changed

+35
-17
lines changed

ports/atmel-samd/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ else
134134
endif
135135
endif
136136

137-
CFLAGS += $(INC) -Wall -Werror -std=gnu11 -nostdlib $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT)
137+
CFLAGS += $(INC) -Wall -Werror -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT)
138138

139139
ifeq ($(CHIP_FAMILY), samd21)
140140
CFLAGS += \
@@ -157,7 +157,7 @@ endif
157157

158158

159159

160-
LDFLAGS = $(CFLAGS) -nostartfiles -fshort-enums -Wl,-nostdlib -Wl,-T,$(GENERATED_LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
160+
LDFLAGS = $(CFLAGS) -nostartfiles -Wl,-nostdlib -Wl,-T,$(GENERATED_LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
161161
LIBS := -lgcc -lc
162162

163163
# Use toolchain libm if we're not using our own.

ports/esp32s2/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ endif
110110

111111
CFLAGS += $(INC) -Werror -Wall -mlongcalls -std=gnu11 -Wl,--gc-sections $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT)
112112

113-
LDFLAGS = $(CFLAGS) -fshort-enums -Wl,-nostdlib -Wl,-Map=$@.map -Wl,-cref
113+
LDFLAGS = $(CFLAGS) -Wl,-nostdlib -Wl,-Map=$@.map -Wl,-cref
114114
LDFLAGS += -L$(BUILD)/esp-idf/esp-idf/esp32s2 \
115115
-Tesp32s2_out.ld \
116116
-L$(BUILD)/esp-idf/esp-idf/esp32s2/ld \

ports/esp32s2/esp-idf

Submodule esp-idf updated 521 files

ports/esp32s2/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#define MICROPY_NLR_THUMB (0)
3333

3434
#define MICROPY_PY_UJSON (0)
35+
#define MICROPY_USE_INTERNAL_PRINTF (0)
3536

3637
#include "py/circuitpy_mpconfig.h"
3738

ports/esp32s2/sdkconfig.defaults

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ CONFIG_ESP32S2_RTC_CLK_CAL_CYCLES=576
259259
CONFIG_ESP_ERR_TO_NAME_LOOKUP=y
260260
CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=32
261261
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2304
262-
CONFIG_ESP_MAIN_TASK_STACK_SIZE=3584
262+
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192
263263
CONFIG_ESP_IPC_TASK_STACK_SIZE=1024
264264
CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048
265265
CONFIG_ESP_CONSOLE_UART_DEFAULT=y

ports/esp32s2/supervisor/internal_flash.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,20 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32
100100
_cache_lba = sector_offset;
101101
}
102102
for (uint8_t b = block_offset; b < blocks_per_sector; b++) {
103+
// Stop copying after the last block.
104+
if (block >= num_blocks) {
105+
break;
106+
}
103107
memcpy(_cache + b * FILESYSTEM_BLOCK_SIZE,
104108
src + block * FILESYSTEM_BLOCK_SIZE,
105109
FILESYSTEM_BLOCK_SIZE);
106110
block++;
107111
}
108112
result = esp_partition_erase_range(_partition, sector_offset, SECTOR_SIZE);
109-
ESP_EARLY_LOGW(TAG, "erase %d", result);
110113
result = esp_partition_write(_partition,
111114
sector_offset,
112115
_cache,
113116
SECTOR_SIZE);
114-
ESP_EARLY_LOGW(TAG, "write %d", result);
115117
}
116118

117119
return 0; // success

ports/esp32s2/supervisor/port.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ void port_sleep_until_interrupt(void) {
152152
// FreeRTOS delay here maybe.
153153
// Light sleep shuts down BLE and wifi.
154154
// esp_light_sleep_start()
155+
if (sleep_time_duration == 0) {
156+
return;
157+
}
155158
vTaskDelayUntil(&sleep_time_set, sleep_time_duration);
156159
}
157160

ports/esp32s2/supervisor/usb.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
#include "lib/utils/interrupt_char.h"
3030
#include "lib/mp-readline/readline.h"
3131

32+
#include "esp-idf/components/soc/soc/esp32s2/include/soc/usb_periph.h"
33+
#include "esp-idf/components/driver/include/driver/periph_ctrl.h"
34+
#include "esp-idf/components/driver/include/driver/gpio.h"
35+
#include "esp-idf/components/esp_rom/include/esp32s2/rom/gpio.h"
36+
3237
#include "freertos/FreeRTOS.h"
3338
#include "freertos/task.h"
3439

@@ -64,16 +69,22 @@ void usb_device_task(void* param)
6469
}
6570

6671
void init_usb_hardware(void) {
72+
periph_module_reset(PERIPH_USB_MODULE);
73+
periph_module_enable(PERIPH_USB_MODULE);
6774
usb_hal_context_t hal = {
6875
.use_external_phy = false // use built-in PHY
6976
};
7077
usb_hal_init(&hal);
7178

79+
// Initialize the pin drive strength.
80+
gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3);
81+
gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3);
82+
7283
(void) xTaskCreateStatic(usb_device_task,
7384
"usbd",
7485
USBD_STACK_SIZE,
7586
NULL,
76-
configMAX_PRIORITIES-1,
87+
5,
7788
usb_device_stack,
7889
&usb_device_taskdef);
7990
}

ports/litex/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ else
8383
### CFLAGS += -flto
8484
endif
8585

86-
CFLAGS += $(INC) -Werror -Wall -std=gnu11 -nostdlib $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT)
86+
CFLAGS += $(INC) -Werror -Wall -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT)
8787

8888
# TODO: check this
8989
CFLAGS += -D__START=main -DFOMU
9090

9191
LD_FILE := boards/$(BOARD)/$(BOARD)-spi.ld
9292

93-
LDFLAGS = $(CFLAGS) -fshort-enums -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs -Wl,-melf32lriscv
93+
LDFLAGS = $(CFLAGS) -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs -Wl,-melf32lriscv
9494
LIBS := -lgcc -lc
9595

9696

ports/mimxrt10xx/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ else
9090
#CFLAGS += -flto -flto-partition=none
9191
endif
9292

93-
CFLAGS += $(INC) -ggdb -Wall -Wno-cast-align -std=gnu11 -nostdlib $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT)
93+
CFLAGS += $(INC) -ggdb -Wall -Wno-cast-align -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT)
9494

9595
# TODO: add these when -Werror is applied
9696
# 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)
112112

113113
LD_SCRIPT_FLAG := -Wl,-T,
114114

115-
LDFLAGS = $(CFLAGS) -nostartfiles -fshort-enums -Wl,-nostdlib $(addprefix $(LD_SCRIPT_FLAG), $(LD_FILES)) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
115+
LDFLAGS = $(CFLAGS) -nostartfiles -Wl,-nostdlib $(addprefix $(LD_SCRIPT_FLAG), $(LD_FILES)) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
116116
LIBS := -lgcc -lc -lnosys -lm
117117

118118
# Use toolchain libm if we're not using our own.

ports/nrf/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ else
9393
endif
9494

9595

96-
CFLAGS += $(INC) -Wall -Werror -std=gnu11 -nostdlib $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT)
96+
CFLAGS += $(INC) -Wall -Werror -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT)
9797

9898
# Undo some warnings.
9999
# nrfx uses undefined preprocessor variables quite casually, so we can't do warning checks for these.
@@ -114,7 +114,7 @@ CFLAGS += \
114114
# TODO: check this
115115
CFLAGS += -D__START=main
116116

117-
LDFLAGS = $(CFLAGS) -nostartfiles -fshort-enums -Wl,-nostdlib -Wl,-T,$(GENERATED_LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
117+
LDFLAGS = $(CFLAGS) -nostartfiles -Wl,-nostdlib -Wl,-T,$(GENERATED_LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
118118
LIBS := -lgcc -lc
119119

120120
LDFLAGS += -mthumb -mcpu=cortex-m4

ports/stm/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ endif
9494
# MCU Series is defined by the HAL package and doesn't need to be specified here
9595
C_DEFS = -D$(MCU_PACKAGE) -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -D$(MCU_VARIANT)
9696

97-
CFLAGS += $(INC) -Werror -Wall -std=gnu11 $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT) -nostdlib -nostartfiles
97+
CFLAGS += $(INC) -Werror -Wall -std=gnu11 -fshort-enums $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT) -nostdlib -nostartfiles
9898

9999
# Undo some warnings.
100100
# STM32 HAL uses undefined preprocessor variables, shadowed variables, casts that change alignment reqs
@@ -136,7 +136,7 @@ ifndef BOOTLOADER_OFFSET
136136
BOOTLOADER_OFFSET := 0x8000000
137137
endif
138138

139-
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
139+
LDFLAGS = $(CFLAGS) -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-T,$(LD_COMMON) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
140140
LIBS := -lgcc -lc
141141

142142
# Use toolchain libm if we're not using our own.

py/circuitpy_defns.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ BASE_CFLAGS = \
4848
-D__$(CHIP_VARIANT)__ \
4949
-ffunction-sections \
5050
-fdata-sections \
51-
-fshort-enums \
5251
-DCIRCUITPY_SOFTWARE_SAFE_MODE=0x0ADABEEF \
5352
-DCIRCUITPY_CANARY_WORD=0xADAF00 \
5453
-DCIRCUITPY_SAFE_RESTART_WORD=0xDEADBEEF \

py/circuitpy_mpconfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@
121121
#define MICROPY_REPL_EVENT_DRIVEN (0)
122122
#define MICROPY_STACK_CHECK (1)
123123
#define MICROPY_STREAMS_NON_BLOCK (1)
124+
#ifndef MICROPY_USE_INTERNAL_PRINTF
124125
#define MICROPY_USE_INTERNAL_PRINTF (1)
126+
#endif
125127

126128
// fatfs configuration used in ffconf.h
127129
//

0 commit comments

Comments
 (0)