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

USB Middleware #1365

Merged
merged 23 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
125d02f
Set up ioc configuration, build system WIP.
liam-ilan Oct 14, 2024
76e210e
88% building
liam-ilan Oct 15, 2024
934934c
Added hal files.
liam-ilan Oct 19, 2024
2e4572c
Build USB on f4 🎉
liam-ilan Oct 22, 2024
8e658f1
Simple echo.
liam-ilan Oct 22, 2024
e55d441
Added USB flag to existing stm 32 functions, dropped dedicated usb fu…
liam-ilan Oct 26, 2024
16f50a7
Fix formatting.
liam-ilan Oct 26, 2024
736ccac
Fixed faulty append in cmake.
liam-ilan Oct 26, 2024
2684a6a
Quick fix to usb srcs.
liam-ilan Oct 26, 2024
6f0d792
Brought back -Werror.
liam-ilan Nov 9, 2024
bf0ff2a
Added clauses to ignore specific warnings in usb files.
liam-ilan Nov 16, 2024
e58fccd
Added ignored diagnostics to H7.
liam-ilan Nov 16, 2024
d06cc06
Leftover debug message :(.
liam-ilan Nov 16, 2024
4080e95
Removed duplicate hal include on f4dev.
liam-ilan Nov 16, 2024
c860ec1
Cleaned up stmlib.cmake usb inclusion.
liam-ilan Nov 16, 2024
2c2b199
Merge branch 'master' into liam-ilan/usb
liam-ilan Nov 16, 2024
36d9243
Merge branch 'master' into liam-ilan/usb
liam-ilan Nov 26, 2024
eaef921
Added USB flag to RSM builds.
liam-ilan Nov 29, 2024
f5e574f
Merge branch 'master' into liam-ilan/usb
liam-ilan Dec 2, 2024
7538b53
Fixed new quintuna boards.
liam-ilan Dec 2, 2024
1779aba
Brought back sysview to h7 cubemx libraries (lost in merge).
liam-ilan Dec 2, 2024
bd63150
Removed dupe usb srcs, moved discovery of USB_MIDDLEWARE_DIR to behin…
liam-ilan Dec 3, 2024
4120b60
Merge branch 'master' into liam-ilan/usb
liam-ilan Dec 7, 2024
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
2 changes: 2 additions & 0 deletions firmware/cmake/bootlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function(stm32f4_boot_binary
"${STM32_HAL_SRCS}"
"${SYSCALLS}"
"${MD5_LOCATION}"
FALSE
)

# Add bootloader-specific files.
Expand Down Expand Up @@ -121,6 +122,7 @@ function(stm32h7_boot_binary
"${STM32_HAL_SRCS}"
"${SYSCALLS}"
"${MD5_LOCATION}"
FALSE
)

# Add bootloader-specific files.
Expand Down
77 changes: 62 additions & 15 deletions firmware/cmake/stmlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ message(" 🔃 Registered stm32f412rx_cube_library() function")
# HAL_CONF_DIR: src/cubemx/Inc
# HAL_SRCS: the ones that we want, stripped prefixes
# SYSCALLS: most of the functions defined inside are weak references, only used to make sure it builds without error.
# USB_ENABLED: flags if usb middleware should be included.
function(stm32f412rx_cube_library
HAL_LIB_NAME
HAL_CONF_DIR
HAL_SRCS
SYSCALLS
IOC_CHECKSUM
USB_ENABLED
Lucien950 marked this conversation as resolved.
Show resolved Hide resolved
)
set(DRIVERS_DIR "${STM32CUBEF4_SOURCE_DIR}/Drivers")
set(FREERTOS_DIR "${STM32CUBEF4_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source")
set(USB_MIDDLEWARE_DIR "${STM32CUBEF4_SOURCE_DIR}/Middlewares/ST/STM32_USB_Device_Library")
Lucien950 marked this conversation as resolved.
Show resolved Hide resolved

# Set include directories for STM32Cube library.
set(STM32CUBE_INCLUDE_DIRS
Expand All @@ -81,9 +84,16 @@ function(stm32f412rx_cube_library
"${SEGGER_SYSTEMVIEW_SOURCE_DIR}/Sample/FreeRTOSV10"
)

file(GLOB USB_SRCS
Copy link
Contributor

Choose a reason for hiding this comment

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

no glob required

please move to line 126

Copy link
Contributor

Choose a reason for hiding this comment

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

actually why this cause down there it's the same files

"${USB_MIDDLEWARE_DIR}/Class/CDC/Src/usbd_cdc.c"

"${USB_MIDDLEWARE_DIR}/Core/Src/usbd_core.c"
"${USB_MIDDLEWARE_DIR}/Core/Src/usbd_ctlreq.c"
"${USB_MIDDLEWARE_DIR}/Core/Src/usbd_ioreq.c"
)

# HAL sources.
set(STM32_HAL_SRCS)

foreach (HAL_SRC ${HAL_SRCS})
list(APPEND STM32_HAL_SRCS "${DRIVERS_DIR}/STM32F4xx_HAL_Driver/Src/${HAL_SRC}")
endforeach ()
Expand Down Expand Up @@ -112,6 +122,20 @@ function(stm32f412rx_cube_library
set(STARTUP_SRC "${DRIVERS_DIR}/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f412rx.s")

set(STM32CUBE_SRCS ${STM32_HAL_SRCS} ${RTOS_SRCS} ${SYSTEMVIEW_SRCS} ${SYSCALLS} ${IOC_CHECKSUM} ${STARTUP_SRC} ${NEWLIB_SRCS})
if(USB_ENABLED)
list(APPEND STM32CUBE_SRCS
"${USB_MIDDLEWARE_DIR}/Class/CDC/Src/usbd_cdc.c"
"${USB_MIDDLEWARE_DIR}/Core/Src/usbd_core.c"
"${USB_MIDDLEWARE_DIR}/Core/Src/usbd_ctlreq.c"
"${USB_MIDDLEWARE_DIR}/Core/Src/usbd_ioreq.c"
)

list(APPEND STM32CUBE_INCLUDE_DIRS
"${USB_MIDDLEWARE_DIR}/Core/Inc"
"${USB_MIDDLEWARE_DIR}/Class/CDC/Inc"
)
endif()

embedded_library(
"${HAL_LIB_NAME}"
"${STM32CUBE_SRCS}"
Expand All @@ -133,26 +157,29 @@ function(stm32h733xx_cube_library
HAL_SRCS
SYSCALLS
IOC_CHECKSUM
USB_ENABLED
)
set(DRIVERS_DIR "${STM32CUBEH7_SOURCE_DIR}/Drivers")
set(FREERTOS_DIR "${STM32CUBEH7_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS/Source")
set(USB_MIDDLEWARE_DIR "${STM32CUBEH7_SOURCE_DIR}/Middlewares/ST/STM32_USB_Device_Library")
Lucien950 marked this conversation as resolved.
Show resolved Hide resolved

# Set include directories for STM32Cube library.
set(STM32CUBE_INCLUDE_DIRS
"${HAL_CONF_DIR}"
"${DRIVERS_DIR}/STM32H7xx_HAL_Driver/Inc"
"${DRIVERS_DIR}/STM32H7xx_HAL_Driver/Inc/Legacy"
"${FREERTOS_DIR}/include"
"${FREERTOS_DIR}/CMSIS_RTOS_V2"
"${FREERTOS_DIR}/portable/GCC/ARM_CM4F"
"${DRIVERS_DIR}/CMSIS/Device/ST/STM32H7xx/Include"
"${DRIVERS_DIR}/CMSIS/Include"
# SEGGER SystemView includes.
"${THIRD_PARTY_DIR}/sysview"
Lucien950 marked this conversation as resolved.
Show resolved Hide resolved
"${SEGGER_SYSTEMVIEW_SOURCE_DIR}/SEGGER"
"${SEGGER_SYSTEMVIEW_SOURCE_DIR}/Config"
"${SEGGER_SYSTEMVIEW_SOURCE_DIR}/Sample/FreeRTOSV10"
"${HAL_CONF_DIR}"
"${DRIVERS_DIR}/STM32H7xx_HAL_Driver/Inc"
"${DRIVERS_DIR}/STM32H7xx_HAL_Driver/Inc/Legacy"
"${FREERTOS_DIR}/include"
"${FREERTOS_DIR}/CMSIS_RTOS_V2"
"${FREERTOS_DIR}/portable/GCC/ARM_CM4F"
"${DRIVERS_DIR}/CMSIS/Device/ST/STM32H7xx/Include"
"${DRIVERS_DIR}/CMSIS/Include"

# SEGGER SystemView includes.
"${SEGGER_SYSTEMVIEW_SOURCE_DIR}/SEGGER"
"${SEGGER_SYSTEMVIEW_SOURCE_DIR}/Config"
"${SEGGER_SYSTEMVIEW_SOURCE_DIR}/Sample/FreeRTOSV10"
)

# HAL sources.
set(STM32_HAL_SRCS)
foreach (HAL_SRC ${HAL_SRCS})
Expand Down Expand Up @@ -184,6 +211,26 @@ function(stm32h733xx_cube_library
set(STARTUP_SRC "${DRIVERS_DIR}/CMSIS/Device/ST/STM32H7xx/Source/Templates/gcc/startup_stm32h733xx.s")

set(STM32CUBE_SRCS ${STM32_HAL_SRCS} ${RTOS_SRCS} ${SYSTEMVIEW_SRCS} ${SYSCALLS} ${IOC_CHECKSUM} ${STARTUP_SRC})

# Handle usb srcs and include directories.
# Currently, all our USB devices are of the Communications Device Class (CDC).
# If we want to ever support different device classes,
# you will need to add a argument to this function with the requested class.
if(USB_ENABLED)
list(APPEND STM32CUBE_SRCS
"${USB_MIDDLEWARE_DIR}/Class/CDC/Src/usbd_cdc.c"
"${USB_MIDDLEWARE_DIR}/Core/Src/usbd_core.c"
"${USB_MIDDLEWARE_DIR}/Core/Src/usbd_ctlreq.c"
"${USB_MIDDLEWARE_DIR}/Core/Src/usbd_ioreq.c"
)

list(APPEND STM32CUBE_INCLUDE_DIRS
"${USB_MIDDLEWARE_DIR}/Core/Inc"
"${USB_MIDDLEWARE_DIR}/Class/CDC/Inc"
)
endif()


embedded_library(
"${HAL_LIB_NAME}"
"${STM32CUBE_SRCS}"
Expand All @@ -197,4 +244,4 @@ function(stm32h733xx_cube_library
STM32H733xx
CANFD
)
endfunction()
endfunction()
4 changes: 4 additions & 0 deletions firmware/dev/f4dev/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ IF ("${TARGET}" STREQUAL "binary")
"stm32f4xx_hal.c"
"stm32f4xx_hal_sd.c"
"stm32f4xx_ll_sdmmc.c"
"stm32f4xx_hal_pcd.c"
"stm32f4xx_hal_pcd_ex.c"
"stm32f4xx_ll_usb.c"
)

# Pass syscalls to the cube library so we can build without warnings.
Expand All @@ -46,6 +49,7 @@ IF ("${TARGET}" STREQUAL "binary")
"${STM32_HAL_SRCS}"
"${SYSCALLS}"
"${MD5_LOCATION}"
TRUE
)

embedded_binary(
Expand Down
2 changes: 1 addition & 1 deletion firmware/dev/f4dev/src/cubemx/Inc/stm32f4xx_hal_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extern "C"
/* #define HAL_SMARTCARD_MODULE_ENABLED */
/* #define HAL_SMBUS_MODULE_ENABLED */
/* #define HAL_WWDG_MODULE_ENABLED */
/* #define HAL_PCD_MODULE_ENABLED */
#define HAL_PCD_MODULE_ENABLED
/* #define HAL_HCD_MODULE_ENABLED */
/* #define HAL_DSI_MODULE_ENABLED */
/* #define HAL_QSPI_MODULE_ENABLED */
Expand Down
1 change: 1 addition & 0 deletions firmware/dev/f4dev/src/cubemx/Inc/stm32f4xx_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ extern "C"
void TIM6_IRQHandler(void);
void CAN2_RX0_IRQHandler(void);
void CAN2_RX1_IRQHandler(void);
void OTG_FS_IRQHandler(void);
/* USER CODE BEGIN EFP */

/* USER CODE END EFP */
Expand Down
103 changes: 103 additions & 0 deletions firmware/dev/f4dev/src/cubemx/Inc/usb_device.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : usb_device.h
* @version : v1.0_Cube
* @brief : Header for usb_device.c file.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USB_DEVICE__H__
#define __USB_DEVICE__H__

#ifdef __cplusplus
extern "C"
{
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
#include "stm32f4xx_hal.h"
#include "usbd_def.h"

/* USER CODE BEGIN INCLUDE */

/* USER CODE END INCLUDE */

/** @addtogroup USBD_OTG_DRIVER
* @{
*/

/** @defgroup USBD_DEVICE USBD_DEVICE
* @brief Device file for Usb otg low level driver.
* @{
*/

/** @defgroup USBD_DEVICE_Exported_Variables USBD_DEVICE_Exported_Variables
* @brief Public variables.
* @{
*/

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/*
* -- Insert your variables declaration here --
*/
/* USER CODE BEGIN VARIABLES */

/* USER CODE END VARIABLES */
/**
* @}
*/

/** @defgroup USBD_DEVICE_Exported_FunctionsPrototype USBD_DEVICE_Exported_FunctionsPrototype
* @brief Declaration of public functions for Usb device.
* @{
*/

/** USB Device initialization function. */
void MX_USB_DEVICE_Init(void);

/*
* -- Insert functions declaration here --
*/
/* USER CODE BEGIN FD */

/* USER CODE END FD */
/**
* @}
*/

/**
* @}
*/

/**
* @}
*/

#ifdef __cplusplus
}
#endif

#endif /* __USB_DEVICE__H__ */
Loading
Loading