Skip to content
Open
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
7 changes: 4 additions & 3 deletions apps/msc_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
#include "tusb.h"
#include "osal_log.h"
#include "socfpga_cache.h"
#include "hcd_dwc3.h"

#define MSC_BLOCK_SIZE (512)

void hcd_device_close(uint8_t rhport, uint8_t dev_addr);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not include "host/hcd.h" ?
Then we need not have this prototype redefined here


static volatile int msc_mount_complete = 0;
static scsi_inquiry_resp_t inquiry_resp;
static volatile bool status_flag_cb = true;
Expand Down Expand Up @@ -82,7 +83,7 @@ bool msc_inquiry_complete_cb(uint8_t dev_addr, tuh_msc_complete_data_t const * c

void tuh_msc_mount_cb(uint8_t dev_addr)
{
PRINT("A MassStorage device mounted");
PRINT("\r\nA MassStorage device mounted");

uint8_t const lun = 0;
tuh_msc_inquiry(dev_addr, lun, &inquiry_resp, msc_inquiry_complete_cb, 0);
Expand All @@ -97,7 +98,7 @@ void tuh_msc_umount_cb(uint8_t dev_addr)
tuh_bus_info_get(dev_addr, &dev_info);
if( dev_info.rhport != SOCFPGA_USB2_OTG_PORT )
{
hcd_dwc3_device_close(dev_info.rhport);
hcd_device_close(dev_info.rhport, 0);
}
PRINT("A MassStorage device is unmounted, address - %d\r\n", dev_addr);
}
Expand Down
4 changes: 3 additions & 1 deletion apps/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@
#endif

#ifndef CFG_TUSB_DEBUG
#define CFG_TUSB_DEBUG 0
#define CFG_TUSB_DEBUG 1
#endif

#define CFG_TUH_LOG_LEVEL 2

/* 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.
Expand Down
9 changes: 9 additions & 0 deletions apps/usb_main.c

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this file make sense in TinyUSB (if we are trying to mainline this)
This should be along side the apps, right?

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
#define USB3_HS_PORT (1)
#define USB3_SS_PORT (2)

/* Host controllers in this build, set by hw/bsp/socfpga/family.cmake (SOCFPGA_HCD) */
#ifndef SOCFPGA_HCD_DWC2
#define SOCFPGA_HCD_DWC2 1

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need either DWC2 , DWC3 or both defined, Lets error if that is not the case
Rather than defining if not set, let logically setup macro errors here (#error)

#endif
#ifndef SOCFPGA_HCD_DWC3
#define SOCFPGA_HCD_DWC3 1
#endif

int usb_wait_to_mount(int timeout)
{
while (timeout >= 0)
Expand Down Expand Up @@ -69,6 +77,7 @@ void usb_task(void *arg)
PRINT("USB3.1 port initialized successfully");
}
}

while (1)
{
tuh_task();
Expand Down
2 changes: 2 additions & 0 deletions examples/host/msc_file_explorer/only.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ mcu:STM32H7RS
mcu:STM32N6
family:samd21
family:samd5x_e5x
family:agilex5
family:socfpga
47 changes: 47 additions & 0 deletions examples/host/msc_file_explorer_freertos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
cmake_minimum_required(VERSION 3.20)

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/main.c
${CMAKE_CURRENT_SOURCE_DIR}/src/msc_app.c
${TOP}/lib/fatfs/source/ff.c
${TOP}/lib/fatfs/source/ffsystem.c
${TOP}/lib/fatfs/source/ffunicode.c
)

# Suppress warnings on fatfs
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
set_source_files_properties(
${TOP}/lib/fatfs/source/ff.c
PROPERTIES
COMPILE_FLAGS "-Wno-conversion -Wno-cast-qual"
)
endif ()

# Example include
target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
${TOP}/lib/fatfs/source
${TOP}/lib/embedded-cli
)

# 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)
6 changes: 6 additions & 0 deletions examples/host/msc_file_explorer_freertos/CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": 6,
"include": [
"../../../hw/bsp/BoardPresets.json"
]
}
27 changes: 27 additions & 0 deletions examples/host/msc_file_explorer_freertos/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
include ../../build_system/make/make.mk

