Openblt usb for F7 (#5365)

* OpenBLT: enable USB for F7

* OpenBLT: simple flash over USB script
This commit is contained in:
Andrey G 2023-07-02 16:22:55 +03:00 committed by GitHub
parent 7a507c62c2
commit d5e9c3a5e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 88 additions and 24 deletions

View File

@ -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);

View File

@ -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
BRDFLAGS += -DBOOT_COM_CAN_CHANNEL_INDEX=0
# USB support
BRDFLAGS += -DBBOOT_COM_USB_ENABLE=1

15
firmware/flash_usb.sh Normal file
View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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"

View File

@ -31,8 +31,15 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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 */

View File

@ -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 */

View File

@ -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 |
#|--------------------------------------------------------------------------------------|