Move atmel-samd to tinyusb and support nRF flash.
This started while adding USB MIDI support (and descriptor support is in this change.) When seeing that I'd have to implement the MIDI class logic twice, once for atmel-samd and once for nrf, I decided to refactor the USB stack so its shared across ports. This has led to a number of changes that remove items from the ports folder and move them into supervisor. Furthermore, we had external SPI flash support for nrf pending so I factored out the connection between the usb stack and the flash API as well. This PR also includes the QSPI support for nRF.
This commit is contained in:
parent
d08747d374
commit
9d91111b1b
2
.gitmodules
vendored
2
.gitmodules
vendored
@ -78,7 +78,7 @@
|
||||
url = https://github.com/adafruit/nrfx.git
|
||||
[submodule "lib/tinyusb"]
|
||||
path = lib/tinyusb
|
||||
url = https://github.com/hathach/tinyusb.git
|
||||
url = https://github.com/tannewt/tinyusb.git
|
||||
branch = develop
|
||||
[submodule "tools/huffman"]
|
||||
path = tools/huffman
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 33c61bfda2c3aada3cb06d36e12d7cf57da02037
|
||||
Subproject commit 30e3c64134789416e10ed867fa12c210b808e98f
|
3
main.c
3
main.c
@ -51,6 +51,7 @@
|
||||
#include "supervisor/shared/autoreload.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
#include "supervisor/shared/rgb_led_status.h"
|
||||
#include "supervisor/shared/status_leds.h"
|
||||
#include "supervisor/shared/stack.h"
|
||||
#include "supervisor/serial.h"
|
||||
|
||||
@ -388,6 +389,8 @@ int __attribute__((used)) main(void) {
|
||||
// initialise the cpu and peripherals
|
||||
safe_mode_t safe_mode = port_init();
|
||||
|
||||
// Turn on LEDs
|
||||
init_status_leds();
|
||||
rgb_led_status_init();
|
||||
|
||||
stack_init();
|
||||
|
@ -45,16 +45,13 @@ INC += -I. \
|
||||
-Iasf4/$(CHIP_FAMILY)/hpl/tc \
|
||||
-Iasf4/$(CHIP_FAMILY)/include \
|
||||
-Iasf4/$(CHIP_FAMILY)/CMSIS/Include \
|
||||
-Iasf4/$(CHIP_FAMILY)/usb \
|
||||
-Iasf4/$(CHIP_FAMILY)/usb/class/cdc \
|
||||
-Iasf4/$(CHIP_FAMILY)/usb/class/hid \
|
||||
-Iasf4/$(CHIP_FAMILY)/usb/class/msc \
|
||||
-Iasf4/$(CHIP_FAMILY)/usb/device \
|
||||
-Iasf4_conf/$(CHIP_FAMILY) \
|
||||
-Iboards/$(BOARD) \
|
||||
-Iboards/ \
|
||||
-Iperipherals/ \
|
||||
-Ifreetouch \
|
||||
-I../../lib/tinyusb/src \
|
||||
-I../../supervisor/shared/usb \
|
||||
-I$(BUILD)
|
||||
|
||||
BASE_CFLAGS = \
|
||||
@ -90,11 +87,15 @@ BASE_CFLAGS = \
|
||||
# NDEBUG disables assert() statements. This reduces code size pretty dramatically, per tannewt.
|
||||
|
||||
ifeq ($(CHIP_FAMILY), samd21)
|
||||
CFLAGS = -Os -DNDEBUG
|
||||
CFLAGS += -Os -DNDEBUG
|
||||
# TinyUSB defines
|
||||
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAMD21 -DCFG_TUD_CDC_RX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=128 -DCFG_TUD_MSC_BUFSIZE=512
|
||||
endif
|
||||
|
||||
ifeq ($(CHIP_FAMILY), samd51)
|
||||
CFLAGS = -Os -DNDEBUG
|
||||
CFLAGS += -O0 -DNDEBUG
|
||||
# TinyUSB defines
|
||||
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAMD51 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=1024
|
||||
endif
|
||||
|
||||
#Debugging/Optimization
|
||||
@ -104,7 +105,7 @@ ifeq ($(DEBUG), 1)
|
||||
# You may want to disable -flto if it interferes with debugging.
|
||||
CFLAGS += -flto
|
||||
# You may want to enable these flags to make setting breakpoints easier.
|
||||
## CFLAGS += -fno-inline -fno-ipa-sra
|
||||
# CFLAGS += -fno-inline -fno-ipa-sra
|
||||
ifeq ($(CHIP_FAMILY), samd21)
|
||||
CFLAGS += -DENABLE_MICRO_TRACE_BUFFER
|
||||
endif
|
||||
@ -204,7 +205,6 @@ SRC_ASF := \
|
||||
hal/src/hal_spi_m_sync.c \
|
||||
hal/src/hal_timer.c \
|
||||
hal/src/hal_usart_async.c \
|
||||
hal/src/hal_usb_device.c \
|
||||
hpl/adc/hpl_adc.c \
|
||||
hpl/core/hpl_init.c \
|
||||
hpl/dac/hpl_dac.c \
|
||||
@ -214,12 +214,6 @@ SRC_ASF := \
|
||||
hpl/rtc/hpl_rtc.c \
|
||||
hpl/sercom/hpl_sercom.c \
|
||||
hpl/systick/hpl_systick.c \
|
||||
hpl/usb/hpl_usb.c \
|
||||
usb/class/cdc/device/cdcdf_acm.c \
|
||||
usb/class/hid/device/hiddf_generic.c \
|
||||
usb/class/msc/device/mscdf.c \
|
||||
usb/device/usbdc.c \
|
||||
usb/usb_protocol.c \
|
||||
hal/utils/src/utils_list.c \
|
||||
hal/utils/src/utils_ringbuffer.c \
|
||||
|
||||
@ -246,7 +240,6 @@ SRC_C = \
|
||||
board_busses.c \
|
||||
background.c \
|
||||
fatfs_port.c \
|
||||
flash_api.c \
|
||||
mphalport.c \
|
||||
reset.c \
|
||||
peripherals/samd/clocks.c \
|
||||
@ -265,8 +258,6 @@ SRC_C = \
|
||||
peripherals/samd/$(CHIP_FAMILY)/sercom.c \
|
||||
peripherals/samd/$(CHIP_FAMILY)/timers.c \
|
||||
tick.c \
|
||||
usb.c \
|
||||
usb_mass_storage.c \
|
||||
bindings/samd/__init__.c \
|
||||
bindings/samd/Clock.c \
|
||||
boards/$(BOARD)/board.c \
|
||||
@ -274,6 +265,8 @@ SRC_C = \
|
||||
lib/oofatfs/ff.c \
|
||||
lib/oofatfs/option/ccsbcs.c \
|
||||
lib/timeutils/timeutils.c \
|
||||
lib/tinyusb/src/portable/microchip/$(CHIP_FAMILY)/dcd.c \
|
||||
lib/tinyusb/src/portable/microchip/$(CHIP_FAMILY)/hal.c \
|
||||
lib/utils/buffer_helper.c \
|
||||
lib/utils/context_manager_helpers.c \
|
||||
lib/utils/interrupt_char.c \
|
||||
@ -282,7 +275,6 @@ SRC_C = \
|
||||
lib/utils/sys_stdio_mphal.c \
|
||||
lib/libc/string0.c \
|
||||
lib/mp-readline/readline.c \
|
||||
$(BUILD)/autogen_usb_descriptor.c \
|
||||
freetouch/adafruit_ptc.c \
|
||||
supervisor/shared/memory.c
|
||||
|
||||
@ -306,19 +298,6 @@ SRC_MOD += $(addprefix $(WIZNET5K_DIR)/,\
|
||||
endif # MICROPY_PY_WIZNET5K
|
||||
endif # MICROPY_PY_NETWORK
|
||||
|
||||
# Choose which flash filesystem impl to use.
|
||||
# (Right now INTERNAL_FLASH_FILESYSTEM and SPI_FLASH_FILESYSTEM are mutually exclusive.
|
||||
# But that might not be true in the future.)
|
||||
ifeq ($(INTERNAL_FLASH_FILESYSTEM),1)
|
||||
SRC_C += internal_flash.c
|
||||
endif
|
||||
ifeq ($(SPI_FLASH_FILESYSTEM),1)
|
||||
SRC_C += external_flash/external_flash.c external_flash/spi_flash.c
|
||||
endif
|
||||
ifeq ($(QSPI_FLASH_FILESYSTEM),1)
|
||||
SRC_C += external_flash/external_flash.c external_flash/qspi_flash.c
|
||||
endif
|
||||
|
||||
SRC_COMMON_HAL = \
|
||||
board/__init__.c \
|
||||
busio/__init__.c \
|
||||
@ -339,7 +318,6 @@ SRC_COMMON_HAL = \
|
||||
rotaryio/IncrementalEncoder.c \
|
||||
rtc/__init__.c \
|
||||
rtc/RTC.c \
|
||||
storage/__init__.c \
|
||||
supervisor/__init__.c \
|
||||
supervisor/Runtime.c \
|
||||
time/__init__.c \
|
||||
@ -352,10 +330,8 @@ SRC_COMMON_HAL = \
|
||||
pulseio/PulseIn.c \
|
||||
pulseio/PulseOut.c \
|
||||
pulseio/PWMOut.c \
|
||||
usb_hid/__init__.c \
|
||||
usb_hid/Device.c \
|
||||
touchio/__init__.c \
|
||||
touchio/TouchIn.c \
|
||||
touchio/TouchIn.c
|
||||
|
||||
ifeq ($(INTERNAL_LIBM),1)
|
||||
SRC_LIBM = $(addprefix lib/,\
|
||||
@ -412,12 +388,17 @@ SRC_SHARED_MODULE = \
|
||||
_stage/__init__.c \
|
||||
_stage/Layer.c \
|
||||
_stage/Text.c \
|
||||
storage/__init__.c \
|
||||
os/__init__.c \
|
||||
random/__init__.c \
|
||||
storage/__init__.c \
|
||||
struct/__init__.c \
|
||||
uheap/__init__.c \
|
||||
ustack/__init__.c
|
||||
ustack/__init__.c \
|
||||
usb_hid/__init__.c \
|
||||
usb_hid/Device.c
|
||||
|
||||
# usb_midi/__init__.c
|
||||
# usb_midi/Port.c
|
||||
|
||||
ifeq ($(MICROPY_PY_NETWORK),1)
|
||||
SRC_SHARED_MODULE += socket/__init__.c network/__init__.c
|
||||
@ -489,21 +470,6 @@ $(BUILD)/firmware.uf2: $(BUILD)/firmware.bin
|
||||
$(STEPECHO) "Create $@"
|
||||
$(Q)$(PYTHON3) $(TOP)/tools/uf2/utils/uf2conv.py -b $(BOOTLOADER_SIZE) -c -o $@ $^
|
||||
|
||||
$(BUILD)/autogen_usb_descriptor.c $(BUILD)/genhdr/autogen_usb_descriptor.h: autogen_usb_descriptor.intermediate
|
||||
|
||||
.INTERMEDIATE: autogen_usb_descriptor.intermediate
|
||||
|
||||
autogen_usb_descriptor.intermediate: tools/gen_usb_descriptor.py Makefile | $(HEADER_BUILD)
|
||||
$(STEPECHO) "GEN $@"
|
||||
$(Q)install -d $(BUILD)/genhdr
|
||||
$(Q)$(PYTHON3) tools/gen_usb_descriptor.py \
|
||||
--manufacturer $(USB_MANUFACTURER)\
|
||||
--product $(USB_PRODUCT)\
|
||||
--vid $(USB_VID)\
|
||||
--pid $(USB_PID)\
|
||||
--output_c_file $(BUILD)/autogen_usb_descriptor.c\
|
||||
--output_h_file $(BUILD)/genhdr/autogen_usb_descriptor.h
|
||||
|
||||
deploy: $(BUILD)/firmware.bin
|
||||
$(ECHO) "Writing $< to the board"
|
||||
$(BOSSAC) -u $<
|
||||
|
@ -27,8 +27,7 @@
|
||||
|
||||
#include "audio_dma.h"
|
||||
#include "tick.h"
|
||||
#include "usb.h"
|
||||
#include "usb_mass_storage.h"
|
||||
#include "supervisor/usb.h"
|
||||
|
||||
#include "shared-module/displayio/__init__.h"
|
||||
#include "shared-module/network/__init__.h"
|
||||
@ -45,8 +44,8 @@ void run_background_tasks(void) {
|
||||
#if MICROPY_PY_NETWORK
|
||||
network_module_background();
|
||||
#endif
|
||||
usb_msc_background();
|
||||
usb_cdc_background();
|
||||
usb_background();
|
||||
|
||||
last_finished_tick = ticks_ms;
|
||||
}
|
||||
|
||||
|
@ -30,13 +30,6 @@
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
gpio_set_pin_function(MICROPY_HW_LED_TX, GPIO_PIN_FUNCTION_OFF);
|
||||
gpio_set_pin_direction(MICROPY_HW_LED_TX, GPIO_DIRECTION_OUT);
|
||||
gpio_set_pin_level(MICROPY_HW_LED_TX, true);
|
||||
|
||||
gpio_set_pin_function(MICROPY_HW_LED_RX, GPIO_PIN_FUNCTION_OFF);
|
||||
gpio_set_pin_direction(MICROPY_HW_LED_RX, GPIO_DIRECTION_OUT);
|
||||
gpio_set_pin_level(MICROPY_HW_LED_RX, true);
|
||||
}
|
||||
|
||||
bool board_requests_safe_mode(void) {
|
||||
|
@ -1,16 +1,14 @@
|
||||
#define MICROPY_HW_BOARD_NAME "Arduino Zero"
|
||||
#define MICROPY_HW_MCU_NAME "samd21g18"
|
||||
|
||||
// #define MICROPY_HW_LED_MSC PIN_PA17 // red
|
||||
#define MICROPY_HW_LED_TX PIN_PA27
|
||||
#define MICROPY_HW_LED_RX PIN_PB03
|
||||
// #define MICROPY_HW_LED_MSC &pin_PA17 // red
|
||||
#define MICROPY_HW_LED_TX &pin_PA27
|
||||
#define MICROPY_HW_LED_RX &pin_PB03
|
||||
|
||||
#define MICROPY_PORT_A (PORT_PA24 | PORT_PA25 | PORT_PA27)
|
||||
#define MICROPY_PORT_B (PORT_PB03)
|
||||
#define MICROPY_PORT_C (0)
|
||||
|
||||
#include "internal_flash.h"
|
||||
|
||||
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000)
|
||||
|
@ -8,52 +8,25 @@
|
||||
#define SPI_FLASH_BAUDRATE (8000000)
|
||||
|
||||
// On-board flash
|
||||
#define SPI_FLASH_MOSI_PIN PIN_PA20
|
||||
#define SPI_FLASH_MISO_PIN PIN_PA16
|
||||
#define SPI_FLASH_SCK_PIN PIN_PA21
|
||||
#define SPI_FLASH_CS_PIN PIN_PB22
|
||||
|
||||
#define SPI_FLASH_MOSI_PIN_FUNCTION PINMUX_PA20D_SERCOM3_PAD2
|
||||
#define SPI_FLASH_MISO_PIN_FUNCTION PINMUX_PA16D_SERCOM3_PAD0
|
||||
#define SPI_FLASH_SCK_PIN_FUNCTION PINMUX_PA21D_SERCOM3_PAD3
|
||||
#define SPI_FLASH_SERCOM SERCOM3
|
||||
#define SPI_FLASH_SERCOM_INDEX 3
|
||||
#define SPI_FLASH_MOSI_PAD 2
|
||||
#define SPI_FLASH_MISO_PAD 0
|
||||
#define SPI_FLASH_SCK_PAD 3
|
||||
|
||||
// <o> Transmit Data Pinout
|
||||
// <0x0=>PAD[0,1]_DO_SCK
|
||||
// <0x1=>PAD[2,3]_DO_SCK
|
||||
// <0x2=>PAD[3,1]_DO_SCK
|
||||
// <0x3=>PAD[0,3]_DO_SCK
|
||||
#define SPI_FLASH_DOPO 1
|
||||
#define SPI_FLASH_DIPO 0 // same as MISO PAD
|
||||
#define SPI_FLASH_MOSI_PIN &pin_PA20
|
||||
#define SPI_FLASH_MISO_PIN &pin_PA16
|
||||
#define SPI_FLASH_SCK_PIN &pin_PA21
|
||||
#define SPI_FLASH_CS_PIN &pin_PB22
|
||||
|
||||
// These are pins not to reset.
|
||||
// PA24 and PA25 are USB.
|
||||
#define MICROPY_PORT_A (PORT_PA16 | PORT_PA20 | PORT_PA21 | PORT_PA24 | PORT_PA25)
|
||||
#define MICROPY_PORT_B (PORT_PB22)
|
||||
#define MICROPY_PORT_A (0)
|
||||
#define MICROPY_PORT_B (0)
|
||||
#define MICROPY_PORT_C (0)
|
||||
|
||||
#define SPEAKER_ENABLE_PIN (&pin_PA30)
|
||||
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
// If you change this, then make sure to update the linker scripts as well to
|
||||
// make sure you don't overwrite code.
|
||||
#define CIRCUITPY_INTERNAL_NVM_SIZE 256
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 2
|
||||
#define EXTERNAL_FLASH_DEVICES S25FL216K, \
|
||||
GD25Q16C
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
#define CALIBRATE_CRYSTALLESS 1
|
||||
|
||||
// Explanation of how a user got into safe mode.
|
||||
|
@ -5,6 +5,8 @@ USB_PRODUCT = "CircuitPlayground Express"
|
||||
USB_MANUFACTURER = "Adafruit Industries LLC"
|
||||
|
||||
SPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 2
|
||||
EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C"
|
||||
LONGINT_IMPL = MPZ
|
||||
|
||||
CHIP_VARIANT = SAMD21G18A
|
||||
|
@ -11,52 +11,24 @@
|
||||
#define SPI_FLASH_BAUDRATE (8000000)
|
||||
|
||||
// On-board flash
|
||||
#define SPI_FLASH_MOSI_PIN PIN_PA20
|
||||
#define SPI_FLASH_MISO_PIN PIN_PA16
|
||||
#define SPI_FLASH_SCK_PIN PIN_PA21
|
||||
#define SPI_FLASH_CS_PIN PIN_PB22
|
||||
|
||||
#define SPI_FLASH_MOSI_PIN_FUNCTION PINMUX_PA20D_SERCOM3_PAD2
|
||||
#define SPI_FLASH_MISO_PIN_FUNCTION PINMUX_PA16D_SERCOM3_PAD0
|
||||
#define SPI_FLASH_SCK_PIN_FUNCTION PINMUX_PA21D_SERCOM3_PAD3
|
||||
#define SPI_FLASH_SERCOM SERCOM3
|
||||
#define SPI_FLASH_SERCOM_INDEX 3
|
||||
#define SPI_FLASH_MOSI_PAD 2
|
||||
#define SPI_FLASH_MISO_PAD 0
|
||||
#define SPI_FLASH_SCK_PAD 3
|
||||
|
||||
// <o> Transmit Data Pinout
|
||||
// <0x0=>PAD[0,1]_DO_SCK
|
||||
// <0x1=>PAD[2,3]_DO_SCK
|
||||
// <0x2=>PAD[3,1]_DO_SCK
|
||||
// <0x3=>PAD[0,3]_DO_SCK
|
||||
#define SPI_FLASH_DOPO 1
|
||||
#define SPI_FLASH_DIPO 0 // same as MISO PAD
|
||||
#define SPI_FLASH_MOSI_PIN &pin_PA20
|
||||
#define SPI_FLASH_MISO_PIN &pin_PA16
|
||||
#define SPI_FLASH_SCK_PIN &pin_PA21
|
||||
#define SPI_FLASH_CS_PIN &pin_PB22
|
||||
|
||||
// These are pins not to reset.
|
||||
// PA24 and PA25 are USB.
|
||||
#define MICROPY_PORT_A (PORT_PA16 | PORT_PA20 | PORT_PA21 | PORT_PA24 | PORT_PA25)
|
||||
#define MICROPY_PORT_B (PORT_PB22)
|
||||
#define MICROPY_PORT_A (0)
|
||||
#define MICROPY_PORT_B (0)
|
||||
#define MICROPY_PORT_C (0)
|
||||
|
||||
#define SPEAKER_ENABLE_PIN (&pin_PA30)
|
||||
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
// If you change this, then make sure to update the linker scripts as well to
|
||||
// make sure you don't overwrite code.
|
||||
#define CIRCUITPY_INTERNAL_NVM_SIZE 256
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 2
|
||||
#define EXTERNAL_FLASH_DEVICES S25FL216K, \
|
||||
GD25Q16C
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
#define CALIBRATE_CRYSTALLESS 1
|
||||
|
||||
// Explanation of how a user got into safe mode.
|
||||
|
@ -5,6 +5,8 @@ USB_PRODUCT = "CircuitPlayground Express with Crickit libraries"
|
||||
USB_MANUFACTURER = "Adafruit Industries LLC"
|
||||
|
||||
SPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 2
|
||||
EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C"
|
||||
# Turn off longints for Crickit build to make room for additional frozen libs.
|
||||
LONGINT_IMPL = NONE
|
||||
|
||||
|
@ -3,12 +3,10 @@
|
||||
#define MICROPY_HW_BOARD_NAME "Adafruit Feather M0 Adalogger"
|
||||
#define MICROPY_HW_MCU_NAME "samd21g18"
|
||||
|
||||
#define MICROPY_PORT_A (PORT_PA24 | PORT_PA25)
|
||||
#define MICROPY_PORT_A (0)
|
||||
#define MICROPY_PORT_B (0)
|
||||
#define MICROPY_PORT_C (0)
|
||||
|
||||
#include "internal_flash.h"
|
||||
|
||||
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000)
|
||||
|
@ -4,12 +4,10 @@
|
||||
#define MICROPY_HW_BOARD_NAME "Adafruit Feather M0 Basic"
|
||||
#define MICROPY_HW_MCU_NAME "samd21g18"
|
||||
|
||||
#define MICROPY_PORT_A (PORT_PA24 | PORT_PA25)
|
||||
#define MICROPY_PORT_A (0)
|
||||
#define MICROPY_PORT_B (0)
|
||||
#define MICROPY_PORT_C (0)
|
||||
|
||||
#include "internal_flash.h"
|
||||
|
||||
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000)
|
||||
|
@ -3,35 +3,16 @@
|
||||
|
||||
#define MICROPY_HW_NEOPIXEL (&pin_PA06)
|
||||
|
||||
// Clock rates are off: Salae reads 12MHz which is the limit even though we set it to the safer 8MHz.
|
||||
#define SPI_FLASH_BAUDRATE (8000000)
|
||||
|
||||
#define SPI_FLASH_MOSI_PIN PIN_PA08
|
||||
#define SPI_FLASH_MISO_PIN PIN_PA14
|
||||
#define SPI_FLASH_SCK_PIN PIN_PA09
|
||||
#define SPI_FLASH_CS_PIN PIN_PA13
|
||||
#define SPI_FLASH_MOSI_PIN_FUNCTION PINMUX_PA08D_SERCOM2_PAD0
|
||||
#define SPI_FLASH_MISO_PIN_FUNCTION PINMUX_PA14C_SERCOM2_PAD2
|
||||
#define SPI_FLASH_SCK_PIN_FUNCTION PINMUX_PA09D_SERCOM2_PAD1
|
||||
#define SPI_FLASH_SERCOM SERCOM2
|
||||
#define SPI_FLASH_SERCOM_INDEX 2
|
||||
#define SPI_FLASH_MOSI_PAD 0
|
||||
#define SPI_FLASH_MISO_PAD 2
|
||||
#define SPI_FLASH_SCK_PAD 1
|
||||
// <o> Transmit Data Pinout
|
||||
// <0x0=>PAD[0,1]_DO_SCK
|
||||
// <0x1=>PAD[2,3]_DO_SCK
|
||||
// <0x2=>PAD[3,1]_DO_SCK
|
||||
// <0x3=>PAD[0,3]_DO_SCK
|
||||
#define SPI_FLASH_DOPO 0
|
||||
#define SPI_FLASH_DIPO 2 // same as MISO pad
|
||||
#define SPI_FLASH_MOSI_PIN &pin_PA08
|
||||
#define SPI_FLASH_MISO_PIN &pin_PA14
|
||||
#define SPI_FLASH_SCK_PIN &pin_PA09
|
||||
#define SPI_FLASH_CS_PIN &pin_PA13
|
||||
|
||||
// These are pins not to reset.
|
||||
#define MICROPY_PORT_A (PORT_PA06 | PORT_PA08 | PORT_PA09 | PORT_PA13 | PORT_PA14 | PORT_PA24 | PORT_PA25)
|
||||
#define MICROPY_PORT_A (PORT_PA06)
|
||||
#define MICROPY_PORT_B ( 0 )
|
||||
#define MICROPY_PORT_C ( 0 )
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
// If you change this, then make sure to update the linker scripts as well to
|
||||
// make sure you don't overwrite code.
|
||||
@ -39,14 +20,6 @@
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 2
|
||||
#define EXTERNAL_FLASH_DEVICES S25FL216K, \
|
||||
GD25Q16C
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
#define BOARD_HAS_CRYSTAL 1
|
||||
|
||||
#define DEFAULT_I2C_BUS_SCL (&pin_PA23)
|
||||
|
@ -5,6 +5,8 @@ USB_PRODUCT = "Feather M0 Express"
|
||||
USB_MANUFACTURER = "Adafruit Industries LLC"
|
||||
|
||||
SPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 2
|
||||
EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C"
|
||||
LONGINT_IMPL = MPZ
|
||||
|
||||
CHIP_VARIANT = SAMD21G18A
|
||||
|
@ -3,50 +3,22 @@
|
||||
|
||||
#define MICROPY_HW_NEOPIXEL (&pin_PA06)
|
||||
|
||||
// Clock rates are off: Salae reads 12MHz which is the limit even though we set it to the safer 8MHz.
|
||||
#define SPI_FLASH_BAUDRATE (8000000)
|
||||
|
||||
#define SPI_FLASH_MOSI_PIN PIN_PA08
|
||||
#define SPI_FLASH_MISO_PIN PIN_PA14
|
||||
#define SPI_FLASH_SCK_PIN PIN_PA09
|
||||
#define SPI_FLASH_CS_PIN PIN_PA13
|
||||
#define SPI_FLASH_MOSI_PIN_FUNCTION PINMUX_PA08D_SERCOM2_PAD0
|
||||
#define SPI_FLASH_MISO_PIN_FUNCTION PINMUX_PA14C_SERCOM2_PAD2
|
||||
#define SPI_FLASH_SCK_PIN_FUNCTION PINMUX_PA09D_SERCOM2_PAD1
|
||||
#define SPI_FLASH_SERCOM SERCOM2
|
||||
#define SPI_FLASH_SERCOM_INDEX 2
|
||||
#define SPI_FLASH_MOSI_PAD 0
|
||||
#define SPI_FLASH_MISO_PAD 2
|
||||
#define SPI_FLASH_SCK_PAD 1
|
||||
// <o> Transmit Data Pinout
|
||||
// <0x0=>PAD[0,1]_DO_SCK
|
||||
// <0x1=>PAD[2,3]_DO_SCK
|
||||
// <0x2=>PAD[3,1]_DO_SCK
|
||||
// <0x3=>PAD[0,3]_DO_SCK
|
||||
#define SPI_FLASH_DOPO 0
|
||||
#define SPI_FLASH_DIPO 2 // same as MISO pad
|
||||
#define SPI_FLASH_MOSI_PIN &pin_PA08
|
||||
#define SPI_FLASH_MISO_PIN &pin_PA14
|
||||
#define SPI_FLASH_SCK_PIN &pin_PA09
|
||||
#define SPI_FLASH_CS_PIN &pin_PA13
|
||||
|
||||
// These are pins not to reset.
|
||||
#define MICROPY_PORT_A (PORT_PA06 | PORT_PA08 | PORT_PA09 | PORT_PA13 | PORT_PA14 | PORT_PA24 | PORT_PA25)
|
||||
#define MICROPY_PORT_A (PORT_PA06)
|
||||
#define MICROPY_PORT_B ( 0 )
|
||||
#define MICROPY_PORT_C ( 0 )
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
// If you change this, then make sure to update the linker scripts as well to
|
||||
// make sure you don't overwrite code.
|
||||
#define CIRCUITPY_INTERNAL_NVM_SIZE 256
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 2
|
||||
#define EXTERNAL_FLASH_DEVICES S25FL216K, \
|
||||
GD25Q16C
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
#define BOARD_HAS_CRYSTAL 1
|
||||
|
||||
#define DEFAULT_I2C_BUS_SCL (&pin_PA23)
|
||||
|
@ -5,6 +5,8 @@ USB_PRODUCT = "Feather M0 Express"
|
||||
USB_MANUFACTURER = "Adafruit Industries LLC"
|
||||
|
||||
SPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 2
|
||||
EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C"
|
||||
LONGINT_IMPL = MPZ
|
||||
|
||||
CHIP_VARIANT = SAMD21G18A
|
||||
|
@ -4,12 +4,10 @@
|
||||
#define MICROPY_HW_BOARD_NAME "Adafruit Feather M0 RFM69"
|
||||
#define MICROPY_HW_MCU_NAME "samd21g18"
|
||||
|
||||
#define MICROPY_PORT_A (PORT_PA24 | PORT_PA25)
|
||||
#define MICROPY_PORT_A (0)
|
||||
#define MICROPY_PORT_B (0)
|
||||
#define MICROPY_PORT_C (0)
|
||||
|
||||
#include "internal_flash.h"
|
||||
|
||||
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000)
|
||||
|
@ -4,12 +4,10 @@
|
||||
#define MICROPY_HW_BOARD_NAME "Adafruit Feather M0 RFM9x"
|
||||
#define MICROPY_HW_MCU_NAME "samd21g18"
|
||||
|
||||
#define MICROPY_PORT_A (PORT_PA24 | PORT_PA25)
|
||||
#define MICROPY_PORT_A (0)
|
||||
#define MICROPY_PORT_B (0)
|
||||
#define MICROPY_PORT_C (0)
|
||||
|
||||
#include "internal_flash.h"
|
||||
|
||||
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000)
|
||||
|
@ -5,49 +5,22 @@
|
||||
|
||||
#define MICROPY_HW_NEOPIXEL (&pin_PA06)
|
||||
|
||||
// Clock rates are off: Salae reads 12MHz which is the limit even though we set it to the safer 8MHz.
|
||||
#define SPI_FLASH_BAUDRATE (8000000)
|
||||
|
||||
#define SPI_FLASH_MOSI_PIN PIN_PA08
|
||||
#define SPI_FLASH_MISO_PIN PIN_PA14
|
||||
#define SPI_FLASH_SCK_PIN PIN_PA09
|
||||
#define SPI_FLASH_CS_PIN PIN_PA13
|
||||
#define SPI_FLASH_MOSI_PIN_FUNCTION PINMUX_PA08D_SERCOM2_PAD0
|
||||
#define SPI_FLASH_MISO_PIN_FUNCTION PINMUX_PA14C_SERCOM2_PAD2
|
||||
#define SPI_FLASH_SCK_PIN_FUNCTION PINMUX_PA09D_SERCOM2_PAD1
|
||||
#define SPI_FLASH_SERCOM SERCOM2
|
||||
#define SPI_FLASH_SERCOM_INDEX 2
|
||||
#define SPI_FLASH_MOSI_PAD 0
|
||||
#define SPI_FLASH_MISO_PAD 2
|
||||
#define SPI_FLASH_SCK_PAD 1
|
||||
// <o> Transmit Data Pinout
|
||||
// <0x0=>PAD[0,1]_DO_SCK
|
||||
// <0x1=>PAD[2,3]_DO_SCK
|
||||
// <0x2=>PAD[3,1]_DO_SCK
|
||||
// <0x3=>PAD[0,3]_DO_SCK
|
||||
#define SPI_FLASH_DOPO 0
|
||||
#define SPI_FLASH_DIPO 2 // same as MISO pad
|
||||
#define SPI_FLASH_MOSI_PIN &pin_PA08
|
||||
#define SPI_FLASH_MISO_PIN &pin_PA14
|
||||
#define SPI_FLASH_SCK_PIN &pin_PA09
|
||||
#define SPI_FLASH_CS_PIN &pin_PA13
|
||||
|
||||
// These are pins not to reset.
|
||||
#define MICROPY_PORT_A (PORT_PA06 | PORT_PA08 | PORT_PA09 | PORT_PA13 | PORT_PA14 | PORT_PA24 | PORT_PA25)
|
||||
#define MICROPY_PORT_A (PORT_PA06)
|
||||
#define MICROPY_PORT_B ( 0 )
|
||||
#define MICROPY_PORT_C ( 0 )
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
// If you change this, then make sure to update the linker scripts as well to
|
||||
// make sure you don't overwrite code.
|
||||
#define CIRCUITPY_INTERNAL_NVM_SIZE 256
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 1
|
||||
#define EXTERNAL_FLASH_DEVICES S25FL064L
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
#define DEFAULT_I2C_BUS_SCL (&pin_PA23)
|
||||
#define DEFAULT_I2C_BUS_SDA (&pin_PA22)
|
||||
|
||||
|
@ -5,6 +5,8 @@ USB_PRODUCT = "Feather M0 Supersized"
|
||||
USB_MANUFACTURER = "Dave Astels"
|
||||
|
||||
SPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 1
|
||||
EXTERNAL_FLASH_DEVICES = "S25FL064L"
|
||||
LONGINT_IMPL = MPZ
|
||||
|
||||
CHIP_VARIANT = SAMD21G18A
|
||||
|
@ -23,15 +23,8 @@
|
||||
|
||||
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 1
|
||||
#define EXTERNAL_FLASH_DEVICES GD25Q16C
|
||||
|
||||
#define EXTERNAL_FLASH_QSPI_DUAL
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
#define BOARD_HAS_CRYSTAL 1
|
||||
|
||||
#define DEFAULT_I2C_BUS_SCL (&pin_PA13)
|
||||
|
@ -5,6 +5,9 @@ USB_PRODUCT = "Feather M4 Express"
|
||||
USB_MANUFACTURER = "Adafruit Industries LLC"
|
||||
|
||||
QSPI_FLASH_FILESYSTEM = 1
|
||||
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 1
|
||||
EXTERNAL_FLASH_DEVICES = GD25Q16C
|
||||
LONGINT_IMPL = MPZ
|
||||
|
||||
CHIP_VARIANT = SAMD51J19A
|
||||
|
@ -3,50 +3,22 @@
|
||||
|
||||
#define MICROPY_HW_NEOPIXEL (&pin_PA22)
|
||||
|
||||
// Clock rates are off: Salae reads 12MHz which is the limit even though we set it to the safer 8MHz.
|
||||
#define SPI_FLASH_BAUDRATE (8000000)
|
||||
|
||||
#define SPI_FLASH_MOSI_PIN PIN_PA31
|
||||
#define SPI_FLASH_MISO_PIN PIN_PA30
|
||||
#define SPI_FLASH_SCK_PIN PIN_PA17
|
||||
#define SPI_FLASH_CS_PIN PIN_PA28
|
||||
#define SPI_FLASH_MOSI_PIN_FUNCTION PINMUX_PA31D_SERCOM1_PAD3
|
||||
#define SPI_FLASH_MISO_PIN_FUNCTION PINMUX_PA30D_SERCOM1_PAD2
|
||||
#define SPI_FLASH_SCK_PIN_FUNCTION PINMUX_PA17C_SERCOM1_PAD1
|
||||
#define SPI_FLASH_SERCOM SERCOM1
|
||||
#define SPI_FLASH_SERCOM_INDEX 1
|
||||
#define SPI_FLASH_MOSI_PAD 3
|
||||
#define SPI_FLASH_MISO_PAD 2
|
||||
#define SPI_FLASH_SCK_PAD 1
|
||||
// <o> Transmit Data Pinout
|
||||
// <0x0=>PAD[0,1]_DO_SCK
|
||||
// <0x1=>PAD[2,3]_DO_SCK
|
||||
// <0x2=>PAD[3,1]_DO_SCK
|
||||
// <0x3=>PAD[0,3]_DO_SCK
|
||||
#define SPI_FLASH_DOPO 2
|
||||
#define SPI_FLASH_DIPO 2 // same as MISO pad
|
||||
#define SPI_FLASH_MOSI_PIN &pin_PA31
|
||||
#define SPI_FLASH_MISO_PIN &pin_PA30
|
||||
#define SPI_FLASH_SCK_PIN &pin_PA17
|
||||
#define SPI_FLASH_CS_PIN &pin_PA28
|
||||
|
||||
// These are pins not to reset.
|
||||
#define MICROPY_PORT_A (PORT_PA17 | PORT_PA22 | PORT_PA24 | PORT_PA25 | PORT_PA28 | PORT_PA30 | PORT_PA31)
|
||||
#define MICROPY_PORT_A (PORT_PA22)
|
||||
#define MICROPY_PORT_B ( 0 )
|
||||
#define MICROPY_PORT_C ( 0 )
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
// If you change this, then make sure to update the linker scripts as well to
|
||||
// make sure you don't overwrite code.
|
||||
#define CIRCUITPY_INTERNAL_NVM_SIZE 256
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 2
|
||||
#define EXTERNAL_FLASH_DEVICES S25FL216K, \
|
||||
GD25Q16C
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
#define BOARD_HAS_CRYSTAL 1
|
||||
|
||||
#define DEFAULT_I2C_BUS_SCL (&pin_PA13)
|
||||
|
@ -5,6 +5,8 @@ USB_PRODUCT = "Feather RadioFruit Zigbee"
|
||||
USB_MANUFACTURER = "Adafruit Industries LLC"
|
||||
|
||||
SPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 2
|
||||
EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C"
|
||||
LONGINT_IMPL = MPZ
|
||||
|
||||
CHIP_VARIANT = SAMR21G18A
|
||||
|
@ -18,8 +18,6 @@
|
||||
#define DEFAULT_UART_BUS_RX (&pin_PA05)
|
||||
#define DEFAULT_UART_BUS_TX (&pin_PA04)
|
||||
|
||||
#include "internal_flash.h"
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000)
|
||||
|
||||
#define IGNORE_PIN_PA03 1
|
||||
|
@ -29,13 +29,6 @@
|
||||
#include "hal/include/hal_gpio.h"
|
||||
|
||||
void board_init(void) {
|
||||
gpio_set_pin_function(MICROPY_HW_LED_TX, GPIO_PIN_FUNCTION_OFF);
|
||||
gpio_set_pin_direction(MICROPY_HW_LED_TX, GPIO_DIRECTION_OUT);
|
||||
gpio_set_pin_level(MICROPY_HW_LED_TX, true);
|
||||
|
||||
gpio_set_pin_function(MICROPY_HW_LED_RX, GPIO_PIN_FUNCTION_OFF);
|
||||
gpio_set_pin_direction(MICROPY_HW_LED_RX, GPIO_DIRECTION_OUT);
|
||||
gpio_set_pin_level(MICROPY_HW_LED_RX, true);
|
||||
}
|
||||
|
||||
bool board_requests_safe_mode(void) {
|
||||
|
@ -5,8 +5,8 @@
|
||||
|
||||
// This is for Rev A which is green
|
||||
|
||||
#define MICROPY_HW_LED_TX PIN_PC30
|
||||
#define MICROPY_HW_LED_RX PIN_PC31
|
||||
#define MICROPY_HW_LED_TX &(pin_PC30)
|
||||
#define MICROPY_HW_LED_RX &(pin_PC31)
|
||||
|
||||
#define MICROPY_HW_NEOPIXEL (&pin_PC24)
|
||||
|
||||
@ -27,13 +27,6 @@
|
||||
|
||||
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 1
|
||||
#define EXTERNAL_FLASH_DEVICES GD25Q64C
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
#define BOARD_HAS_CRYSTAL 1
|
||||
|
||||
#define DEFAULT_I2C_BUS_SCL (&pin_PB21)
|
||||
|
@ -5,6 +5,9 @@ USB_PRODUCT = "Grand Central M4 Express"
|
||||
USB_MANUFACTURER = "Adafruit Industries LLC"
|
||||
|
||||
QSPI_FLASH_FILESYSTEM = 1
|
||||
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 1
|
||||
EXTERNAL_FLASH_DEVICES = "GD25Q64C"
|
||||
LONGINT_IMPL = MPZ
|
||||
|
||||
CHIP_VARIANT = SAMD51P20A
|
||||
|
@ -3,51 +3,22 @@
|
||||
|
||||
#define MICROPY_HW_NEOPIXEL (&pin_PA12)
|
||||
|
||||
// Clock rates are off: Saleae reads 12MHz which is the limit even though we set it to the safer 8MHz.
|
||||
#define SPI_FLASH_BAUDRATE (8000000)
|
||||
|
||||
#define SPI_FLASH_MOSI_PIN PIN_PB10
|
||||
#define SPI_FLASH_MISO_PIN PIN_PA13
|
||||
#define SPI_FLASH_SCK_PIN PIN_PB11
|
||||
#define SPI_FLASH_CS_PIN PIN_PA07
|
||||
#define SPI_FLASH_MOSI_PIN_FUNCTION PINMUX_PB10D_SERCOM4_PAD2
|
||||
#define SPI_FLASH_MISO_PIN_FUNCTION PINMUX_PA13D_SERCOM4_PAD1
|
||||
#define SPI_FLASH_SCK_PIN_FUNCTION PINMUX_PB11D_SERCOM4_PAD3
|
||||
#define SPI_FLASH_SERCOM SERCOM4
|
||||
#define SPI_FLASH_SERCOM_INDEX 4
|
||||
#define SPI_FLASH_MOSI_PAD 2
|
||||
#define SPI_FLASH_MISO_PAD 1
|
||||
#define SPI_FLASH_SCK_PAD 3
|
||||
// <o> Transmit Data Pinout
|
||||
// <0x0=>PAD[0,1]_DO_SCK
|
||||
// <0x1=>PAD[2,3]_DO_SCK
|
||||
// <0x2=>PAD[3,1]_DO_SCK
|
||||
// <0x3=>PAD[0,3]_DO_SCK
|
||||
#define SPI_FLASH_DOPO 0x1
|
||||
#define SPI_FLASH_DIPO 1 // same as MISO pad
|
||||
#define SPI_FLASH_MOSI_PIN &pin_PB10
|
||||
#define SPI_FLASH_MISO_PIN &pin_PA13
|
||||
#define SPI_FLASH_SCK_PIN &pin_PB11
|
||||
#define SPI_FLASH_CS_PIN &pin_PA07
|
||||
|
||||
// These are pins not to reset.
|
||||
#define MICROPY_PORT_A ( PORT_PA01 | PORT_PA07 | PORT_PA12 | PORT_PA13 | PORT_PA24 | PORT_PA25 | PORT_PA27 | PORT_PA28)
|
||||
#define MICROPY_PORT_B ( PORT_PB10 | PORT_PB11 | PORT_PB22 | PORT_PB23 )
|
||||
#define MICROPY_PORT_A ( PORT_PA01 | PORT_PA12 | PORT_PA27 | PORT_PA28)
|
||||
#define MICROPY_PORT_B ( PORT_PB22 | PORT_PB23 )
|
||||
#define MICROPY_PORT_C ( 0 )
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
// If you change this, then make sure to update the linker scripts as well to
|
||||
// make sure you don't overwrite code.
|
||||
#define CIRCUITPY_INTERNAL_NVM_SIZE 256
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 2
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICES W25Q64JV_IQ, \
|
||||
GD25Q64C
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
#define DEFAULT_I2C_BUS_SCL (&pin_PA17)
|
||||
#define DEFAULT_I2C_BUS_SDA (&pin_PA16)
|
||||
|
||||
|
@ -5,6 +5,8 @@ USB_PRODUCT = "HalloWing M0 Express"
|
||||
USB_MANUFACTURER = "Adafruit Industries LLC"
|
||||
|
||||
SPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 2
|
||||
EXTERNAL_FLASH_DEVICES = "W25Q64JV_IQ, GD25Q64C"
|
||||
LONGINT_IMPL = MPZ
|
||||
|
||||
CHIP_VARIANT = SAMD21G18A
|
||||
|
@ -5,32 +5,14 @@
|
||||
#define MICROPY_HW_APA102_MOSI (&pin_PA01)
|
||||
#define MICROPY_HW_APA102_SCK (&pin_PA00)
|
||||
|
||||
// Saleae reads 12mhz which is the limit even though we set it to the safer 8mhz.
|
||||
#define SPI_FLASH_BAUDRATE (8000000)
|
||||
|
||||
#define SPI_FLASH_MOSI_PIN PIN_PB22
|
||||
#define SPI_FLASH_MISO_PIN PIN_PB03
|
||||
#define SPI_FLASH_SCK_PIN PIN_PB23
|
||||
#define SPI_FLASH_CS_PIN PIN_PA27
|
||||
#define SPI_FLASH_MOSI_PIN_FUNCTION PINMUX_PB22D_SERCOM5_PAD2
|
||||
#define SPI_FLASH_MISO_PIN_FUNCTION PINMUX_PB03D_SERCOM5_PAD1
|
||||
#define SPI_FLASH_SCK_PIN_FUNCTION PINMUX_PB23D_SERCOM5_PAD3
|
||||
#define SPI_FLASH_SERCOM SERCOM5
|
||||
#define SPI_FLASH_SERCOM_INDEX 5
|
||||
#define SPI_FLASH_MOSI_PAD 2
|
||||
#define SPI_FLASH_MISO_PAD 1
|
||||
#define SPI_FLASH_SCK_PAD 3
|
||||
// <o> Transmit Data Pinout
|
||||
// <0x0=>PAD[0,1]_DO_SCK
|
||||
// <0x1=>PAD[2,3]_DO_SCK
|
||||
// <0x2=>PAD[3,1]_DO_SCK
|
||||
// <0x3=>PAD[0,3]_DO_SCK
|
||||
#define SPI_FLASH_DOPO 1
|
||||
#define SPI_FLASH_DIPO 1 // same as MISO pad
|
||||
#define SPI_FLASH_MOSI_PIN &pin_PB22
|
||||
#define SPI_FLASH_MISO_PIN &pin_PB03
|
||||
#define SPI_FLASH_SCK_PIN &pin_PB23
|
||||
#define SPI_FLASH_CS_PIN &pin_PA27
|
||||
|
||||
// These are pins not to reset.
|
||||
#define MICROPY_PORT_A (PORT_PA00 | PORT_PA01 | PORT_PA27 | PORT_PA24 | PORT_PA25)
|
||||
#define MICROPY_PORT_B (PORT_PB22 | PORT_PB23 | PORT_PB03 )
|
||||
#define MICROPY_PORT_A (PORT_PA00 | PORT_PA01)
|
||||
#define MICROPY_PORT_B (0)
|
||||
#define MICROPY_PORT_C (0)
|
||||
|
||||
// If you change this, then make sure to update the linker scripts as well to
|
||||
@ -39,14 +21,6 @@
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 2
|
||||
#define EXTERNAL_FLASH_DEVICES W25Q16FW, \
|
||||
GD25Q16C
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
#define DEFAULT_I2C_BUS_SCL (&pin_PA23)
|
||||
#define DEFAULT_I2C_BUS_SDA (&pin_PA22)
|
||||
|
||||
|
@ -5,6 +5,8 @@ USB_PRODUCT = "ItsyBitsy M0 Express"
|
||||
USB_MANUFACTURER = "Adafruit Industries LLC"
|
||||
|
||||
SPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 2
|
||||
EXTERNAL_FLASH_DEVICES = "W25Q16FW, GD25Q16C"
|
||||
LONGINT_IMPL = MPZ
|
||||
|
||||
CHIP_VARIANT = SAMD21G18A
|
||||
|
@ -25,13 +25,6 @@
|
||||
|
||||
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 1
|
||||
#define EXTERNAL_FLASH_DEVICES GD25Q16C
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
#define DEFAULT_I2C_BUS_SCL (&pin_PA13)
|
||||
#define DEFAULT_I2C_BUS_SDA (&pin_PA12)
|
||||
|
||||
|
@ -5,6 +5,8 @@ USB_PRODUCT = "ItsyBitsy M4 Express"
|
||||
USB_MANUFACTURER = "Adafruit Industries LLC"
|
||||
|
||||
QSPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 1
|
||||
EXTERNAL_FLASH_DEVICES = GD25Q16C
|
||||
LONGINT_IMPL = MPZ
|
||||
|
||||
CHIP_VARIANT = SAMD51G19A
|
||||
|
@ -1,15 +1,11 @@
|
||||
#define MICROPY_HW_BOARD_NAME "Meow Meow"
|
||||
#define MICROPY_HW_MCU_NAME "samd21g18"
|
||||
|
||||
|
||||
// These are pins not to reset.
|
||||
// PA24 and PA25 are USB.
|
||||
#define MICROPY_PORT_A (PORT_PA24 | PORT_PA25)
|
||||
#define MICROPY_PORT_A (0)
|
||||
#define MICROPY_PORT_B (0)
|
||||
#define MICROPY_PORT_C (0)
|
||||
|
||||
#include "internal_flash.h"
|
||||
|
||||
// If you change this, then make sure to update the linker scripts as well to
|
||||
// make sure you don't overwrite code.
|
||||
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
|
||||
|
@ -1,37 +1,22 @@
|
||||
#define MICROPY_HW_BOARD_NAME "Adafruit Metro M0 Express"
|
||||
#define MICROPY_HW_MCU_NAME "samd21g18"
|
||||
|
||||
#define MICROPY_HW_LED_TX PIN_PA27
|
||||
//#define MICROPY_HW_LED_RX PIN_PA31
|
||||
//#define MICROPY_HW_LED_TX &pin_PA27
|
||||
//#define MICROPY_HW_LED_RX &pin_PA31
|
||||
|
||||
#define MICROPY_HW_NEOPIXEL (&pin_PA30)
|
||||
|
||||
// Clock rates are off: Salae reads 12MHz which is the limit even though we set it to the safer 8MHz.
|
||||
#define SPI_FLASH_BAUDRATE (8000000)
|
||||
|
||||
#define SPI_FLASH_MOSI_PIN PIN_PB22
|
||||
#define SPI_FLASH_MISO_PIN PIN_PB03
|
||||
#define SPI_FLASH_SCK_PIN PIN_PB23
|
||||
#define SPI_FLASH_CS_PIN PIN_PA13
|
||||
#define SPI_FLASH_MOSI_PIN_FUNCTION PINMUX_PB22D_SERCOM5_PAD2
|
||||
#define SPI_FLASH_MISO_PIN_FUNCTION PINMUX_PB03D_SERCOM5_PAD1
|
||||
#define SPI_FLASH_SCK_PIN_FUNCTION PINMUX_PB23D_SERCOM5_PAD3
|
||||
#define SPI_FLASH_SERCOM SERCOM5
|
||||
#define SPI_FLASH_SERCOM_INDEX 5
|
||||
#define SPI_FLASH_MOSI_PAD 2
|
||||
#define SPI_FLASH_MISO_PAD 1
|
||||
#define SPI_FLASH_SCK_PAD 3
|
||||
// <o> Transmit Data Pinout
|
||||
// <0x0=>PAD[0,1]_DO_SCK
|
||||
// <0x1=>PAD[2,3]_DO_SCK
|
||||
// <0x2=>PAD[3,1]_DO_SCK
|
||||
// <0x3=>PAD[0,3]_DO_SCK
|
||||
#define SPI_FLASH_DOPO 1
|
||||
#define SPI_FLASH_DIPO 1 // same as MISO pad
|
||||
#define SPI_FLASH_MOSI_PIN &pin_PB22
|
||||
#define SPI_FLASH_MISO_PIN &pin_PB03
|
||||
#define SPI_FLASH_SCK_PIN &pin_PB23
|
||||
#define SPI_FLASH_CS_PIN &pin_PA13
|
||||
|
||||
// These are pins not to reset.
|
||||
#define MICROPY_PORT_A (PORT_PA13 |PORT_PA24 | PORT_PA25 | PORT_PA27 | PORT_PA30 | PORT_PA31)
|
||||
#define MICROPY_PORT_B (PORT_PB03 | PORT_PB22 | PORT_PB23)
|
||||
#define MICROPY_PORT_A (PORT_PA24 | PORT_PA25 | PORT_PA30 | PORT_PA31)
|
||||
#define MICROPY_PORT_B (0)
|
||||
#define MICROPY_PORT_C (0)
|
||||
|
||||
// If you change this, then make sure to update the linker scripts as well to
|
||||
@ -40,14 +25,6 @@
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 2
|
||||
#define EXTERNAL_FLASH_DEVICES S25FL216K, \
|
||||
GD25Q16C
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
#define BOARD_HAS_CRYSTAL 1
|
||||
|
||||
#define DEFAULT_I2C_BUS_SCL (&pin_PA23)
|
||||
|
@ -12,3 +12,7 @@ CHIP_FAMILY = samd21
|
||||
|
||||
MICROPY_PY_NETWORK = 1
|
||||
MICROPY_PY_WIZNET5K = 5500
|
||||
|
||||
SPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 2
|
||||
EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C"
|
||||
|
@ -29,13 +29,6 @@
|
||||
#include "hal/include/hal_gpio.h"
|
||||
|
||||
void board_init(void) {
|
||||
gpio_set_pin_function(MICROPY_HW_LED_TX, GPIO_PIN_FUNCTION_OFF);
|
||||
gpio_set_pin_direction(MICROPY_HW_LED_TX, GPIO_DIRECTION_OUT);
|
||||
gpio_set_pin_level(MICROPY_HW_LED_TX, true);
|
||||
|
||||
gpio_set_pin_function(MICROPY_HW_LED_RX, GPIO_PIN_FUNCTION_OFF);
|
||||
gpio_set_pin_direction(MICROPY_HW_LED_RX, GPIO_DIRECTION_OUT);
|
||||
gpio_set_pin_level(MICROPY_HW_LED_RX, true);
|
||||
}
|
||||
|
||||
bool board_requests_safe_mode(void) {
|
||||
|
@ -5,16 +5,16 @@
|
||||
|
||||
// This is for Rev F which is green
|
||||
|
||||
#define MICROPY_HW_LED_TX PIN_PA27
|
||||
#define MICROPY_HW_LED_RX PIN_PB06
|
||||
#define MICROPY_HW_LED_TX (&pin_PA27)
|
||||
#define MICROPY_HW_LED_RX (&pin_PB06)
|
||||
|
||||
#define MICROPY_HW_NEOPIXEL (&pin_PB22)
|
||||
|
||||
// These are pins not to reset.
|
||||
// QSPI Data pins and TX LED
|
||||
#define MICROPY_PORT_A (PORT_PA08 | PORT_PA09 | PORT_PA10 | PORT_PA11 | PORT_PA27)
|
||||
// RX LED, QSPI CS, QSPI SCK and NeoPixel pin
|
||||
#define MICROPY_PORT_B ( PORT_PB06 | PORT_PB10 | PORT_PB11 | PORT_PB22)
|
||||
// QSPI Data pins
|
||||
#define MICROPY_PORT_A (PORT_PA08 | PORT_PA09 | PORT_PA10 | PORT_PA11)
|
||||
// QSPI CS, QSPI SCK and NeoPixel pin
|
||||
#define MICROPY_PORT_B (PORT_PB10 | PORT_PB11 | PORT_PB22)
|
||||
#define MICROPY_PORT_C (0)
|
||||
#define MICROPY_PORT_D (0)
|
||||
|
||||
@ -26,13 +26,6 @@
|
||||
|
||||
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 3
|
||||
#define EXTERNAL_FLASH_DEVICES S25FL116K, S25FL216K, GD25Q16C
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
#define BOARD_HAS_CRYSTAL 1
|
||||
|
||||
#define DEFAULT_I2C_BUS_SCL (&pin_PB03)
|
||||
|
@ -5,6 +5,9 @@ USB_PRODUCT = "Metro M4 Express"
|
||||
USB_MANUFACTURER = "Adafruit Industries LLC"
|
||||
|
||||
QSPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 3
|
||||
EXTERNAL_FLASH_DEVICES = "S25FL116K, S25FL216K, GD25Q16C"
|
||||
|
||||
LONGINT_IMPL = MPZ
|
||||
|
||||
CHIP_VARIANT = SAMD51J19A
|
||||
|
@ -15,8 +15,6 @@
|
||||
// A number of modules are removed for pIRKey to make room for frozen libraries.
|
||||
#define PIRKEY_M0 (1)
|
||||
|
||||
#include "internal_flash.h"
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000)
|
||||
|
||||
#define IGNORE_PIN_PA02 1
|
||||
|
@ -26,13 +26,6 @@
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 1
|
||||
#define EXTERNAL_FLASH_DEVICES GD25Q64C
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
#define DEFAULT_I2C_BUS_SCL (&pin_PB08)
|
||||
#define DEFAULT_I2C_BUS_SDA (&pin_PB09)
|
||||
|
||||
|
@ -5,6 +5,8 @@ USB_PRODUCT = "Trellis M4 Express"
|
||||
USB_MANUFACTURER = "Adafruit Industries LLC"
|
||||
|
||||
QSPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 1
|
||||
EXTERNAL_FLASH_DEVICES = GD25Q64C
|
||||
LONGINT_IMPL = MPZ
|
||||
|
||||
CHIP_VARIANT = SAMD51G19A
|
||||
|
@ -9,8 +9,6 @@
|
||||
#define MICROPY_PORT_B (0)
|
||||
#define MICROPY_PORT_C (0)
|
||||
|
||||
#include "internal_flash.h"
|
||||
|
||||
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000)
|
||||
|
@ -5,56 +5,24 @@
|
||||
// #define MICROPY_HW_APA102_MOSI (&pin_PA00)
|
||||
// #define MICROPY_HW_APA102_SCK (&pin_PA01)
|
||||
|
||||
// Salae reads 12mhz which is the limit even though we set it to the
|
||||
// safer 8mhz.
|
||||
#define SPI_FLASH_BAUDRATE (8000000)
|
||||
|
||||
#define SPI_FLASH_MOSI_PIN PIN_PA16
|
||||
#define SPI_FLASH_MISO_PIN PIN_PA19
|
||||
#define SPI_FLASH_SCK_PIN PIN_PA17
|
||||
#define SPI_FLASH_CS_PIN PIN_PA11
|
||||
#define SPI_FLASH_MOSI_PIN_FUNCTION PINMUX_PA16D_SERCOM3_PAD0
|
||||
#define SPI_FLASH_MISO_PIN_FUNCTION PINMUX_PA19D_SERCOM3_PAD3
|
||||
#define SPI_FLASH_SCK_PIN_FUNCTION PINMUX_PA17D_SERCOM3_PAD1
|
||||
#define SPI_FLASH_SERCOM SERCOM3
|
||||
#define SPI_FLASH_SERCOM_INDEX 3
|
||||
#define SPI_FLASH_MOSI_PAD 0
|
||||
#define SPI_FLASH_MISO_PAD 3
|
||||
#define SPI_FLASH_SCK_PAD 1
|
||||
// <o> Transmit Data Pinout
|
||||
// <0x0=>PAD[0,1]_DO_SCK
|
||||
// <0x1=>PAD[2,3]_DO_SCK
|
||||
// <0x2=>PAD[3,1]_DO_SCK
|
||||
// <0x3=>PAD[0,3]_DO_SCK
|
||||
#define SPI_FLASH_DOPO 0
|
||||
#define SPI_FLASH_DIPO 3 // same as MISO pad
|
||||
|
||||
#define SPI_FLASH_CS PIN_PA11
|
||||
#define SPI_FLASH_MOSI_PIN &pin_PA16
|
||||
#define SPI_FLASH_MISO_PIN &pin_PA19
|
||||
#define SPI_FLASH_SCK_PIN &pin_PA17
|
||||
#define SPI_FLASH_CS_PIN &pin_PA11
|
||||
|
||||
// These are pins not to reset.
|
||||
#define MICROPY_PORT_A (PORT_PA00 | PORT_PA01 | PORT_PA11 | PORT_PA16 |\
|
||||
PORT_PA17 | PORT_PA18 | PORT_PA19 | PORT_PA24 |\
|
||||
PORT_PA25)
|
||||
#define MICROPY_PORT_A (PORT_PA00 | PORT_PA01 | PORT_PA18)
|
||||
#define MICROPY_PORT_B (0)
|
||||
#define MICROPY_PORT_C (0)
|
||||
|
||||
#define CALIBRATE_CRYSTALLESS 1
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
// If you change this, then make sure to update the linker scripts as well to
|
||||
// make sure you don't overwrite code.
|
||||
#define CIRCUITPY_INTERNAL_NVM_SIZE 256
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 1
|
||||
#define EXTERNAL_FLASH_DEVICES W25Q32BV
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
#define DEFAULT_I2C_BUS_SCL (&pin_PA09)
|
||||
#define DEFAULT_I2C_BUS_SDA (&pin_PA08)
|
||||
|
||||
|
@ -5,6 +5,8 @@ USB_PRODUCT="Trinket M0 Haxpress"
|
||||
USB_MANUFACTURER="Radomir Dopieralski"
|
||||
|
||||
SPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 1
|
||||
EXTERNAL_FLASH_DEVICES = W25Q32BV
|
||||
LONGINT_IMPL = MPZ
|
||||
|
||||
CHIP_VARIANT = SAMD21E18A
|
||||
|
@ -1,53 +1,24 @@
|
||||
#define MICROPY_HW_BOARD_NAME "uGame10"
|
||||
#define MICROPY_HW_MCU_NAME "samd21e18"
|
||||
|
||||
// Salae reads 12mhz which is the limit even though we set it to the
|
||||
// safer 8mhz.
|
||||
#define SPI_FLASH_BAUDRATE (8000000)
|
||||
|
||||
#define SPI_FLASH_MOSI_PIN PIN_PA16
|
||||
#define SPI_FLASH_MISO_PIN PIN_PA19
|
||||
#define SPI_FLASH_SCK_PIN PIN_PA17
|
||||
#define SPI_FLASH_CS_PIN PIN_PA18
|
||||
#define SPI_FLASH_MOSI_PIN_FUNCTION PINMUX_PA16D_SERCOM3_PAD0
|
||||
#define SPI_FLASH_MISO_PIN_FUNCTION PINMUX_PA19D_SERCOM3_PAD3
|
||||
#define SPI_FLASH_SCK_PIN_FUNCTION PINMUX_PA17D_SERCOM3_PAD1
|
||||
#define SPI_FLASH_SERCOM SERCOM3
|
||||
#define SPI_FLASH_SERCOM_INDEX 3
|
||||
#define SPI_FLASH_MOSI_PAD 0
|
||||
#define SPI_FLASH_MISO_PAD 3
|
||||
#define SPI_FLASH_SCK_PAD 1
|
||||
// <o> Transmit Data Pinout
|
||||
// <0x0=>PAD[0,1]_DO_SCK
|
||||
// <0x1=>PAD[2,3]_DO_SCK
|
||||
// <0x2=>PAD[3,1]_DO_SCK
|
||||
// <0x3=>PAD[0,3]_DO_SCK
|
||||
#define SPI_FLASH_DOPO 0
|
||||
#define SPI_FLASH_DIPO 3 // same as MISO pad
|
||||
#define SPI_FLASH_MOSI_PIN &pin_PA16
|
||||
#define SPI_FLASH_MISO_PIN &pin_PA19
|
||||
#define SPI_FLASH_SCK_PIN &pin_PA17
|
||||
#define SPI_FLASH_CS_PIN &pin_PA18
|
||||
|
||||
// These are pins not to reset.
|
||||
#define MICROPY_PORT_A (PORT_PA16 | PORT_PA17 | PORT_PA18 | PORT_PA19 |\
|
||||
PORT_PA24 | PORT_PA25)
|
||||
#define MICROPY_PORT_A (0)
|
||||
#define MICROPY_PORT_B (0)
|
||||
#define MICROPY_PORT_C (0)
|
||||
|
||||
#define CALIBRATE_CRYSTALLESS 1
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
// If you change this, then make sure to update the linker scripts as well to
|
||||
// make sure you don't overwrite code.
|
||||
#define CIRCUITPY_INTERNAL_NVM_SIZE 256
|
||||
|
||||
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 1
|
||||
#define EXTERNAL_FLASH_DEVICES S25FL216K
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
||||
#define EXTRA_BUILTIN_MODULES \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_audioio), (mp_obj_t)&audioio_module }, \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_gamepad),(mp_obj_t)&gamepad_module }, \
|
||||
|
@ -6,6 +6,8 @@ USB_PRODUCT = "uGame10"
|
||||
USB_MANUFACTURER = "Radomir Dopieralski"
|
||||
|
||||
SPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 1
|
||||
EXTERNAL_FLASH_DEVICES = S25FL216K
|
||||
LONGINT_IMPL = MPZ
|
||||
|
||||
CHIP_VARIANT = SAMD21E18A
|
||||
|
@ -31,6 +31,8 @@
|
||||
#include "hpl_sercom_config.h"
|
||||
#include "peripheral_clk_config.h"
|
||||
|
||||
#include "boards/board.h"
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
#include "hal/include/hal_gpio.h"
|
||||
#include "hal/include/hal_spi_m_sync.h"
|
||||
#include "hal/include/hpl_spi_m_sync.h"
|
||||
@ -39,6 +41,43 @@
|
||||
#include "samd/dma.h"
|
||||
#include "samd/sercom.h"
|
||||
|
||||
bool never_reset_sercoms[SERCOM_INST_NUM];
|
||||
|
||||
void never_reset_sercom(Sercom* sercom) {
|
||||
// Reset all SERCOMs except the ones being used by on-board devices.
|
||||
Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS;
|
||||
for (int i = 0; i < SERCOM_INST_NUM; i++) {
|
||||
if (sercom_instances[i] == sercom) {
|
||||
never_reset_sercoms[i] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void reset_sercoms(void) {
|
||||
// Reset all SERCOMs except the ones being used by on-board devices.
|
||||
Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS;
|
||||
for (int i = 0; i < SERCOM_INST_NUM; i++) {
|
||||
if (never_reset_sercoms[i]) {
|
||||
continue;
|
||||
}
|
||||
#ifdef MICROPY_HW_APA102_SERCOM
|
||||
if (sercom_instances[i] == MICROPY_HW_APA102_SERCOM) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
#ifdef CIRCUITPY_DISPLAYIO
|
||||
// TODO(tannewt): Make this dynamic.
|
||||
if (sercom_instances[i] == board_display_obj.bus.spi_desc.dev.prvt) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
// SWRST is same for all modes of SERCOMs.
|
||||
sercom_instances[i]->SPI.CTRLA.bit.SWRST = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
||||
const mcu_pin_obj_t * clock, const mcu_pin_obj_t * mosi,
|
||||
const mcu_pin_obj_t * miso) {
|
||||
@ -186,6 +225,14 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
||||
spi_m_sync_enable(&self->spi_desc);
|
||||
}
|
||||
|
||||
void common_hal_busio_spi_never_reset(busio_spi_obj_t *self) {
|
||||
never_reset_sercom(self->spi_desc.dev.prvt);
|
||||
|
||||
never_reset_pin_number(self->clock_pin);
|
||||
never_reset_pin_number(self->MOSI_pin);
|
||||
never_reset_pin_number(self->MISO_pin);
|
||||
}
|
||||
|
||||
bool common_hal_busio_spi_deinited(busio_spi_obj_t *self) {
|
||||
return self->clock_pin == NO_PIN;
|
||||
}
|
||||
|
@ -42,4 +42,7 @@ typedef struct {
|
||||
uint8_t MISO_pin;
|
||||
} busio_spi_obj_t;
|
||||
|
||||
void reset_sercoms(void);
|
||||
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H
|
||||
|
@ -43,8 +43,12 @@ bool apa102_mosi_in_use;
|
||||
bool speaker_enable_in_use;
|
||||
#endif
|
||||
|
||||
#define PORT_COUNT (PORT_BITS / 32 + 1)
|
||||
|
||||
STATIC uint32_t never_reset_pins[PORT_COUNT];
|
||||
|
||||
void reset_all_pins(void) {
|
||||
uint32_t pin_mask[PORT_BITS / 32 + 1] = PORT_OUT_IMPLEMENTED;
|
||||
uint32_t pin_mask[PORT_COUNT] = PORT_OUT_IMPLEMENTED;
|
||||
|
||||
// Do not full reset USB or SWD lines.
|
||||
pin_mask[0] &= ~(PORT_PA24 | PORT_PA25 | PORT_PA30 | PORT_PA31);
|
||||
@ -53,6 +57,11 @@ void reset_all_pins(void) {
|
||||
pin_mask[0] &= ~(PORT_PA31);
|
||||
#endif
|
||||
|
||||
for (uint32_t i = 0; i < PORT_COUNT; i++) {
|
||||
pin_mask[i] &= ~(PORT_PA31);
|
||||
pin_mask[i] &= ~never_reset_pins[i];
|
||||
}
|
||||
|
||||
gpio_set_port_direction(GPIO_PORTA, pin_mask[0] & ~MICROPY_PORT_A, GPIO_DIRECTION_OFF);
|
||||
gpio_set_port_direction(GPIO_PORTB, pin_mask[1] & ~MICROPY_PORT_B, GPIO_DIRECTION_OFF);
|
||||
#if PORT_BITS > 64
|
||||
@ -91,6 +100,10 @@ void reset_all_pins(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void never_reset_pin_number(uint8_t pin_number) {
|
||||
never_reset_pins[GPIO_PORT(pin_number)] |= 1 << GPIO_PIN(pin_number);
|
||||
}
|
||||
|
||||
void reset_pin_number(uint8_t pin_number) {
|
||||
if (pin_number >= PORT_BITS) {
|
||||
return;
|
||||
|
@ -43,6 +43,7 @@ void reset_all_pins(void);
|
||||
// reset_pin_number takes the pin number instead of the pointer so that objects don't
|
||||
// need to store a full pointer.
|
||||
void reset_pin_number(uint8_t pin_number);
|
||||
void never_reset_pin_number(uint8_t pin_number);
|
||||
void claim_pin(const mcu_pin_obj_t* pin);
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_MICROCONTROLLER_PIN_H
|
||||
|
@ -107,7 +107,6 @@ const nvm_bytearray_obj_t common_hal_mcu_nvm_obj = {
|
||||
|
||||
// This maps MCU pin names to pin objects.
|
||||
STATIC const mp_rom_map_elem_t mcu_pin_global_dict_table[] = {
|
||||
// Pins in datasheet order.
|
||||
#if defined(PIN_PA00) && !defined(IGNORE_PIN_PA00)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA00), MP_ROM_PTR(&pin_PA00) },
|
||||
#endif
|
||||
@ -120,24 +119,6 @@ STATIC const mp_rom_map_elem_t mcu_pin_global_dict_table[] = {
|
||||
#if defined(PIN_PA03) && !defined(IGNORE_PIN_PA03)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA03), MP_ROM_PTR(&pin_PA03) },
|
||||
#endif
|
||||
#if defined(PIN_PB04) && !defined(IGNORE_PIN_PB04)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB04), MP_ROM_PTR(&pin_PB04) },
|
||||
#endif
|
||||
#if defined(PIN_PB05) && !defined(IGNORE_PIN_PB05)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB05), MP_ROM_PTR(&pin_PB05) },
|
||||
#endif
|
||||
#if defined(PIN_PB06) && !defined(IGNORE_PIN_PB06)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB06), MP_ROM_PTR(&pin_PB06) },
|
||||
#endif
|
||||
#if defined(PIN_PB07) && !defined(IGNORE_PIN_PB07)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB07), MP_ROM_PTR(&pin_PB07) },
|
||||
#endif
|
||||
#if defined(PIN_PB08) && !defined(IGNORE_PIN_PB08)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB08), MP_ROM_PTR(&pin_PB08) },
|
||||
#endif
|
||||
#if defined(PIN_PB09) && !defined(IGNORE_PIN_PB09)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB09), MP_ROM_PTR(&pin_PB09) },
|
||||
#endif
|
||||
#if defined(PIN_PA04) && !defined(IGNORE_PIN_PA04)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA04), MP_ROM_PTR(&pin_PA04) },
|
||||
#endif
|
||||
@ -162,26 +143,6 @@ STATIC const mp_rom_map_elem_t mcu_pin_global_dict_table[] = {
|
||||
#if defined(PIN_PA11) && !defined(IGNORE_PIN_PA11)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA11), MP_ROM_PTR(&pin_PA11) },
|
||||
#endif
|
||||
#if defined(PIN_PB10) && !defined(IGNORE_PIN_PB10)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB10), MP_ROM_PTR(&pin_PB10) },
|
||||
#endif
|
||||
#if defined(PIN_PB11) && !defined(IGNORE_PIN_PB11)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB11), MP_ROM_PTR(&pin_PB11) },
|
||||
#endif
|
||||
#if defined(PIN_PB12) && !defined(IGNORE_PIN_PB12)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB12), MP_ROM_PTR(&pin_PB12) },
|
||||
#endif
|
||||
#if defined(PIN_PB13) && !defined(IGNORE_PIN_PB13)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB13), MP_ROM_PTR(&pin_PB13) },
|
||||
#endif
|
||||
#if defined(PIN_PB14) && !defined(IGNORE_PIN_PB14)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB14), MP_ROM_PTR(&pin_PB14) },
|
||||
#endif
|
||||
|
||||
// Second page.
|
||||
#if defined(PIN_PB15) && !defined(IGNORE_PIN_PB15)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB15), MP_ROM_PTR(&pin_PB15) },
|
||||
#endif
|
||||
#if defined(PIN_PA12) && !defined(IGNORE_PIN_PA12)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA12), MP_ROM_PTR(&pin_PA12) },
|
||||
#endif
|
||||
@ -206,12 +167,6 @@ STATIC const mp_rom_map_elem_t mcu_pin_global_dict_table[] = {
|
||||
#if defined(PIN_PA19) && !defined(IGNORE_PIN_PA19)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA19), MP_ROM_PTR(&pin_PA19) },
|
||||
#endif
|
||||
#if defined(PIN_PB16) && !defined(IGNORE_PIN_PB16)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB16), MP_ROM_PTR(&pin_PB16) },
|
||||
#endif
|
||||
#if defined(PIN_PB17) && !defined(IGNORE_PIN_PB17)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB17), MP_ROM_PTR(&pin_PB17) },
|
||||
#endif
|
||||
#if defined(PIN_PA20) && !defined(IGNORE_PIN_PA20)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA20), MP_ROM_PTR(&pin_PA20) },
|
||||
#endif
|
||||
@ -230,12 +185,6 @@ STATIC const mp_rom_map_elem_t mcu_pin_global_dict_table[] = {
|
||||
#if defined(PIN_PA25) && !defined(IGNORE_PIN_PA25)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA25), MP_ROM_PTR(&pin_PA25) },
|
||||
#endif
|
||||
#if defined(PIN_PB22) && !defined(IGNORE_PIN_PB22)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB22), MP_ROM_PTR(&pin_PB22) },
|
||||
#endif
|
||||
#if defined(PIN_PB23) && !defined(IGNORE_PIN_PB23)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB23), MP_ROM_PTR(&pin_PB23) },
|
||||
#endif
|
||||
#if defined(PIN_PA27) && !defined(IGNORE_PIN_PA27)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA27), MP_ROM_PTR(&pin_PA27) },
|
||||
#endif
|
||||
@ -248,12 +197,7 @@ STATIC const mp_rom_map_elem_t mcu_pin_global_dict_table[] = {
|
||||
#if defined(PIN_PA31) && !defined(IGNORE_PIN_PA31)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PA31), MP_ROM_PTR(&pin_PA31) },
|
||||
#endif
|
||||
#if defined(PIN_PB30) && !defined(IGNORE_PIN_PB30)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB30), MP_ROM_PTR(&pin_PB30) },
|
||||
#endif
|
||||
#if defined(PIN_PB31) && !defined(IGNORE_PIN_PB31)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB31), MP_ROM_PTR(&pin_PB31) },
|
||||
#endif
|
||||
|
||||
#if defined(PIN_PB00) && !defined(IGNORE_PIN_PB00)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB00), MP_ROM_PTR(&pin_PB00) },
|
||||
#endif
|
||||
@ -266,14 +210,176 @@ STATIC const mp_rom_map_elem_t mcu_pin_global_dict_table[] = {
|
||||
#if defined(PIN_PB03) && !defined(IGNORE_PIN_PB03)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB03), MP_ROM_PTR(&pin_PB03) },
|
||||
#endif
|
||||
#if defined(PIN_PB04) && !defined(IGNORE_PIN_PB04)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB04), MP_ROM_PTR(&pin_PB04) },
|
||||
#endif
|
||||
#if defined(PIN_PB05) && !defined(IGNORE_PIN_PB05)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB05), MP_ROM_PTR(&pin_PB05) },
|
||||
#endif
|
||||
#if defined(PIN_PB06) && !defined(IGNORE_PIN_PB06)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB06), MP_ROM_PTR(&pin_PB06) },
|
||||
#endif
|
||||
#if defined(PIN_PB07) && !defined(IGNORE_PIN_PB07)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB07), MP_ROM_PTR(&pin_PB07) },
|
||||
#endif
|
||||
#if defined(PIN_PB08) && !defined(IGNORE_PIN_PB08)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB08), MP_ROM_PTR(&pin_PB08) },
|
||||
#endif
|
||||
#if defined(PIN_PB09) && !defined(IGNORE_PIN_PB09)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB09), MP_ROM_PTR(&pin_PB09) },
|
||||
#endif
|
||||
#if defined(PIN_PB10) && !defined(IGNORE_PIN_PB10)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB10), MP_ROM_PTR(&pin_PB10) },
|
||||
#endif
|
||||
#if defined(PIN_PB11) && !defined(IGNORE_PIN_PB11)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB11), MP_ROM_PTR(&pin_PB11) },
|
||||
#endif
|
||||
#if defined(PIN_PB12) && !defined(IGNORE_PIN_PB12)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB12), MP_ROM_PTR(&pin_PB12) },
|
||||
#endif
|
||||
#if defined(PIN_PB13) && !defined(IGNORE_PIN_PB13)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB13), MP_ROM_PTR(&pin_PB13) },
|
||||
#endif
|
||||
#if defined(PIN_PB14) && !defined(IGNORE_PIN_PB14)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB14), MP_ROM_PTR(&pin_PB14) },
|
||||
#endif
|
||||
#if defined(PIN_PB15) && !defined(IGNORE_PIN_PB15)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB15), MP_ROM_PTR(&pin_PB15) },
|
||||
#endif
|
||||
#if defined(PIN_PB16) && !defined(IGNORE_PIN_PB16)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB16), MP_ROM_PTR(&pin_PB16) },
|
||||
#endif
|
||||
#if defined(PIN_PB17) && !defined(IGNORE_PIN_PB17)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB17), MP_ROM_PTR(&pin_PB17) },
|
||||
#endif
|
||||
#if defined(PIN_PB22) && !defined(IGNORE_PIN_PB22)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB22), MP_ROM_PTR(&pin_PB22) },
|
||||
#endif
|
||||
#if defined(PIN_PB23) && !defined(IGNORE_PIN_PB23)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB23), MP_ROM_PTR(&pin_PB23) },
|
||||
#endif
|
||||
#if defined(PIN_PB30) && !defined(IGNORE_PIN_PB30)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB30), MP_ROM_PTR(&pin_PB30) },
|
||||
#endif
|
||||
#if defined(PIN_PB31) && !defined(IGNORE_PIN_PB31)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PB31), MP_ROM_PTR(&pin_PB31) },
|
||||
#endif
|
||||
|
||||
// These are SAMD51 specific so we assume we want them in RAM
|
||||
#if defined(PIN_PC00)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC00), MP_ROM_PTR(&pin_PC00) },
|
||||
#endif
|
||||
#if defined(PIN_PC01)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC01), MP_ROM_PTR(&pin_PC01) },
|
||||
#endif
|
||||
#if defined(PIN_PC02)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC02), MP_ROM_PTR(&pin_PC02) },
|
||||
#endif
|
||||
#if defined(PIN_PC03)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC03), MP_ROM_PTR(&pin_PC03) },
|
||||
#endif
|
||||
#if defined(PIN_PC04)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC04), MP_ROM_PTR(&pin_PC04) },
|
||||
#endif
|
||||
#if defined(PIN_PC05)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC05), MP_ROM_PTR(&pin_PC05) },
|
||||
#endif
|
||||
#if defined(PIN_PC06)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC06), MP_ROM_PTR(&pin_PC06) },
|
||||
#endif
|
||||
#if defined(PIN_PC07)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC07), MP_ROM_PTR(&pin_PC07) },
|
||||
#endif
|
||||
#if defined(PIN_PC10)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC10), MP_ROM_PTR(&pin_PC10) },
|
||||
#endif
|
||||
#if defined(PIN_PC11)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC11), MP_ROM_PTR(&pin_PC11) },
|
||||
#endif
|
||||
#if defined(PIN_PC12)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC12), MP_ROM_PTR(&pin_PC12) },
|
||||
#endif
|
||||
#if defined(PIN_PC13)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC13), MP_ROM_PTR(&pin_PC13) },
|
||||
#endif
|
||||
#if defined(PIN_PC14)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC14), MP_ROM_PTR(&pin_PC14) },
|
||||
#endif
|
||||
#if defined(PIN_PC15)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC15), MP_ROM_PTR(&pin_PC15) },
|
||||
#endif
|
||||
#if defined(PIN_PC16)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC16), MP_ROM_PTR(&pin_PC16) },
|
||||
#endif
|
||||
#if defined(PIN_PC17)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC17), MP_ROM_PTR(&pin_PC17) },
|
||||
#endif
|
||||
#if defined(PIN_PC18)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC18), MP_ROM_PTR(&pin_PC18) },
|
||||
#endif
|
||||
#if defined(PIN_PC19)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC19), MP_ROM_PTR(&pin_PC19) },
|
||||
#endif
|
||||
#if defined(PIN_PC20)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC20), MP_ROM_PTR(&pin_PC20) },
|
||||
#endif
|
||||
#if defined(PIN_PC21)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC21), MP_ROM_PTR(&pin_PC21) },
|
||||
#endif
|
||||
#if defined(PIN_PC22)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC22), MP_ROM_PTR(&pin_PC22) },
|
||||
#endif
|
||||
#if defined(PIN_PC23)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC23), MP_ROM_PTR(&pin_PC23) },
|
||||
#endif
|
||||
#if defined(PIN_PC24)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC24), MP_ROM_PTR(&pin_PC24) },
|
||||
#endif
|
||||
#if defined(PIN_PC25)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC25), MP_ROM_PTR(&pin_PC25) },
|
||||
#endif
|
||||
#if defined(PIN_PC26)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC26), MP_ROM_PTR(&pin_PC26) },
|
||||
#endif
|
||||
#if defined(PIN_PC27)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC27), MP_ROM_PTR(&pin_PC27) },
|
||||
#endif
|
||||
#if defined(PIN_PC28)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC28), MP_ROM_PTR(&pin_PC28) },
|
||||
#endif
|
||||
#if defined(PIN_PC30)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC30), MP_ROM_PTR(&pin_PC30) },
|
||||
#endif
|
||||
#if defined(PIN_PC31)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PC31), MP_ROM_PTR(&pin_PC31) },
|
||||
#endif
|
||||
|
||||
#if defined(PIN_PD00)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PD00), MP_ROM_PTR(&pin_PD00) },
|
||||
#endif
|
||||
#if defined(PIN_PD01)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_PD01) },
|
||||
#endif
|
||||
#if defined(PIN_PD08)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PD08), MP_ROM_PTR(&pin_PD08) },
|
||||
#endif
|
||||
#if defined(PIN_PD09)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PD09), MP_ROM_PTR(&pin_PD09) },
|
||||
#endif
|
||||
#if defined(PIN_PD10)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PD10), MP_ROM_PTR(&pin_PD10) },
|
||||
#endif
|
||||
#if defined(PIN_PD11)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PD11), MP_ROM_PTR(&pin_PD11) },
|
||||
#endif
|
||||
#if defined(PIN_PD12)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PD12), MP_ROM_PTR(&pin_PD12) },
|
||||
#endif
|
||||
#if defined(PIN_PD20)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PD20), MP_ROM_PTR(&pin_PD20) },
|
||||
#endif
|
||||
#if defined(PIN_PD21)
|
||||
{ MP_ROM_QSTR(MP_QSTR_PD21), MP_ROM_PTR(&pin_PD21) },
|
||||
#endif
|
||||
};
|
||||
MP_DEFINE_CONST_DICT(mcu_pin_globals, mcu_pin_global_dict_table);
|
||||
|
@ -26,13 +26,12 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "shared-bindings/supervisor/Runtime.h"
|
||||
#include "usb.h"
|
||||
#include "supervisor/serial.h"
|
||||
|
||||
bool common_hal_get_serial_connected(void) {
|
||||
return (bool) usb_connected();
|
||||
return (bool) serial_connected();
|
||||
}
|
||||
|
||||
bool common_hal_get_serial_bytes_available(void) {
|
||||
return (bool) usb_bytes_available();
|
||||
return (bool) serial_bytes_available();
|
||||
}
|
||||
|
||||
|
@ -1,106 +0,0 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 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 <string.h>
|
||||
|
||||
#include "common-hal/usb_hid/Device.h"
|
||||
|
||||
#include "py/runtime.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "shared-bindings/usb_hid/Device.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
#include "genhdr/autogen_usb_descriptor.h"
|
||||
|
||||
#include "tick.h"
|
||||
|
||||
#include "usb/class/hid/device/hiddf_generic.h"
|
||||
|
||||
static uint32_t usb_hid_send_report(usb_hid_device_obj_t *self, uint8_t* report, uint8_t len) {
|
||||
|
||||
int32_t status;
|
||||
|
||||
// Don't get stuck if USB fails in some way; timeout after a while.
|
||||
uint64_t end_ticks = ticks_ms + 2000;
|
||||
|
||||
while (ticks_ms < end_ticks) {
|
||||
status = usb_d_ep_get_status(self->endpoint, NULL);
|
||||
if (status == USB_BUSY) {
|
||||
continue;
|
||||
}
|
||||
if (status == USB_OK) {
|
||||
break;
|
||||
}
|
||||
// Some error. Give up.
|
||||
return status;
|
||||
}
|
||||
|
||||
// Copy the data only when endpoint is ready to send. The previous
|
||||
// buffer load gets zero'd out when transaction completes, so if
|
||||
// you copy before it's ready, only zeros will get sent.
|
||||
|
||||
// Prefix with a report id if one is supplied.
|
||||
if (self->report_id > 0) {
|
||||
self->report_buffer[0] = self->report_id;
|
||||
memcpy(&(self->report_buffer[1]), report, len);
|
||||
return hiddf_generic_write(self->report_buffer, len + 1);
|
||||
} else {
|
||||
memcpy(self->report_buffer, report, len);
|
||||
return hiddf_generic_write(self->report_buffer, len);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void common_hal_usb_hid_device_send_report(usb_hid_device_obj_t *self, uint8_t* report, uint8_t len) {
|
||||
if (len != self->report_length) {
|
||||
mp_raise_ValueError_varg(translate("Buffer incorrect size. Should be %d bytes."), self->report_length);
|
||||
}
|
||||
int32_t status = usb_hid_send_report(self, report, len);
|
||||
if (status != ERR_NONE) {
|
||||
mp_raise_msg(&mp_type_OSError, status == USB_BUSY ? translate("USB Busy") : translate("USB Error"));
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t common_hal_usb_hid_device_get_usage_page(usb_hid_device_obj_t *self) {
|
||||
return self->usage_page;
|
||||
}
|
||||
|
||||
uint8_t common_hal_usb_hid_device_get_usage(usb_hid_device_obj_t *self) {
|
||||
return self->usage;
|
||||
}
|
||||
|
||||
|
||||
void usb_hid_init() {
|
||||
}
|
||||
|
||||
void usb_hid_reset() {
|
||||
// We don't actually reset. We just set a report that is empty to prevent
|
||||
// long keypresses and such.
|
||||
uint8_t report[USB_HID_MAX_REPORT_LENGTH] = {0};
|
||||
|
||||
for (size_t i = 0; i < USB_HID_NUM_DEVICES; i++) {
|
||||
usb_hid_send_report(&usb_hid_devices[i], report, usb_hid_devices[i].report_length);
|
||||
}
|
||||
}
|
@ -1,152 +0,0 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 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 "py/obj.h"
|
||||
#include "py/mphal.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "common-hal/usb_hid/Device.h"
|
||||
|
||||
#include "shared-bindings/usb_hid/Device.h"
|
||||
|
||||
#include "genhdr/autogen_usb_descriptor.h"
|
||||
|
||||
// Buffers are report size + 1 to include the Report ID prefix byte if needed.
|
||||
#ifdef USB_HID_REPORT_ID_KEYBOARD
|
||||
static uint8_t keyboard_report_buffer[USB_HID_REPORT_LENGTH_KEYBOARD + 1];
|
||||
#endif
|
||||
#ifdef USB_HID_REPORT_ID_MOUSE
|
||||
static uint8_t mouse_report_buffer[USB_HID_REPORT_LENGTH_MOUSE + 1];
|
||||
#endif
|
||||
#ifdef USB_HID_REPORT_ID_CONSUMER
|
||||
static uint8_t consumer_report_buffer[USB_HID_REPORT_LENGTH_CONSUMER + 1];
|
||||
#endif
|
||||
#ifdef USB_HID_REPORT_ID_SYS_CONTROL
|
||||
static uint8_t sys_control_report_buffer[USB_HID_REPORT_LENGTH_SYS_CONTROL + 1];
|
||||
#endif
|
||||
#ifdef USB_HID_REPORT_ID_GAMEPAD
|
||||
static uint8_t gamepad_report_buffer[USB_HID_REPORT_LENGTH_GAMEPAD + 1];
|
||||
#endif
|
||||
#ifdef USB_HID_REPORT_ID_DIGITIZER
|
||||
static uint8_t digitizer_report_buffer[USB_HID_REPORT_LENGTH_DIGITIZER + 1];
|
||||
#endif
|
||||
|
||||
usb_hid_device_obj_t usb_hid_devices[USB_HID_NUM_DEVICES] = {
|
||||
#ifdef USB_HID_REPORT_ID_KEYBOARD
|
||||
{
|
||||
.base = { .type = &usb_hid_device_type },
|
||||
.report_buffer = keyboard_report_buffer,
|
||||
.endpoint = USB_HID_ENDPOINT_IN,
|
||||
.report_id = USB_HID_REPORT_ID_KEYBOARD,
|
||||
.report_length = USB_HID_REPORT_LENGTH_KEYBOARD,
|
||||
.usage_page = 0x01,
|
||||
.usage = 0x06,
|
||||
},
|
||||
#endif
|
||||
#ifdef USB_HID_REPORT_ID_MOUSE
|
||||
{
|
||||
.base = { .type = &usb_hid_device_type },
|
||||
.report_buffer = mouse_report_buffer,
|
||||
.endpoint = USB_HID_ENDPOINT_IN,
|
||||
.report_id = USB_HID_REPORT_ID_MOUSE,
|
||||
.report_length = USB_HID_REPORT_LENGTH_MOUSE,
|
||||
.usage_page = 0x01,
|
||||
.usage = 0x02,
|
||||
},
|
||||
#endif
|
||||
#ifdef USB_HID_REPORT_ID_CONSUMER
|
||||
{
|
||||
.base = { .type = &usb_hid_device_type },
|
||||
.report_buffer = consumer_report_buffer,
|
||||
.endpoint = USB_HID_ENDPOINT_IN,
|
||||
.report_id = USB_HID_REPORT_ID_CONSUMER,
|
||||
.report_length = USB_HID_REPORT_LENGTH_CONSUMER,
|
||||
.usage_page = 0x0C,
|
||||
.usage = 0x01,
|
||||
},
|
||||
#endif
|
||||
#ifdef USB_HID_REPORT_ID_SYS_CONTROL
|
||||
{
|
||||
.base = { .type = &usb_hid_device_type },
|
||||
.report_buffer = sys_control_report_buffer,
|
||||
.endpoint = USB_HID_ENDPOINT_IN,
|
||||
.report_id = USB_HID_REPORT_ID_SYS_CONTROL,
|
||||
.report_length = USB_HID_REPORT_LENGTH_SYS_CONTROL,
|
||||
.usage_page = 0x01,
|
||||
.usage = 0x80,
|
||||
},
|
||||
#endif
|
||||
#ifdef USB_HID_REPORT_ID_GAMEPAD
|
||||
{
|
||||
.base = { .type = &usb_hid_device_type },
|
||||
.report_buffer = gamepad_report_buffer,
|
||||
.endpoint = USB_HID_ENDPOINT_IN,
|
||||
.report_id = USB_HID_REPORT_ID_GAMEPAD,
|
||||
.report_length = USB_HID_REPORT_LENGTH_GAMEPAD,
|
||||
.usage_page = 0x01,
|
||||
.usage = 0x05,
|
||||
},
|
||||
#endif
|
||||
#ifdef USB_HID_REPORT_ID_DIGITIZER
|
||||
{
|
||||
.base = { .type = &usb_hid_device_type },
|
||||
.report_buffer = digitizer_report_buffer,
|
||||
.endpoint = USB_HID_ENDPOINT_IN,
|
||||
.report_id = USB_HID_REPORT_ID_DIGITIZER,
|
||||
.report_length = USB_HID_REPORT_LENGTH_DIGITIZER,
|
||||
.usage_page = 0x0D,
|
||||
.usage = 0x02,
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
mp_obj_tuple_t common_hal_usb_hid_devices = {
|
||||
.base = {
|
||||
.type = &mp_type_tuple,
|
||||
},
|
||||
.len = USB_HID_NUM_DEVICES,
|
||||
.items = {
|
||||
#if USB_HID_NUM_DEVICES >= 1
|
||||
(mp_obj_t) &usb_hid_devices[0],
|
||||
#endif
|
||||
#if USB_HID_NUM_DEVICES >= 2
|
||||
(mp_obj_t) &usb_hid_devices[1],
|
||||
#endif
|
||||
#if USB_HID_NUM_DEVICES >= 3
|
||||
(mp_obj_t) &usb_hid_devices[2],
|
||||
#endif
|
||||
#if USB_HID_NUM_DEVICES >= 4
|
||||
(mp_obj_t) &usb_hid_devices[3],
|
||||
#endif
|
||||
#if USB_HID_NUM_DEVICES >= 5
|
||||
(mp_obj_t) &usb_hid_devices[4],
|
||||
#endif
|
||||
#if USB_HID_NUM_DEVICES >= 6
|
||||
(mp_obj_t) &usb_hid_devices[5],
|
||||
#endif
|
||||
}
|
||||
};
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013, 2014 Damien P. George
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_EXTERNAL_FLASH_H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_EXTERNAL_FLASH_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "mpconfigport.h"
|
||||
|
||||
// We use this when we can allocate the whole cache in RAM.
|
||||
#define FLASH_ROOT_POINTERS \
|
||||
uint8_t** flash_ram_cache; \
|
||||
|
||||
// Erase sector size.
|
||||
#define SPI_FLASH_SECTOR_SIZE (0x1000 - 100)
|
||||
|
||||
// These are common across all NOR Flash.
|
||||
#define SPI_FLASH_ERASE_SIZE (1 << 12)
|
||||
#define SPI_FLASH_PAGE_SIZE (256)
|
||||
|
||||
#define SPI_FLASH_SYSTICK_MASK (0x1ff) // 512ms
|
||||
#define SPI_FLASH_IDLE_TICK(tick) (((tick) & SPI_FLASH_SYSTICK_MASK) == 2)
|
||||
|
||||
void external_flash_init(void);
|
||||
uint32_t external_flash_get_block_size(void);
|
||||
uint32_t external_flash_get_block_count(void);
|
||||
void external_flash_irq_handler(void);
|
||||
void external_flash_flush(void);
|
||||
bool external_flash_read_block(uint8_t *dest, uint32_t block);
|
||||
bool external_flash_write_block(const uint8_t *src, uint32_t block);
|
||||
|
||||
// these return 0 on success, non-zero on error
|
||||
mp_uint_t external_flash_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blocks);
|
||||
mp_uint_t external_flash_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks);
|
||||
|
||||
extern const struct _mp_obj_type_t external_flash_type;
|
||||
|
||||
struct _fs_user_mount_t;
|
||||
void flash_init_vfs(struct _fs_user_mount_t *vfs);
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_EXTERNAL_FLASH_H
|
@ -154,6 +154,7 @@ typedef long mp_off_t;
|
||||
#define CIRCUITPY_MCU_FAMILY samd21
|
||||
#define MICROPY_PY_SYS_PLATFORM "Atmel SAMD21"
|
||||
#define PORT_HEAP_SIZE (16384 + 4096)
|
||||
#define SPI_FLASH_MAX_BAUDRATE 8000000
|
||||
#define CIRCUITPY_DEFAULT_STACK_SIZE 4096
|
||||
#define MICROPY_CPYTHON_COMPAT (0)
|
||||
#define MICROPY_MODULE_WEAK_LINKS (0)
|
||||
@ -169,6 +170,7 @@ typedef long mp_off_t;
|
||||
#define CIRCUITPY_MCU_FAMILY samd51
|
||||
#define MICROPY_PY_SYS_PLATFORM "MicroChip SAMD51"
|
||||
#define PORT_HEAP_SIZE (0x20000) // 128KiB
|
||||
#define SPI_FLASH_MAX_BAUDRATE 24000000
|
||||
#define CIRCUITPY_DEFAULT_STACK_SIZE 8192
|
||||
#define MICROPY_CPYTHON_COMPAT (1)
|
||||
#define MICROPY_MODULE_WEAK_LINKS (1)
|
||||
@ -421,8 +423,13 @@ extern const struct _mp_obj_module_t wiznet_module;
|
||||
|
||||
#define MP_STATE_PORT MP_STATE_VM
|
||||
|
||||
void run_background_tasks(void);
|
||||
#define MICROPY_VM_HOOK_LOOP run_background_tasks();
|
||||
#define MICROPY_VM_HOOK_RETURN run_background_tasks();
|
||||
|
||||
#include "peripherals/samd/dma.h"
|
||||
|
||||
#include "supervisor/flash_root_pointers.h"
|
||||
#if MICROPY_PY_NETWORK
|
||||
#define NETWORK_ROOT_POINTERS mp_obj_list_t mod_network_nic_list;
|
||||
#else
|
||||
@ -438,9 +445,6 @@ extern const struct _mp_obj_module_t wiznet_module;
|
||||
mp_obj_t gamepad_singleton; \
|
||||
NETWORK_ROOT_POINTERS \
|
||||
|
||||
void run_background_tasks(void);
|
||||
#define MICROPY_VM_HOOK_LOOP run_background_tasks();
|
||||
#define MICROPY_VM_HOOK_RETURN run_background_tasks();
|
||||
|
||||
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
|
||||
#define CIRCUITPY_BOOT_OUTPUT_FILE "/boot_out.txt"
|
||||
|
@ -14,6 +14,6 @@ ifeq ($(LONGINT_IMPL),LONGLONG)
|
||||
MPY_TOOL_LONGINT_IMPL = -mlongint-impl=longlong
|
||||
endif
|
||||
|
||||
|
||||
INTERNAL_LIBM = 1
|
||||
|
||||
USB_SERIAL_NUMBER_LENGTH = 32
|
||||
|
@ -46,43 +46,9 @@
|
||||
#include "mphalport.h"
|
||||
#include "reset.h"
|
||||
#include "tick.h"
|
||||
#include "usb.h"
|
||||
|
||||
extern struct usart_module usart_instance;
|
||||
extern uint32_t common_hal_mcu_processor_get_frequency(void);
|
||||
|
||||
int mp_hal_stdin_rx_chr(void) {
|
||||
for (;;) {
|
||||
#ifdef MICROPY_VM_HOOK_LOOP
|
||||
MICROPY_VM_HOOK_LOOP
|
||||
#endif
|
||||
// if (reload_requested) {
|
||||
// return CHAR_CTRL_D;
|
||||
// }
|
||||
if (usb_bytes_available()) {
|
||||
#ifdef MICROPY_HW_LED_RX
|
||||
gpio_toggle_pin_level(MICROPY_HW_LED_RX);
|
||||
#endif
|
||||
return usb_read();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mp_hal_stdout_tx_strn(const char *str, size_t len) {
|
||||
#ifdef MICROPY_HW_LED_TX
|
||||
gpio_toggle_pin_level(MICROPY_HW_LED_TX);
|
||||
#endif
|
||||
|
||||
#ifdef CIRCUITPY_BOOT_OUTPUT_FILE
|
||||
if (boot_output_file != NULL) {
|
||||
UINT bytes_written = 0;
|
||||
f_write(boot_output_file, str, len, &bytes_written);
|
||||
}
|
||||
#endif
|
||||
|
||||
usb_write(str, len);
|
||||
}
|
||||
|
||||
void mp_hal_delay_ms(mp_uint_t delay) {
|
||||
uint64_t start_tick = ticks_ms;
|
||||
uint64_t duration = 0;
|
||||
|
@ -41,8 +41,6 @@ static inline mp_uint_t mp_hal_ticks_ms(void) {
|
||||
volatile uint8_t usb_rx_count;
|
||||
volatile bool mp_cdc_enabled;
|
||||
|
||||
FIL* boot_output_file;
|
||||
|
||||
int receive_usb(void);
|
||||
|
||||
void mp_hal_set_interrupt_char(int c);
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit d0dcba251c27f629c0a89b5ced4433dd0a609ca3
|
||||
Subproject commit f20fcf642b5654ee68d7d551ea7db39716ef83bf
|
@ -34,10 +34,6 @@ void reset(void) {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
void reset_to_bootloader(void) {
|
||||
_bootloader_dbl_tap = DBL_TAP_MAGIC;
|
||||
reset();
|
||||
}
|
||||
|
||||
extern uint32_t _srelocate;
|
||||
bool bootloader_available(void) {
|
||||
|
@ -23,7 +23,6 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#include "internal_flash.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
@ -42,9 +41,9 @@
|
||||
|
||||
#include "supervisor/shared/rgb_led_status.h"
|
||||
|
||||
static struct flash_descriptor internal_flash_desc;
|
||||
static struct flash_descriptor supervisor_flash_desc;
|
||||
|
||||
void internal_flash_init(void) {
|
||||
void supervisor_flash_init(void) {
|
||||
// Activity LED for flash writes.
|
||||
#ifdef MICROPY_HW_LED_MSC
|
||||
struct port_config pin_conf;
|
||||
@ -61,22 +60,22 @@ void internal_flash_init(void) {
|
||||
#ifdef SAMD21
|
||||
_pm_enable_bus_clock(PM_BUS_APBB, NVMCTRL);
|
||||
#endif
|
||||
flash_init(&internal_flash_desc, NVMCTRL);
|
||||
flash_init(&supervisor_flash_desc, NVMCTRL);
|
||||
}
|
||||
|
||||
uint32_t internal_flash_get_block_size(void) {
|
||||
uint32_t supervisor_flash_get_block_size(void) {
|
||||
return FILESYSTEM_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
uint32_t internal_flash_get_block_count(void) {
|
||||
uint32_t supervisor_flash_get_block_count(void) {
|
||||
return INTERNAL_FLASH_PART1_START_BLOCK + INTERNAL_FLASH_PART1_NUM_BLOCKS;
|
||||
}
|
||||
|
||||
void internal_flash_flush(void) {
|
||||
void supervisor_flash_flush(void) {
|
||||
}
|
||||
|
||||
void flash_flush(void) {
|
||||
internal_flash_flush();
|
||||
supervisor_flash_flush();
|
||||
}
|
||||
|
||||
static void build_partition(uint8_t *buf, int boot, int type, uint32_t start_block, uint32_t num_blocks) {
|
||||
@ -125,7 +124,7 @@ static int32_t convert_block_to_flash_addr(uint32_t block) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool internal_flash_read_block(uint8_t *dest, uint32_t block) {
|
||||
bool supervisor_flash_read_block(uint8_t *dest, uint32_t block) {
|
||||
if (block == 0) {
|
||||
// fake the MBR so we can decide on our own partition table
|
||||
|
||||
@ -150,12 +149,12 @@ bool internal_flash_read_block(uint8_t *dest, uint32_t block) {
|
||||
// bad block number
|
||||
return false;
|
||||
}
|
||||
int32_t error_code = flash_read(&internal_flash_desc, src, dest, FILESYSTEM_BLOCK_SIZE);
|
||||
int32_t error_code = flash_read(&supervisor_flash_desc, src, dest, FILESYSTEM_BLOCK_SIZE);
|
||||
return error_code == ERR_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
bool internal_flash_write_block(const uint8_t *src, uint32_t block) {
|
||||
bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) {
|
||||
if (block == 0) {
|
||||
// can't write MBR, but pretend we did
|
||||
return true;
|
||||
@ -172,14 +171,14 @@ bool internal_flash_write_block(const uint8_t *src, uint32_t block) {
|
||||
return false;
|
||||
}
|
||||
int32_t error_code;
|
||||
error_code = flash_erase(&internal_flash_desc,
|
||||
error_code = flash_erase(&supervisor_flash_desc,
|
||||
dest,
|
||||
FILESYSTEM_BLOCK_SIZE / flash_get_page_size(&internal_flash_desc));
|
||||
FILESYSTEM_BLOCK_SIZE / flash_get_page_size(&supervisor_flash_desc));
|
||||
if (error_code != ERR_NONE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
error_code = flash_append(&internal_flash_desc, dest, src, FILESYSTEM_BLOCK_SIZE);
|
||||
error_code = flash_append(&supervisor_flash_desc, dest, src, FILESYSTEM_BLOCK_SIZE);
|
||||
if (error_code != ERR_NONE) {
|
||||
return false;
|
||||
}
|
||||
@ -191,95 +190,20 @@ bool internal_flash_write_block(const uint8_t *src, uint32_t block) {
|
||||
}
|
||||
}
|
||||
|
||||
mp_uint_t internal_flash_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blocks) {
|
||||
mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blocks) {
|
||||
for (size_t i = 0; i < num_blocks; i++) {
|
||||
if (!internal_flash_read_block(dest + i * FILESYSTEM_BLOCK_SIZE, block_num + i)) {
|
||||
if (!supervisor_flash_read_block(dest + i * FILESYSTEM_BLOCK_SIZE, block_num + i)) {
|
||||
return 1; // error
|
||||
}
|
||||
}
|
||||
return 0; // success
|
||||
}
|
||||
|
||||
mp_uint_t internal_flash_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) {
|
||||
mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) {
|
||||
for (size_t i = 0; i < num_blocks; i++) {
|
||||
if (!internal_flash_write_block(src + i * FILESYSTEM_BLOCK_SIZE, block_num + i)) {
|
||||
if (!supervisor_flash_write_block(src + i * FILESYSTEM_BLOCK_SIZE, block_num + i)) {
|
||||
return 1; // error
|
||||
}
|
||||
}
|
||||
return 0; // success
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// MicroPython bindings
|
||||
//
|
||||
// Expose the flash as an object with the block protocol.
|
||||
|
||||
// there is a singleton Flash object
|
||||
STATIC const mp_obj_base_t internal_flash_obj = {&internal_flash_type};
|
||||
|
||||
STATIC mp_obj_t internal_flash_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// check arguments
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
|
||||
// return singleton object
|
||||
return (mp_obj_t)&internal_flash_obj;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t internal_flash_obj_readblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE);
|
||||
mp_uint_t ret = internal_flash_read_blocks(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / FILESYSTEM_BLOCK_SIZE);
|
||||
return MP_OBJ_NEW_SMALL_INT(ret);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(internal_flash_obj_readblocks_obj, internal_flash_obj_readblocks);
|
||||
|
||||
STATIC mp_obj_t internal_flash_obj_writeblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
|
||||
mp_uint_t ret = internal_flash_write_blocks(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / FILESYSTEM_BLOCK_SIZE);
|
||||
return MP_OBJ_NEW_SMALL_INT(ret);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(internal_flash_obj_writeblocks_obj, internal_flash_obj_writeblocks);
|
||||
|
||||
STATIC mp_obj_t internal_flash_obj_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) {
|
||||
mp_int_t cmd = mp_obj_get_int(cmd_in);
|
||||
switch (cmd) {
|
||||
case BP_IOCTL_INIT: internal_flash_init(); return MP_OBJ_NEW_SMALL_INT(0);
|
||||
case BP_IOCTL_DEINIT: internal_flash_flush(); return MP_OBJ_NEW_SMALL_INT(0); // TODO properly
|
||||
case BP_IOCTL_SYNC: internal_flash_flush(); return MP_OBJ_NEW_SMALL_INT(0);
|
||||
case BP_IOCTL_SEC_COUNT: return MP_OBJ_NEW_SMALL_INT(internal_flash_get_block_count());
|
||||
case BP_IOCTL_SEC_SIZE: return MP_OBJ_NEW_SMALL_INT(internal_flash_get_block_size());
|
||||
default: return mp_const_none;
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(internal_flash_obj_ioctl_obj, internal_flash_obj_ioctl);
|
||||
|
||||
STATIC const mp_rom_map_elem_t internal_flash_obj_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&internal_flash_obj_readblocks_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&internal_flash_obj_writeblocks_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&internal_flash_obj_ioctl_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(internal_flash_obj_locals_dict, internal_flash_obj_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t internal_flash_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_InternalFlash,
|
||||
.make_new = internal_flash_obj_make_new,
|
||||
.locals_dict = (mp_obj_t)&internal_flash_obj_locals_dict,
|
||||
};
|
||||
|
||||
void flash_init_vfs(fs_user_mount_t *vfs) {
|
||||
vfs->base.type = &mp_fat_vfs_type;
|
||||
vfs->flags |= FSUSER_NATIVE | FSUSER_HAVE_IOCTL;
|
||||
vfs->fatfs.drv = vfs;
|
||||
vfs->fatfs.part = 1; // flash filesystem lives on first partition
|
||||
vfs->readblocks[0] = (mp_obj_t)&internal_flash_obj_readblocks_obj;
|
||||
vfs->readblocks[1] = (mp_obj_t)&internal_flash_obj;
|
||||
vfs->readblocks[2] = (mp_obj_t)internal_flash_read_blocks; // native version
|
||||
vfs->writeblocks[0] = (mp_obj_t)&internal_flash_obj_writeblocks_obj;
|
||||
vfs->writeblocks[1] = (mp_obj_t)&internal_flash_obj;
|
||||
vfs->writeblocks[2] = (mp_obj_t)internal_flash_write_blocks; // native version
|
||||
vfs->u.ioctl[0] = (mp_obj_t)&internal_flash_obj_ioctl_obj;
|
||||
vfs->u.ioctl[1] = (mp_obj_t)&internal_flash_obj;
|
||||
}
|
31
ports/atmel-samd/supervisor/internal_flash_root_pointers.h
Normal file
31
ports/atmel-samd/supervisor/internal_flash_root_pointers.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries LLC
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_INTERNAL_FLASH_ROOT_POINTERS_H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_INTERNAL_FLASH_ROOT_POINTERS_H
|
||||
|
||||
#define FLASH_ROOT_POINTERS
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_INTERNAL_FLASH_ROOT_POINTERS_H
|
@ -32,7 +32,6 @@
|
||||
#include "hal/include/hal_delay.h"
|
||||
#include "hal/include/hal_gpio.h"
|
||||
#include "hal/include/hal_init.h"
|
||||
#include "hal/include/hal_usb_device.h"
|
||||
#include "hpl/gclk/hpl_gclk_base.h"
|
||||
#include "hpl/pm/hpl_pm_base.h"
|
||||
|
||||
@ -48,13 +47,13 @@
|
||||
#include "common-hal/audiobusio/PDMIn.h"
|
||||
#include "common-hal/audiobusio/I2SOut.h"
|
||||
#include "common-hal/audioio/AudioOut.h"
|
||||
#include "common-hal/busio/SPI.h"
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
#include "common-hal/pulseio/PulseIn.h"
|
||||
#include "common-hal/pulseio/PulseOut.h"
|
||||
#include "common-hal/pulseio/PWMOut.h"
|
||||
#include "common-hal/rtc/RTC.h"
|
||||
#include "common-hal/touchio/TouchIn.h"
|
||||
#include "common-hal/usb_hid/Device.h"
|
||||
#include "samd/cache.h"
|
||||
#include "samd/clocks.h"
|
||||
#include "samd/events.h"
|
||||
@ -62,8 +61,10 @@
|
||||
#include "samd/dma.h"
|
||||
#include "shared-bindings/rtc/__init__.h"
|
||||
#include "board_busses.h"
|
||||
#include "reset.h"
|
||||
#include "tick.h"
|
||||
#include "usb.h"
|
||||
|
||||
#include "tusb.h"
|
||||
|
||||
#ifdef CIRCUITPY_GAMEPAD_TICKS
|
||||
#include "shared-module/gamepad/__init__.h"
|
||||
@ -225,28 +226,7 @@ safe_mode_t port_init(void) {
|
||||
}
|
||||
|
||||
void reset_port(void) {
|
||||
// Reset all SERCOMs except the ones being used by on-board devices.
|
||||
Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS;
|
||||
for (int i = 0; i < SERCOM_INST_NUM; i++) {
|
||||
#ifdef SPI_FLASH_SERCOM
|
||||
if (sercom_instances[i] == SPI_FLASH_SERCOM) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
#ifdef MICROPY_HW_APA102_SERCOM
|
||||
if (sercom_instances[i] == MICROPY_HW_APA102_SERCOM) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
#ifdef CIRCUITPY_DISPLAYIO
|
||||
// TODO(tannewt): Make this dynamic.
|
||||
if (sercom_instances[i] == board_display_obj.bus.spi_desc.dev.prvt) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
// SWRST is same for all modes of SERCOMs.
|
||||
sercom_instances[i]->SPI.CTRLA.bit.SWRST = 1;
|
||||
}
|
||||
reset_sercoms();
|
||||
|
||||
#if defined(EXPRESS_BOARD) && !defined(__SAMR21G18A__)
|
||||
audio_dma_reset();
|
||||
@ -290,13 +270,16 @@ void reset_port(void) {
|
||||
// gpio_set_pin_function(PIN_PB15, GPIO_PIN_FUNCTION_M); // GCLK1, D6
|
||||
// #endif
|
||||
|
||||
usb_hid_reset();
|
||||
|
||||
if (usb_connected()) {
|
||||
if (tud_cdc_connected()) {
|
||||
save_usb_clock_calibration();
|
||||
}
|
||||
}
|
||||
|
||||
void reset_to_bootloader(void) {
|
||||
_bootloader_dbl_tap = DBL_TAP_MAGIC;
|
||||
reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Default interrupt handler for unused IRQs.
|
||||
*/
|
||||
|
@ -24,14 +24,15 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "spi_flash_api.h"
|
||||
#include "supervisor/spi_flash_api.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mpconfigboard.h" // for EXTERNAL_FLASH_QSPI_DUAL
|
||||
|
||||
#include "external_flash/common_commands.h"
|
||||
#include "supervisor/shared/external_flash/common_commands.h"
|
||||
#include "supervisor/shared/external_flash/qspi_flash.h"
|
||||
#include "samd/cache.h"
|
||||
#include "samd/dma.h"
|
||||
|
||||
@ -225,18 +226,7 @@ void spi_flash_init(void) {
|
||||
}
|
||||
|
||||
void spi_flash_init_device(const external_flash_device* device) {
|
||||
// Verify that QSPI mode is enabled.
|
||||
uint8_t status;
|
||||
spi_flash_read_command(CMD_READ_STATUS2, &status, 1);
|
||||
check_quad_enable(device);
|
||||
|
||||
// Bit 1 is Quad Enable
|
||||
if ((status & 0x2) == 0) {
|
||||
uint8_t full_status[2] = {0x0, 0x2};
|
||||
spi_flash_command(CMD_ENABLE_WRITE);
|
||||
if (device->write_status_register_split) {
|
||||
spi_flash_write_command(CMD_WRITE_STATUS_BYTE2, full_status + 1, 1);
|
||||
} else {
|
||||
spi_flash_write_command(CMD_WRITE_STATUS_BYTE1, full_status, 2);
|
||||
}
|
||||
}
|
||||
// TODO(tannewt): Adjust the speed for the found device.
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 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 <string.h>
|
||||
|
||||
#include "supervisor/serial.h"
|
||||
|
||||
#include "common-hal/usb_hid/Device.h"
|
||||
|
||||
#include "usb.h"
|
||||
#include "genhdr/autogen_usb_descriptor.h"
|
||||
|
||||
// Serial number as hex characters. This writes directly to the USB
|
||||
// descriptor.
|
||||
void load_serial_number(void) {
|
||||
char nibble_to_hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
#ifdef SAMD21
|
||||
uint32_t* addresses[4] = {(uint32_t *) 0x0080A00C, (uint32_t *) 0x0080A040,
|
||||
(uint32_t *) 0x0080A044, (uint32_t *) 0x0080A048};
|
||||
#endif
|
||||
#ifdef SAMD51
|
||||
uint32_t* addresses[4] = {(uint32_t *) 0x008061FC, (uint32_t *) 0x00806010,
|
||||
(uint32_t *) 0x00806014, (uint32_t *) 0x00806018};
|
||||
#endif
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 8; j++) {
|
||||
uint8_t nibble = (*(addresses[i]) >> j * 4) & 0xf;
|
||||
// Strings are UTF-16-LE encoded.
|
||||
serial_number[i * 16 + j * 2] = nibble_to_hex[nibble];
|
||||
serial_number[i * 16 + j * 2 + 1] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void serial_init(void) {
|
||||
load_serial_number();
|
||||
init_usb();
|
||||
usb_hid_init();
|
||||
}
|
||||
|
||||
bool serial_connected(void) {
|
||||
return usb_connected();
|
||||
}
|
||||
|
||||
char serial_read(void) {
|
||||
return usb_read();
|
||||
}
|
||||
|
||||
bool serial_bytes_available(void) {
|
||||
return usb_bytes_available();
|
||||
}
|
||||
|
||||
void serial_write(const char* text) {
|
||||
usb_write(text, strlen(text));
|
||||
}
|
59
ports/atmel-samd/supervisor/usb.c
Normal file
59
ports/atmel-samd/supervisor/usb.c
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017, 2018 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 "atmel_start_pins.h"
|
||||
#include "hpl/pm/hpl_pm_base.h"
|
||||
#include "hpl/gclk/hpl_gclk_base.h"
|
||||
#include "hal_gpio.h"
|
||||
|
||||
void init_usb_hardware(void) {
|
||||
#ifdef SAMD21
|
||||
_pm_enable_bus_clock(PM_BUS_APBB, USB);
|
||||
_pm_enable_bus_clock(PM_BUS_AHB, USB);
|
||||
_gclk_enable_channel(USB_GCLK_ID, GCLK_CLKCTRL_GEN_GCLK0_Val);
|
||||
#endif
|
||||
|
||||
#ifdef SAMD51
|
||||
hri_gclk_write_PCHCTRL_reg(GCLK, USB_GCLK_ID, GCLK_PCHCTRL_GEN_GCLK1_Val | GCLK_PCHCTRL_CHEN);
|
||||
hri_mclk_set_AHBMASK_USB_bit(MCLK);
|
||||
hri_mclk_set_APBBMASK_USB_bit(MCLK);
|
||||
#endif
|
||||
|
||||
gpio_set_pin_direction(PIN_PA24, GPIO_DIRECTION_OUT);
|
||||
gpio_set_pin_level(PIN_PA24, false);
|
||||
gpio_set_pin_pull_mode(PIN_PA24, GPIO_PULL_OFF);
|
||||
gpio_set_pin_direction(PIN_PA25, GPIO_DIRECTION_OUT);
|
||||
gpio_set_pin_level(PIN_PA25, false);
|
||||
gpio_set_pin_pull_mode(PIN_PA25, GPIO_PULL_OFF);
|
||||
#ifdef SAMD21
|
||||
gpio_set_pin_function(PIN_PA24, PINMUX_PA24G_USB_DM);
|
||||
gpio_set_pin_function(PIN_PA25, PINMUX_PA25G_USB_DP);
|
||||
#endif
|
||||
#ifdef SAMD51
|
||||
gpio_set_pin_function(PIN_PA24, PINMUX_PA24H_USB_DM);
|
||||
gpio_set_pin_function(PIN_PA25, PINMUX_PA25H_USB_DP);
|
||||
#endif
|
||||
}
|
@ -26,7 +26,7 @@
|
||||
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_TICK_H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_TICK_H
|
||||
|
||||
#include "mpconfigport.h"
|
||||
#include "py/mpconfig.h"
|
||||
|
||||
extern volatile uint64_t ticks_ms;
|
||||
|
||||
|
@ -1,326 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 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 "usb.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// We must include this early because it sets values used in the ASF4 includes
|
||||
// below.
|
||||
#include "py/mpconfig.h"
|
||||
|
||||
#include "hal/include/hal_gpio.h"
|
||||
#include "usb/class/cdc/device/cdcdf_acm.h"
|
||||
#include "usb/class/hid/device/hiddf_generic.h"
|
||||
#include "usb/class/composite/device/composite_desc.h"
|
||||
#include "usb/class/msc/device/mscdf.h"
|
||||
#include "peripheral_clk_config.h"
|
||||
#include "hpl/pm/hpl_pm_base.h"
|
||||
#include "hpl/gclk/hpl_gclk_base.h"
|
||||
|
||||
#include "lib/utils/interrupt_char.h"
|
||||
#include "genhdr/autogen_usb_descriptor.h"
|
||||
#include "reset.h"
|
||||
#include "usb_mass_storage.h"
|
||||
|
||||
#include "supervisor/shared/autoreload.h"
|
||||
|
||||
extern struct usbd_descriptors descriptor_bounds;
|
||||
|
||||
// Store received characters on our own so that we can filter control characters
|
||||
// and act immediately on CTRL-C for example.
|
||||
|
||||
// Receive buffer
|
||||
static uint8_t usb_rx_buf[USB_RX_BUF_SIZE];
|
||||
|
||||
// Receive buffer head
|
||||
static volatile uint8_t usb_rx_buf_head = 0;
|
||||
|
||||
// Receive buffer tail
|
||||
static volatile uint8_t usb_rx_buf_tail = 0;
|
||||
|
||||
// Number of bytes in receive buffer
|
||||
volatile uint8_t usb_rx_count = 0;
|
||||
|
||||
volatile bool mp_cdc_enabled = false;
|
||||
volatile bool usb_transmitting = false;
|
||||
|
||||
/** Ctrl endpoint buffer */
|
||||
COMPILER_ALIGNED(4) static uint8_t ctrl_buffer[64];
|
||||
|
||||
static void init_hardware(void) {
|
||||
#ifdef SAMD21
|
||||
_pm_enable_bus_clock(PM_BUS_APBB, USB);
|
||||
_pm_enable_bus_clock(PM_BUS_AHB, USB);
|
||||
_gclk_enable_channel(USB_GCLK_ID, GCLK_CLKCTRL_GEN_GCLK0_Val);
|
||||
#endif
|
||||
|
||||
#ifdef SAMD51
|
||||
hri_gclk_write_PCHCTRL_reg(GCLK, USB_GCLK_ID, CONF_GCLK_USB_SRC | GCLK_PCHCTRL_CHEN);
|
||||
hri_mclk_set_AHBMASK_USB_bit(MCLK);
|
||||
hri_mclk_set_APBBMASK_USB_bit(MCLK);
|
||||
#endif
|
||||
|
||||
usb_d_init();
|
||||
|
||||
gpio_set_pin_direction(PIN_PA24, GPIO_DIRECTION_OUT);
|
||||
gpio_set_pin_level(PIN_PA24, false);
|
||||
gpio_set_pin_pull_mode(PIN_PA24, GPIO_PULL_OFF);
|
||||
gpio_set_pin_direction(PIN_PA25, GPIO_DIRECTION_OUT);
|
||||
gpio_set_pin_level(PIN_PA25, false);
|
||||
gpio_set_pin_pull_mode(PIN_PA25, GPIO_PULL_OFF);
|
||||
#ifdef SAMD21
|
||||
gpio_set_pin_function(PIN_PA24, PINMUX_PA24G_USB_DM);
|
||||
gpio_set_pin_function(PIN_PA25, PINMUX_PA25G_USB_DP);
|
||||
#endif
|
||||
#ifdef SAMD51
|
||||
gpio_set_pin_function(PIN_PA24, PINMUX_PA24H_USB_DM);
|
||||
gpio_set_pin_function(PIN_PA25, PINMUX_PA25H_USB_DP);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define CDC_BULKOUT_SIZE CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_MAXPKSZ
|
||||
COMPILER_ALIGNED(4) uint8_t cdc_packet_buffer[CDC_BULKOUT_SIZE];
|
||||
static volatile bool pending_read;
|
||||
|
||||
static int32_t start_read(void) {
|
||||
pending_read = true;
|
||||
int32_t result = cdcdf_acm_read(cdc_packet_buffer, CDC_BULKOUT_SIZE);
|
||||
if (result != ERR_NONE) {
|
||||
pending_read = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool read_complete(const uint8_t ep, const enum usb_xfer_code rc, const uint32_t count) {
|
||||
if (rc != USB_XFER_DONE) {
|
||||
return false; // No errors.
|
||||
}
|
||||
pending_read = false;
|
||||
volatile hal_atomic_t flags;
|
||||
atomic_enter_critical(&flags);
|
||||
// If our buffer can't fit the data received, then error out.
|
||||
if (count > (uint8_t) (USB_RX_BUF_SIZE - usb_rx_count)) {
|
||||
atomic_leave_critical(&flags);
|
||||
return true;
|
||||
}
|
||||
|
||||
for (uint16_t i = 0; i < count; i++) {
|
||||
uint8_t c = cdc_packet_buffer[i];
|
||||
if (c == mp_interrupt_char) {
|
||||
mp_keyboard_interrupt();
|
||||
// If interrupted, flush all the input.
|
||||
usb_rx_count = 0;
|
||||
usb_rx_buf_head = 0;
|
||||
usb_rx_buf_tail = 0;
|
||||
break;
|
||||
} else {
|
||||
// The count of characters present in receive buffer is
|
||||
// incremented.
|
||||
usb_rx_count++;
|
||||
usb_rx_buf[usb_rx_buf_tail] = c;
|
||||
usb_rx_buf_tail++;
|
||||
if (usb_rx_buf_tail == USB_RX_BUF_SIZE) {
|
||||
// Reached the end of buffer, revert back to beginning of
|
||||
// buffer.
|
||||
usb_rx_buf_tail = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
atomic_leave_critical(&flags);
|
||||
|
||||
/* No error. */
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool write_complete(const uint8_t ep,
|
||||
const enum usb_xfer_code rc,
|
||||
const uint32_t count) {
|
||||
if (rc != USB_XFER_DONE) {
|
||||
return false; // No errors.
|
||||
}
|
||||
// This is called after writes are finished.
|
||||
|
||||
usb_transmitting = false;
|
||||
|
||||
/* No error. */
|
||||
return false;
|
||||
}
|
||||
|
||||
volatile bool reset_on_disconnect = false;
|
||||
volatile bool cdc_connected = false;
|
||||
|
||||
static bool usb_device_cb_state_c(usb_cdc_control_signal_t state)
|
||||
{
|
||||
cdc_connected = state.rs232.DTR;
|
||||
if (state.rs232.DTR) {
|
||||
} else if (!state.rs232.DTR && reset_on_disconnect) {
|
||||
reset_to_bootloader();
|
||||
}
|
||||
|
||||
/* No error. */
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool usb_device_cb_line_coding_c(const usb_cdc_line_coding_t* coding)
|
||||
{
|
||||
reset_on_disconnect = coding->dwDTERate == 1200;
|
||||
/* Ok to change. */
|
||||
return true;
|
||||
}
|
||||
|
||||
void init_usb(void) {
|
||||
init_hardware();
|
||||
|
||||
mp_cdc_enabled = false;
|
||||
|
||||
usbdc_init(ctrl_buffer);
|
||||
|
||||
/* usbdc_register_function inside */
|
||||
cdcdf_acm_init();
|
||||
pending_read = false;
|
||||
|
||||
mscdf_init(1);
|
||||
mscdf_register_callback(MSCDF_CB_INQUIRY_DISK, (FUNC_PTR)usb_msc_inquiry_info);
|
||||
mscdf_register_callback(MSCDF_CB_GET_DISK_CAPACITY, (FUNC_PTR)usb_msc_get_capacity);
|
||||
mscdf_register_callback(MSCDF_CB_START_READ_DISK, (FUNC_PTR)usb_msc_new_read);
|
||||
mscdf_register_callback(MSCDF_CB_START_WRITE_DISK, (FUNC_PTR)usb_msc_new_write);
|
||||
mscdf_register_callback(MSCDF_CB_EJECT_DISK, (FUNC_PTR)usb_msc_disk_eject);
|
||||
mscdf_register_callback(MSCDF_CB_TEST_DISK_READY, (FUNC_PTR)usb_msc_disk_is_ready);
|
||||
mscdf_register_callback(MSCDF_CB_XFER_BLOCKS_DONE, (FUNC_PTR)usb_msc_xfer_done);
|
||||
mscdf_register_callback(MSCDF_CB_IS_WRITABLE, (FUNC_PTR)usb_msc_disk_is_writable);
|
||||
|
||||
hiddf_generic_init(hid_report_descriptor, sizeof(hid_report_descriptor));
|
||||
|
||||
usbdc_start(&descriptor_bounds);
|
||||
|
||||
usbdc_attach();
|
||||
|
||||
|
||||
}
|
||||
|
||||
static bool cdc_enabled(void) {
|
||||
if (!cdcdf_acm_is_enabled()) {
|
||||
mp_cdc_enabled = false;
|
||||
return false;
|
||||
}
|
||||
if (!mp_cdc_enabled) {
|
||||
cdcdf_acm_register_callback(CDCDF_ACM_CB_READ, (FUNC_PTR)read_complete);
|
||||
cdcdf_acm_register_callback(CDCDF_ACM_CB_WRITE, (FUNC_PTR)write_complete);
|
||||
cdcdf_acm_register_callback(CDCDF_ACM_CB_STATE_C, (FUNC_PTR)usb_device_cb_state_c);
|
||||
cdcdf_acm_register_callback(CDCDF_ACM_CB_LINE_CODING_C, (FUNC_PTR)usb_device_cb_line_coding_c);
|
||||
mp_cdc_enabled = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool usb_bytes_available(void) {
|
||||
// Check if the buffer has data, but not enough
|
||||
// space to hold another read.
|
||||
if (usb_rx_count > USB_RX_BUF_SIZE - CDC_BULKOUT_SIZE) {
|
||||
return true;
|
||||
}
|
||||
// Buffer has enough room
|
||||
if (cdc_enabled() && !pending_read) {
|
||||
start_read();
|
||||
}
|
||||
// Buffer is empty and/or no new data is available
|
||||
if (usb_rx_count == 0) {
|
||||
return false;
|
||||
}
|
||||
return usb_rx_count > 0;
|
||||
}
|
||||
|
||||
int usb_read(void) {
|
||||
if (!cdc_enabled() || usb_rx_count == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Copy from head.
|
||||
int data;
|
||||
CRITICAL_SECTION_ENTER();
|
||||
data = usb_rx_buf[usb_rx_buf_head];
|
||||
usb_rx_buf_head++;
|
||||
usb_rx_count--;
|
||||
if (usb_rx_buf_head == USB_RX_BUF_SIZE) {
|
||||
usb_rx_buf_head = 0;
|
||||
}
|
||||
CRITICAL_SECTION_LEAVE();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// TODO(tannewt): See if we can disable the internal CDC IN cache since we
|
||||
// we manage this one ourselves.
|
||||
#define CDC_BULKIN_SIZE CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_MAXPKSZ
|
||||
COMPILER_ALIGNED(4) uint8_t cdc_output_buffer[CDC_BULKIN_SIZE];
|
||||
|
||||
void usb_write(const char* buffer, uint32_t len) {
|
||||
if (!cdc_enabled()) {
|
||||
return;
|
||||
}
|
||||
if (!cdc_connected) {
|
||||
// TODO(tannewt): Should we write to a file instead?
|
||||
return;
|
||||
}
|
||||
uint8_t * output_buffer;
|
||||
uint32_t output_len;
|
||||
while (len > 0) {
|
||||
while (usb_transmitting) {}
|
||||
output_buffer = (uint8_t *) buffer;
|
||||
output_len = len;
|
||||
// Use our own cache in two different cases:
|
||||
// * When we're at the end of a transmission and we'll return before
|
||||
// the given buffer is actually transferred to the USB device.
|
||||
// * When our given buffer isn't aligned on word boundaries.
|
||||
if (output_len <= CDC_BULKIN_SIZE || ((uint32_t) buffer) % 4 != 0) {
|
||||
output_buffer = cdc_output_buffer;
|
||||
output_len = output_len > CDC_BULKIN_SIZE ? CDC_BULKIN_SIZE : output_len;
|
||||
memcpy(cdc_output_buffer, buffer, output_len);
|
||||
} else {
|
||||
output_len = CDC_BULKIN_SIZE;
|
||||
}
|
||||
usb_transmitting = true;
|
||||
cdcdf_acm_write(output_buffer, output_len);
|
||||
buffer += output_len * sizeof(char);
|
||||
len -= output_len;
|
||||
}
|
||||
}
|
||||
|
||||
bool usb_connected(void) {
|
||||
return cdc_enabled();
|
||||
}
|
||||
|
||||
// Poll for input if keyboard interrupts are enabled,
|
||||
// so that we can check for the interrupt char. read_complete() does the checking.
|
||||
// also make sure we have enough room in the local buffer
|
||||
void usb_cdc_background() {
|
||||
//
|
||||
if (mp_interrupt_char != -1 && cdc_enabled() && !pending_read && (usb_rx_count < USB_RX_BUF_SIZE - CDC_BULKOUT_SIZE)) {
|
||||
start_read();
|
||||
}
|
||||
}
|
@ -1,338 +0,0 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 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 <string.h>
|
||||
|
||||
#include "usb_mass_storage.h"
|
||||
#include "supervisor/shared/autoreload.h"
|
||||
|
||||
#include "hal/utils/include/err_codes.h"
|
||||
#include "hal/utils/include/utils.h"
|
||||
#include "usb/class/msc/device/mscdf.h"
|
||||
|
||||
#include "extmod/vfs.h"
|
||||
#include "extmod/vfs_fat.h"
|
||||
#include "lib/oofatfs/ff.h"
|
||||
#include "lib/oofatfs/diskio.h"
|
||||
#include "lib/oofatfs/ffconf.h"
|
||||
#include "py/mpconfig.h"
|
||||
#include "py/mphal.h"
|
||||
#include "py/mpstate.h"
|
||||
#include "py/misc.h"
|
||||
|
||||
// The root FS is always at the end of the list.
|
||||
static fs_user_mount_t* get_vfs(int lun) {
|
||||
// TODO(tannewt): Return the mount which matches the lun where 0 is the end
|
||||
// and is counted in reverse.
|
||||
if (lun > 0) {
|
||||
return NULL;
|
||||
}
|
||||
mp_vfs_mount_t* current_mount = MP_STATE_VM(vfs_mount_table);
|
||||
if (current_mount == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
while (current_mount->next != NULL) {
|
||||
current_mount = current_mount->next;
|
||||
}
|
||||
return current_mount->obj;
|
||||
}
|
||||
|
||||
/* Inquiry Information */
|
||||
// This is designed to handle the common case where we have an internal file
|
||||
// system and an optional SD card.
|
||||
COMPILER_ALIGNED(4) static uint8_t inquiry_info[2][36];
|
||||
|
||||
/* Capacities of Disk */
|
||||
COMPILER_ALIGNED(4) static uint8_t format_capa[2][8];
|
||||
|
||||
/**
|
||||
* \brief Eject Disk
|
||||
* \param[in] lun logic unit number
|
||||
* \return Operation status.
|
||||
*/
|
||||
int32_t usb_msc_disk_eject(uint8_t lun) {
|
||||
if (lun > 1) {
|
||||
return ERR_NOT_FOUND;
|
||||
}
|
||||
fs_user_mount_t* current_mount = get_vfs(lun);
|
||||
// Return ERR_NOT_READY if not ready, otherwise ERR_NONE.
|
||||
if (current_mount == NULL) {
|
||||
return ERR_NOT_FOUND;
|
||||
}
|
||||
// TODO(tannewt): Should we flush here?
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Inquiry whether Disk is writable. ERR_DENIED if it is not writable.
|
||||
* ERR_NONE if it is. ERR_NOT_FOUND if its missing.
|
||||
* \param[in] lun logic unit number
|
||||
* \return Operation status.
|
||||
*/
|
||||
int32_t usb_msc_disk_is_writable(uint8_t lun) {
|
||||
if (lun > 1) {
|
||||
return ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
fs_user_mount_t* vfs = get_vfs(lun);
|
||||
if (vfs == NULL) {
|
||||
return ERR_NOT_FOUND;
|
||||
}
|
||||
if (vfs->writeblocks[0] == MP_OBJ_NULL ||
|
||||
(vfs->flags & FSUSER_USB_WRITABLE) == 0) {
|
||||
return ERR_DENIED;
|
||||
}
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Inquiry whether Disk is ready
|
||||
* \param[in] lun logic unit number
|
||||
* \return Operation status.
|
||||
*/
|
||||
int32_t usb_msc_disk_is_ready(uint8_t lun) {
|
||||
if (lun > 1) {
|
||||
return ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
fs_user_mount_t* current_mount = get_vfs(lun);
|
||||
if (current_mount == NULL) {
|
||||
return ERR_NOT_FOUND;
|
||||
}
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Callback invoked when inquiry data command received
|
||||
* \param[in] lun logic unit number
|
||||
* \return Operation status.
|
||||
*/
|
||||
uint8_t *usb_msc_inquiry_info(uint8_t lun) {
|
||||
if (lun > 1) {
|
||||
return NULL;
|
||||
} else {
|
||||
for (uint8_t i = 0; i < 36; i++) {
|
||||
inquiry_info[lun][i] = 0;
|
||||
}
|
||||
inquiry_info[lun][0] = SCSI_INQ_PQ_CONNECTED | SCSI_INQ_DT_DIR_ACCESS;
|
||||
// connected, direct access
|
||||
inquiry_info[lun][1] = SCSI_INQ_RMB; // removable medium
|
||||
inquiry_info[lun][2] = SCSI_INQ_VER_SPC; // SBC version of SCSI primary commands
|
||||
inquiry_info[lun][3] = SCSI_INQ_RSP_SPC2;// SPC-2 response format
|
||||
inquiry_info[lun][4] = 31; // 31 bytes following
|
||||
return &inquiry_info[lun][0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Callback invoked when read format capacities command received
|
||||
* \param[in] lun logic unit number
|
||||
*/
|
||||
uint8_t *usb_msc_get_capacity(uint8_t lun) {
|
||||
if (lun > 1) {
|
||||
return NULL;
|
||||
} else {
|
||||
fs_user_mount_t * vfs = get_vfs(lun);
|
||||
uint32_t last_valid_sector = 0;
|
||||
uint32_t sector_size = 0;
|
||||
if (vfs == NULL ||
|
||||
disk_ioctl(vfs, GET_SECTOR_COUNT, &last_valid_sector) != RES_OK ||
|
||||
disk_ioctl(vfs, GET_SECTOR_SIZE, §or_size) != RES_OK) {
|
||||
return NULL;
|
||||
}
|
||||
// Subtract one from the sector count to get the last valid sector.
|
||||
last_valid_sector--;
|
||||
|
||||
format_capa[lun][0] = (uint8_t)(last_valid_sector >> 24);
|
||||
format_capa[lun][1] = (uint8_t)(last_valid_sector >> 16);
|
||||
format_capa[lun][2] = (uint8_t)(last_valid_sector >> 8);
|
||||
format_capa[lun][3] = (uint8_t)(last_valid_sector >> 0);
|
||||
format_capa[lun][4] = (uint8_t)(sector_size >> 24);
|
||||
format_capa[lun][5] = (uint8_t)(sector_size >> 16);
|
||||
format_capa[lun][6] = (uint8_t)(sector_size >> 8);
|
||||
format_capa[lun][7] = (uint8_t)(sector_size >> 0);
|
||||
|
||||
// 8 byte response. First 4 bytes are last block address. Second 4
|
||||
// bytes are sector size.
|
||||
return &format_capa[lun][0];
|
||||
}
|
||||
}
|
||||
|
||||
// USB transfer state.
|
||||
volatile bool usb_busy;
|
||||
volatile bool active_read;
|
||||
volatile bool active_write;
|
||||
volatile uint8_t active_lun;
|
||||
volatile uint32_t active_addr;
|
||||
volatile uint32_t active_nblocks;
|
||||
volatile bool sector_loaded;
|
||||
COMPILER_ALIGNED(4) uint8_t sector_buffer[512];
|
||||
|
||||
/**
|
||||
* \brief Callback invoked when a new read blocks command received
|
||||
* \param[in] lun logic unit number
|
||||
* \param[in] addr start address of disk to be read
|
||||
* \param[in] nblocks block amount to be read
|
||||
* \return Operation status.
|
||||
*/
|
||||
int32_t usb_msc_new_read(uint8_t lun, uint32_t addr, uint32_t nblocks) {
|
||||
if (lun > 1) {
|
||||
return ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
// Store transfer info so we can service it in the "background".
|
||||
active_lun = lun;
|
||||
active_addr = addr;
|
||||
active_nblocks = nblocks;
|
||||
active_read = true;
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Callback invoked when a new write blocks command received
|
||||
* \param[in] lun logic unit number
|
||||
* \param[in] addr start address of disk to be written
|
||||
* \param[in] nblocks block amount to be written
|
||||
* \return Operation status.
|
||||
*/
|
||||
int32_t usb_msc_new_write(uint8_t lun, uint32_t addr, uint32_t nblocks) {
|
||||
if (lun > 1) {
|
||||
return ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
fs_user_mount_t * vfs = get_vfs(lun);
|
||||
// This is used to determine the writeability of the disk from USB.
|
||||
if (vfs == NULL) {
|
||||
return ERR_NOT_FOUND;
|
||||
}
|
||||
if (vfs->writeblocks[0] == MP_OBJ_NULL ||
|
||||
(vfs->flags & FSUSER_USB_WRITABLE) == 0) {
|
||||
return ERR_DENIED;
|
||||
}
|
||||
|
||||
// Store transfer info so we can service it in the "background".
|
||||
active_lun = lun;
|
||||
active_addr = addr;
|
||||
active_nblocks = nblocks;
|
||||
active_write = true;
|
||||
sector_loaded = false;
|
||||
|
||||
// Return ERR_DENIED when the file system is read-only to the USB host.
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Callback invoked when a blocks transfer is done
|
||||
* \param[in] lun logic unit number
|
||||
* \return Operation status.
|
||||
*/
|
||||
int32_t usb_msc_xfer_done(uint8_t lun) {
|
||||
if (lun > 1) {
|
||||
return ERR_DENIED;
|
||||
}
|
||||
|
||||
CRITICAL_SECTION_ENTER();
|
||||
if (active_read) {
|
||||
active_addr += 1;
|
||||
active_nblocks--;
|
||||
if (active_nblocks == 0) {
|
||||
active_read = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (active_write) {
|
||||
sector_loaded = true;
|
||||
}
|
||||
usb_busy = false;
|
||||
CRITICAL_SECTION_LEAVE();
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
// The start_read callback begins a read transaction which we accept
|
||||
// but delay our response until the "main thread" calls
|
||||
// usb_msc_background. Once it does, we read immediately from the
|
||||
// drive into our cache and trigger the USB DMA to output the
|
||||
// sector. Once the sector is transmitted, xfer_done will be called.
|
||||
void usb_msc_background(void) {
|
||||
// Check USB busy first because we never want to queue another transfer if it is. Checking
|
||||
// active_read or active_write first leaves the possibility that they are true, an xfer done
|
||||
// interrupt occurs (setting them false), turning off usb_busy and causing us to queue a
|
||||
// spurious transfer.
|
||||
if (usb_busy) {
|
||||
return;
|
||||
}
|
||||
if (active_read) {
|
||||
fs_user_mount_t * vfs = get_vfs(active_lun);
|
||||
disk_read(vfs, sector_buffer, active_addr, 1);
|
||||
CRITICAL_SECTION_ENTER();
|
||||
int32_t result = mscdf_xfer_blocks(true, sector_buffer, 1);
|
||||
usb_busy = result == ERR_NONE;
|
||||
CRITICAL_SECTION_LEAVE();
|
||||
}
|
||||
if (active_write) {
|
||||
if (sector_loaded) {
|
||||
fs_user_mount_t * vfs = get_vfs(active_lun);
|
||||
disk_write(vfs, sector_buffer, active_addr, 1);
|
||||
// Since by getting here we assume the mount is read-only to
|
||||
// MicroPython let's update the cached FatFs sector if it's the one
|
||||
// we just wrote.
|
||||
#if _MAX_SS != _MIN_SS
|
||||
if (vfs->ssize == FILESYSTEM_BLOCK_SIZE) {
|
||||
#else
|
||||
// The compiler can optimize this away.
|
||||
if (_MAX_SS == FILESYSTEM_BLOCK_SIZE) {
|
||||
#endif
|
||||
if (active_addr == vfs->fatfs.winsect && active_addr > 0) {
|
||||
memcpy(vfs->fatfs.win,
|
||||
sector_buffer,
|
||||
FILESYSTEM_BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
sector_loaded = false;
|
||||
active_addr += 1;
|
||||
active_nblocks--;
|
||||
}
|
||||
// Load more blocks from USB if they are needed.
|
||||
if (active_nblocks > 0) {
|
||||
// Turn off interrupts because with them on,
|
||||
// usb_msc_xfer_done could be called before we update
|
||||
// usb_busy. If that happened, we'd overwrite the fact that
|
||||
// the transfer actually already finished.
|
||||
CRITICAL_SECTION_ENTER();
|
||||
int32_t result = mscdf_xfer_blocks(false, sector_buffer, 1);
|
||||
usb_busy = result == ERR_NONE;
|
||||
CRITICAL_SECTION_LEAVE();
|
||||
} else {
|
||||
mscdf_xfer_blocks(false, NULL, 0);
|
||||
active_write = false;
|
||||
// This write is complete, start the autoreload clock.
|
||||
autoreload_start();
|
||||
}
|
||||
}
|
||||
}
|
@ -119,7 +119,6 @@ SRC_COMMON_HAL = \
|
||||
multiterminal/__init__.c \
|
||||
neopixel_write/__init__.c \
|
||||
os/__init__.c \
|
||||
storage/__init__.c \
|
||||
time/__init__.c \
|
||||
board/__init__.c
|
||||
|
||||
@ -147,7 +146,6 @@ SRC_SHARED_MODULE = \
|
||||
multiterminal/__init__.c \
|
||||
os/__init__.c \
|
||||
random/__init__.c \
|
||||
storage/__init__.c \
|
||||
struct/__init__.c
|
||||
|
||||
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \
|
||||
|
@ -162,7 +162,6 @@ extern const struct _mp_obj_module_t esp_module;
|
||||
extern const struct _mp_obj_module_t network_module;
|
||||
extern const struct _mp_obj_module_t os_module;
|
||||
extern const struct _mp_obj_module_t random_module;
|
||||
extern const struct _mp_obj_module_t storage_module;
|
||||
extern const struct _mp_obj_module_t struct_module;
|
||||
extern const struct _mp_obj_module_t mp_module_lwip;
|
||||
extern const struct _mp_obj_module_t mp_module_machine;
|
||||
@ -194,7 +193,6 @@ extern const struct _mp_obj_module_t neopixel_write_module;
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pulseio), (mp_obj_t)&pulseio_module }, \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_busio), (mp_obj_t)&busio_module }, \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_bitbangio), (mp_obj_t)&bitbangio_module }, \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_storage), (mp_obj_t)&storage_module }, \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_random), (mp_obj_t)&random_module }, \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_struct), (mp_obj_t)&struct_module }, \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_math), (mp_obj_t)&math_module }, \
|
||||
|
@ -29,6 +29,10 @@ FROZEN_MPY_DIR = freeze
|
||||
# include py core make definitions
|
||||
include ../../py/py.mk
|
||||
|
||||
ifneq ($(MCU_SUB_VARIANT),nrf52840)
|
||||
USB = FALSE
|
||||
endif
|
||||
|
||||
include $(TOP)/supervisor/supervisor.mk
|
||||
|
||||
FATFS_DIR = lib/oofatfs
|
||||
@ -51,7 +55,7 @@ INC += -I./bluetooth
|
||||
INC += -I./peripherals
|
||||
INC += -I../../lib/mp-readline
|
||||
INC += -I../../lib/tinyusb/src
|
||||
INC += -I./usb
|
||||
INC += -I../../supervisor/shared/usb
|
||||
|
||||
NRF_DEFINES += -DCONFIG_GPIO_AS_PINRESET
|
||||
|
||||
@ -68,6 +72,9 @@ LDFLAGS += -Xlinker -Map=$(@:.elf=.map)
|
||||
LDFLAGS += -mthumb -mabi=aapcs -T $(LD_FILE) -L boards/
|
||||
LDFLAGS += -Wl,--gc-sections
|
||||
|
||||
# TinyUSB defines
|
||||
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_NRF5X -DCFG_TUD_CDC_RX_BUFSIZE=1024 -DCFG_TUD_CDC_TX_BUFSIZE=1024 -DCFG_TUD_MSC_BUFSIZE=4096
|
||||
|
||||
#Debugging/Optimization
|
||||
ifeq ($(DEBUG), 1)
|
||||
#ASMFLAGS += -g -gtabs+
|
||||
@ -94,10 +101,16 @@ SRC_NRFX = $(addprefix nrfx/,\
|
||||
drivers/src/nrfx_uarte.c \
|
||||
)
|
||||
|
||||
ifdef EXTERNAL_FLASH_DEVICES
|
||||
ifeq ($(QSPI_FLASH_FILESYSTEM),1)
|
||||
SRC_NRFX += nrfx/drivers/src/nrfx_qspi.c
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
SRC_C += \
|
||||
background.c \
|
||||
fatfs_port.c \
|
||||
internal_flash.c \
|
||||
mphalport.c \
|
||||
tick.c \
|
||||
board_busses.c \
|
||||
@ -147,7 +160,6 @@ SRC_COMMON_HAL += \
|
||||
pulseio/PulseIn.c \
|
||||
pulseio/PulseOut.c \
|
||||
pulseio/__init__.c \
|
||||
storage/__init__.c \
|
||||
supervisor/Runtime.c \
|
||||
supervisor/__init__.c \
|
||||
time/__init__.c \
|
||||
@ -185,14 +197,9 @@ SRC_BINDINGS_ENUMS += \
|
||||
bleio/UUIDType.c
|
||||
endif
|
||||
|
||||
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
|
||||
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
|
||||
$(addprefix common-hal/, $(SRC_COMMON_HAL))
|
||||
|
||||
SRC_SHARED_MODULE = \
|
||||
os/__init__.c \
|
||||
random/__init__.c \
|
||||
storage/__init__.c \
|
||||
struct/__init__.c \
|
||||
gamepad/__init__.c \
|
||||
gamepad/GamePad.c \
|
||||
@ -201,44 +208,36 @@ SRC_SHARED_MODULE = \
|
||||
bitbangio/OneWire.c \
|
||||
bitbangio/SPI.c \
|
||||
busio/OneWire.c \
|
||||
storage/__init__.c
|
||||
|
||||
# uheap/__init__.c \
|
||||
ustack/__init__.c
|
||||
|
||||
SRC_SHARED_BINDINGS = \
|
||||
struct/__init__.c \
|
||||
gamepad/__init__.c \
|
||||
gamepad/GamePad.c \
|
||||
bitbangio/__init__.c \
|
||||
bitbangio/I2C.c \
|
||||
bitbangio/SPI.c \
|
||||
bitbangio/OneWire.c \
|
||||
random/__init__.c \
|
||||
|
||||
# USB source files for nrf52840
|
||||
ifeq ($(MCU_SUB_VARIANT),nrf52840)
|
||||
|
||||
SRC_C += \
|
||||
usb/usb.c \
|
||||
usb/usb_msc_flash.c \
|
||||
usb/usb_desc.c \
|
||||
lib/tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c \
|
||||
lib/tinyusb/src/portable/nordic/nrf5x/hal_nrf5x.c \
|
||||
lib/tinyusb/src/common/tusb_fifo.c \
|
||||
lib/tinyusb/src/device/control.c \
|
||||
lib/tinyusb/src/device/usbd.c \
|
||||
lib/tinyusb/src/class/msc/msc_device.c \
|
||||
lib/tinyusb/src/class/cdc/cdc_device.c \
|
||||
lib/tinyusb/src/class/hid/hid_device.c \
|
||||
lib/tinyusb/src/tusb.c \
|
||||
|
||||
SRC_COMMON_HAL += \
|
||||
SRC_SHARED_MODULE += \
|
||||
usb_hid/__init__.c \
|
||||
usb_hid/Device.c \
|
||||
|
||||
endif
|
||||
|
||||
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
|
||||
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
|
||||
$(addprefix common-hal/, $(SRC_COMMON_HAL))
|
||||
|
||||
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_BINDINGS)) \
|
||||
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \
|
||||
$(addprefix shared-module/, $(SRC_SHARED_MODULE))
|
||||
|
||||
SRC_S = supervisor/cpu.s
|
||||
@ -346,9 +345,10 @@ dfu-gen: $(BUILD)/dfu-package.zip
|
||||
$(BUILD)/dfu-package.zip: $(BUILD)/$(OUTPUT_FILENAME).hex
|
||||
$(NRFUTIL) dfu genpkg --sd-req 0xFFFE --dev-type 0x0052 --application $^ $(BUILD)/dfu-package.zip
|
||||
|
||||
# You must have $^ here because it deduplicates entries in $(OBJ)
|
||||
$(BUILD)/$(OUTPUT_FILENAME).elf: $(OBJ)
|
||||
$(ECHO) "LINK $@"
|
||||
$(Q)$(CC) $(LDFLAGS) -o $@ $(OBJ) -Wl,--start-group $(LIBS) -Wl,--end-group
|
||||
$(Q)$(CC) $(LDFLAGS) -o $@ $^ -Wl,--start-group $(LIBS) -Wl,--end-group
|
||||
$(Q)$(SIZE) $@
|
||||
|
||||
# List of sources for qstr extraction
|
||||
|
@ -61,7 +61,7 @@ To build and flash issue the following command inside the ports/nrf/ folder:
|
||||
|
||||
First prepare the bluetooth folder by downloading Bluetooth LE stacks and headers:
|
||||
|
||||
./drivers/bluetooth/download_ble_stack.sh
|
||||
./bluetooth/download_ble_stack.sh
|
||||
|
||||
If the Bluetooth stacks has been downloaded, compile the target with the following command:
|
||||
|
||||
|
@ -24,11 +24,12 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "tusb.h"
|
||||
#ifdef NRF52840
|
||||
#include "supervisor/usb.h"
|
||||
#endif
|
||||
|
||||
void run_background_tasks(void) {
|
||||
#ifdef NRF52840_XXAA
|
||||
tusb_task();
|
||||
tud_cdc_write_flush();
|
||||
#ifdef NRF52840
|
||||
usb_background();
|
||||
#endif
|
||||
}
|
||||
|
@ -30,8 +30,8 @@
|
||||
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
#include "mpconfigboard.h"
|
||||
#include "nrf/pins.h"
|
||||
#include "py/mpconfig.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#if !defined(DEFAULT_I2C_BUS_SDA) || !defined(DEFAULT_I2C_BUS_SCL)
|
||||
|
@ -25,10 +25,8 @@
|
||||
*/
|
||||
|
||||
#include "boards/board.h"
|
||||
#include "usb.h"
|
||||
|
||||
void board_init(void) {
|
||||
usb_init();
|
||||
}
|
||||
|
||||
bool board_requests_safe_mode(void) {
|
||||
|
@ -25,6 +25,8 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "nrfx/hal/nrf_gpio.h"
|
||||
|
||||
#define FEATHER52840
|
||||
|
||||
#define MICROPY_HW_BOARD_NAME "Adafruit Feather nRF52840 Express"
|
||||
@ -33,12 +35,12 @@
|
||||
|
||||
#define MICROPY_HW_NEOPIXEL (&pin_P0_13)
|
||||
|
||||
#define MICROPY_QSPI_DATA0 (&pin_P1_09)
|
||||
#define MICROPY_QSPI_DATA1 (&pin_P0_11)
|
||||
#define MICROPY_QSPI_DATA2 (&pin_P0_12)
|
||||
#define MICROPY_QSPI_DATA3 (&pin_P0_14)
|
||||
#define MICROPY_QSPI_SCK (&pin_P0_08)
|
||||
#define MICROPY_QSPI_CS (&pin_P1_08)
|
||||
#define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(1, 9)
|
||||
#define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 11)
|
||||
#define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 12)
|
||||
#define MICROPY_QSPI_DATA3 NRF_GPIO_PIN_MAP(0, 14)
|
||||
#define MICROPY_QSPI_SCK NRF_GPIO_PIN_MAP(0, 8)
|
||||
#define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(1, 8)
|
||||
|
||||
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
|
||||
|
||||
@ -49,14 +51,7 @@
|
||||
|
||||
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
// TODO #include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 1
|
||||
#define EXTERNAL_FLASH_DEVICES GD25Q16C
|
||||
|
||||
#define EXTERNAL_FLASH_QSPI_DUAL
|
||||
|
||||
// TODO include "external_flash/external_flash.h"
|
||||
#define EXTERNAL_FLASH_QSPI_DUAL (1)
|
||||
|
||||
#define BOARD_HAS_CRYSTAL 1
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
USB_VID = 0x239A
|
||||
USB_PID = 0x802A
|
||||
USB_PRODUCT = "Feather nRF52840 Express"
|
||||
USB_MANUFACTURER = "Adafruit Industries LLC"
|
||||
|
||||
MCU_SERIES = m4
|
||||
MCU_VARIANT = nrf52
|
||||
MCU_SUB_VARIANT = nrf52840
|
||||
@ -14,3 +19,7 @@ else
|
||||
endif
|
||||
|
||||
NRF_DEFINES += -DNRF52840_XXAA -DNRF52840
|
||||
|
||||
QSPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 1
|
||||
EXTERNAL_FLASH_DEVICES = "GD25Q64C"
|
||||
|
@ -25,10 +25,8 @@
|
||||
*/
|
||||
|
||||
#include "boards/board.h"
|
||||
#include "usb.h"
|
||||
|
||||
void board_init(void) {
|
||||
usb_init();
|
||||
}
|
||||
|
||||
bool board_requests_safe_mode(void) {
|
||||
|
@ -25,18 +25,20 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "nrfx/hal/nrf_gpio.h"
|
||||
|
||||
#define MAKERDIARYNRF52840MDK
|
||||
|
||||
#define MICROPY_HW_BOARD_NAME "MakerDiary nRF52840 MDK"
|
||||
#define MICROPY_HW_MCU_NAME "nRF52840"
|
||||
#define MICROPY_PY_SYS_PLATFORM "MakerDiary52840MDK"
|
||||
|
||||
#define MICROPY_QSPI_DATA0 (&pin_P1_05)
|
||||
#define MICROPY_QSPI_DATA1 (&pin_P1_04)
|
||||
#define MICROPY_QSPI_DATA2 (&pin_P1_02)
|
||||
#define MICROPY_QSPI_DATA3 (&pin_P1_01)
|
||||
#define MICROPY_QSPI_SCK (&pin_P1_03)
|
||||
#define MICROPY_QSPI_CS (&pin_P1_06)
|
||||
#define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(1, 5)
|
||||
#define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(1, 4)
|
||||
#define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(1, 2)
|
||||
#define MICROPY_QSPI_DATA3 NRF_GPIO_PIN_MAP(1, 1)
|
||||
#define MICROPY_QSPI_SCK NRF_GPIO_PIN_MAP(1, 3)
|
||||
#define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(1, 8)
|
||||
|
||||
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
|
||||
|
||||
@ -47,17 +49,6 @@
|
||||
|
||||
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
// TODO #include "external_flash/devices.h"
|
||||
|
||||
#define EXTERNAL_FLASH_DEVICE_COUNT 1
|
||||
// Datasheet for when this is implemented:
|
||||
// http://www.mxic.com.tw/Lists/Datasheet/Attachments/7428/MX25R6435F,%20Wide%20Range,%2064Mb,%20v1.4.pdf
|
||||
#define EXTERNAL_FLASH_DEVICES MX25R6435F
|
||||
|
||||
#define EXTERNAL_FLASH_QSPI_DUAL
|
||||
|
||||
// TODO include "external_flash/external_flash.h"
|
||||
|
||||
#define BOARD_HAS_CRYSTAL 0
|
||||
|
||||
#define DEFAULT_UART_BUS_RX (&pin_P0_19)
|
||||
|
@ -1,3 +1,8 @@
|
||||
USB_VID = 0x239A
|
||||
USB_PID = 0x802A
|
||||
USB_PRODUCT = "nRF52840-MDK"
|
||||
USB_MANUFACTURER = "makerdiary"
|
||||
|
||||
MCU_SERIES = m4
|
||||
MCU_VARIANT = nrf52
|
||||
MCU_SUB_VARIANT = nrf52840
|
||||
@ -14,3 +19,7 @@ else
|
||||
endif
|
||||
|
||||
NRF_DEFINES += -DNRF52840_XXAA -DNRF52840
|
||||
|
||||
QSPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 1
|
||||
EXTERNAL_FLASH_DEVICES = "MX25R6435F"
|
||||
|
@ -25,10 +25,8 @@
|
||||
*/
|
||||
|
||||
#include "boards/board.h"
|
||||
#include "usb.h"
|
||||
|
||||
void board_init(void) {
|
||||
usb_init();
|
||||
}
|
||||
|
||||
bool board_requests_safe_mode(void) {
|
||||
|
@ -24,6 +24,8 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "nrfx/hal/nrf_gpio.h"
|
||||
|
||||
#define MICROPY_HW_BOARD_NAME "PCA10056 nRF52840-DK"
|
||||
#define MICROPY_HW_MCU_NAME "nRF52840"
|
||||
#define MICROPY_PY_SYS_PLATFORM "nRF52840-DK"
|
||||
@ -40,3 +42,24 @@
|
||||
|
||||
#define DEFAULT_UART_BUS_RX (&pin_P1_01)
|
||||
#define DEFAULT_UART_BUS_TX (&pin_P1_02)
|
||||
|
||||
// Flash operation mode is determined by MICROPY_QSPI_DATAn pin configuration.
|
||||
// A pin config is valid if it is defined and its value is not 0xFF.
|
||||
// Quad mode: If all DATA0 --> DATA3 are valid
|
||||
// Dual mode: If DATA0 and DATA1 are valid while either DATA2 and/or DATA3 are invalid
|
||||
// Single mode: If only DATA0 is valid
|
||||
#ifdef QSPI_FLASH_FILESYSTEM
|
||||
#define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 20)
|
||||
#define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 21)
|
||||
#define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 22)
|
||||
#define MICROPY_QSPI_DATA3 NRF_GPIO_PIN_MAP(0, 23)
|
||||
#define MICROPY_QSPI_SCK NRF_GPIO_PIN_MAP(0, 19)
|
||||
#define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 17)
|
||||
#endif
|
||||
|
||||
#ifdef SPI_FLASH_FILESYSTEM
|
||||
#define SPI_FLASH_MOSI_PIN &pin_P0_20
|
||||
#define SPI_FLASH_MISO_PIN &pin_P0_21
|
||||
#define SPI_FLASH_SCK_PIN &pin_P0_19
|
||||
#define SPI_FLASH_CS_PIN &pin_P0_17
|
||||
#endif
|
||||
|
@ -1,3 +1,8 @@
|
||||
USB_VID = 0x239A
|
||||
USB_PID = 0x802A
|
||||
USB_PRODUCT = "PCA10056"
|
||||
USB_MANUFACTURER = "Nordic Semiconductor"
|
||||
|
||||
MCU_SERIES = m4
|
||||
MCU_VARIANT = nrf52
|
||||
MCU_SUB_VARIANT = nrf52840
|
||||
@ -14,3 +19,7 @@ else
|
||||
endif
|
||||
|
||||
NRF_DEFINES += -DNRF52840_XXAA -DNRF52840
|
||||
|
||||
QSPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 1
|
||||
EXTERNAL_FLASH_DEVICES = "MX25R6435F"
|
||||
|
@ -24,14 +24,9 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include "boards/board.h"
|
||||
#include "nrfx.h"
|
||||
#include "usb.h"
|
||||
|
||||
void board_init(void) {
|
||||
usb_init();
|
||||
}
|
||||
|
||||
bool board_requests_safe_mode(void) {
|
||||
|
@ -1,3 +1,8 @@
|
||||
USB_VID = 0x239A
|
||||
USB_PID = 0x802A
|
||||
USB_PRODUCT = "PCA10059"
|
||||
USB_MANUFACTURER = "Nordic Semiconductor"
|
||||
|
||||
MCU_SERIES = m4
|
||||
MCU_VARIANT = nrf52
|
||||
MCU_SUB_VARIANT = nrf52840
|
||||
|
@ -59,12 +59,30 @@ STATIC spim_peripheral_t spim_peripherals[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC bool never_reset[4];
|
||||
|
||||
void spi_reset(void) {
|
||||
for (size_t i = 0 ; i < MP_ARRAY_SIZE(spim_peripherals); i++) {
|
||||
if (never_reset[i]) {
|
||||
continue;
|
||||
}
|
||||
nrf_spim_disable(spim_peripherals[i].spim.p_reg);
|
||||
}
|
||||
}
|
||||
|
||||
void common_hal_busio_spi_never_reset(busio_spi_obj_t *self) {
|
||||
for (size_t i = 0 ; i < MP_ARRAY_SIZE(spim_peripherals); i++) {
|
||||
if (self->spim_peripheral == &spim_peripherals[i]) {
|
||||
never_reset[i] = true;
|
||||
|
||||
never_reset_pin_number(self->clock_pin_number);
|
||||
never_reset_pin_number(self->MOSI_pin_number);
|
||||
never_reset_pin_number(self->MISO_pin_number);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Convert frequency to clock-speed-dependent value. Choose the next lower baudrate if in between
|
||||
// available baudrates.
|
||||
static nrf_spim_frequency_t baudrate_to_spim_frequency(const uint32_t baudrate) {
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "shared-bindings/busio/UART.h"
|
||||
|
||||
#include "mpconfigport.h"
|
||||
#include "py/mpconfig.h"
|
||||
#include "py/gc.h"
|
||||
#include "py/mperrno.h"
|
||||
#include "py/runtime.h"
|
||||
|
@ -30,6 +30,11 @@
|
||||
|
||||
#include "nrf_gpio.h"
|
||||
|
||||
void common_hal_digitalio_digitalinout_never_reset(
|
||||
digitalio_digitalinout_obj_t *self) {
|
||||
never_reset_pin_number(self->pin->number);
|
||||
}
|
||||
|
||||
digitalinout_result_t common_hal_digitalio_digitalinout_construct(
|
||||
digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin) {
|
||||
claim_pin(pin);
|
||||
|
@ -45,13 +45,18 @@ bool speaker_enable_in_use;
|
||||
|
||||
// Bit mask of claimed pins on each of up to two ports. nrf52832 has one port; nrf52840 has two.
|
||||
STATIC uint32_t claimed_pins[GPIO_COUNT];
|
||||
STATIC uint32_t never_reset_pins[GPIO_COUNT];
|
||||
|
||||
void reset_all_pins(void) {
|
||||
return;
|
||||
for (size_t i = 0; i < GPIO_COUNT; i++) {
|
||||
claimed_pins[i] = 0;
|
||||
claimed_pins[i] = never_reset_pins[i];
|
||||
}
|
||||
|
||||
for (uint32_t pin = 0; pin < NUMBER_OF_PINS; ++pin) {
|
||||
if (!(never_reset_pins[nrf_pin_port(pin)] & (1 << nrf_relative_pin_number(pin)))) {
|
||||
continue;
|
||||
}
|
||||
nrf_gpio_cfg_default(pin);
|
||||
}
|
||||
|
||||
@ -72,6 +77,7 @@ void reset_all_pins(void) {
|
||||
|
||||
// Mark pin as free and return it to a quiescent state.
|
||||
void reset_pin_number(uint8_t pin_number) {
|
||||
return;
|
||||
if (pin_number == NO_PIN) {
|
||||
return;
|
||||
}
|
||||
@ -108,6 +114,11 @@ void reset_pin_number(uint8_t pin_number) {
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void never_reset_pin_number(uint8_t pin_number) {
|
||||
never_reset_pins[nrf_pin_port(pin_number)] |= 1 << nrf_relative_pin_number(pin_number);
|
||||
}
|
||||
|
||||
void claim_pin(const mcu_pin_obj_t* pin) {
|
||||
// Set bit in claimed_pins bitmask.
|
||||
claimed_pins[nrf_pin_port(pin->number)] |= 1 << nrf_relative_pin_number(pin->number);
|
||||
|
@ -44,6 +44,7 @@ void reset_all_pins(void);
|
||||
// need to store a full pointer.
|
||||
void reset_pin_number(uint8_t pin);
|
||||
void claim_pin(const mcu_pin_obj_t* pin);
|
||||
void never_reset_pin_number(uint8_t pin_number);
|
||||
|
||||
// Lower 5 bits of a pin number are the pin number in a port.
|
||||
// upper bits (just one bit for current chips) is port number.
|
||||
|
@ -72,12 +72,7 @@ uint32_t common_hal_mcu_processor_get_frequency(void) {
|
||||
}
|
||||
|
||||
void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
|
||||
|
||||
uint32_t* id_addresses[2] = {(uint32_t *) 0x060, (uint32_t *) 0x064};
|
||||
|
||||
for (int i=0; i<2; i++) {
|
||||
for (int k=0; k<4; k++) {
|
||||
raw_id[4 * i + k] = (*(id_addresses[i]) >> k * 8) & 0xff;
|
||||
}
|
||||
((uint32_t*) raw_id)[i] = NRF_FICR->DEVICEID[i];
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "mpconfigport.h"
|
||||
#include "py/mpconfig.h"
|
||||
#include "py/gc.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "mpconfigport.h"
|
||||
#include "py/mpconfig.h"
|
||||
#include "nrf/pins.h"
|
||||
#include "nrf/timers.h"
|
||||
#include "py/gc.h"
|
||||
|
@ -1,94 +0,0 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 hathach 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.
|
||||
*/
|
||||
|
||||
#ifndef COMMON_HAL_USB_HID_DEVICE_H
|
||||
#define COMMON_HAL_USB_HID_DEVICE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// 1 to enable device, 0 to disable
|
||||
#define USB_HID_DEVICE_KEYBOARD 1
|
||||
#define USB_HID_DEVICE_MOUSE 1
|
||||
#define USB_HID_DEVICE_CONSUMER 1
|
||||
#define USB_HID_DEVICE_SYS_CONTROL 1
|
||||
#define USB_HID_DEVICE_GAMEPAD 1
|
||||
#define USB_HID_DEVICE_DIGITIZER 0 // not supported yet
|
||||
|
||||
enum {
|
||||
USB_HID_REPORT_ID_UNUSED = 0,
|
||||
|
||||
#if USB_HID_DEVICE_KEYBOARD
|
||||
USB_HID_REPORT_ID_KEYBOARD,
|
||||
#endif
|
||||
|
||||
#if USB_HID_DEVICE_MOUSE
|
||||
USB_HID_REPORT_ID_MOUSE,
|
||||
#endif
|
||||
|
||||
#if USB_HID_DEVICE_CONSUMER
|
||||
USB_HID_REPORT_ID_CONSUMER,
|
||||
#endif
|
||||
|
||||
#if USB_HID_DEVICE_SYS_CONTROL
|
||||
USB_HID_REPORT_ID_SYS_CONTROL,
|
||||
#endif
|
||||
|
||||
#if USB_HID_DEVICE_GAMEPAD
|
||||
USB_HID_REPORT_ID_GAMEPAD,
|
||||
#endif
|
||||
|
||||
#if USB_HID_DEVICE_DIGITIZER
|
||||
USB_HID_REPORT_ID_DIGITIZER,
|
||||
#endif
|
||||
};
|
||||
|
||||
#define USB_HID_NUM_DEVICES (USB_HID_DEVICE_KEYBOARD + USB_HID_DEVICE_MOUSE + USB_HID_DEVICE_CONSUMER + \
|
||||
USB_HID_DEVICE_SYS_CONTROL + USB_HID_DEVICE_GAMEPAD + USB_HID_DEVICE_DIGITIZER )
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
uint8_t* report_buffer;
|
||||
uint8_t report_id;
|
||||
uint8_t report_length;
|
||||
uint8_t usage_page;
|
||||
uint8_t usage;
|
||||
} usb_hid_device_obj_t;
|
||||
|
||||
|
||||
extern usb_hid_device_obj_t usb_hid_devices[];
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* COMMON_HAL_USB_HID_DEVICE_H */
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user