FATFS_PATH = lib/fatfs/source

INC += \
src \
$(TOP)/hw \
$(TOP)/$(FATFS_PATH) \
$(TOP)/lib/embedded-cli \

# Example source
EXAMPLE_SOURCE = \
src/main.c \
src/msc_app.c \

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

# FatFS source
SRC_C += \
$(FATFS_PATH)/ff.c \
$(FATFS_PATH)/ffsystem.c \
$(FATFS_PATH)/ffunicode.c \

# suppress warning caused by fatfs
CFLAGS_GCC += -Wno-error=cast-qual

include ../../build_system/make/rules.mk
24 changes: 24 additions & 0 deletions examples/host/msc_file_explorer_freertos/only.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
mcu:CH32V20X
mcu:KINETIS_KL
mcu:LPC175X_6X
mcu:LPC177X_8X
mcu:LPC18XX
mcu:LPC40XX
mcu:LPC43XX
mcu:MIMXRT1XXX
mcu:MIMXRT10XX
mcu:MIMXRT11XX
mcu:RP2040
mcu:MSP432E4
mcu:RX65X
mcu:RAXXX
mcu:MAX3421
mcu:STM32F4
mcu:STM32F7
mcu:STM32H7
mcu:STM32H7RS
mcu:STM32N6
family:samd21
family:samd5x_e5x
family:agilex5
family:socfpga
148 changes: 148 additions & 0 deletions examples/host/msc_file_explorer_freertos/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* 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.
*
*/

/* Example to show how to navigate mass storage device with built-in command line.
* Type help for list of supported commands and syntax (mostly linux commands)

> help
* help
Print list of commands
* cat
Usage: cat [FILE]...
Concatenate FILE(s) to standard output..
* cd
Usage: cd [DIR]...
Change the current directory to DIR.
* cp
Usage: cp SOURCE DEST
Copy SOURCE to DEST.
* ls
Usage: ls [DIR]...
List information about the FILEs (the current directory by default).
* pwd
Usage: pwd
Print the name of the current working directory.
* mkdir
Usage: mkdir DIR...
Create the DIRECTORY(ies), if they do not already exist..
* mv
Usage: mv SOURCE DEST...
Rename SOURCE to DEST.
* rm
Usage: rm [FILE]...
Remove (unlink) the FILE(s).
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "bsp/board_api.h"
#include "tusb.h"

#include "msc_app.h"

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

#define USBH_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) * (CFG_TUSB_DEBUG ? 2 : 1)

void led_blinking_task(void);

static void usb_host_task(void *param);

/*------------- MAIN -------------*/
int main(void) {
board_init();

printf("TinyUSB Host MassStorage Explorer Example\r\n");

xTaskCreate(usb_host_task, "usbd", USBH_STACK_SIZE, NULL, configMAX_PRIORITIES-1, NULL);

vTaskStartScheduler();

return 0;
}

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

// init host stack on configured roothub port
tusb_rhport_init_t host_init = {
.role = TUSB_ROLE_HOST,
.speed = TUSB_SPEED_AUTO
};

if (!tusb_init(BOARD_TUH_RHPORT, &host_init)) {
printf("Failed to init USB Host Stack\r\n");
vTaskSuspend(NULL);
}

board_init_after_tusb();

msc_app_init();

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

msc_app_task();

osal_task_delay(10);
}
}

//--------------------------------------------------------------------+
// TinyUSB Callbacks
//--------------------------------------------------------------------+

void tuh_mount_cb(uint8_t dev_addr) {
(void) dev_addr;
}

void tuh_umount_cb(uint8_t dev_addr) {
(void) dev_addr;
}

//--------------------------------------------------------------------+
// Blinking Task
//--------------------------------------------------------------------+
void led_blinking_task(void) {
const uint32_t interval_ms = 1000;
static uint32_t start_ms = 0;

static bool led_state = false;

// Blink every interval ms
if (board_millis() - start_ms < interval_ms) return; // not enough time
start_ms += interval_ms;

board_led_write(led_state);
led_state = 1 - led_state; // toggle
}
Loading
Loading