Skip to content

Commit fcddfd0

Browse files
authored
Merge pull request #3083 from tannewt/esp32s2_busio
Add busio support for the ESP32-S2
2 parents 0e5dfba + 367d380 commit fcddfd0

File tree

52 files changed

+1589
-142
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1589
-142
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ jobs:
370370
board:
371371
- "espressif_saola_1_wroom"
372372
- "espressif_saola_1_wrover"
373+
- "unexpectedmaker_feathers2"
373374

374375
steps:
375376
- name: Set up Python 3.8

Makefile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,49 @@ stubs:
243243
update-frozen-libraries:
244244
@echo "Updating all frozen libraries to latest tagged version."
245245
cd frozen; for library in *; do cd $$library; ../../tools/git-checkout-latest-tag.sh; cd ..; done
246+
247+
one-of-each: samd21 samd51 esp32s2 litex mimxrt10xx nrf stm
248+
249+
samd21:
250+
$(MAKE) -C ports/atmel-samd BOARD=trinket_m0
251+
252+
samd51:
253+
$(MAKE) -C ports/atmel-samd BOARD=feather_m4_express
254+
255+
esp32s2:
256+
$(MAKE) -C ports/esp32s2 BOARD=espressif_saola_1_wroom
257+
258+
litex:
259+
$(MAKE) -C ports/litex BOARD=fomu
260+
261+
mimxrt10xx:
262+
$(MAKE) -C ports/mimxrt10xx BOARD=feather_mimxrt1011
263+
264+
nrf:
265+
$(MAKE) -C ports/nrf BOARD=feather_nrf52840_express
266+
267+
stm:
268+
$(MAKE) -C ports/stm BOARD=feather_stm32f405_express
269+
270+
clean-one-of-each: clean-samd21 clean-samd51 clean-esp32s2 clean-litex clean-mimxrt10xx clean-nrf clean-stm
271+
272+
clean-samd21:
273+
$(MAKE) -C ports/atmel-samd BOARD=trinket_m0 clean
274+
275+
clean-samd51:
276+
$(MAKE) -C ports/atmel-samd BOARD=feather_m4_express clean
277+
278+
clean-esp32s2:
279+
$(MAKE) -C ports/esp32s2 BOARD=espressif_saola_1_wroom clean
280+
281+
clean-litex:
282+
$(MAKE) -C ports/litex BOARD=fomu clean
283+
284+
clean-mimxrt10xx:
285+
$(MAKE) -C ports/mimxrt10xx BOARD=feather_mimxrt1011 clean
286+
287+
clean-nrf:
288+
$(MAKE) -C ports/nrf BOARD=feather_nrf52840_express clean
289+
290+
clean-stm:
291+
$(MAKE) -C ports/stm BOARD=feather_stm32f405_express clean

ports/atmel-samd/common-hal/busio/SPI.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self,
341341
return status >= 0; // Status is number of chars read or an error code < 0.
342342
}
343343

344-
bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, uint8_t *data_out, uint8_t *data_in, size_t len) {
344+
bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_out, uint8_t *data_in, size_t len) {
345345
if (len == 0) {
346346
return true;
347347
}
@@ -350,7 +350,7 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, uint8_t *data_out, uin
350350
status = sercom_dma_transfer(self->spi_desc.dev.prvt, data_out, data_in, len);
351351
} else {
352352
struct spi_xfer xfer;
353-
xfer.txbuf = data_out;
353+
xfer.txbuf = (uint8_t*) data_out;
354354
xfer.rxbuf = data_in;
355355
xfer.size = len;
356356
status = spi_m_sync_transfer(&self->spi_desc, &xfer);

ports/atmel-samd/common-hal/busio/UART.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
5858
const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx,
5959
const mcu_pin_obj_t * rts, const mcu_pin_obj_t * cts,
6060
const mcu_pin_obj_t * rs485_dir, bool rs485_invert,
61-
uint32_t baudrate, uint8_t bits, uart_parity_t parity, uint8_t stop,
61+
uint32_t baudrate, uint8_t bits, busio_uart_parity_t parity, uint8_t stop,
6262
mp_float_t timeout, uint16_t receiver_buffer_size, byte* receiver_buffer,
6363
bool sigint_enabled) {
6464

@@ -195,7 +195,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
195195
SERCOM_USART_CTRLA_FORM_Msk);
196196
sercom->USART.CTRLA.reg |= SERCOM_USART_CTRLA_TXPO(tx_pad / 2) |
197197
SERCOM_USART_CTRLA_RXPO(rx_pad) |
198-
(parity == PARITY_NONE ? 0 : SERCOM_USART_CTRLA_FORM(1));
198+
(parity == BUSIO_UART_PARITY_NONE ? 0 : SERCOM_USART_CTRLA_FORM(1));
199199

