Skip to content

Commit a2638e8

Browse files
authored
Merge pull request #68 from RebelTechnology/feature/usbd-startup-refactor
v22.4.rc1
2 parents f9e2721 + c569cb4 commit a2638e8

233 files changed

Lines changed: 7025 additions & 26665 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ACDC/ACDC.ioc

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,16 @@ Mcu.IP15=TIM4
148148
Mcu.IP16=TIM8
149149
Mcu.IP17=UART5
150150
Mcu.IP18=UART7
151-
Mcu.IP19=USB_DEVICE
151+
Mcu.IP19=USB_OTG_FS
152152
Mcu.IP2=DEBUG
153-
Mcu.IP20=USB_OTG_FS
154153
Mcu.IP3=DMA
155154
Mcu.IP4=FMC
156155
Mcu.IP5=FREERTOS
157156
Mcu.IP6=NVIC
158157
Mcu.IP7=QUADSPI
159158
Mcu.IP8=RCC
160159
Mcu.IP9=SAI1
161-
Mcu.IPNb=21
160+
Mcu.IPNb=20
162161
Mcu.Name=STM32H743IIKx
163162
Mcu.Package=UFBGA176
164163
Mcu.Pin0=PE3
@@ -176,7 +175,6 @@ Mcu.Pin108=PB11
176175
Mcu.Pin109=VP_FREERTOS_VS_CMSIS_V1
177176
Mcu.Pin11=PE5
178177
Mcu.Pin110=VP_SYS_VS_Systick
179-
Mcu.Pin111=VP_USB_DEVICE_VS_USB_DEVICE_AUDIO_FS
180178
Mcu.Pin12=PE6
181179
Mcu.Pin13=PB7
182180
Mcu.Pin14=PB6
@@ -273,7 +271,7 @@ Mcu.Pin96=PD8
273271
Mcu.Pin97=PA3
274272
Mcu.Pin98=PA7
275273
Mcu.Pin99=PB1
276-
Mcu.PinsNb=112
274+
Mcu.PinsNb=111
277275
Mcu.ThirdPartyNb=0
278276
Mcu.UserConstants=
279277
Mcu.UserName=STM32H743IIKx
@@ -532,8 +530,8 @@ ProjectManager.FreePins=true
532530
ProjectManager.HalAssertFull=true
533531
ProjectManager.HeapSize=0x200
534532
ProjectManager.KeepUserCode=true
535-
ProjectManager.LastFirmware=true
536-
ProjectManager.LibraryCopy=1
533+
ProjectManager.LastFirmware=false
534+
ProjectManager.LibraryCopy=2
537535
ProjectManager.MainLocation=Core/Src
538536
ProjectManager.NoMain=false
539537
ProjectManager.PreviousToolchain=
@@ -545,7 +543,7 @@ ProjectManager.StackSize=0x400
545543
ProjectManager.TargetToolchain=Other Toolchains (GPDSC)
546544
ProjectManager.ToolChainLocation=
547545
ProjectManager.UnderRoot=false
548-
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-MX_DMA_Init-DMA-false-HAL-true,3-SystemClock_Config-RCC-false-HAL-false,4-MX_QUADSPI_Init-QUADSPI-false-HAL-true,5-MX_FMC_Init-FMC-false-HAL-true,6-MX_SAI1_Init-SAI1-false-HAL-true,7-MX_ADC1_Init-ADC1-false-HAL-true,8-MX_SPI2_Init-SPI2-false-HAL-true,9-MX_SPI3_Init-SPI3-false-HAL-true,10-MX_TIM2_Init-TIM2-false-HAL-true,11-MX_TIM4_Init-TIM4-false-HAL-true,12-MX_UART5_Init-UART5-false-HAL-true,13-MX_UART7_Init-UART7-false-HAL-true,14-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,15-MX_TIM8_Init-TIM8-false-HAL-true,16-MX_TIM3_Init-TIM3-false-HAL-true,0-MX_CORTEX_M7_Init-CORTEX_M7-false-HAL-true
546+
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-MX_DMA_Init-DMA-false-HAL-true,3-SystemClock_Config-RCC-false-HAL-false,4-MX_QUADSPI_Init-QUADSPI-false-HAL-true,5-MX_FMC_Init-FMC-false-HAL-true,6-MX_SAI1_Init-SAI1-false-HAL-true,7-MX_ADC1_Init-ADC1-false-HAL-true,8-MX_SPI2_Init-SPI2-false-HAL-true,9-MX_SPI3_Init-SPI3-false-HAL-true,10-MX_TIM2_Init-TIM2-false-HAL-true,11-MX_TIM4_Init-TIM4-false-HAL-true,12-MX_UART5_Init-UART5-false-HAL-true,13-MX_UART7_Init-UART7-false-HAL-true,14-MX_TIM8_Init-TIM8-false-HAL-true,15-MX_TIM3_Init-TIM3-false-HAL-true,16-MX_USB_OTG_FS_PCD_Init-USB_OTG_FS-false-HAL-true,0-MX_CORTEX_M7_Init-CORTEX_M7-false-HAL-true
549547
QUADSPI.ClockPrescaler=9
550548
QUADSPI.FifoThreshold=4
551549
QUADSPI.FlashSize=22
@@ -863,20 +861,10 @@ TIM8.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2
863861
TIM8.IPParameters=Channel-PWM Generation1 CH1,Channel-PWM Generation2 CH2,Period,Prescaler
864862
TIM8.Period=1023
865863
TIM8.Prescaler=100
866-
USB_DEVICE.CLASS_NAME_FS=AUDIO
867-
USB_DEVICE.IPParameters=VirtualMode-AUDIO_FS,VirtualModeFS,CLASS_NAME_FS,VID-AUDIO_FS,MANUFACTURER_STRING-AUDIO_FS,PID_AUDIO_FS,PRODUCT_STRING_AUDIO_FS
868-
USB_DEVICE.MANUFACTURER_STRING-AUDIO_FS=Rebel Technology
869-
USB_DEVICE.PID_AUDIO_FS=0xDADA
870-
USB_DEVICE.PRODUCT_STRING_AUDIO_FS=OWL-ACDC
871-
USB_DEVICE.VID-AUDIO_FS=0x1209
872-
USB_DEVICE.VirtualMode-AUDIO_FS=Audio
873-
USB_DEVICE.VirtualModeFS=Audio_FS
874864
USB_OTG_FS.IPParameters=VirtualMode
875865
USB_OTG_FS.VirtualMode=Device_Only
876866
VP_FREERTOS_VS_CMSIS_V1.Mode=CMSIS_V1
877867
VP_FREERTOS_VS_CMSIS_V1.Signal=FREERTOS_VS_CMSIS_V1
878868
VP_SYS_VS_Systick.Mode=SysTick
879869
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
880-
VP_USB_DEVICE_VS_USB_DEVICE_AUDIO_FS.Mode=AUDIO_FS
881-
VP_USB_DEVICE_VS_USB_DEVICE_AUDIO_FS.Signal=USB_DEVICE_VS_USB_DEVICE_AUDIO_FS
882870
board=custom

