Merge pull request #5800 from tannewt/rpi_zero

Initial Pi Zero support
This commit is contained in:
Dan Halbert 2022-01-07 09:05:30 -05:00 committed by GitHub
commit afd686986a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 266 additions and 61 deletions

View File

@ -420,7 +420,10 @@ static sdmmc_err_t cis_tuple_func_manfid(const void* p, uint8_t* data, FILE* fp)
int size = *(data++); int size = *(data++);
fprintf(fp, "TUPLE: %s, size: %d\n", tuple->name, size); fprintf(fp, "TUPLE: %s, size: %d\n", tuple->name, size);
CIS_CHECK_SIZE(size, 4); CIS_CHECK_SIZE(size, 4);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
fprintf(fp, " MANF: %04X, CARD: %04X\n", *(uint16_t*)(data), *(uint16_t*)(data+2)); fprintf(fp, " MANF: %04X, CARD: %04X\n", *(uint16_t*)(data), *(uint16_t*)(data+2));
#pragma GCC diagnostic pop
return SDMMC_OK; return SDMMC_OK;
} }
@ -480,7 +483,10 @@ static sdmmc_err_t cis_tuple_func_cftable_entry(const void* p, uint8_t* data, FI
CIS_CHECK_SIZE(size, 2); CIS_CHECK_SIZE(size, 2);
size-=2; size-=2;
CIS_CHECK_UNSUPPORTED(mem_space==1); //other cases not handled yet CIS_CHECK_UNSUPPORTED(mem_space==1); //other cases not handled yet
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
int len = *(uint16_t*)data; int len = *(uint16_t*)data;
#pragma GCC diagnostic pop
fprintf(fp, " LEN: %04X\n", len); fprintf(fp, " LEN: %04X\n", len);
data+=2; data+=2;
} }

@ -1 +1 @@
Subproject commit ae73873b5cba0eb11c89165f4559964940430d44 Subproject commit 3b09b82123a50bef6b18cf90c2734ae7581da4a3

7
main.c
View File

