Skip to content
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

Add max3421 support for esp32 #2270

Merged
merged 12 commits into from
Sep 28, 2023
Merged
21 changes: 2 additions & 19 deletions .github/workflows/build_esp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ jobs:
fail-fast: false
matrix:
board:
# Alphabetical order
# ESP32-S2
- 'espressif_saola_1'
- 'espressif_kaluga_1'
# ESP32-S3
#- 'espressif_s3_devkitm'
# S3 compile error with "dangerous relocation: call8: call target out of range: memcpy"
- 'espressif_s3_devkitm'

steps:
- name: Setup Python
Expand All @@ -48,20 +46,5 @@ jobs:
- name: Checkout TinyUSB
uses: actions/checkout@v3

- name: Checkout hathach/linkermap
uses: actions/checkout@v3
with:
repository: hathach/linkermap
path: linkermap

- name: Build
run: docker run --rm -v $PWD:/project -w /project espressif/idf:latest python3 tools/build_esp32.py ${{ matrix.board }}

- name: Linker Map
run: |
pip install linkermap/
# find -quit to only print linkermap of 1 board per example
for ex in `ls -d examples/device/*/`
do
find ${ex} -maxdepth 3 -name *.map -print -quit | xargs -I % sh -c 'echo "::group::%"; linkermap -v %; echo "::endgroup::"'
done
26 changes: 17 additions & 9 deletions .idea/cmake.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions examples/device/cdc_msc_freertos/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
DEPS_SUBMODULES += lib/FreeRTOS-Kernel

include ../../make.mk

FREERTOS_SRC = lib/FreeRTOS-Kernel
Expand All @@ -10,7 +8,7 @@ INC += \
src/FreeRTOSConfig \
$(TOP)/hw \
$(TOP)/$(FREERTOS_SRC)/include \
$(TOP)/$(FREERTOS_PORTABLE_SRC)
$(TOP)/$(FREERTOS_PORTABLE_SRC) \

# Example source
EXAMPLE_SOURCE = \
Expand Down
70 changes: 26 additions & 44 deletions examples/device/cdc_msc_freertos/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#define USBD_STACK_SIZE 4096
#else

#include "FreeRTOS.h"
#include "semphr.h"
#include "queue.h"
Expand All @@ -54,15 +55,15 @@
#define CDC_STACK_SZIE configMINIMAL_STACK_SIZE

//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTYPES
// MACRO CONSTANT TYPEDEF PROTOTYPES
//--------------------------------------------------------------------+

/* Blink pattern
* - 250 ms : device not mounted
* - 1000 ms : device mounted
* - 2500 ms : device is suspended
*/
enum {
enum {
BLINK_NOT_MOUNTED = 250,
BLINK_MOUNTED = 1000,
BLINK_SUSPENDED = 2500,
Expand All @@ -81,16 +82,15 @@ StaticTask_t cdc_taskdef;

TimerHandle_t blinky_tm;

void led_blinky_cb(TimerHandle_t xTimer);
void usb_device_task(void* param);
void cdc_task(void* params);
static void led_blinky_cb(TimerHandle_t xTimer);
static void usb_device_task(void *param);
void cdc_task(void *params);

//--------------------------------------------------------------------+
// Main
//--------------------------------------------------------------------+

int main(void)
{
int main(void) {
board_init();

#if configSUPPORT_STATIC_ALLOCATION
Expand All @@ -104,8 +104,8 @@ int main(void)
xTaskCreateStatic(cdc_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, cdc_stack, &cdc_taskdef);
#else
blinky_tm = xTimerCreate(NULL, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), true, NULL, led_blinky_cb);
xTaskCreate( usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, NULL);
xTaskCreate( cdc_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, NULL);
xTaskCreate(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL);
xTaskCreate(cdc_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES - 2, NULL);
#endif

xTimerStart(blinky_tm, 0);
Expand All @@ -119,16 +119,14 @@ int main(void)
}

#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
void app_main(void)
{
void app_main(void) {
main();
}
#endif

// USB Device Driver task
// This top level thread process all usb events and invoke callbacks
void usb_device_task(void* param)
{
static void usb_device_task(void *param) {
(void) param;

// init device stack on configured roothub port
Expand All @@ -141,8 +139,7 @@ void usb_device_task(void* param)
}

// RTOS forever loop
while (1)
{
while (1) {
// put this thread to waiting state until there is new events
tud_task();

Expand All @@ -156,56 +153,46 @@ void usb_device_task(void* param)
//--------------------------------------------------------------------+

// Invoked when device is mounted
void tud_mount_cb(void)
{
void tud_mount_cb(void) {
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_MOUNTED), 0);
}

// Invoked when device is unmounted
void tud_umount_cb(void)
{
void tud_umount_cb(void) {
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), 0);
}

// Invoked when usb bus is suspended
// remote_wakeup_en : if host allow us to perform remote wakeup
// Within 7ms, device must draw an average of current less than 2.5 mA from bus
void tud_suspend_cb(bool remote_wakeup_en)
{
void tud_suspend_cb(bool remote_wakeup_en) {
(void) remote_wakeup_en;
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_SUSPENDED), 0);
}

// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
if (tud_mounted())
{
void tud_resume_cb(void) {
if (tud_mounted()) {
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_MOUNTED), 0);
}
else
{
} else {
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), 0);
}
}