ACDC/Core/Inc/hardware.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
#define OWL_XIBECA
55
#define HARDWARE_ID XIBECA_HARDWARE
66
#define HARDWARE_VERSION "AC/DC"
7+
#define USBD_PRODUCT_STRING_FSHS "OWL-ACDC"
8+
79
/* #define NO_EXTERNAL_RAM */
810
/* #define NO_CCM_RAM */
911
#define DMA_RAM __attribute__ ((section (".dmadata")))
1012

1113
/* note that with H750, PLUS_RAM may be used by firmware */
1214
#define USE_PLUS_RAM
1315

16+
#define USE_FAST_POW_RESOURCES
17+
1418
#ifdef NDEBUG
1519
#define USE_ICACHE
1620
#define USE_DCACHE

ACDC/Core/Src/ACDC.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "message.h"
88
#include "Codec.h"
99
#include "flash.h"
10+
#include "Storage.h"
11+
#include "ServiceCall.h"
1012

1113
#define XIBECA_PIN3 GPIOD, GPIO_PIN_2
1214
#define XIBECA_PIN4 GPIOG, GPIO_PIN_10
@@ -182,3 +184,30 @@ void onLoop(void){
182184
setLed(i+5, getParameterValue(PARAMETER_BA+i));
183185
}
184186
}
187+
188+
#ifdef USE_FAST_POW_RESOURCES
189+
uint32_t fast_log_table_size = 0;
190+
uint32_t fast_pow_table_size = 0;
191+
float fast_log_table[16384] __attribute__ ((section (".d2data")));
192+
uint32_t fast_pow_table[2048] __attribute__ ((section (".d2data")));
193+
void onResourceUpdate(){
194+
Resource* res = storage.getResourceByName(SYSTEM_TABLE_LOG ".bin");
195+
if(res && res->isValid()){
196+
fast_log_table_size = std::min(res->getDataSize()/sizeof(float), 16384U);
197+
storage.readResource(res->getHeader(), fast_log_table, 0, fast_log_table_size*sizeof(float));
198+
}else{
199+
fast_log_table_size = 0;
200+
}
201+
res = storage.getResourceByName(SYSTEM_TABLE_POW ".bin");
202+
if(res && res->isValid()){
203+
fast_pow_table_size = std::min(res->getDataSize()/sizeof(uint32_t), 2048U);
204+
storage.readResource(res->getHeader(), fast_pow_table, 0, fast_pow_table_size*sizeof(uint32_t));
205+
}else{
206+
fast_pow_table_size = 0;
207+
}
208+
debugMessage("log/pow", fast_log_table_size, fast_pow_table_size);
209+
}
210+
#else
211+
#include "FastLogTable.h"
212+
#include "FastPowTable.h"
213+
#endif