@ -812,9 +812,10 @@ int __attribute__((used)) main(void) {
// A power brownout here could make it appear as if there's // A power brownout here could make it appear as if there's
// no SPI flash filesystem, and we might erase the existing one. // no SPI flash filesystem, and we might erase the existing one.
// Check whether CIRCUITPY is available. Don't check if it already hasn't been found. // Check whether CIRCUITPY is available. No need to reset to get safe mode
if ((safe_mode != NO_CIRCUITPY) && !filesystem_init(safe_mode == NO_SAFE_MODE, false)) { // since we haven't run user code yet.
reset_into_safe_mode(NO_CIRCUITPY); if (!filesystem_init(safe_mode == NO_SAFE_MODE, false)) {
safe_mode = NO_CIRCUITPY;
} }
// displays init after filesystem, since they could share the flash SPI // displays init after filesystem, since they could share the flash SPI

View File

@ -31,7 +31,20 @@ include $(TOP)/supervisor/supervisor.mk
# Include make rules and variables common across CircuitPython builds. # Include make rules and variables common across CircuitPython builds.
include $(TOP)/py/circuitpy_defns.mk include $(TOP)/py/circuitpy_defns.mk
HAL_DIR=hal/$(MCU_SERIES) ifeq ($(CHIP_VARIANT), "bcm2711")
CFLAGS += -mcpu=cortex-a72 -DBCM_VERSION=2711
CROSS_COMPILE = aarch64-none-elf-
SUFFIX = 8
else ifeq ($(CHIP_VARIANT), "bcm2837")
CFLAGS += -mcpu=cortex-a53 -DBCM_VERSION=2837
CROSS_COMPILE = aarch64-none-elf-
SUFFIX = 8
else ifeq ($(CHIP_VARIANT), "bcm2835")
CFLAGS += -mcpu=arm1176jzf-s -DBCM_VERSION=2835
CROSS_COMPILE = arm-none-eabi-
SUFFIX =
# TODO add 32-bit support for Cortex-A7 in 2836
endif
INC += -I. \ INC += -I. \
-I../.. \ -I../.. \
@ -69,6 +82,7 @@ SRC_C += bindings/videocore/__init__.c \
peripherals/broadcom/mmu.c \ peripherals/broadcom/mmu.c \
peripherals/broadcom/vcmailbox.c peripherals/broadcom/vcmailbox.c
SRC_S = peripherals/broadcom/boot$(SUFFIX).s
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \ SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \ $(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
@ -82,7 +96,6 @@ SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE))
# because a few modules have files both in common-hal/ and shared-modules/. # because a few modules have files both in common-hal/ and shared-modules/.
# Doing a $(sort ...) removes duplicates as part of sorting. # Doing a $(sort ...) removes duplicates as part of sorting.
SRC_COMMON_HAL_SHARED_MODULE_EXPANDED = $(sort $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)) SRC_COMMON_HAL_SHARED_MODULE_EXPANDED = $(sort $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED))
SRC_S = peripherals/broadcom/boot8.s
OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_SHARED_MODULE_EXPANDED:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_SHARED_MODULE_EXPANDED:.c=.o))
@ -96,15 +109,6 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
# BCM CLFAGS # BCM CLFAGS
CFLAGS += -ffreestanding -nostartfiles -DMICROPY_HW_MCU_NAME="\"$(CHIP_VARIANT)\"" CFLAGS += -ffreestanding -nostartfiles -DMICROPY_HW_MCU_NAME="\"$(CHIP_VARIANT)\""
ifeq ($(CHIP_VARIANT), "bcm2711")
CFLAGS += -mcpu=cortex-a72 -DBCM_VERSION=2711
CROSS_COMPILE = aarch64-none-elf-
else
CFLAGS += -mcpu=cortex-a53 -DBCM_VERSION=2837
CROSS_COMPILE = aarch64-none-elf-
# TODO add 32-bit support for Cortex-A7 and ARM1176
endif
OPTIMIZATION_FLAGS ?= -O3 OPTIMIZATION_FLAGS ?= -O3
CFLAGS += $(OPTIMIZATION_FLAGS) CFLAGS += $(OPTIMIZATION_FLAGS)
@ -134,32 +138,32 @@ CFLAGS += $(INC) -Wall -Werror -std=gnu11 $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) $
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED) SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
LDFLAGS += $(CFLAGS) -T peripherals/broadcom/link8.ld -Wl,--gc-sections -Wl,-Map=$@.map # -Wl,--cref LDFLAGS += $(CFLAGS) -T peripherals/broadcom/link$(SUFFIX).ld -Wl,--gc-sections -Wl,-Map=$@.map # -Wl,--cref
# Use toolchain libm if we're not using our own. # Use toolchain libm if we're not using our own.
ifndef INTERNAL_LIBM ifndef INTERNAL_LIBM
LIBS += -lm LIBS += -lm
endif endif
all: $(BUILD)/firmware.kernel8.img $(BUILD)/firmware.disk.img.zip all: $(BUILD)/firmware.kernel$(SUFFIX).img $(BUILD)/firmware.disk.img.zip
%.o: %.c %.o: %.c
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -c $< -o $@
$(BUILD)/kernel8.elf: $(OBJ) $(BUILD)/kernel$(SUFFIX).elf: $(OBJ)
$(STEPECHO) "LINK $@" $(STEPECHO) "LINK $@"
$(Q)echo $(OBJ) > $(BUILD)/firmware.objs $(Q)echo $(OBJ) > $(BUILD)/firmware.objs
$(Q)$(CC) -o $@ $(LDFLAGS) @$(BUILD)/firmware.objs -Wl,--start-group $(LIBS) -Wl,--end-group $(Q)$(CC) -o $@ $(LDFLAGS) @$(BUILD)/firmware.objs -Wl,--start-group $(LIBS) -Wl,--end-group
$(BUILD)/kernel8.img: $(BUILD)/kernel8.elf $(BUILD)/kernel$(SUFFIX).img: $(BUILD)/kernel$(SUFFIX).elf
$(STEPECHO) "Create $@" $(STEPECHO) "Create $@"
$(OBJCOPY) -O binary $(BUILD)/kernel8.elf $@ $(OBJCOPY) -O binary $(BUILD)/kernel$(SUFFIX).elf $@
$(BUILD)/firmware.kernel8.img: $(BUILD)/kernel8.img $(BUILD)/firmware.kernel$(SUFFIX).img: $(BUILD)/kernel$(SUFFIX).img
$(STEPECHO) "Create $@" $(STEPECHO) "Create $@"
$(CP) $^ $@ $(CP) $^ $@
$(BUILD)/firmware.disk.img.zip: $(BUILD)/kernel8.img $(BUILD)/firmware.disk.img.zip: $(BUILD)/kernel$(SUFFIX).img
$(STEPECHO) "Create $@" $(STEPECHO) "Create $@"
$(Q)dd if=/dev/zero of=$(BUILD)/circuitpython-disk.img bs=1 count=0 seek=256M $(Q)dd if=/dev/zero of=$(BUILD)/circuitpython-disk.img bs=1 count=0 seek=256M
$(Q)parted -s $(BUILD)/circuitpython-disk.img mktable msdos $(Q)parted -s $(BUILD)/circuitpython-disk.img mktable msdos
@ -167,7 +171,7 @@ $(BUILD)/firmware.disk.img.zip: $(BUILD)/kernel8.img
$(Q)mkfs.fat -F 32 -n BOOT --offset=2048 $(BUILD)/circuitpython-disk.img $(Q)mkfs.fat -F 32 -n BOOT --offset=2048 $(BUILD)/circuitpython-disk.img
$(Q)mcopy -i $(BUILD)/circuitpython-disk.img@@1M config.txt firmware/bootcode.bin firmware/fixup* firmware/start* firmware/*.dtb :: $(Q)mcopy -i $(BUILD)/circuitpython-disk.img@@1M config.txt firmware/bootcode.bin firmware/fixup* firmware/start* firmware/*.dtb ::
$(Q)mcopy -i $(BUILD)/circuitpython-disk.img@@1M $(BUILD)/kernel8.img :: $(Q)mcopy -i $(BUILD)/circuitpython-disk.img@@1M $(BUILD)/kernel$(SUFFIX).img ::
$(Q)zip $@ $(BUILD)/circuitpython-disk.img $(Q)zip $@ $(BUILD)/circuitpython-disk.img
$(Q)rm $(BUILD)/circuitpython-disk.img $(Q)rm $(BUILD)/circuitpython-disk.img

View File

@ -0,0 +1,56 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2021 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "supervisor/board.h"
#include "mpconfigboard.h"
#include "bindings/videocore/Framebuffer.h"
#include "shared-module/displayio/__init__.h"
#include "shared-bindings/framebufferio/FramebufferDisplay.h"
void board_init(void) {
videocore_framebuffer_obj_t *fb = &allocate_display_bus()->videocore;
fb->base.type = &videocore_framebuffer_type;
common_hal_videocore_framebuffer_construct(fb, 640, 480);
framebufferio_framebufferdisplay_obj_t *display = &displays[0].framebuffer_display;
display->base.type = &framebufferio_framebufferdisplay_type;
common_hal_framebufferio_framebufferdisplay_construct(
display,
MP_OBJ_FROM_PTR(fb),
0,
true);
}
bool board_requests_safe_mode(void) {
return false;
}
void reset_board(void) {
}
void board_deinit(void) {
}

View File

@ -0,0 +1,6 @@
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Zero W"
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO3)
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO2)
#define MICROPY_HW_LED_STATUS (&pin_GPIO47)

View File

@ -0,0 +1,6 @@
USB_VID = 0x2E8A
USB_PID = 0xf015
USB_PRODUCT = "Raspberry Pi Zero"
USB_MANUFACTURER = "Raspberry Pi"
CHIP_VARIANT = "bcm2835"

View File

@ -0,0 +1,62 @@
#include "shared-bindings/board/__init__.h"
#include "shared-module/displayio/__init__.h"
STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
// These match the names used in Blinka
{ MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO2) },
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO2) },
{ MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO3) },
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO3) },
{ MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO4) },
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO5) },
{ MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO6) },
{ MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO7) },
{ MP_ROM_QSTR(MP_QSTR_CE1), MP_ROM_PTR(&pin_GPIO7) },
{ MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_CE0), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO9) },
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO9) },
{ MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO10) },
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO10) },
{ MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_SCLK), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO12) },
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO13) },
{ MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_GPIO14) },
{ MP_ROM_QSTR(MP_QSTR_TXD), MP_ROM_PTR(&pin_GPIO14) },
{ MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_GPIO15) },
{ MP_ROM_QSTR(MP_QSTR_RXD), MP_ROM_PTR(&pin_GPIO15) },
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO14) },
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO15) },
{ MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_GPIO16) },
{ MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_GPIO17) },
{ MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_GPIO18) },
{ MP_ROM_QSTR(MP_QSTR_D19), MP_ROM_PTR(&pin_GPIO19) },
{ MP_ROM_QSTR(MP_QSTR_MISO_1), MP_ROM_PTR(&pin_GPIO19) },
{ MP_ROM_QSTR(MP_QSTR_D20), MP_ROM_PTR(&pin_GPIO20) },
{ MP_ROM_QSTR(MP_QSTR_MOSI_1), MP_ROM_PTR(&pin_GPIO20) },
{ MP_ROM_QSTR(MP_QSTR_D21), MP_ROM_PTR(&pin_GPIO21) },
{ MP_ROM_QSTR(MP_QSTR_SCLK_1), MP_ROM_PTR(&pin_GPIO21) },
{ MP_ROM_QSTR(MP_QSTR_SCK_1), MP_ROM_PTR(&pin_GPIO21) },
{ MP_ROM_QSTR(MP_QSTR_D22), MP_ROM_PTR(&pin_GPIO22) },
{ MP_ROM_QSTR(MP_QSTR_D23), MP_ROM_PTR(&pin_GPIO23) },
{ MP_ROM_QSTR(MP_QSTR_D24), MP_ROM_PTR(&pin_GPIO24) },
{ MP_ROM_QSTR(MP_QSTR_D25), MP_ROM_PTR(&pin_GPIO25) },
{ MP_ROM_QSTR(MP_QSTR_D26), MP_ROM_PTR(&pin_GPIO26) },
{ MP_ROM_QSTR(MP_QSTR_D27), MP_ROM_PTR(&pin_GPIO27) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)},
};
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

View File

@ -48,9 +48,9 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t *digitalinout,
while (port_get_raw_ticks(NULL) < next_start_raw_ticks) { while (port_get_raw_ticks(NULL) < next_start_raw_ticks) {
} }
BP_Function_Enum alt_function; BP_Function_Enum alt_function = GPIO_FUNCTION_OUTPUT;
uint8_t index; uint8_t index = 0;
uint8_t channel; uint8_t channel = 0;
bool found = false; bool found = false;
for (size_t i = 0; i < NUM_ALT_FUNC; i++) { for (size_t i = 0; i < NUM_ALT_FUNC; i++) {
const pin_function_t *f = &digitalinout->pin->functions[i]; const pin_function_t *f = &digitalinout->pin->functions[i];

View File

@ -37,6 +37,7 @@
#include "supervisor/port.h" #include "supervisor/port.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate.h"
#include "peripherals/broadcom/cpu.h"
#include "peripherals/broadcom/defines.h" #include "peripherals/broadcom/defines.h"
#include "peripherals/broadcom/gpio.h" #include "peripherals/broadcom/gpio.h"
@ -235,21 +236,29 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self,
if (clock != NULL) { if (clock != NULL) {
gpio_set_function(clock->number, GPIO_GPFSEL4_FSEL48_SD1_CLK); gpio_set_function(clock->number, GPIO_GPFSEL4_FSEL48_SD1_CLK);
gpio_set_pull(clock->number, BP_PULL_NONE); gpio_set_pull(clock->number, BP_PULL_NONE);
self->clock_pin = clock->number;
gpio_set_function(command->number, GPIO_GPFSEL4_FSEL49_SD1_CMD); gpio_set_function(command->number, GPIO_GPFSEL4_FSEL49_SD1_CMD);
gpio_set_pull(command->number, BP_PULL_UP); gpio_set_pull(command->number, BP_PULL_UP);
self->command_pin = command->number;
gpio_set_function(data[0]->number, GPIO_GPFSEL5_FSEL50_SD1_DAT0); gpio_set_function(data[0]->number, GPIO_GPFSEL5_FSEL50_SD1_DAT0);
gpio_set_pull(data[0]->number, BP_PULL_UP); gpio_set_pull(data[0]->number, BP_PULL_UP);
self->data_pins[0] = data[0]->number;
gpio_set_function(data[1]->number, GPIO_GPFSEL5_FSEL51_SD1_DAT1); gpio_set_function(data[1]->number, GPIO_GPFSEL5_FSEL51_SD1_DAT1);
gpio_set_pull(data[1]->number, BP_PULL_UP); gpio_set_pull(data[1]->number, BP_PULL_UP);
self->data_pins[1] = data[1]->number;
gpio_set_function(data[2]->number, GPIO_GPFSEL5_FSEL52_SD1_DAT2); gpio_set_function(data[2]->number, GPIO_GPFSEL5_FSEL52_SD1_DAT2);
gpio_set_pull(data[2]->number, BP_PULL_UP); gpio_set_pull(data[2]->number, BP_PULL_UP);
self->data_pins[2] = data[2]->number;
gpio_set_function(data[3]->number, GPIO_GPFSEL5_FSEL53_SD1_DAT3); gpio_set_function(data[3]->number, GPIO_GPFSEL5_FSEL53_SD1_DAT3);
gpio_set_pull(data[3]->number, BP_PULL_UP); gpio_set_pull(data[3]->number, BP_PULL_UP);
self->data_pins[3] = data[3]->number;
} else { } else {
// Switch the sdcard to use the old arasan interface. // Switch the sdcard to use the old arasan interface.
GPIO->EXTRA_MUX_b.SDIO = GPIO_EXTRA_MUX_SDIO_ARASAN; GPIO->EXTRA_MUX_b.SDIO = GPIO_EXTRA_MUX_SDIO_ARASAN;
} }
COMPLETE_MEMORY_READS;
self->host_info = (sdmmc_host_t) { self->host_info = (sdmmc_host_t) {
.flags = SDMMC_HOST_FLAG_1BIT | SDMMC_HOST_FLAG_4BIT | SDMMC_HOST_FLAG_DEINIT_ARG, .flags = SDMMC_HOST_FLAG_1BIT | SDMMC_HOST_FLAG_4BIT | SDMMC_HOST_FLAG_DEINIT_ARG,
.slot = 0, .slot = 0,
@ -280,9 +289,22 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self,
// Start clocking the card. // Start clocking the card.
_set_card_clk(0, 400); _set_card_clk(0, 400);
sdmmc_card_init(&self->host_info, &self->card_info); sdmmc_err_t err = SDMMC_ERR_INVALID_RESPONSE;
size_t tries = 3;
while (err == SDMMC_ERR_INVALID_RESPONSE && tries > 0) {
err = sdmmc_card_init(&self->host_info, &self->card_info);
if (err != SDMMC_OK) {
mp_printf(&mp_plat_print, "SD card init failed %d\n", err);
} else if (tries < 3) {
mp_printf(&mp_plat_print, "SD card init success\n");
}
tries--;
}
self->init = err == SDMMC_OK;
self->capacity = self->card_info.csd.capacity; self->capacity = self->card_info.csd.capacity;
COMPLETE_MEMORY_READS;
} }
uint32_t common_hal_sdioio_sdcard_get_count(sdioio_sdcard_obj_t *self) { uint32_t common_hal_sdioio_sdcard_get_count(sdioio_sdcard_obj_t *self) {
@ -297,9 +319,6 @@ uint8_t common_hal_sdioio_sdcard_get_width(sdioio_sdcard_obj_t *self) {
return self->num_data; return self->num_data;
} }
STATIC void check_for_deinit(sdioio_sdcard_obj_t *self) {
}
STATIC void check_whole_block(mp_buffer_info_t *bufinfo) { STATIC void check_whole_block(mp_buffer_info_t *bufinfo) {
if (bufinfo->len % 512) { if (bufinfo->len % 512) {
mp_raise_ValueError(translate("Buffer length must be a multiple of 512")); mp_raise_ValueError(translate("Buffer length must be a multiple of 512"));
@ -307,14 +326,16 @@ STATIC void check_whole_block(mp_buffer_info_t *bufinfo) {
} }
int common_hal_sdioio_sdcard_writeblocks(sdioio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *bufinfo) { int common_hal_sdioio_sdcard_writeblocks(sdioio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *bufinfo) {
check_for_deinit(self); if (!self->init) {
return -EIO;
}
check_whole_block(bufinfo); check_whole_block(bufinfo);
self->state_programming = true; self->state_programming = true;
// mp_printf(&mp_plat_print, "write %d %d %d %d\n", start_block, bufinfo->len / 512, self->card_info.csd.capacity, self->card_info.csd.sector_size); COMPLETE_MEMORY_READS;
sdmmc_err_t error = sdmmc_write_sectors(&self->card_info, bufinfo->buf, sdmmc_err_t error = sdmmc_write_sectors(&self->card_info, bufinfo->buf,
start_block, bufinfo->len / 512); start_block, bufinfo->len / 512);
COMPLETE_MEMORY_READS;
if (error != SDMMC_OK) { if (error != SDMMC_OK) {
mp_printf(&mp_plat_print, "write sectors result %d\n", error); mp_printf(&mp_plat_print, "write sectors result %d\n", error);
@ -325,10 +346,14 @@ int common_hal_sdioio_sdcard_writeblocks(sdioio_sdcard_obj_t *self, uint32_t sta
} }
int common_hal_sdioio_sdcard_readblocks(sdioio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *bufinfo) { int common_hal_sdioio_sdcard_readblocks(sdioio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *bufinfo) {
check_for_deinit(self); if (!self->init) {
return -EIO;
}
check_whole_block(bufinfo); check_whole_block(bufinfo);
COMPLETE_MEMORY_READS;
sdmmc_err_t error = sdmmc_read_sectors(&self->card_info, bufinfo->buf, sdmmc_err_t error = sdmmc_read_sectors(&self->card_info, bufinfo->buf,
start_block, bufinfo->len / 512); start_block, bufinfo->len / 512);
COMPLETE_MEMORY_READS;
if (error != SDMMC_OK) { if (error != SDMMC_OK) {
mp_printf(&mp_plat_print, "read sectors result %d when reading block %d for %d\n", error, start_block, bufinfo->len / 512); mp_printf(&mp_plat_print, "read sectors result %d when reading block %d for %d\n", error, start_block, bufinfo->len / 512);
@ -339,7 +364,9 @@ int common_hal_sdioio_sdcard_readblocks(sdioio_sdcard_obj_t *self, uint32_t star
} }
bool common_hal_sdioio_sdcard_configure(sdioio_sdcard_obj_t *self, uint32_t frequency, uint8_t bits) { bool common_hal_sdioio_sdcard_configure(sdioio_sdcard_obj_t *self, uint32_t frequency, uint8_t bits) {
check_for_deinit(self); if (!self->init) {
return false;
}
return true; return true;
} }
@ -361,7 +388,14 @@ void common_hal_sdioio_sdcard_deinit(sdioio_sdcard_obj_t *self) {
self->data_pins[1] = COMMON_HAL_MCU_NO_PIN; self->data_pins[1] = COMMON_HAL_MCU_NO_PIN;
self->data_pins[2] = COMMON_HAL_MCU_NO_PIN; self->data_pins[2] = COMMON_HAL_MCU_NO_PIN;
self->data_pins[3] = COMMON_HAL_MCU_NO_PIN; self->data_pins[3] = COMMON_HAL_MCU_NO_PIN;
self->init = false;
} }
void common_hal_sdioio_sdcard_never_reset(sdioio_sdcard_obj_t *self) { void common_hal_sdioio_sdcard_never_reset(sdioio_sdcard_obj_t *self) {
never_reset_pin_number(self->command_pin);
never_reset_pin_number(self->clock_pin);
never_reset_pin_number(self->data_pins[0]);
never_reset_pin_number(self->data_pins[1]);
never_reset_pin_number(self->data_pins[2]);
never_reset_pin_number(self->data_pins[3]);
} }

View File

@ -37,6 +37,7 @@ typedef struct {
uint8_t num_data; uint8_t num_data;
bool state_programming; bool state_programming;
bool has_lock; bool has_lock;
bool init;
uint8_t command_pin; uint8_t command_pin;
uint8_t clock_pin; uint8_t clock_pin;
uint8_t data_pins[4]; uint8_t data_pins[4];

View File

@ -16,7 +16,13 @@ void common_hal_videocore_framebuffer_construct(videocore_framebuffer_obj_t *sel
// TODO: Make the FB twice as tall if double buffering. // TODO: Make the FB twice as tall if double buffering.
uint32_t physical_height = height; uint32_t physical_height = height;
uint32_t pitch = 0; uint32_t pitch = 0;
self->framebuffer = vcmailbox_get_framebuffer(&virtual_width, &virtual_height, &physical_width, &physical_height, &pitch); uint32_t bits_per_pixel = 0;
self->framebuffer = vcmailbox_get_framebuffer(&virtual_width,
&virtual_height,
&physical_width,
&physical_height,
&pitch,
&bits_per_pixel);
if (self->framebuffer == NULL) { if (self->framebuffer == NULL) {
if (gc_alloc_possible()) { if (gc_alloc_possible()) {
mp_raise_ValueError(translate("no fb")); mp_raise_ValueError(translate("no fb"));

View File

@ -36,7 +36,11 @@
#define MICROPY_PY_SYS_PLATFORM "BROADCOM" #define MICROPY_PY_SYS_PLATFORM "BROADCOM"
#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1) #define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1)
#define MICROPY_PY_FUNCTION_ATTRS (1) #define MICROPY_PY_FUNCTION_ATTRS (1)
#if BCM_VERSION == 2837 || BCM_VERSION == 2711
#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_A) #define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_A)
#elif BCM_VERSION == 2835
#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_C)
#endif
#define CIRCUITPY_DEFAULT_STACK_SIZE (0x10000) #define CIRCUITPY_DEFAULT_STACK_SIZE (0x10000)
#define CIRCUITPY_DISPLAY_AREA_BUFFER_SIZE (1920) #define CIRCUITPY_DISPLAY_AREA_BUFFER_SIZE (1920)
#define CIRCUITPY_PROCESSOR_COUNT (4) #define CIRCUITPY_PROCESSOR_COUNT (4)

View File

@ -41,16 +41,16 @@ mp_uint_t cpu_get_regs_and_sp(mp_uint_t *regs) {
__asm__ ("mov %[out], x28" : [out] "=r" (regs[9])); __asm__ ("mov %[out], x28" : [out] "=r" (regs[9]));
#else #else
__asm__ ("mov %[out], sp" : [out] "=r" (sp)); __asm__ ("mov %[out], sp" : [out] "=r" (sp));
__asm__ ("mov %[out], x19" : [out] "=r" (regs[0])); __asm__ ("mov %[out], r4" : [out] "=r" (regs[0]));
__asm__ ("mov %[out], x20" : [out] "=r" (regs[1])); __asm__ ("mov %[out], r5" : [out] "=r" (regs[1]));
__asm__ ("mov %[out], x21" : [out] "=r" (regs[2])); __asm__ ("mov %[out], r6" : [out] "=r" (regs[2]));
__asm__ ("mov %[out], x22" : [out] "=r" (regs[3])); __asm__ ("mov %[out], r7" : [out] "=r" (regs[3]));
__asm__ ("mov %[out], x23" : [out] "=r" (regs[4])); __asm__ ("mov %[out], r8" : [out] "=r" (regs[4]));
__asm__ ("mov %[out], x24" : [out] "=r" (regs[5])); __asm__ ("mov %[out], r9" : [out] "=r" (regs[5]));
__asm__ ("mov %[out], x25" : [out] "=r" (regs[6])); __asm__ ("mov %[out], r10" : [out] "=r" (regs[6]));
__asm__ ("mov %[out], x26" : [out] "=r" (regs[7])); __asm__ ("mov %[out], r11" : [out] "=r" (regs[7]));
__asm__ ("mov %[out], x27" : [out] "=r" (regs[8])); __asm__ ("mov %[out], r12" : [out] "=r" (regs[8]));
__asm__ ("mov %[out], x28" : [out] "=r" (regs[9])); __asm__ ("mov %[out], r13" : [out] "=r" (regs[9]));
#endif #endif
return sp; return sp;

@ -1 +1 @@
Subproject commit 2c10889a4b2d78987bc4e0783db2e7584aa4d572 Subproject commit 08370086080759ed54ac1136d62d2ad24c6fa267

View File

@ -60,6 +60,7 @@ void supervisor_flash_init(void) {
NULL, NULL, NULL, NULL,
0, NULL, 8000000); 0, NULL, 8000000);
#endif #endif
common_hal_sdioio_sdcard_never_reset(&sd);
uint32_t buffer[512 / sizeof(uint32_t)]; uint32_t buffer[512 / sizeof(uint32_t)];
mp_buffer_info_t bufinfo; mp_buffer_info_t bufinfo;

View File

@ -116,42 +116,57 @@ void reset_to_bootloader(void) {
} }
void reset_cpu(void) { void reset_cpu(void) {
// Don't actually reset because we can't store the safe mode info.
// PM->WDOG = 1 << PM_WDOG_TIME_Pos | PM_WDOG_PASSWD_PASSWD << PM_WDOG_PASSWD_Pos;
// PM->RSTC = PM_RSTC_WRCFG_FULL_RESET << PM_RSTC_WRCFG_Pos | PM_RSTC_PASSWD_PASSWD << PM_RSTC_PASSWD_Pos;
while (true) { while (true) {
} }
} }
bool port_has_fixed_stack(void) { bool port_has_fixed_stack(void) {
#ifdef __aarch64__
return true; return true;
} #else
return false;
uint32_t *port_stack_get_limit(void) { #endif
return (uint32_t *)0x4;
}
uint32_t *port_stack_get_top(void) {
return (uint32_t *)0x80000;
} }
// From the linker script // From the linker script
extern uint32_t __bss_end; extern uint32_t __bss_end;
extern uint32_t _ld_ram_end;
uint32_t *port_stack_get_limit(void) {
#ifdef __aarch64__
return (uint32_t *)0x4;
#else
return &__bss_end;
#endif
}
uint32_t *port_stack_get_top(void) {
#ifdef __aarch64__
return (uint32_t *)0x80000;
#else
return &_ld_ram_end;
#endif
}
uint32_t *port_heap_get_bottom(void) { uint32_t *port_heap_get_bottom(void) {
return &__bss_end; return &__bss_end;
} }
uint32_t *port_heap_get_top(void) { uint32_t *port_heap_get_top(void) {
// 32M heap // 32M heap
return (uint32_t *)(((uint64_t)&__bss_end) + 32 * 1024 * 1024); return (uint32_t *)(((size_t)&__bss_end) + 32 * 1024 * 1024);
} }
void port_set_saved_word(uint32_t value) { void port_set_saved_word(uint32_t value) {
// NOTE: This doesn't survive pressing the reset button (aka toggling RUN). // NOTE: This doesn't survive pressing the reset button (aka toggling RUN).
// watchdog_hw->scratch[0] = value; __bss_end = value;
data_clean_and_invalidate(&__bss_end, sizeof(uint32_t));
} }
uint32_t port_get_saved_word(void) { uint32_t port_get_saved_word(void) {
// return watchdog_hw->scratch[0]; return __bss_end;
return 0;
} }
uint64_t port_get_raw_ticks(uint8_t *subticks) { uint64_t port_get_raw_ticks(uint8_t *subticks) {

View File

@ -156,7 +156,7 @@ SRC_C += \
boards/$(BOARD)/flash_config.c \ boards/$(BOARD)/flash_config.c \
boards/$(BOARD)/pins.c \ boards/$(BOARD)/pins.c \
fatfs_port.c \ fatfs_port.c \
lib/tinyusb/src/portable/nxp/transdimension/dcd_transdimension.c \ lib/tinyusb/src/portable/chipidea/ci_hs/dcd_ci_hs.c \
mphalport.c \ mphalport.c \
peripherals/mimxrt10xx/$(CHIP_FAMILY)/clocks.c \ peripherals/mimxrt10xx/$(CHIP_FAMILY)/clocks.c \
peripherals/mimxrt10xx/$(CHIP_FAMILY)/periph.c \ peripherals/mimxrt10xx/$(CHIP_FAMILY)/periph.c \

View File

@ -32,6 +32,7 @@ DFU = ("dfu",)
BIN_DFU = ("bin", "dfu") BIN_DFU = ("bin", "dfu")
COMBINED_HEX = ("combined.hex",) COMBINED_HEX = ("combined.hex",)
KERNEL8_IMG = ("disk.img.zip", "kernel8.img") KERNEL8_IMG = ("disk.img.zip", "kernel8.img")
KERNEL_IMG = ("disk.img.zip", "kernel.img")
# Default extensions # Default extensions
extension_by_port = { extension_by_port = {
@ -70,6 +71,8 @@ extension_by_board = {
# esp32c3 # esp32c3
"ai_thinker_esp32-c3s": BIN, "ai_thinker_esp32-c3s": BIN,
"microdev_micro_c3": BIN, "microdev_micro_c3": BIN,
# broadcom
"raspberrypi_zero_w": KERNEL_IMG,
} }
language_allow_list = set( language_allow_list = set(