Skip to content

Commit

Permalink
hil add stm32f723disco, add test flags for device/host/dual
Browse files Browse the repository at this point in the history
  • Loading branch information
hathach committed Nov 13, 2024
1 parent 839ec17 commit aeae296
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 84 deletions.
2 changes: 1 addition & 1 deletion examples/device/cdc_msc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.17)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
#set_property(GLOBAL PROPERTY USE_FOLDERS ON)

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

Expand Down
20 changes: 10 additions & 10 deletions examples/host/device_info/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTYPES
//--------------------------------------------------------------------+

static uint32_t blink_interval_ms = 1000;
enum {
BLINK_NOT_MOUNTED = 250,
BLINK_MOUNTED = 1000,
BLINK_SUSPENDED = 2500,
};
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;

void led_blinking_task(void* param);
static void print_utf16(uint16_t* temp_buf, size_t buf_len);
Expand Down Expand Up @@ -102,6 +106,8 @@ int main(void) {

// Invoked when device is mounted (configured)
void tuh_mount_cb(uint8_t daddr) {
blink_interval_ms = BLINK_MOUNTED;

// Get Device Descriptor
tusb_desc_device_t desc_device;
uint8_t xfer_result = tuh_descriptor_get_device_sync(daddr, &desc_device, 18);
Expand Down Expand Up @@ -161,6 +167,7 @@ void tuh_mount_cb(uint8_t daddr) {

// Invoked when device is unmounted (bus reset/unplugged)
void tuh_umount_cb(uint8_t daddr) {
blink_interval_ms = BLINK_NOT_MOUNTED;
printf("Device removed, address = %d\r\n", daddr);
}

Expand Down Expand Up @@ -227,15 +234,8 @@ void led_blinking_task(void* param) {

while (1) {
#if CFG_TUSB_OS == OPT_OS_FREERTOS
if (blink_interval_ms == 0) {
vTaskSuspend(NULL);
} else {
vTaskDelay(blink_interval_ms / portTICK_PERIOD_MS);
}
vTaskDelay(blink_interval_ms / portTICK_PERIOD_MS);
#else
if (blink_interval_ms == 0) {
return;
}
if (board_millis() - start_ms < blink_interval_ms) {
return; // not enough time
}
Expand Down
6 changes: 3 additions & 3 deletions hw/bsp/stm32f7/boards/stm32f723disco/board.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F723xE_FLASH.ld)

set(RHPORT_SPEED OPT_MODE_FULL_SPEED OPT_MODE_HIGH_SPEED)

# device default to PORT 1 High Speed
# For Hardware test: device default to PORT 0, Host to port 1
if (NOT DEFINED RHPORT_DEVICE)
set(RHPORT_DEVICE 1)
set(RHPORT_DEVICE 0)
endif()
if (NOT DEFINED RHPORT_HOST)
set(RHPORT_HOST 0)
set(RHPORT_HOST 1)
endif()

function(update_board TARGET)
Expand Down
5 changes: 3 additions & 2 deletions hw/bsp/stm32f7/boards/stm32f723disco/board.mk
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
MCU_VARIANT = stm32f723xx

# For Hardware test: device default to PORT 0, Host to port 1
RHPORT_SPEED = OPT_MODE_FULL_SPEED OPT_MODE_HIGH_SPEED
RHPORT_DEVICE ?= 1
RHPORT_HOST ?= 0
RHPORT_DEVICE ?= 0
RHPORT_HOST ?= 1

CFLAGS += \
-DSTM32F723xx \
Expand Down
29 changes: 19 additions & 10 deletions hw/bsp/stm32f7/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ typedef struct {

#include "board.h"

//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+

#ifdef UART_DEV
UART_HandleTypeDef UartHandle = {
.Instance = UART_DEV,
.Init = {
.BaudRate = CFG_BOARD_UART_BAUDRATE,
.WordLength = UART_WORDLENGTH_8B,
.StopBits = UART_STOPBITS_1,
.Parity = UART_PARITY_NONE,
.HwFlowCtl = UART_HWCONTROL_NONE,
.Mode = UART_MODE_TX_RX,
.OverSampling = UART_OVERSAMPLING_16,
}
};
#endif

//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
Expand All @@ -54,8 +73,6 @@ void OTG_HS_IRQHandler(void) {
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+

UART_HandleTypeDef UartHandle;

void board_init(void) {
board_clock_init();

Expand Down Expand Up @@ -89,14 +106,6 @@ void board_init(void) {
#endif

#ifdef UART_DEV
UartHandle.Instance = UART_DEV;
UartHandle.Init.BaudRate = CFG_BOARD_UART_BAUDRATE;
UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
UartHandle.Init.StopBits = UART_STOPBITS_1;
UartHandle.Init.Parity = UART_PARITY_NONE;
UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
UartHandle.Init.Mode = UART_MODE_TX_RX;
UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
HAL_UART_Init(&UartHandle);
#endif

Expand Down
6 changes: 3 additions & 3 deletions src/portable/synopsys/dwc2/hcd_dwc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1181,8 +1181,7 @@ static bool handle_sof_irq(uint8_t rhport, bool in_isr) {
}

// Config HCFG FS/LS clock and HFIR for SOF interval according to link speed (value is in PHY clock unit)
static void port0_enable(dwc2_regs_t* dwc2) {
const tusb_speed_t speed = hprt_speed_get(dwc2);
static void port0_enable(dwc2_regs_t* dwc2, tusb_speed_t speed) {
uint32_t hcfg = dwc2->hcfg & ~HCFG_FSLS_PHYCLK_SEL;

const dwc2_gusbcfg_t gusbcfg_bm = dwc2->gusbcfg_bm;
Expand Down Expand Up @@ -1252,7 +1251,8 @@ static void handle_hprt_irq(uint8_t rhport, bool in_isr) {

if (hprt_bm.enable) {
// Port enable
port0_enable(dwc2);
const tusb_speed_t speed = hprt_speed_get(dwc2);
port0_enable(dwc2, speed);
} else {
// TU_ASSERT(false, );
}
Expand Down
Loading

0 comments on commit aeae296

Please sign in to comment.