ACDC/Core/Src/main.c

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
/* Includes ------------------------------------------------------------------*/
2121
#include "main.h"
2222
#include "cmsis_os.h"
23-
#include "usb_device.h"
24-
#include "usb_device.h"
2523

2624
/* Private includes ----------------------------------------------------------*/
2725
/* USER CODE BEGIN Includes */
@@ -66,6 +64,8 @@ TIM_HandleTypeDef htim8;
6664
UART_HandleTypeDef huart5;
6765
UART_HandleTypeDef huart7;
6866

67+
PCD_HandleTypeDef hpcd_USB_OTG_FS;
68+
6969
SDRAM_HandleTypeDef hsdram1;
7070

7171
osThreadId defaultTaskHandle;
@@ -90,6 +90,7 @@ static void MX_UART5_Init(void);
9090
static void MX_UART7_Init(void);
9191
static void MX_TIM8_Init(void);
9292
static void MX_TIM3_Init(void);
93+
static void MX_USB_OTG_FS_PCD_Init(void);
9394
void StartDefaultTask(void const * argument);
9495

9596
/* USER CODE BEGIN PFP */
@@ -176,6 +177,7 @@ int main(void)
176177
MX_UART7_Init();
177178
MX_TIM8_Init();
178179
MX_TIM3_Init();
180+
MX_USB_OTG_FS_PCD_Init();
179181
/* USER CODE BEGIN 2 */
180182

181183
#ifdef USE_EXTERNAL_RAM
@@ -951,6 +953,42 @@ static void MX_UART7_Init(void)
951953

952954
}
953955

956+
/**
957+
* @brief USB_OTG_FS Initialization Function
958+
* @param None
959+
* @retval None
960+
*/
961+
static void MX_USB_OTG_FS_PCD_Init(void)
962+
{
963+
964+
/* USER CODE BEGIN USB_OTG_FS_Init 0 */
965+
966+
/* USER CODE END USB_OTG_FS_Init 0 */
967+
968+
/* USER CODE BEGIN USB_OTG_FS_Init 1 */
969+
970+
/* USER CODE END USB_OTG_FS_Init 1 */
971+
hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
972+
hpcd_USB_OTG_FS.Init.dev_endpoints = 9;
973+
hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
974+
hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
975+
hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
976+
hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE;
977+
hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
978+
hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
979+
hpcd_USB_OTG_FS.Init.battery_charging_enable = ENABLE;
980+
hpcd_USB_OTG_FS.Init.vbus_sensing_enable = ENABLE;
981+
hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
982+
if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)
983+
{
984+
Error_Handler();
985+
}
986+
/* USER CODE BEGIN USB_OTG_FS_Init 2 */
987+
988+
/* USER CODE END USB_OTG_FS_Init 2 */
989+
990+
}
991+
954992
/**
955993
* Enable DMA controller clock
956994
*/
@@ -1182,8 +1220,6 @@ static void MX_GPIO_Init(void)
11821220
/* USER CODE END Header_StartDefaultTask */
11831221
void StartDefaultTask(void const * argument)
11841222
{
1185-
/* init code for USB_DEVICE */
1186-
MX_USB_DEVICE_Init();
11871223
/* USER CODE BEGIN 5 */
11881224

11891225
setup();

ACDC/Core/Src/stm32h7xx_hal_msp.c

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,95 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
799799

800800
}
801801