200200
// Enable tx and/or rx based on whether the pins were specified.
201201
// CHSIZE is 0 for 8 bits, 5, 6, 7 for 5, 6, 7 bits. 1 for 9 bits, but we don't support that.
@@ -206,7 +206,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
206206
SERCOM_USART_CTRLB_CHSIZE_Msk);
207207
sercom->USART.CTRLB.reg |= (have_tx ? SERCOM_USART_CTRLB_TXEN : 0) |
208208
(have_rx ? SERCOM_USART_CTRLB_RXEN : 0) |
209-
(parity == PARITY_ODD ? SERCOM_USART_CTRLB_PMODE : 0) |
209+
(parity == BUSIO_UART_PARITY_ODD ? SERCOM_USART_CTRLB_PMODE : 0) |
210210
(stop > 1 ? SERCOM_USART_CTRLB_SBMODE : 0) |
211211
SERCOM_USART_CTRLB_CHSIZE(bits % 8);
212212

ports/cxd56/common-hal/busio/SPI.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self, uint8_t *data, size_t len,
130130
return true;
131131
}
132132

133-
bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, uint8_t *data_out, uint8_t *data_in, size_t len) {
133+
bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_out, uint8_t *data_in, size_t len) {
134134
SPI_EXCHANGE(self->spi_dev, data_out, data_in, len);
135135

136136
return true;

ports/cxd56/common-hal/busio/UART.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
5656
const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx,
5757
const mcu_pin_obj_t * rts, const mcu_pin_obj_t * cts,
5858
const mcu_pin_obj_t * rs485_dir, bool rs485_invert,
59-
uint32_t baudrate, uint8_t bits, uart_parity_t parity, uint8_t stop,
59+
uint32_t baudrate, uint8_t bits, busio_uart_parity_t parity, uint8_t stop,
6060
mp_float_t timeout, uint16_t receiver_buffer_size, byte* receiver_buffer,
6161
bool sigint_enabled) {
6262
struct termios tio;
@@ -69,7 +69,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
6969
mp_raise_ValueError(translate("Could not initialize UART"));
7070
}
7171

