diff --git a/firmware/config/boards/subaru_eg33/openblt/main_external_osc.c b/firmware/config/boards/subaru_eg33/openblt/main_external_osc.c index 142ac3e6b0..5fb51f13e2 100644 --- a/firmware/config/boards/subaru_eg33/openblt/main_external_osc.c +++ b/firmware/config/boards/subaru_eg33/openblt/main_external_osc.c @@ -113,7 +113,7 @@ static void SystemClock_Config(void) RCC_OscInitStruct.PLL.PLLM = 25; RCC_OscInitStruct.PLL.PLLN = 432; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; - RCC_OscInitStruct.PLL.PLLQ = 2; + RCC_OscInitStruct.PLL.PLLQ = 9; //48 MHz for USB if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { /* Clock configuration incorrect or hardware failure. Hang the system to prevent @@ -176,6 +176,10 @@ void HAL_MspInit(void) /* CAN clock enable. */ __HAL_RCC_CAN1_CLK_ENABLE(); #endif +#if (BOOT_COM_USB_ENABLE > 0) + /* USB clock enable. */ + __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); +#endif /* Configure GPIO pin for the Red LED. */ GPIO_InitStruct.Pin = STATUS_LED_PIN; @@ -217,7 +221,15 @@ void HAL_MspInit(void) GPIO_InitStruct.Alternate = GPIO_AF9_CAN1; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); #endif - +#if (BOOT_COM_USB_ENABLE > 0) + /* USB pin configuration. */ + GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); +#endif } /*** end of HAL_MspInit ***/ @@ -240,6 +252,14 @@ void HAL_MspDeInit(void) HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7); HAL_GPIO_DeInit(GPIOC, GPIO_PIN_13); +#if (BOOT_COM_USB_ENABLE > 0) + /* Deinit used GPIOs. */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11); + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_12); + /* USB clock enable. */ + __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); +#endif + #if (BOOT_COM_CAN_ENABLE > 0) /* Deinit used GPIOs. */ HAL_GPIO_DeInit(GPIOD, GPIO_PIN_0); diff --git a/firmware/config/boards/subaru_eg33/openblt/oblt_board.mk b/firmware/config/boards/subaru_eg33/openblt/oblt_board.mk index 24d73b9ba1..4ce6378110 100644 --- a/firmware/config/boards/subaru_eg33/openblt/oblt_board.mk +++ b/firmware/config/boards/subaru_eg33/openblt/oblt_board.mk @@ -22,4 +22,6 @@ BRDFLAGS += -DBOOT_CPU_XTAL_SPEED_KHZ=25000 BRDFLAGS += -DBOOT_CPU_SYSTEM_SPEED_KHZ=216000 BRDFLAGS += -DBOOT_COM_RS232_CHANNEL_INDEX=0 # \brief Select the desired CAN peripheral as a zero based index. -BRDFLAGS += -DBOOT_COM_CAN_CHANNEL_INDEX=0 \ No newline at end of file +BRDFLAGS += -DBOOT_COM_CAN_CHANNEL_INDEX=0 +# USB support +BRDFLAGS += -DBBOOT_COM_USB_ENABLE=1 diff --git a/firmware/flash_usb.sh b/firmware/flash_usb.sh new file mode 100644 index 0000000000..829c50a618 --- /dev/null +++ b/firmware/flash_usb.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# This script will try to flash/update RusEFI part of firmware over USB interface. + +echo This script may need root privileges for accessing USB device or special udev rules (TODO) + +BootCommander -t=xcp_usb deliver/rusefi_update.srec + +# OR +# You can build it from sources with: +# (cd ext/openblt/Host/Source/LibOpenBLT/ ; mkdir build ; cd build ; cmake .. ; make -j ) +# and +# (cd ext/openblt/Host/Source/BootCommander/ ; mkdir build ; cd build ; cmake .. ; make -j ) +# And run: +# ext/openblt/Host/BootCommander -t=xcp_usb deliver/rusefi_update.srec diff --git a/firmware/hw_layer/openblt/blt_conf.h b/firmware/hw_layer/openblt/blt_conf.h index e1cf252ec2..619f154dde 100644 --- a/firmware/hw_layer/openblt/blt_conf.h +++ b/firmware/hw_layer/openblt/blt_conf.h @@ -53,6 +53,19 @@ /**************************************************************************************** * C O M M U N I C A T I O N I N T E R F A C E C O N F I G U R A T I O N ****************************************************************************************/ +/* The USB communication interface is selected by setting the BOOT_COM_USB_ENABLE + * configurable to 1. The maximum amount of data bytes in a message for data transmission + * and reception is set through BOOT_COM_USB_TX_MAX_DATA and BOOT_COM_USB_RX_MAX_DATA, + * respectively. + * + */ +/** \brief Enable/disable USB transport layer. */ +#define BOOT_COM_USB_ENABLE (1) +/** \brief Configure number of bytes in the target->host data packet. */ +#define BOOT_COM_USB_TX_MAX_DATA (63) +/** \brief Configure number of bytes in the host->target data packet. */ +#define BOOT_COM_USB_RX_MAX_DATA (63) + /* The CAN communication interface is selected by setting the BOOT_COM_CAN_ENABLE * configurable to 1. Configurable BOOT_COM_CAN_BAUDRATE selects the communication speed * in bits/second. Two CAN messages are reserved for communication with the host. The diff --git a/firmware/hw_layer/openblt/openblt.mk b/firmware/hw_layer/openblt/openblt.mk index 016a934198..5c525ef89b 100644 --- a/firmware/hw_layer/openblt/openblt.mk +++ b/firmware/hw_layer/openblt/openblt.mk @@ -85,18 +85,16 @@ PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/led.h PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/shared_params.c PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/shared_params.h -ifeq ($(PROJECT_CPU),ARCH_STM32F4) - # USB support - PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/usbd_desc.c - PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/usbd_desc.h - PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/usbd_conf.c - PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/usbd_conf.h - PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/usbd_bulk.c - PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/usbd_bulk.h - # Common USB lib - PROJ_FILES += $(wildcard $(PROJECT_DIR)/ext/openblt/Target/Demo/ARMCM4_STM32F4_Nucleo_F429ZI_GCC/Boot/lib/STM32_USB_Device_Library/Core/Src/*.c) - PROJ_FILES += $(wildcard $(PROJECT_DIR)/ext/openblt/Target/Demo/ARMCM4_STM32F4_Nucleo_F429ZI_GCC/Boot/lib/STM32_USB_Device_Library/Core/Inc/*.h) -endif +# USB support +PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/usbd_desc.c +PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/usbd_desc.h +PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/usbd_conf.c +PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/usbd_conf.h +PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/usbd_bulk.c +PROJ_FILES += $(PROJECT_DIR)/hw_layer/openblt/usbd_bulk.h +# Common USB lib +PROJ_FILES += $(wildcard $(PROJECT_DIR)/ext/openblt/Target/Demo/ARMCM4_STM32F4_Nucleo_F429ZI_GCC/Boot/lib/STM32_USB_Device_Library/Core/Src/*.c) +PROJ_FILES += $(wildcard $(PROJECT_DIR)/ext/openblt/Target/Demo/ARMCM4_STM32F4_Nucleo_F429ZI_GCC/Boot/lib/STM32_USB_Device_Library/Core/Inc/*.h) # CPU-dependent sources ifeq ($(PROJECT_CPU),ARCH_STM32F4) diff --git a/firmware/hw_layer/openblt/usbd_conf.c b/firmware/hw_layer/openblt/usbd_conf.c index b3cb3f588b..66ac100b17 100644 --- a/firmware/hw_layer/openblt/usbd_conf.c +++ b/firmware/hw_layer/openblt/usbd_conf.c @@ -20,8 +20,18 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "stm32f4xx.h" +#ifdef STM32F429xx +#include "stm32f4xx.h" /* STM32 CPU and HAL header */ #include "stm32f4xx_hal.h" +#endif +#ifdef STM32F767xx +#include "stm32f7xx.h" /* STM32 CPU and HAL header */ +#include "stm32f7xx_hal.h" +#endif +#ifdef STM32H743xx +#include "stm32h7xx.h" /* STM32 CPU and HAL header */ +#include "stm32h7xx_hal.h" +#endif #include "usbd_def.h" #include "usbd_core.h" #include "usbd_bulk.h" diff --git a/firmware/hw_layer/openblt/usbd_conf.h b/firmware/hw_layer/openblt/usbd_conf.h index 80c3498403..86b159c890 100644 --- a/firmware/hw_layer/openblt/usbd_conf.h +++ b/firmware/hw_layer/openblt/usbd_conf.h @@ -31,8 +31,15 @@ #include #include #include -#include "stm32f4xx.h" -#include "stm32f4xx_hal.h" +#ifdef STM32F429xx +#include "stm32f4xx.h" /* STM32 CPU and HAL header */ +#endif +#ifdef STM32F767xx +#include "stm32f7xx.h" /* STM32 CPU and HAL header */ +#endif +#ifdef STM32H743xx +#include "stm32h7xx.h" /* STM32 CPU and HAL header */ +#endif /* USER CODE BEGIN INCLUDE */ diff --git a/firmware/hw_layer/ports/stm32/stm32f7/openblt/lib/stm32f7xx_hal_conf.h b/firmware/hw_layer/ports/stm32/stm32f7/openblt/lib/stm32f7xx_hal_conf.h index 4329b9b38b..7edc964399 100644 --- a/firmware/hw_layer/ports/stm32/stm32f7/openblt/lib/stm32f7xx_hal_conf.h +++ b/firmware/hw_layer/ports/stm32/stm32f7/openblt/lib/stm32f7xx_hal_conf.h @@ -82,7 +82,7 @@ /* #define HAL_IRDA_MODULE_ENABLED */ /* #define HAL_SMARTCARD_MODULE_ENABLED */ /* #define HAL_WWDG_MODULE_ENABLED */ -/* #define HAL_PCD_MODULE_ENABLED */ +#define HAL_PCD_MODULE_ENABLED /* #define HAL_HCD_MODULE_ENABLED */ /* #define HAL_DFSDM_MODULE_ENABLED */ /* #define HAL_DSI_MODULE_ENABLED */ diff --git a/firmware/hw_layer/ports/stm32/stm32f7/openblt/port.mk b/firmware/hw_layer/ports/stm32/stm32f7/openblt/port.mk index ea24185cd3..333a50e3b3 100644 --- a/firmware/hw_layer/ports/stm32/stm32f7/openblt/port.mk +++ b/firmware/hw_layer/ports/stm32/stm32f7/openblt/port.mk @@ -5,11 +5,10 @@ # exclude flash-layout.c as this one is directly included in a source file, when used. PROJ_FILES += $(filter-out $(OPENBLT_PORT_DIR)/flash_layout.c, $(call rwildcard, $(OPENBLT_PORT_DIR), *.c *.h *.s)) # reuse ST32F7xx HAL and CMSIS from one of OpenBLT examples to avoid having copy in rusEFI git -PROJ_FILES += $(filter-out uip, $(call rwildcard, $(OPENBLT_TRGT_DIR)/Demo/ARMCM7_STM32F7_Nucleo_F767ZI_GCC/Boot/lib/CMSIS/, *.c *.h *.s)) -PROJ_FILES += $(filter-out uip, $(call rwildcard, $(OPENBLT_TRGT_DIR)/Demo/ARMCM7_STM32F7_Nucleo_F767ZI_GCC/Boot/lib/STM32F7xx_HAL_Driver/, *.c *.h *.s)) -PROJ_FILES += $(wildcard $(OPENBLT_TRGT_DIR)/Demo/ARMCM7_STM32F7_Nucleo_F746ZG_GCC/Boot/lib/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_can.c) -PROJ_FILES += $(wildcard $(OPENBLT_TRGT_DIR)/Demo/ARMCM7_STM32F7_Nucleo_F746ZG_GCC/Boot/lib/STM32F7xx_HAL_Driver/Inc/stm32f7xx_hal_can.h) - +PROJ_FILES += $(filter-out uip, $(call rwildcard, $(OPENBLT_TRGT_DIR)/Demo/ARMCM7_STM32F7_Nucleo_F746ZG_GCC/Boot/lib/CMSIS/, *.c *.h *.s)) +PROJ_FILES += $(filter-out uip, $(call rwildcard, $(OPENBLT_TRGT_DIR)/Demo/ARMCM7_STM32F7_Nucleo_F746ZG_GCC/Boot/lib/STM32F7xx_HAL_Driver/, *.c *.h *.s)) +# stm32f767xx.h +PROJ_FILES += $(wildcard $(OPENBLT_TRGT_DIR)/Demo/ARMCM7_STM32F7_Nucleo_F767ZI_GCC/Boot/lib/CMSIS/Device/ST/STM32F7xx/Include/*.h) #|--------------------------------------------------------------------------------------| #| Specific options for toolchain binaries | #|--------------------------------------------------------------------------------------|