From ba306a56894c6caafad7b5b284a1d2a4a6ba6b65 Mon Sep 17 00:00:00 2001 From: aprochazka Date: Wed, 1 Mar 2023 23:24:28 +0100 Subject: [PATCH] add TinyUSB --- Firmware/CMakeLists.txt | 5 +- Firmware/Core/Inc/main.h | 1 + Firmware/Core/Inc/tusb_config.h | 6 +-- Firmware/Core/Src/main.c | 47 ++++++++++++++++--- Firmware/Core/Src/stm32l4xx_it.c | 4 +- .../docs/contributing/code_of_conduct.rst | 1 - .../Core/tinyusb/docs/info/contributors.rst | 1 - .../boards/adafruit_clue/nrf52840_s140_v6.ld | 0 .../arduino_nano33_ble/arduino_nano33_ble.ld | 0 .../nrf52840_s140_v6.ld | 0 .../hw/mcu/sony/cxd56/tools/flash_writer.py | 0 .../Core/tinyusb/src/class/bth/bth_device.c | 0 .../Core/tinyusb/src/class/bth/bth_device.h | 0 .../Core/tinyusb/tools/pcapng_to_corpus.py | 0 Firmware/Dockerfile | 28 ----------- Firmware/Makefile | 6 ++- Firmware/docker-compose.yml | 33 ------------- 17 files changed, 55 insertions(+), 77 deletions(-) mode change 100755 => 100644 Firmware/Core/Inc/main.h mode change 100755 => 100644 Firmware/Core/Src/main.c delete mode 120000 Firmware/Core/tinyusb/docs/contributing/code_of_conduct.rst delete mode 120000 Firmware/Core/tinyusb/docs/info/contributors.rst mode change 100755 => 100644 Firmware/Core/tinyusb/hw/bsp/nrf/boards/adafruit_clue/nrf52840_s140_v6.ld mode change 100755 => 100644 Firmware/Core/tinyusb/hw/bsp/nrf/boards/arduino_nano33_ble/arduino_nano33_ble.ld mode change 100755 => 100644 Firmware/Core/tinyusb/hw/bsp/nrf/boards/circuitplayground_bluefruit/nrf52840_s140_v6.ld mode change 100755 => 100644 Firmware/Core/tinyusb/hw/mcu/sony/cxd56/tools/flash_writer.py mode change 100755 => 100644 Firmware/Core/tinyusb/src/class/bth/bth_device.c mode change 100755 => 100644 Firmware/Core/tinyusb/src/class/bth/bth_device.h mode change 100755 => 100644 Firmware/Core/tinyusb/tools/pcapng_to_corpus.py delete mode 100644 Firmware/Dockerfile delete mode 100644 Firmware/docker-compose.yml diff --git a/Firmware/CMakeLists.txt b/Firmware/CMakeLists.txt index af8a35a..103fffb 100644 --- a/Firmware/CMakeLists.txt +++ b/Firmware/CMakeLists.txt @@ -49,7 +49,10 @@ set(STM32CUBEMX_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/CMSIS/Device/ST/${MCU_FAMILY}/Include ${CMAKE_CURRENT_SOURCE_DIR}/Drivers/CMSIS/Include) -set(PROJECT_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}) +set(PROJECT_INCLUDE_DIRECTORIES +${CMAKE_CURRENT_SOURCE_DIR} +${CMAKE_CURRENT_SOURCE_DIR}/Core/Cam +) set (TINY_USB_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/Core/tinyusb/src diff --git a/Firmware/Core/Inc/main.h b/Firmware/Core/Inc/main.h old mode 100755 new mode 100644 index 6fdb84b..13aee20 --- a/Firmware/Core/Inc/main.h +++ b/Firmware/Core/Inc/main.h @@ -37,6 +37,7 @@ extern "C" #include #include "stdbool.h" #include "tusb.h" +#include "Cam.h" // #include "portable/st/synopsys/dcd_synopsys.c" // #include "portable/st/synopsys/synopsys_common.h" diff --git a/Firmware/Core/Inc/tusb_config.h b/Firmware/Core/Inc/tusb_config.h index 89e2868..520fe0a 100644 --- a/Firmware/Core/Inc/tusb_config.h +++ b/Firmware/Core/Inc/tusb_config.h @@ -51,9 +51,9 @@ extern "C" #define CFG_TUSB_MCU OPT_MCU_STM32L4 #define CFG_TUSB_OS OPT_OS_NONE -#define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED -#define BOARD_DEVICE_RHPORT_NUM 0 -#define CFG_TUSB_RHPORT_MODE (OPT_MODE_DEVICE | OPT_MODE_FULL_SPEED) +#define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED +#define BOARD_DEVICE_RHPORT_NUM 1 +#define CFG_TUSB_RHPORT_MODE (OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED) // defined by compiler flags for flexibility #ifndef CFG_TUSB_MCU diff --git a/Firmware/Core/Src/main.c b/Firmware/Core/Src/main.c old mode 100755 new mode 100644 index 3b39e09..a13eea4 --- a/Firmware/Core/Src/main.c +++ b/Firmware/Core/Src/main.c @@ -68,6 +68,37 @@ static void MX_USB_PCD_Init(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ +void cdc_task(void) +{ + // connected() check for DTR bit + // Most but not all terminal client set this when making connection + // if ( tud_cdc_connected() ) + { + + // connected and there are data available + if (tud_cdc_available()) + { + Debug_LED_On(); + + // read data + char buf[64]; + uint32_t count = tud_cdc_read(buf, sizeof(buf)); + (void)count; + + //char buf_2[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; + //uint32_t count_2 = 10; + // Echo back + // Note: Skip echo by commenting out write() and write_flush() + // for throughput test e.g + // $ dd if=/dev/zero of=/dev/ttyACM0 count=10000 + tud_cdc_write(buf, count); + //tud_cdc_n_write(10, buf_2, count_2); + tud_cdc_write_flush(); + } + } +} + + /* USER CODE END 0 */ /** @@ -77,7 +108,6 @@ static void MX_USB_PCD_Init(void); int main(void) { /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ @@ -86,7 +116,6 @@ int main(void) HAL_Init(); /* USER CODE BEGIN Init */ - // tusb_init(); /* USER CODE END Init */ @@ -94,6 +123,7 @@ int main(void) SystemClock_Config(); /* USER CODE BEGIN SysInit */ + HAL_PWREx_EnableVddUSB(); /* USER CODE END SysInit */ @@ -105,21 +135,24 @@ int main(void) MX_I2C1_Init(); MX_USB_PCD_Init(); /* USER CODE BEGIN 2 */ + tud_init(BOARD_DEVICE_RHPORT_NUM); - // HAL_Delay(10); - // SPI_Init(&hspi1); + HAL_Delay(10); + SPI_Init(&hspi1); // Wait for power stabilization - // HAL_Delay(1000); + HAL_Delay(1000); - // Cam_Init(&hi2c1, &hspi1); + //Cam_Init(&hi2c1, &hspi1); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { - // tud_task(); + tud_task(); + cdc_task(); + /* Cam_Capture(&hspi1); diff --git a/Firmware/Core/Src/stm32l4xx_it.c b/Firmware/Core/Src/stm32l4xx_it.c index 8399542..4cd6411 100644 --- a/Firmware/Core/Src/stm32l4xx_it.c +++ b/Firmware/Core/Src/stm32l4xx_it.c @@ -250,8 +250,8 @@ void USB_IRQHandler(void) { /* USER CODE BEGIN USB_IRQn 0 */ - // tud_int_handler(0); - // return; + tud_int_handler(BOARD_DEVICE_RHPORT_NUM); + return; /* USER CODE END USB_IRQn 0 */ HAL_PCD_IRQHandler(&hpcd_USB_FS); /* USER CODE BEGIN USB_IRQn 1 */ diff --git a/Firmware/Core/tinyusb/docs/contributing/code_of_conduct.rst b/Firmware/Core/tinyusb/docs/contributing/code_of_conduct.rst deleted file mode 120000 index b52bf14..0000000 --- a/Firmware/Core/tinyusb/docs/contributing/code_of_conduct.rst +++ /dev/null @@ -1 +0,0 @@ -../../CODE_OF_CONDUCT.rst \ No newline at end of file diff --git a/Firmware/Core/tinyusb/docs/info/contributors.rst b/Firmware/Core/tinyusb/docs/info/contributors.rst deleted file mode 120000 index b3748cc..0000000 --- a/Firmware/Core/tinyusb/docs/info/contributors.rst +++ /dev/null @@ -1 +0,0 @@ -../../CONTRIBUTORS.rst \ No newline at end of file diff --git a/Firmware/Core/tinyusb/hw/bsp/nrf/boards/adafruit_clue/nrf52840_s140_v6.ld b/Firmware/Core/tinyusb/hw/bsp/nrf/boards/adafruit_clue/nrf52840_s140_v6.ld old mode 100755 new mode 100644 diff --git a/Firmware/Core/tinyusb/hw/bsp/nrf/boards/arduino_nano33_ble/arduino_nano33_ble.ld b/Firmware/Core/tinyusb/hw/bsp/nrf/boards/arduino_nano33_ble/arduino_nano33_ble.ld old mode 100755 new mode 100644 diff --git a/Firmware/Core/tinyusb/hw/bsp/nrf/boards/circuitplayground_bluefruit/nrf52840_s140_v6.ld b/Firmware/Core/tinyusb/hw/bsp/nrf/boards/circuitplayground_bluefruit/nrf52840_s140_v6.ld old mode 100755 new mode 100644 diff --git a/Firmware/Core/tinyusb/hw/mcu/sony/cxd56/tools/flash_writer.py b/Firmware/Core/tinyusb/hw/mcu/sony/cxd56/tools/flash_writer.py old mode 100755 new mode 100644 diff --git a/Firmware/Core/tinyusb/src/class/bth/bth_device.c b/Firmware/Core/tinyusb/src/class/bth/bth_device.c old mode 100755 new mode 100644 diff --git a/Firmware/Core/tinyusb/src/class/bth/bth_device.h b/Firmware/Core/tinyusb/src/class/bth/bth_device.h old mode 100755 new mode 100644 diff --git a/Firmware/Core/tinyusb/tools/pcapng_to_corpus.py b/Firmware/Core/tinyusb/tools/pcapng_to_corpus.py old mode 100755 new mode 100644 diff --git a/Firmware/Dockerfile b/Firmware/Dockerfile deleted file mode 100644 index 0cafe73..0000000 --- a/Firmware/Dockerfile +++ /dev/null @@ -1,28 +0,0 @@ -FROM fedora:34 - -RUN dnf update -y && dnf install -y \ - git \ - wget \ - lbzip2 \ - make \ - cmake \ - glibc-locale-source \ - findutils \ - clang-tools-extra - -RUN wget -q https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 -O /tmp/gcc-arm-none-eabi-10.3.tar.bz2 -RUN mkdir -p /opt/gcc-arm-none-eabi-10.3 -RUN tar -xf /tmp/gcc-arm-none-eabi-10.3.tar.bz2 -C /opt/gcc-arm-none-eabi-10.3 --strip-components=1 -RUN ln -s /opt/gcc-arm-none-eabi-10.3/bin/* /usr/local/bin -RUN rm -rf /tmp/* - -ARG UID -ARG GID -ARG USERNAME -ARG GROUPNAME -RUN groupadd --gid $GID $GROUPNAME -RUN useradd --uid $UID --gid $GID $USERNAME -RUN usermod --append --groups $GROUPNAME $USERNAME -RUN usermod --shell /bin/bash $USERNAME - -USER $USERNAME diff --git a/Firmware/Makefile b/Firmware/Makefile index a92b9fd..8c78770 100644 --- a/Firmware/Makefile +++ b/Firmware/Makefile @@ -34,7 +34,8 @@ $(BUILD_DIR)/Makefile: CMakeLists.txt -DDUMP_ASM=OFF # Formats all user modified source files (add ones that are missing) -SRCS := $(shell find Project -name '*.[ch]' -or -name '*.[ch]pp') Core/Src/main.c +# SRCS := $(shell find Project -name '*.[ch]' -or -name '*.[ch]pp') Core/Src/main.c +SRCS := $(shell find Core -name '*.[ch]' -or -name '*.[ch]pp') Core/Src/main.c format: $(addsuffix .format,$(SRCS)) %.format: % clang-format -i $< @@ -131,3 +132,6 @@ clean-image: $(CONTAINER_TOOL) image rmi -f $(IMAGE_NAME) 2> /dev/null > /dev/null || true clean-all: clean clean-image + +flash: + openocd -f interface/stlink.cfg -f target/stm32l4x.cfg -c "program build/Probe.bin verify reset exit 0x08000000" diff --git a/Firmware/docker-compose.yml b/Firmware/docker-compose.yml deleted file mode 100644 index 95925e5..0000000 --- a/Firmware/docker-compose.yml +++ /dev/null @@ -1,33 +0,0 @@ -version: '3' -services: - - container: - build: - context: . - dockerfile: ./Dockerfile - image: fedora-arm-embedded-dev - container_name: fedora-arm-embedded-dev - volumes: - - ${PWD}/:/workdir - working_dir: /workdir - hostname: fedora-arm-embedded-dev - - stmbuild: - extends: - service: container - command: bash -lc 'make -j8' - - stmrebuild: - extends: - service: container - command: bash -lc 'make clean && make -j8' - - stmclean: - extends: - service: container - command: bash -lc 'make clean' - - shell: - extends: - service: container - command: bash -l