Skip to content

Initial Pi Zero support #5800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/sdmmc/sdmmc_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,10 @@ static sdmmc_err_t cis_tuple_func_manfid(const void* p, uint8_t* data, FILE* fp)
int size = *(data++);
fprintf(fp, "TUPLE: %s, size: %d\n", tuple->name, size);
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));
#pragma GCC diagnostic pop
return SDMMC_OK;
}

Expand Down Expand Up @@ -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);
size-=2;
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;
#pragma GCC diagnostic pop
fprintf(fp, " LEN: %04X\n", len);
data+=2;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/tinyusb
Submodule tinyusb updated 156 files
7 changes: 4 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,9 +812,10 @@ int __attribute__((used)) main(void) {
// A power brownout here could make it appear as if there's
// 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.
if ((safe_mode != NO_CIRCUITPY) && !filesystem_init(safe_mode == NO_SAFE_MODE, false)) {
reset_into_safe_mode(NO_CIRCUITPY);
// Check whether CIRCUITPY is available. No need to reset to get safe mode
// since we haven't run user code yet.
if (!filesystem_init(safe_mode == NO_SAFE_MODE, false)) {
safe_mode = NO_CIRCUITPY;
}

// displays init after filesystem, since they could share the flash SPI
Expand Down
42 changes: 23 additions & 19 deletions ports/broadcom/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,20 @@ include $(TOP)/supervisor/supervisor.mk
# Include make rules and variables common across CircuitPython builds.
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. \
-I../.. \
Expand Down Expand Up @@ -69,6 +82,7 @@ SRC_C += bindings/videocore/__init__.c \
peripherals/broadcom/mmu.c \
peripherals/broadcom/vcmailbox.c

SRC_S = peripherals/broadcom/boot$(SUFFIX).s

SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
Expand All @@ -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/.
# 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_S = peripherals/broadcom/boot8.s

OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_SHARED_MODULE_EXPANDED:.c=.o))
Expand All @@ -96,15 +109,6 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
# BCM CLFAGS
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
CFLAGS += $(OPTIMIZATION_FLAGS)
Expand Down Expand Up @@ -134,40 +138,40 @@ 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)

LDFLAGS += $(CFLAGS) -T peripherals/broadcom/link8.ld -Wl,--gc-sections -Wl,[email protected] # -Wl,--cref
LDFLAGS += $(CFLAGS) -T peripherals/broadcom/link$(SUFFIX).ld -Wl,--gc-sections -Wl,[email protected] # -Wl,--cref

# Use toolchain libm if we're not using our own.
ifndef INTERNAL_LIBM
LIBS += -lm
endif

all: $(BUILD)/firmware.kernel8.img $(BUILD)/firmware.disk.img.zip
all: $(BUILD)/firmware.kernel$(SUFFIX).img $(BUILD)/firmware.disk.img.zip

%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@

$(BUILD)/kernel8.elf: $(OBJ)
$(BUILD)/kernel$(SUFFIX).elf: $(OBJ)
$(STEPECHO) "LINK $@"
$(Q)echo $(OBJ) > $(BUILD)/firmware.objs
$(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 $@"
$(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 $@"
$(CP) $^ $@

$(BUILD)/firmware.disk.img.zip: $(BUILD)/kernel8.img
$(BUILD)/firmware.disk.img.zip: $(BUILD)/kernel$(SUFFIX).img
$(STEPECHO) "Create $@"
$(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 mkpart primary fat32 0% 100%
$(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 $(BUILD)/kernel8.img ::
$(Q)mcopy -i $(BUILD)/circuitpython-disk.img@@1M $(BUILD)/kernel$(SUFFIX).img ::
$(Q)zip $@ $(BUILD)/circuitpython-disk.img
$(Q)rm $(BUILD)/circuitpython-disk.img

Expand Down
56 changes: 56 additions & 0 deletions ports/broadcom/boards/raspberrypi_zero_w/board.c
Original file line number Diff line number Diff line change
@@ -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) {
}
6 changes: 6 additions & 0 deletions ports/broadcom/boards/raspberrypi_zero_w/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions ports/broadcom/boards/raspberrypi_zero_w/mpconfigboard.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
USB_VID = 0x2E8A
USB_PID = 0xf015
USB_PRODUCT = "Raspberry Pi Zero"
USB_MANUFACTURER = "Raspberry Pi"

CHIP_VARIANT = "bcm2835"
62 changes: 62 additions & 0 deletions ports/broadcom/boards/raspberrypi_zero_w/pins.c
Original file line number Diff line number Diff line change
@@ -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);
6 changes: 3 additions & 3 deletions ports/broadcom/common-hal/neopixel_write/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}

BP_Function_Enum alt_function;
uint8_t index;
uint8_t channel;
BP_Function_Enum alt_function = GPIO_FUNCTION_OUTPUT;
uint8_t index = 0;
uint8_t channel = 0;
bool found = false;
for (size_t i = 0; i < NUM_ALT_FUNC; i++) {
const pin_function_t *f = &digitalinout->pin->functions[i];
Expand Down
Loading