802+
/**
803+
* @brief PCD MSP Initialization
804+
* This function configures the hardware resources used in this example
805+
* @param hpcd: PCD handle pointer
806+
* @retval None
807+
*/
808+
void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
809+
{
810+
GPIO_InitTypeDef GPIO_InitStruct = {0};
811+
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
812+
if(hpcd->Instance==USB_OTG_FS)
813+
{
814+
/* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
815+
816+
/* USER CODE END USB_OTG_FS_MspInit 0 */
817+
/** Initializes the peripherals clock
818+
*/
819+
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
820+
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
821+
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
822+
{
823+
Error_Handler();
824+
}
825+
/** Enable USB Voltage detector
826+
*/
827+
HAL_PWREx_EnableUSBVoltageDetector();
828+
829+
__HAL_RCC_GPIOA_CLK_ENABLE();
830+
/**USB_OTG_FS GPIO Configuration
831+
PA12 ------> USB_OTG_FS_DP
832+
PA11 ------> USB_OTG_FS_DM
833+
PA9 ------> USB_OTG_FS_VBUS
834+
*/
835+
GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_11;
836+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
837+
GPIO_InitStruct.Pull = GPIO_NOPULL;
838+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
839+
GPIO_InitStruct.Alternate = GPIO_AF10_OTG1_FS;
840+
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
841+
842+
GPIO_InitStruct.Pin = GPIO_PIN_9;
843+
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
844+
GPIO_InitStruct.Pull = GPIO_NOPULL;
845+
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
846+
847+
/* Peripheral clock enable */
848+
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
849+
/* USB_OTG_FS interrupt Init */
850+
HAL_NVIC_SetPriority(OTG_FS_IRQn, 5, 0);
851+
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
852+
/* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
853+
854+
/* USER CODE END USB_OTG_FS_MspInit 1 */
855+
}
856+
857+
}
858+
859+
/**
860+
* @brief PCD MSP De-Initialization
861+
* This function freeze the hardware resources used in this example
862+
* @param hpcd: PCD handle pointer
863+
* @retval None
864+
*/
865+
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
866+
{
867+
if(hpcd->Instance==USB_OTG_FS)
868+
{
869+
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
870+
871+
/* USER CODE END USB_OTG_FS_MspDeInit 0 */
872+
/* Peripheral clock disable */
873+
__HAL_RCC_USB_OTG_FS_CLK_DISABLE();
874+
875+
/**USB_OTG_FS GPIO Configuration
876+
PA12 ------> USB_OTG_FS_DP
877+
PA11 ------> USB_OTG_FS_DM
878+
PA9 ------> USB_OTG_FS_VBUS
879+
*/
880+
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_12|GPIO_PIN_11|GPIO_PIN_9);
881+
882+
/* USB_OTG_FS interrupt DeInit */
883+
HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
884+
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
885+
886+
/* USER CODE END USB_OTG_FS_MspDeInit 1 */
887+
}
888+
889+
}
890+
802891
static uint32_t FMC_Initialized = 0;
803892

804893
static void HAL_FMC_MspInit(void){

ACDC/Core/Src/stm32h7xx_it.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
/* USER CODE END 0 */
5959

6060
/* External variables --------------------------------------------------------*/
61-
extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
6261
extern DMA_HandleTypeDef hdma_adc1;
6362
extern ADC_HandleTypeDef hadc1;
6463
extern QSPI_HandleTypeDef hqspi;
@@ -68,6 +67,7 @@ extern SAI_HandleTypeDef hsai_BlockA1;
6867
extern SAI_HandleTypeDef hsai_BlockB1;
6968
extern DMA_HandleTypeDef hdma_spi3_tx;
7069
extern SPI_HandleTypeDef hspi3;
70+
extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
7171
/* USER CODE BEGIN EV */
7272

7373
/* USER CODE END EV */

ACDC/Makefile

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,26 @@ PROJECT = ACDC
22
BUILDROOT = .
33
OPENWARE ?= $(BUILDROOT)/..
44

5-
LDSCRIPT = $(OPENWARE)/Hardware/xibeca.ld
6-
include $(OPENWARE)/Hardware/owl3.mk
5+
include $(OPENWARE)/Hardware/xibeca.mk
76

87
C_SRC = $(wildcard Core/Src/*.c)
98
CPP_SRC = $(wildcard Core/Src/*.cpp)
109
C_SRC += $(OPENWARE)/Source/pcm3168a.c
11-
C_SRC += $(OPENWARE)/Source/usbd_audio.c
1210
C_SRC += $(OPENWARE)/Source/sdram-as4cXm32.c
1311
C_SRC += $(OPENWARE)/Source/flash-qspi.c
14-
S_SRC = $(BUILDROOT)/Core/Src/startup_stm32h743xx.s
15-
C_SRC += $(BUILDROOT)/USB_DEVICE/App/usb_device.c
16-
C_SRC += $(BUILDROOT)/USB_DEVICE/App/usbd_desc.c
17-
C_SRC += $(BUILDROOT)/USB_DEVICE/Target/usbd_conf.c
1812

1913
include $(OPENWARE)/Hardware/sources.mk
2014

2115
C_SRC += $(C_SRC_SAI)
22-
# C_SRC += $(C_SRC_DAC)
2316
C_SRC += $(C_SRC_SDRAM)
24-
C_SRC += $(C_SRC_USBD)
25-
# C_SRC += $(C_SRC_USBH)
2617
C_SRC += $(C_SRC_DSP)
2718
C_SRC += $(C_SRC_OS)
2819
C_SRC += $(C_SRC_UART)
2920
C_SRC += $(C_SRC_I2C)
3021
C_SRC += $(C_SRC_QSPI)
3122
C_SRC += $(C_SRC_MDMA)
23+
C_SRC += $(C_SRC_USBD)
24+
C_SRC += $(C_SRC_USBD_AUDIO)
3225

3326
include $(OPENWARE)/Hardware/h7.mk
3427

0 commit comments

Comments
 (0)