add TinyUSB

main
aprochazka 2 years ago
parent e05a91eec0
commit ba306a5689

@ -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

@ -37,6 +37,7 @@ extern "C"
#include <string.h>
#include "stdbool.h"
#include "tusb.h"
#include "Cam.h"
// #include "portable/st/synopsys/dcd_synopsys.c"
// #include "portable/st/synopsys/synopsys_common.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

@ -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);

@ -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 */

@ -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

@ -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"

@ -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
Loading…
Cancel
Save