72-
if (parity != PARITY_NONE) {
72+
if (parity != BUSIO_UART_PARITY_NONE) {
7373
mp_raise_ValueError(translate("Could not initialize UART"));
7474
}
7575

ports/esp32s2/Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ INC += -Iesp-idf/components/freertos/xtensa/include
7878
INC += -Iesp-idf/components/esp32s2/include
7979
INC += -Iesp-idf/components/xtensa/esp32s2/include
8080
INC += -Iesp-idf/components/esp_common/include
81+
INC += -Iesp-idf/components/esp_ringbuf/include
8182
INC += -Iesp-idf/components/esp_rom/include
8283
INC += -Iesp-idf/components/xtensa/include
8384
INC += -Iesp-idf/components/esp_timer/include
@@ -257,7 +258,7 @@ ESP_AUTOGEN_LD = $(BUILD)/esp-idf/esp-idf/esp32s2/esp32s2_out.ld $(BUILD)/esp-id
257258

258259
FLASH_FLAGS = --flash_mode $(CIRCUITPY_ESP_FLASH_MODE) --flash_freq $(CIRCUITPY_ESP_FLASH_FREQ) --flash_size $(CIRCUITPY_ESP_FLASH_SIZE)
259260

260-
all: $(BUILD)/firmware.bin
261+
all: $(BUILD)/firmware.bin $(BUILD)/firmware.uf2
261262

262263
$(BUILD)/firmware.elf: $(OBJ) | $(ESP_IDF_COMPONENTS_EXPANDED) $(ESP_AUTOGEN_LD)
263264
$(STEPECHO) "LINK $@"
@@ -273,8 +274,15 @@ $(BUILD)/circuitpython-firmware.bin: $(BUILD)/firmware.elf
273274
$(BUILD)/firmware.bin: $(BUILD)/esp-idf/partition_table/partition-table.bin $(BUILD)/esp-idf/bootloader/bootloader.bin $(BUILD)/circuitpython-firmware.bin
274275
$(Q)$(PYTHON) ../../tools/join_bins.py $@ 0x1000 $(BUILD)/esp-idf/bootloader/bootloader.bin 0x8000 $(BUILD)/esp-idf/partition_table/partition-table.bin 0x10000 $(BUILD)/circuitpython-firmware.bin
275276

277+
$(BUILD)/firmware.uf2: $(BUILD)/circuitpython-firmware.bin
278+
$(STEPECHO) "Create $@"
279+
$(Q)$(PYTHON3) $(TOP)/tools/uf2/utils/uf2conv.py -f 0xbfdd4eee -b 0x0000 -c -o $@ $^
280+
276281
flash: $(BUILD)/firmware.bin
277-
esptool.py --chip esp32s2 -p $(PORT) -b 460800 --before=default_reset --after=hard_reset write_flash $(FLASH_FLAGS) 0x0000 $^
282+
esptool.py --chip esp32s2 -p $(PORT) --no-stub -b 460800 --before=default_reset --after=hard_reset write_flash $(FLASH_FLAGS) 0x0000 $^
283+
284+
flash-circuitpython-only: $(BUILD)/circuitpython-firmware.bin
285+
esptool.py --chip esp32s2 -p $(PORT) --no-stub -b 460800 --before=default_reset --after=hard_reset write_flash $(FLASH_FLAGS) 0x10000 $^
278286

279287
include $(TOP)/py/mkrules.mk
280288

ports/esp32s2/background.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,14 @@ void run_background_tasks(void) {
4747
return;
4848
}
4949

50-
// Delay for 1 tick so that we don't starve the idle task.
51-
// TODO: 1 tick is 10ms which is a long time! Can we delegate to idle for a minimal amount of
52-
// time?
53-
vTaskDelay(1);
50+
// Zero delay in case FreeRTOS wants to switch to something else.
51+
vTaskDelay(0);
5452
running_background_tasks = true;
5553
filesystem_background();
5654

57-
// #if CIRCUITPY_DISPLAYIO
58-
// displayio_background();
59-
// #endif
55+
#if CIRCUITPY_DISPLAYIO
56+
displayio_background();
57+
#endif
6058
running_background_tasks = false;
6159

6260
assert_heap_ok();

ports/esp32s2/boards/espressif_saola_1_wroom/board.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030

3131
void board_init(void) {
3232
// USB
33-
never_reset_pin(&pin_GPIO19);
34-
never_reset_pin(&pin_GPIO20);
33+
common_hal_never_reset_pin(&pin_GPIO19);
34+
common_hal_never_reset_pin(&pin_GPIO20);
3535

3636
// Debug UART
37-
never_reset_pin(&pin_GPIO43);
38-
never_reset_pin(&pin_GPIO44);
37+
common_hal_never_reset_pin(&pin_GPIO43);
38+
common_hal_never_reset_pin(&pin_GPIO44);
3939
}
4040

4141
bool board_requests_safe_mode(void) {

ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ LONGINT_IMPL = MPZ
1111
CFLAGS += -DCFG_TUD_TASK_QUEUE_SZ=32
1212

1313
CIRCUITPY_NEOPIXEL_WRITE = 0
14-
CIRCUITPY_DIGITALIO = 0
15-
CIRCUITPY_MICROCONTROLLER = 0
1614

1715
CIRCUITPY_ESP_FLASH_MODE=dio
1816
CIRCUITPY_ESP_FLASH_FREQ=40m

0 commit comments

Comments
 (0)