Skip to content

Move atmel-samd to tinyusb and support nRF flash. #1321

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/tinyusb
Submodule tinyusb updated 78 files
+2 −40 examples/device/nrf52840/src/msc_flash_qspi.c
+1 −1 examples/device/nrf52840/src/tusb_config.h
+8 −5 examples/device/nrf52840_freertos/segger/nrf5x_freertos.emProject
+11 −4 examples/device/nrf52840_freertos/src/main.c
+35 −44 examples/device/nrf52840_freertos/src/msc_app.c
+64 −0 examples/device/nrf52840_freertos/src/msc_app.h
+124 −0 examples/device/nrf52840_freertos/src/msc_flash_qspi.c
+6 −4 examples/device/nrf52840_freertos/src/tusb_config.h
+1 −1 examples/obsolete/device/src/mouse_device_app.c
+2 −2 examples/obsolete/host/src/cdc_serial_host_app.c
+1 −1 examples/obsolete/host/src/keyboard_host_app.c
+1 −1 examples/obsolete/host/src/mouse_host_app.c
+3 −3 examples/obsolete/host/src/msc_cli.c
+9 −19 hw/bsp/pca10056/board_pca10056.c
+167 −0 hw/mcu/nordic/FreeRTOSConfig.h
+8 −1 src/class/cdc/cdc.h
+46 −27 src/class/cdc/cdc_device.c
+2 −1 src/class/cdc/cdc_device.h
+2 −2 src/class/cdc/cdc_host.c
+4 −4 src/class/cdc/cdc_rndis_host.c
+2 −2 src/class/custom/custom_device.c
+1 −0 src/class/custom/custom_device.h
+2 −2 src/class/custom/custom_host.c
+5 −0 src/class/hid/hid.h
+46 −33 src/class/hid/hid_device.c
+2 −3 src/class/hid/hid_device.h
+3 −3 src/class/hid/hid_host.c
+16 −8 src/class/msc/msc.h
+79 −77 src/class/msc/msc_device.c
+35 −11 src/class/msc/msc_device.h
+2 −2 src/class/msc/msc_host.c
+871 −0 src/common/sys_queue.h
+4 −31 src/common/tusb_common.h
+50 −44 src/common/tusb_fifo.c
+19 −39 src/common/tusb_fifo.h
+6 −3 src/common/tusb_types.h
+8 −8 src/common/tusb_verify.h
+262 −0 src/device/control.c
+98 −0 src/device/control.h
+54 −29 src/device/dcd.h
+144 −322 src/device/usbd.c
+2 −20 src/device/usbd_pvt.h
+5 −5 src/host/ehci/ehci.c
+2 −2 src/host/hub.c
+3 −3 src/host/ohci/ohci.c
+1 −1 src/host/usbh.c
+0 −1 src/osal/osal.c
+9 −11 src/osal/osal.h
+44 −57 src/osal/osal_freertos.h
+6 −7 src/osal/osal_mynewt.h
+72 −126 src/osal/osal_none.h
+341 −0 src/portable/microchip/samd21/dcd.c
+35 −46 src/portable/microchip/samd21/hal.c
+360 −0 src/portable/microchip/samd51/dcd.c
+88 −0 src/portable/microchip/samd51/hal.c
+34 −109 src/portable/nordic/nrf5x/dcd_nrf5x.c
+17 −7 src/portable/nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c
+23 −12 src/portable/nxp/lpc17xx/dcd_lpc175x_6x.c
+24 −14 src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c
+1 −0 src/tusb.h
+5 −0 src/tusb_option.h
+4 −4 tests/lpc175x_6x/test/test_dcd_lpc175x_6x.c
+1 −1 tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c
+1 −1 tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_open.c
+2 −2 tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_xfer.c
+1 −1 tests/lpc18xx_43xx/test/host/ehci/test_pipe_control_open.c
+2 −2 tests/lpc18xx_43xx/test/host/ehci/test_pipe_control_xfer.c
+2 −2 tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_open.c
+2 −2 tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_xfer.c
+1 −1 tests/lpc18xx_43xx/test/host/ehci/test_pipe_isochronous_open.c
+1 −1 tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c
+1 −1 tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c
+1 −1 tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c
+2 −2 tests/support/ehci_controller_fake.c
+2 −2 tests/support/type_helper.h
+0 −168 tools/usbtreeview/UsbTreeView.txt
+ tools/usbtreeview/Win32/UsbTreeView.exe
+ tools/usbtreeview/x64/UsbTreeView.exe
3 changes: 3 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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();
Expand Down
72 changes: 19 additions & 53 deletions ports/atmel-samd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 = \
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 \
Expand All @@ -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 \

Expand All @@ -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 \
Expand All @@ -265,15 +258,15 @@ 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 \
boards/$(BOARD)/pins.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 \
Expand All @@ -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

Expand All @@ -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 \
Expand All @@ -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 \
Expand All @@ -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/,\
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 $<
Expand Down
7 changes: 3 additions & 4 deletions ports/atmel-samd/background.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
}

Expand Down
4 changes: 1 addition & 3 deletions ports/atmel-samd/boards/arduino_mkr1300/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#define MICROPY_HW_BOARD_NAME "Arduino MKR1300"
#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)
Expand Down
7 changes: 0 additions & 7 deletions ports/atmel-samd/boards/arduino_zero/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 4 additions & 6 deletions ports/atmel-samd/boards/arduino_zero/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -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_A (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)
Expand Down
40 changes: 6 additions & 34 deletions ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading