From df546a5951a117ea1c84ff3331d7c8c89e3cc865 Mon Sep 17 00:00:00 2001 From: mikee47 Date: Thu, 9 Mar 2023 09:10:51 +0000 Subject: [PATCH 1/6] Update pico-sdk to develop --- .../Rp2040/Components/rp2040/component.mk | 6 +- .../Components/rp2040/cyw43-driver.patch | 99 ++++++++----------- Sming/Arch/Rp2040/Components/rp2040/pico-sdk | 2 +- .../Rp2040/Components/rp2040/pico-sdk.patch | 80 +++++++-------- .../Network/Arch/Rp2040/Platform/init.cpp | 5 +- 5 files changed, 82 insertions(+), 110 deletions(-) diff --git a/Sming/Arch/Rp2040/Components/rp2040/component.mk b/Sming/Arch/Rp2040/Components/rp2040/component.mk index 984e650012..4166b6e7c0 100644 --- a/Sming/Arch/Rp2040/Components/rp2040/component.mk +++ b/Sming/Arch/Rp2040/Components/rp2040/component.mk @@ -54,7 +54,6 @@ SDK_INTERFACES := \ common/pico_util \ rp2040/hardware_regs \ rp2040/hardware_structs \ - rp2_common/cyw43_driver \ rp2_common/hardware_gpio \ rp2_common/pico_platform \ rp2_common/hardware_base \ @@ -75,13 +74,16 @@ SDK_INTERFACES := \ rp2_common/hardware_vreg \ rp2_common/hardware_watchdog \ rp2_common/hardware_xosc \ + rp2_common/pico_async_context \ rp2_common/pico_bootrom \ rp2_common/pico_double \ rp2_common/pico_int64_ops \ rp2_common/pico_float \ + rp2_common/pico_rand \ rp2_common/pico_runtime \ rp2_common/pico_unique_id \ - rp2_common/pico_cyw43_arch + rp2_common/pico_cyw43_arch \ + rp2_common/pico_cyw43_driver COMPONENT_INCDIRS := \ src/include \ diff --git a/Sming/Arch/Rp2040/Components/rp2040/cyw43-driver.patch b/Sming/Arch/Rp2040/Components/rp2040/cyw43-driver.patch index 7aec785c94..30ea7daf99 100644 --- a/Sming/Arch/Rp2040/Components/rp2040/cyw43-driver.patch +++ b/Sming/Arch/Rp2040/Components/rp2040/cyw43-driver.patch @@ -1,8 +1,8 @@ diff --git a/src/cyw43_ctrl.c b/src/cyw43_ctrl.c -index 30f3d83..5329372 100644 +index c6c2df6..753bfa8 100644 --- a/src/cyw43_ctrl.c +++ b/src/cyw43_ctrl.c -@@ -277,13 +277,17 @@ STATIC const char *const cyw43_async_event_name_table[89] = { +@@ -296,13 +296,17 @@ STATIC const char *const cyw43_async_event_name_table[89] = { [CYW43_EV_SET_SSID] = "SET_SSID", [CYW43_EV_JOIN] = "JOIN", [CYW43_EV_AUTH] = "AUTH", @@ -21,18 +21,10 @@ index 30f3d83..5329372 100644 [CYW43_EV_ASSOC_REQ_IE] = "ASSOC_REQ_IE", [CYW43_EV_ASSOC_RESP_IE] = "ASSOC_RESP_IE", diff --git a/src/cyw43_ll.c b/src/cyw43_ll.c -index 4b495ac..7848655 100644 +index 7f4229b..107f371 100644 --- a/src/cyw43_ll.c +++ b/src/cyw43_ll.c -@@ -34,6 +34,7 @@ - #include - #include - #include -+#include - #include - #include - -@@ -55,9 +56,6 @@ int sdio_transfer(uint32_t cmd, uint32_t arg, uint32_t *resp); +@@ -55,9 +55,6 @@ int sdio_transfer(uint32_t cmd, uint32_t arg, uint32_t *resp); void sdio_enable_high_speed_4bit(void); #endif @@ -42,35 +34,32 @@ index 4b495ac..7848655 100644 struct pbuf; uint16_t pbuf_copy_partial(const struct pbuf *p, void *dataptr, uint16_t len, uint16_t offset); -@@ -69,19 +67,10 @@ extern bool enable_spi_packet_dumping; +@@ -69,10 +66,6 @@ extern bool enable_spi_packet_dumping; #define CYW43_RAM_SIZE (512 * 1024) --#if CYW43_USE_SPI --extern const char fw_43439A0_7_95_49_00_start[225240]; // 43439A0-7.95.49.00.combined --#define CYW43_FW_LEN (224190) // 43439A0.bin --#define CYW43_CLM_LEN (984) // 43439_raspberrypi_picow_v5_220624.clm_blob --const uintptr_t fw_data = (uintptr_t)&fw_43439A0_7_95_49_00_start[0]; --#else --#define CYW43_FW_LEN (383110) // 7.45.98.50 --extern const char fw_4343WA1_7_45_98_50_start[426094]; --#define CYW43_CLM_LEN (7222) --const uintptr_t fw_data = (uintptr_t)&fw_4343WA1_7_45_98_50_start[0]; -+#ifndef CYW43_USE_SPI -+static_assert(false, "CYW43_USE_SPI undefined") - #endif - --#define CYW43_CLM_ADDR (fw_data + ALIGN_UINT(CYW43_FW_LEN, 512)) +-// Include the file containing the WiFi+CLM firmware blob as a C array. +-#include CYW43_CHIPSET_FIRMWARE_INCLUDE_FILE +- +-#define CYW43_CLM_ADDR (fw_data + ALIGN_UINT(CYW43_WIFI_FW_LEN, 512)) #define VERIFY_FIRMWARE_DOWNLOAD (0) #define ALIGN_UINT(val, align) (((val) + (align) - 1) & ~((align) - 1)) -@@ -362,58 +351,31 @@ static void cyw43_write_backplane(cyw43_int_t *self, uint32_t addr, size_t size, - #define MAX_BLOCK_SIZE 16384 +@@ -377,58 +370,31 @@ static int cyw43_read_backplane_mem(cyw43_int_t *self, uint32_t addr, uint32_t l + } #endif -static int cyw43_download_resource(cyw43_int_t *self, uint32_t addr, size_t raw_len, int from_storage, uintptr_t source) { - // round up len to simplify download - size_t len = (raw_len + 255) & ~255; +- +- CYW43_VDEBUG("writing %lu bytes to 0x%lx\n", (uint32_t)len, (uint32_t)addr); +- +- uint32_t block_size = CYW43_BUS_MAX_BLOCK_SIZE; +- if (from_storage) { +- // reused the spid_buf to copy the data (must be larger than 512 storage block size) +- block_size = sizeof(self->spid_buf); +- CYW43_DEBUG("data comes from external storage via buffer of size %u\n", (uint)block_size); +static uint32_t storage_get_chunksize() +{ + const uint32_t chunkTag = 0x4b4e4843; // "CHNK" @@ -83,7 +72,7 @@ index 4b495ac..7848655 100644 + if (res != sizeof(chunk)) { + CYW43_WARN("Bad chunk header %d\n", res); + return 0; -+ } + } + if (chunk.tag != chunkTag) { + CYW43_WARN("Bad chunk tag %08x\n", chunk.tag); + return 0; @@ -92,16 +81,6 @@ index 4b495ac..7848655 100644 + return chunk.length; +} -+static int cyw43_download_resource(cyw43_int_t *self, uint32_t addr, size_t len, int from_storage, uintptr_t source) { - CYW43_VDEBUG("writing %lu bytes to 0x%lx\n", (uint32_t)len, (uint32_t)addr); - - uint32_t block_size = MAX_BLOCK_SIZE; -- if (from_storage) { -- // reused the spid_buf to copy the data (must be larger than 512 storage block size) -- block_size = sizeof(self->spid_buf); -- CYW43_DEBUG("data comes from external storage via buffer of size %u\n", (uint)block_size); -- } -- - if (addr == 0) { - // check that firmware is actually there - @@ -137,14 +116,17 @@ index 4b495ac..7848655 100644 - CYW43_WARN("could not find valid firmware\n"); - return CYW43_FAIL_FAST_CHECK(-CYW43_EIO); - } -- ++static int cyw43_download_resource(cyw43_int_t *self, uint32_t addr, size_t len, int from_storage, uintptr_t source) { ++ CYW43_VDEBUG("writing %lu bytes to 0x%lx\n", (uint32_t)len, (uint32_t)addr); + - // print wifi firmware version info - CYW43_DEBUG("%s\n", &b[fw_end - 3 - found]); - } ++ const uint32_t block_size = 16384; #if VERIFY_FIRMWARE_DOWNLOAD uint32_t t_start = cyw43_hal_ticks_us(); -@@ -431,7 +393,7 @@ static int cyw43_download_resource(cyw43_int_t *self, uint32_t addr, size_t raw_ +@@ -446,7 +412,7 @@ static int cyw43_download_resource(cyw43_int_t *self, uint32_t addr, size_t raw_ cyw43_set_backplane_window(self, dest_addr); const uint8_t *src; if (from_storage) { @@ -153,7 +135,7 @@ index 4b495ac..7848655 100644 src = self->spid_buf; } else { src = (const uint8_t *)source + offset; -@@ -444,6 +406,10 @@ static int cyw43_download_resource(cyw43_int_t *self, uint32_t addr, size_t raw_ +@@ -459,6 +425,10 @@ static int cyw43_download_resource(cyw43_int_t *self, uint32_t addr, size_t raw_ } #if VERIFY_FIRMWARE_DOWNLOAD @@ -164,7 +146,7 @@ index 4b495ac..7848655 100644 uint32_t t_end = cyw43_hal_ticks_us(); uint32_t dt = t_end - t_start; CYW43_VDEBUG("done dnload; dt = %u us; speed = %u kbytes/sec\n", (uint)dt, (uint)(len * 1000 / dt)); -@@ -465,7 +431,7 @@ static int cyw43_download_resource(cyw43_int_t *self, uint32_t addr, size_t raw_ +@@ -480,7 +450,7 @@ static int cyw43_download_resource(cyw43_int_t *self, uint32_t addr, size_t raw_ cyw43_read_bytes(self, BACKPLANE_FUNCTION, dest_addr & BACKPLANE_ADDR_MASK, sz, buf); const uint8_t *src; if (from_storage) { @@ -173,7 +155,7 @@ index 4b495ac..7848655 100644 src = self->spid_buf; } else { src = (const uint8_t *)source + offset; -@@ -1367,8 +1333,8 @@ void cyw43_ll_bus_sleep(cyw43_ll_t *self_in, bool can_sleep) { +@@ -1383,8 +1353,8 @@ void cyw43_ll_bus_sleep(cyw43_ll_t *self_in, bool can_sleep) { #define CLM_CHUNK_LEN 1024 + 512 #endif @@ -184,7 +166,7 @@ index 4b495ac..7848655 100644 uint8_t *buf = &self->spid_buf[SDPCM_HEADER_LEN + 16]; const size_t clm_dload_chunk_len = CLM_CHUNK_LEN; -@@ -1393,7 +1359,7 @@ static void cyw43_clm_load(cyw43_int_t *self, const uint8_t *clm_ptr, size_t clm +@@ -1409,7 +1379,7 @@ static void cyw43_clm_load(cyw43_int_t *self, const uint8_t *clm_ptr, size_t clm *(uint32_t *)(buf + 12) = len; *(uint32_t *)(buf + 16) = 0; #pragma GCC diagnostic pop @@ -193,22 +175,22 @@ index 4b495ac..7848655 100644 CYW43_VDEBUG("clm data send %lu/%zu\n", off + len, clm_len); -@@ -1637,12 +1603,9 @@ alp_set: +@@ -1665,12 +1635,9 @@ alp_set: cyw43_write_backplane(self, SOCSRAM_BANKX_INDEX, 4, 0x3); cyw43_write_backplane(self, SOCSRAM_BANKX_PDA, 4, 0); - // Take firmware from the address space -- cyw43_download_resource(self, 0x00000000, CYW43_FW_LEN, 0, fw_data); +- cyw43_download_resource(self, 0x00000000, CYW43_WIFI_FW_LEN, 0, fw_data); - /* // Take firmware from storage block device -- cyw43_download_resource(self, 0x00000000, CYW43_FW_LEN, 1, 0x100 + 0x1000); +- cyw43_download_resource(self, 0x00000000, CYW43_WIFI_FW_LEN, 1, 0x100 + 0x1000); - */ + cyw43_storage_init(); + cyw43_download_resource(self, 0x00000000, storage_get_chunksize(), 1, 0); size_t wifi_nvram_len = ALIGN_UINT(sizeof(wifi_nvram_4343), 64); const uint8_t *wifi_nvram_data = wifi_nvram_4343; -@@ -1756,9 +1719,11 @@ f2_ready: +@@ -1787,9 +1754,11 @@ f2_ready: // Load the CLM data; it sits just after main firmware CYW43_VDEBUG("cyw43_clm_load start\n"); @@ -221,7 +203,7 @@ index 4b495ac..7848655 100644 cyw43_write_iovar_u32(self, "bus:txglom", 0, WWD_STA_INTERFACE); // tx glomming off cyw43_write_iovar_u32(self, "apsta", 1, WWD_STA_INTERFACE); // apsta on -@@ -1854,6 +1819,10 @@ int cyw43_ll_wifi_on(cyw43_ll_t *self_in, uint32_t country) { +@@ -1893,6 +1862,10 @@ int cyw43_ll_wifi_on(cyw43_ll_t *self_in, uint32_t country) { cyw43_delay_ms(50); #ifndef NDEBUG @@ -232,7 +214,7 @@ index 4b495ac..7848655 100644 // Get and print CLM version memcpy(buf, "clmver\x00", 7); cyw43_do_ioctl(self, SDPCM_GET, WLC_GET_VAR, 128, buf, WWD_STA_INTERFACE); -@@ -1883,8 +1852,8 @@ int cyw43_ll_wifi_on(cyw43_ll_t *self_in, uint32_t country) { +@@ -1922,8 +1895,8 @@ int cyw43_ll_wifi_on(cyw43_ll_t *self_in, uint32_t country) { CLR_EV(buf, 19); // roam attempt occurred CLR_EV(buf, 20); // tx fail CLR_EV(buf, 40); // radio @@ -243,10 +225,10 @@ index 4b495ac..7848655 100644 #undef CLR_EV memcpy(buf, "bsscfg:event_msgs", 18); diff --git a/src/cyw43_ll.h b/src/cyw43_ll.h -index e6405e7..80da5fc 100644 +index cf442db..a7ad227 100644 --- a/src/cyw43_ll.h +++ b/src/cyw43_ll.h -@@ -64,15 +64,19 @@ +@@ -65,15 +65,19 @@ #define CYW43_EV_SET_SSID (0) #define CYW43_EV_JOIN (1) #define CYW43_EV_AUTH (3) @@ -266,10 +248,11 @@ index e6405e7..80da5fc 100644 #define CYW43_EV_CSA_COMPLETE_IND (80) #define CYW43_EV_ASSOC_REQ_IE (87) #define CYW43_EV_ASSOC_RESP_IE (88) -@@ -291,6 +295,10 @@ void cyw43_cb_ensure_awake(void *cb_data); - void cyw43_cb_process_async_event(void *cb_data, const cyw43_async_event_t *ev); - void cyw43_cb_process_ethernet(void *cb_data, int itf, size_t len, const uint8_t *buf); +@@ -312,6 +316,11 @@ uint32_t cyw43_ll_read_backplane_reg(cyw43_ll_t *self_in, uint32_t addr); + int cyw43_ll_write_backplane_mem(cyw43_ll_t *self_in, uint32_t addr, uint32_t len, const uint8_t *buf); + int cyw43_ll_read_backplane_mem(cyw43_ll_t *self_in, uint32_t addr, uint32_t len, uint8_t *buf); ++// Sming framework methods for accessing partition storage +int cyw43_storage_init(); +uint32_t cyw43_storage_read(void *dest, uint32_t length); +void cyw43_storage_cleanup(void); diff --git a/Sming/Arch/Rp2040/Components/rp2040/pico-sdk b/Sming/Arch/Rp2040/Components/rp2040/pico-sdk index 021a1b6bad..dca773f36b 160000 --- a/Sming/Arch/Rp2040/Components/rp2040/pico-sdk +++ b/Sming/Arch/Rp2040/Components/rp2040/pico-sdk @@ -1 +1 @@ -Subproject commit 021a1b6bad56480c05aebc039bd5e42816597d54 +Subproject commit dca773f36b038dc81a0bf477534e0bc85336a5e8 diff --git a/Sming/Arch/Rp2040/Components/rp2040/pico-sdk.patch b/Sming/Arch/Rp2040/Components/rp2040/pico-sdk.patch index a915dc6ce3..4d6c1d9e75 100644 --- a/Sming/Arch/Rp2040/Components/rp2040/pico-sdk.patch +++ b/Sming/Arch/Rp2040/Components/rp2040/pico-sdk.patch @@ -2,51 +2,41 @@ diff --git a/lib/cyw43-driver b/lib/cyw43-driver --- a/lib/cyw43-driver +++ b/lib/cyw43-driver @@ -1 +1 @@ --Subproject commit 2ab6ca93f9cd044bc6f35c1403b1284e4161294a -+Subproject commit 2ab6ca93f9cd044bc6f35c1403b1284e4161294a-dirty -diff --git a/src/rp2_common/cyw43_driver/CMakeLists.txt b/src/rp2_common/cyw43_driver/CMakeLists.txt -index 42e2a30..4128a30 100644 ---- a/src/rp2_common/cyw43_driver/CMakeLists.txt -+++ b/src/rp2_common/cyw43_driver/CMakeLists.txt -@@ -71,7 +71,6 @@ if (EXISTS ${PICO_CYW43_DRIVER_PATH}/${CYW43_DRIVER_TEST_FILE}) - ) - target_link_libraries(cyw43_driver_picow INTERFACE - cyw43_driver_base -- pico_stdlib - hardware_pio - hardware_dma - hardware_exception -diff --git a/src/rp2_common/cyw43_driver/cyw43_bus_pio_spi.c b/src/rp2_common/cyw43_driver/cyw43_bus_pio_spi.c -index 21af77d..974472d 100644 ---- a/src/rp2_common/cyw43_driver/cyw43_bus_pio_spi.c -+++ b/src/rp2_common/cyw43_driver/cyw43_bus_pio_spi.c -@@ -8,7 +8,6 @@ - #include - #include +-Subproject commit 9bfca61173a94432839cd39210f1d1afdf602c42 ++Subproject commit 9bfca61173a94432839cd39210f1d1afdf602c42-dirty +diff --git a/src/rp2_common/hardware_base/include/hardware/address_mapped.h b/src/rp2_common/hardware_base/include/hardware/address_mapped.h +index 8e92d8b..da5feac 100644 +--- a/src/rp2_common/hardware_base/include/hardware/address_mapped.h ++++ b/src/rp2_common/hardware_base/include/hardware/address_mapped.h +@@ -105,12 +105,12 @@ __force_inline static uint32_t xip_alias_check_addr(const void *addr) { + #define xip_nocache_noalloc_alias_untyped(addr) ((void *)(XIP_NOCACHE_NOALLOC_BASE | xip_alias_check_addr(addr))) --#include "pico/stdlib.h" - #include "hardware/gpio.h" - #include "hardware/pio.h" - #include "hardware/clocks.h" -diff --git a/src/rp2_common/pico_platform/include/pico/platform.h b/src/rp2_common/pico_platform/include/pico/platform.h -index fab7f29..d7eed51 100644 ---- a/src/rp2_common/pico_platform/include/pico/platform.h -+++ b/src/rp2_common/pico_platform/include/pico/platform.h -@@ -362,7 +362,7 @@ static __force_inline void tight_loop_contents(void) {} - * \return a * b - */ - __force_inline static int32_t __mul_instruction(int32_t a, int32_t b) { -- asm ("mul %0, %1" : "+l" (a) : "l" (b) : ); -+ __asm__ ("mul %0, %1" : "+l" (a) : "l" (b) : ); - return a; - } + // Typed conversion alias pointer generation macros +-#define hw_set_alias(p) ((typeof(p))hw_set_alias_untyped(p)) +-#define hw_clear_alias(p) ((typeof(p))hw_clear_alias_untyped(p)) +-#define hw_xor_alias(p) ((typeof(p))hw_xor_alias_untyped(p)) +-#define xip_noalloc_alias(p) ((typeof(p))xip_noalloc_alias_untyped(p)) +-#define xip_nocache_alias(p) ((typeof(p))xip_nocache_alias_untyped(p)) +-#define xip_nocache_noalloc_alias(p) ((typeof(p))xip_nocache_noalloc_alias_untyped(p)) ++#define hw_set_alias(p) ((__typeof__(p))hw_set_alias_untyped(p)) ++#define hw_clear_alias(p) ((__typeof__(p))hw_clear_alias_untyped(p)) ++#define hw_xor_alias(p) ((__typeof__(p))hw_xor_alias_untyped(p)) ++#define xip_noalloc_alias(p) ((__typeof__(p))xip_noalloc_alias_untyped(p)) ++#define xip_nocache_alias(p) ((__typeof__(p))xip_nocache_alias_untyped(p)) ++#define xip_nocache_noalloc_alias(p) ((__typeof__(p))xip_nocache_noalloc_alias_untyped(p)) -@@ -398,7 +398,7 @@ __force_inline static int32_t __mul_instruction(int32_t a, int32_t b) { - */ - static inline uint __get_current_exception(void) { - uint exception; -- asm ("mrs %0, ipsr" : "=l" (exception)); -+ __asm ("mrs %0, ipsr" : "=l" (exception)); - return exception; - } + /*! \brief Atomically set the specified bits to 1 in a HW register + * \ingroup hardware_base +diff --git a/src/rp2_common/pico_standard_link/memmap_default.ld b/src/rp2_common/pico_standard_link/memmap_default.ld +index 638e994..3fb53cd 100644 +--- a/src/rp2_common/pico_standard_link/memmap_default.ld ++++ b/src/rp2_common/pico_standard_link/memmap_default.ld +@@ -231,7 +231,7 @@ SECTIONS + } > SCRATCH_Y + .flash_end : { +- PROVIDE(__flash_binary_end = .); ++ __flash_binary_end = .; + } > FLASH + + /* stack limit is poorly named, but historically is maximum heap ptr */ diff --git a/Sming/Components/Network/Arch/Rp2040/Platform/init.cpp b/Sming/Components/Network/Arch/Rp2040/Platform/init.cpp index cf6e16d0e4..1530928f30 100644 --- a/Sming/Components/Network/Arch/Rp2040/Platform/init.cpp +++ b/Sming/Components/Network/Arch/Rp2040/Platform/init.cpp @@ -40,10 +40,7 @@ void rp2040_network_initialise() void rp2040_network_service() { - if(cyw43_poll_required) { - cyw43_poll_required = false; - cyw43_poll(); - } + cyw43_arch_poll(); } extern "C" void __wrap_cyw43_cb_process_async_event(cyw43_t* self, const cyw43_async_event_t* ev) From f8e8600dbf5a7fd8b4462d21ca00b5c1d8031aac Mon Sep 17 00:00:00 2001 From: mikee47 Date: Thu, 9 Mar 2023 09:12:54 +0000 Subject: [PATCH 2/6] Don't apply coding style to generated source files --- Sming/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sming/Makefile b/Sming/Makefile index b42993d4a1..a11ebab62a 100644 --- a/Sming/Makefile +++ b/Sming/Makefile @@ -215,7 +215,8 @@ CS_SEARCH_DIRS ?= $(call ListAllSubDirs,$(CS_ROOT_DIRS)) # Resultant set of directories whose contents to apply coding style to CS_DIRS ?= $(patsubst %/.cs,%,$(wildcard $(foreach d,$(CS_SEARCH_DIRS),$d/.cs))) # Files to apply coding style to -CS_FILES = $(if $(CS_DIRS),$(sort $(call rwildcard,$(CS_DIRS:=/*),%.cpp %.hpp %.h %.c))) +CS_ALL_FILES = $(if $(CS_DIRS),$(sort $(call rwildcard,$(CS_DIRS:=/*),%.cpp %.hpp %.h %.c))) +CS_FILES = $(foreach f,$(CS_ALL_FILES),$(if $(findstring /out/,$f),,$f)) .PHONY: cs cs: ##Apply coding style to all core files From ff7d9dd573d5c8c6d8ea0db8c7c076e9ccd9dd0f Mon Sep 17 00:00:00 2001 From: mikee47 Date: Thu, 9 Mar 2023 20:12:47 +0000 Subject: [PATCH 3/6] Add USB library --- .gitmodules | 6 +- .../Components/rp2040/sdk/tusb_config.h | 92 ------------------- Sming/Libraries/USB | 1 + Sming/Libraries/USB.no-recursive | 0 4 files changed, 6 insertions(+), 93 deletions(-) delete mode 100644 Sming/Arch/Rp2040/Components/rp2040/sdk/tusb_config.h create mode 160000 Sming/Libraries/USB create mode 100644 Sming/Libraries/USB.no-recursive diff --git a/.gitmodules b/.gitmodules index 336694de9b..3bad0fa976 100644 --- a/.gitmodules +++ b/.gitmodules @@ -373,10 +373,14 @@ path = Sming/Libraries/UPnP url = /~https://github.com/mikee47/Sming-UPnP ignore = dirty -[submodule "Sming/Libraries/UPnP-Schema"] +[submodule "Libraries.UPnP-Schema"] path = Sming/Libraries/UPnP-Schema url = /~https://github.com/mikee47/UPnP-Schema ignore = dirty +[submodule "Libraries.USB"] + path = Sming/Libraries/USB + url = /~https://github.com/mikee47/Sming-USB + ignore = dirty [submodule "Libraries.VT100"] path = Sming/Libraries/VT100 url = /~https://github.com/mikee47/VT100 diff --git a/Sming/Arch/Rp2040/Components/rp2040/sdk/tusb_config.h b/Sming/Arch/Rp2040/Components/rp2040/sdk/tusb_config.h deleted file mode 100644 index 0c98598d40..0000000000 --- a/Sming/Arch/Rp2040/Components/rp2040/sdk/tusb_config.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2019 Ha Thach (tinyusb.org) - * - * 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 _TUSB_CONFIG_H_ -#define _TUSB_CONFIG_H_ - -#ifdef __cplusplus - extern "C" { -#endif - -//-------------------------------------------------------------------- -// COMMON CONFIGURATION -//-------------------------------------------------------------------- - -#ifndef CFG_TUSB_MCU - #define CFG_TUSB_MCU OPT_MCU_RP2040 -#endif - -#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE -#define CFG_TUSB_OS OPT_OS_PICO - -// CFG_TUSB_DEBUG is defined by compiler in DEBUG build -#ifndef CFG_TUSB_DEBUG -#define CFG_TUSB_DEBUG 0 -#endif - -/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. - * Tinyusb use follows macros to declare transferring memory so that they can be put - * into those specific section. - * e.g - * - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") )) - * - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4))) - */ -#ifndef CFG_TUSB_MEM_SECTION -#define CFG_TUSB_MEM_SECTION -#endif - -#ifndef CFG_TUSB_MEM_ALIGN -#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4))) -#endif - -//-------------------------------------------------------------------- -// DEVICE CONFIGURATION -//-------------------------------------------------------------------- - -#ifndef CFG_TUD_ENDPOINT0_SIZE -#define CFG_TUD_ENDPOINT0_SIZE 64 -#endif - -//------------- CLASS -------------// -#define CFG_TUD_HID (2) -#define CFG_TUD_CDC (1) -#define CFG_TUD_MSC (0) -#define CFG_TUD_MIDI (1) -#define CFG_TUD_VENDOR (0) - -#define CFG_TUD_CDC_RX_BUFSIZE (256) -#define CFG_TUD_CDC_TX_BUFSIZE (256) - -#define CFG_TUD_MIDI_RX_BUFSIZE (64) -#define CFG_TUD_MIDI_TX_BUFSIZE (64) - -// HID buffer size Should be sufficient to hold ID (if any) + Data -#define CFG_TUD_HID_EP_BUFSIZE (64) - -#ifdef __cplusplus - } -#endif - -#endif /* _TUSB_CONFIG_H_ */ diff --git a/Sming/Libraries/USB b/Sming/Libraries/USB new file mode 160000 index 0000000000..9055f1b444 --- /dev/null +++ b/Sming/Libraries/USB @@ -0,0 +1 @@ +Subproject commit 9055f1b4443d3bd5fbdd08147c74a6f0528a6a8a diff --git a/Sming/Libraries/USB.no-recursive b/Sming/Libraries/USB.no-recursive new file mode 100644 index 0000000000..e69de29bb2 From 1121591fdf7a0759ab6b95350ae055a113a9a5af Mon Sep 17 00:00:00 2001 From: mikee47 Date: Sun, 12 Mar 2023 11:54:08 +0000 Subject: [PATCH 4/6] Add USB support to Basic_IFS sample --- samples/Basic_IFS/README.rst | 4 ++ samples/Basic_IFS/app/application.cpp | 71 ++++++++++++++++++++++++++- samples/Basic_IFS/component.mk | 9 ++++ samples/Basic_IFS/fsimage.fwfs | 3 +- samples/Basic_IFS/usb.json | 5 ++ 5 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 samples/Basic_IFS/usb.json diff --git a/samples/Basic_IFS/README.rst b/samples/Basic_IFS/README.rst index 2d01da92bb..354e75d4ba 100644 --- a/samples/Basic_IFS/README.rst +++ b/samples/Basic_IFS/README.rst @@ -35,3 +35,7 @@ To add support for SD Cards to this sample:: make ENABLE_SDCARD=1 See :library:`FatIFS` for further details of SD Card and FAT filing system support. + +To add support for a USB storage device:: + + make ENABLE_USB_STORAGE=1 diff --git a/samples/Basic_IFS/app/application.cpp b/samples/Basic_IFS/app/application.cpp index f27538b2df..5bdfc2787a 100644 --- a/samples/Basic_IFS/app/application.cpp +++ b/samples/Basic_IFS/app/application.cpp @@ -35,6 +35,12 @@ #endif +#ifdef ENABLE_USB_STORAGE +#include +#include +USB::MSC::HostDevice usbStorage; +#endif + namespace { #ifdef ENABLE_FLASHSTRING_IMAGE @@ -237,6 +243,69 @@ bool initFileSystem() #endif +#ifdef ENABLE_USB_STORAGE + USB::begin(); + USB::MSC::onMount([](auto inst) { + usbStorage.begin(inst); + usbStorage.enumerate([](auto& unit, const USB::MSC::Inquiry& inquiry) { +#define OUT(name, value) Serial << String(name).padLeft(30) << ": " << value << endl; +#define OUTR(name) OUT(#name, inquiry.resp.name) + Serial << _F("USB device '") << unit.getName() << _F("' mounted") << endl; + OUT("Vendor ID", inquiry.vendorId()) + OUT("Product ID", inquiry.productId()) + OUT("Product Revision", inquiry.productRev()) + OUTR(peripheral_device_type) + OUTR(peripheral_qualifier) + OUTR(is_removable) + OUTR(version) + OUTR(response_data_format) + OUTR(hierarchical_support) + OUTR(normal_aca) + OUTR(additional_length) + OUTR(protect) + OUTR(third_party_copy) + OUTR(target_port_group_support) + OUTR(access_control_coordinator) + OUTR(scc_support) + OUTR(addr16) + OUTR(multi_port) + OUTR(enclosure_service) + OUTR(cmd_que) + OUTR(sync) + OUTR(wbus16) +#undef OUTR +#undef OUT + + Storage::registerDevice(&unit); + unit.allocateBuffers(16); + + for(auto part : unit.partitions()) { + Serial << part << endl; + } + auto part = *unit.partitions().begin(); + auto fatfs = IFS::createFatFilesystem(part); + if(fatfs && fatfs->mount() == FS_OK) { + getFileSystem()->setVolume(3, fatfs); + Serial << F("FAT partition mounted") << endl; + } else { + Serial << F("FAT mount failed") << endl; + delete fatfs; + } + + return false; // Ignore other LUNs + }); + + return &usbStorage; + }); + + USB::MSC::onUnmount([](USB::MSC::HostDevice& dev) { + if(dev == usbStorage) { + getFileSystem()->setVolume(3, nullptr); + Serial << _F("USB '") << dev.getName() << _F("' unmounted") << endl; + } + }); +#endif + debug_i("File system initialised"); return true; } @@ -403,13 +472,11 @@ Timer statTimer; void init() { -#if DEBUG_BUILD Serial.begin(COM_SPEED_SERIAL); Serial.systemDebugOutput(true); debug_i("\n\n********************************************************\n" "Hello\n"); -#endif // Delay at startup so terminal gets time to start auto timer = new AutoDeleteTimer; diff --git a/samples/Basic_IFS/component.mk b/samples/Basic_IFS/component.mk index ca20fbd102..d0255d498a 100644 --- a/samples/Basic_IFS/component.mk +++ b/samples/Basic_IFS/component.mk @@ -21,5 +21,14 @@ COMPONENT_CXXFLAGS += -DENABLE_SDCARD COMPONENT_DEPENDS += SdStorage FatIFS endif +CONFIG_VARS += ENABLE_USB_STORAGE +ifeq ($(ENABLE_USB_STORAGE),1) +COMPONENT_CXXFLAGS += -DENABLE_USB_STORAGE +COMPONENT_DEPENDS += USB +USB_CONFIG := usb.json +endif + +ifeq ($(SMING_ARCH),Rp2040) # For Rp2040, put firmware into partition LINK_CYW43_FIRMWARE := 0 +endif diff --git a/samples/Basic_IFS/fsimage.fwfs b/samples/Basic_IFS/fsimage.fwfs index cc8b6bfb88..302af234c3 100644 --- a/samples/Basic_IFS/fsimage.fwfs +++ b/samples/Basic_IFS/fsimage.fwfs @@ -15,7 +15,8 @@ "mountpoints": { "littlefs": 0, "spiffs": 1, - "fat": 2 + "sdcard": 2, + "usb": 3 }, // Rules for file metadata. All rules are evaluated in sequence for every file "rules": [ diff --git a/samples/Basic_IFS/usb.json b/samples/Basic_IFS/usb.json new file mode 100644 index 0000000000..60dfe5cc7e --- /dev/null +++ b/samples/Basic_IFS/usb.json @@ -0,0 +1,5 @@ +{ + "host": { + "msc": 1 + } +} \ No newline at end of file From 865c10b4dd12d52b11b55e11446bc18799b1e6b8 Mon Sep 17 00:00:00 2001 From: mikee47 Date: Mon, 13 Mar 2023 15:17:00 +0000 Subject: [PATCH 5/6] Use `.usbcfg` file extension --- samples/Basic_IFS/{usb.json => basic_ifs.usbcfg} | 0 samples/Basic_IFS/component.mk | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename samples/Basic_IFS/{usb.json => basic_ifs.usbcfg} (100%) diff --git a/samples/Basic_IFS/usb.json b/samples/Basic_IFS/basic_ifs.usbcfg similarity index 100% rename from samples/Basic_IFS/usb.json rename to samples/Basic_IFS/basic_ifs.usbcfg diff --git a/samples/Basic_IFS/component.mk b/samples/Basic_IFS/component.mk index d0255d498a..33da075365 100644 --- a/samples/Basic_IFS/component.mk +++ b/samples/Basic_IFS/component.mk @@ -25,7 +25,7 @@ CONFIG_VARS += ENABLE_USB_STORAGE ifeq ($(ENABLE_USB_STORAGE),1) COMPONENT_CXXFLAGS += -DENABLE_USB_STORAGE COMPONENT_DEPENDS += USB -USB_CONFIG := usb.json +USB_CONFIG := basic_ifs.usbcfg endif ifeq ($(SMING_ARCH),Rp2040) From 65d57a8c470b517ba44f41506352fac5817143cf Mon Sep 17 00:00:00 2001 From: mikee47 Date: Mon, 13 Mar 2023 15:41:18 +0000 Subject: [PATCH 6/6] Add .usbcfg association to vscode workspace files --- Tools/ide/vscode/template/workspace.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Tools/ide/vscode/template/workspace.json b/Tools/ide/vscode/template/workspace.json index 78c5eb2397..c8085183cc 100644 --- a/Tools/ide/vscode/template/workspace.json +++ b/Tools/ide/vscode/template/workspace.json @@ -9,6 +9,7 @@ "files.associations": { "*.hw": "jsonc", "*.fwfs": "jsonc", + "*.usbcfg": "jsonc", "optional": "cpp" }, "json.schemas": [ @@ -23,6 +24,12 @@ "*.fwfs" ], "url": "file://${SMING_HOME}/Components/IFS/fsbuild/schema.json" + }, + { + "fileMatch": [ + "*.usbcfg" + ], + "url": "file://${SMING_HOME}/Libraries/USB/schema.json" } ] }