//--------------------------------------------------------------------+
// USB CDC
//--------------------------------------------------------------------+
void cdc_task(void* params)
{
void cdc_task(void *params) {
(void) params;

// RTOS forever loop
while ( 1 )
{
while (1) {
// connected() check for DTR bit
// Most but not all terminal client set this when making connection
// if ( tud_cdc_connected() )
{
// There are data available
while ( tud_cdc_available() )
{
while (tud_cdc_available()) {
uint8_t buf[64];

// read and echo back
Expand All @@ -228,32 +215,27 @@ void cdc_task(void* params)
}

// Invoked when cdc when line state changed e.g connected/disconnected
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
{
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
(void) itf;
(void) rts;

// TODO set some indicator
if ( dtr )
{
if (dtr) {
// Terminal connected
}else
{
} else {
// Terminal disconnected
}
}

// Invoked when CDC interface received data from host
void tud_cdc_rx_cb(uint8_t itf)
{
void tud_cdc_rx_cb(uint8_t itf) {
(void) itf;
}

//--------------------------------------------------------------------+
// BLINKING TASK
//--------------------------------------------------------------------+
void led_blinky_cb(TimerHandle_t xTimer)
{
static void led_blinky_cb(TimerHandle_t xTimer) {
(void) xTimer;
static bool led_state = false;

Expand Down
5 changes: 5 additions & 0 deletions examples/host/bare_api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ project(${PROJECT} C CXX ASM)
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})

# Espressif has its own cmake build system
if(FAMILY STREQUAL "espressif")
return()
endif()

add_executable(${PROJECT})

# Example source
Expand Down
10 changes: 0 additions & 10 deletions examples/host/bare_api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,4 @@ EXAMPLE_SOURCE += \

SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))

# TinyUSB Host Stack source
SRC_C += \
src/class/cdc/cdc_host.c \
src/class/hid/hid_host.c \
src/class/msc/msc_host.c \
src/host/hub.c \
src/host/usbh.c \
src/portable/ohci/ohci.c \
src/portable/nxp/lpc17_40/hcd_lpc17_40.c

include ../../rules.mk
5 changes: 5 additions & 0 deletions examples/host/cdc_msc_hid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ project(${PROJECT} C CXX ASM)
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})

# Espressif has its own cmake build system
if(FAMILY STREQUAL "espressif")
return()
endif()

add_executable(${PROJECT})

# Example source
Expand Down
10 changes: 0 additions & 10 deletions examples/host/cdc_msc_hid/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,4 @@ EXAMPLE_SOURCE = \

SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))

# TinyUSB Host Stack source
SRC_C += \
src/class/cdc/cdc_host.c \
src/class/hid/hid_host.c \
src/class/msc/msc_host.c \
src/host/hub.c \
src/host/usbh.c \
src/portable/ohci/ohci.c \
src/portable/nxp/lpc17_40/hcd_lpc17_40.c

include ../../rules.mk
36 changes: 36 additions & 0 deletions examples/host/cdc_msc_hid_freertos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 3.17)

include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)

# gets PROJECT name for the example (e.g. <BOARD>-<DIR_NAME>)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})

project(${PROJECT} C CXX ASM)

# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})

# Espressif has its own cmake build system
if(FAMILY STREQUAL "espressif")
return()
endif()

add_executable(${PROJECT})

# Example source
target_sources(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src/cdc_app.c
${CMAKE_CURRENT_SOURCE_DIR}/src/freertos_hook.c
${CMAKE_CURRENT_SOURCE_DIR}/src/hid_app.c
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
${CMAKE_CURRENT_SOURCE_DIR}/src/msc_app.c
)

# Example include
target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)

# Configure compilation flags and libraries for the example without RTOS.
# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
family_configure_host_example(${PROJECT} freertos)
Loading