Skip to content

Commit

Permalink
Refs #1229. Added support for firmware updates via USB to the Olimexi…
Browse files Browse the repository at this point in the history
…no-STM32F3 demo programs.

git-svn-id: https://svn.code.sf.net/p/openblt/code/trunk@1063 5dc33758-31d5-4daf-9ae8-b24bf3d40d73
  • Loading branch information
feaser committed Jun 12, 2023
1 parent e6b0c32 commit f05796b
Show file tree
Hide file tree
Showing 29 changed files with 10,518 additions and 628 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Device/ST/STM32F3xx/Include"/>
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Include"/>
<listOptionValue builtIn="false" value="../App"/>
<listOptionValue builtIn="false" value="../Library/STM32_USB_Device_Library/Core/Inc"/>
<listOptionValue builtIn="false" value="../USB_DEVICE/App"/>
<listOptionValue builtIn="false" value="../USB_DEVICE/Target"/>
<listOptionValue builtIn="false" value="../../../../Source"/>
<listOptionValue builtIn="false" value="../../../../Source/ARMCM4_STM32F3"/>
</option>
Expand Down Expand Up @@ -79,9 +82,11 @@
</folderInfo>
<sourceEntries>
<entry excluding="flash_layout.c" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="App"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="Library"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="Loader"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="USB_DEVICE"/>
</sourceEntries>
</configuration>
</storageModule>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@
/** \brief Select the desired UART peripheral as a zero based index. */
#define BOOT_COM_RS232_CHANNEL_INDEX (2)

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


/****************************************************************************************
* B A C K D O O R E N T R Y C O N F I G U R A T I O N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,65 @@ blt_bool CpuUserProgramStartHook(void)
#endif /* BOOT_CPU_USER_PROGRAM_START_HOOK > 0 */


/****************************************************************************************
* U S B C O M M U N I C A T I O N I N T E R F A C E H O O K F U N C T I O N S
****************************************************************************************/

#if (BOOT_COM_USB_ENABLE > 0)
/************************************************************************************//**
** \brief Callback that gets called whenever the USB device should be connected
** to the USB bus.
** \details The connect to the USB bus, a pull-up resistor on the USB D+ line needs to
** be activated. The DISC (PC12) GPIO controls the gate of a P-MOSFET, which
** in turn controls the enabling/disabling of the pull-up resistor on the
** USB D+ line. When DISC is low (default), the Vgs is 0 - Vcc. With a
** negative Vgs, the P-MOSFET is on and the pull-up enabled. When DISC is
** high the P-MOSFET is off, disabling the pull-up.
** \param connect BLT_TRUE to connect and BLT_FALSE to disconnect.
** \return none.
**
****************************************************************************************/
void UsbConnectHook(blt_bool connect)
{
/* determine if the USB should be connected or disconnected */
if (connect == BLT_TRUE)
{
/* the GPIO has a pull-up so to connect to the USB bus the pin needs to go low */
LL_GPIO_ResetOutputPin(GPIOC, LL_GPIO_PIN_12);
}
else
{
/* the GPIO has a pull-up so to disconnect to the USB bus the pin needs to go high */
LL_GPIO_SetOutputPin(GPIOC, LL_GPIO_PIN_12);
}
} /*** end of UsbConnect ***/


/************************************************************************************//**
** \brief Callback that gets called whenever the USB host requests the device
** to enter a low power mode.
** \return none.
**
****************************************************************************************/
void UsbEnterLowPowerModeHook(void)
{
/* support to enter a low power mode can be implemented here */
} /*** end of UsbEnterLowPowerMode ***/


/************************************************************************************//**
** \brief Callback that gets called whenever the USB host requests the device to
** exit low power mode.
** \return none.
**
****************************************************************************************/
void UsbLeaveLowPowerModeHook(void)
{
/* support to leave a low power mode can be implemented here */
} /*** end of UsbLeaveLowPowerMode ***/
#endif /* BOOT_COM_USB_ENABLE > 0 */


/****************************************************************************************
* W A T C H D O G D R I V E R H O O K F U N C T I O N S
****************************************************************************************/
Expand Down
25 changes: 16 additions & 9 deletions Target/Demo/ARMCM4_STM32F3_Olimexino_STM32F3_CubeIDE/Boot/Boot.ioc
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@ Mcu.IP0=CAN
Mcu.IP1=NVIC
Mcu.IP2=RCC
Mcu.IP3=USART3
Mcu.IPNb=4
Mcu.IP4=USB
Mcu.IPNb=5
Mcu.Name=STM32F303R(B-C)Tx
Mcu.Package=LQFP64
Mcu.Pin0=PF0-OSC_IN
Mcu.Pin1=PF1-OSC_OUT
Mcu.Pin10=PB9
Mcu.Pin2=PA0
Mcu.Pin3=PA5
Mcu.Pin4=PB10
Mcu.Pin5=PB11
Mcu.Pin6=PC12
Mcu.Pin7=PB8
Mcu.Pin8=PB9
Mcu.PinsNb=9
Mcu.Pin6=PA11
Mcu.Pin7=PA12
Mcu.Pin8=PC12
Mcu.Pin9=PB8
Mcu.PinsNb=11
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32F303RCTx
Expand All @@ -51,6 +54,10 @@ PA0.GPIOParameters=GPIO_PuPd
PA0.GPIO_PuPd=GPIO_PULLUP
PA0.Locked=true
PA0.Signal=GPIO_Input
PA11.Mode=Device
PA11.Signal=USB_DM
PA12.Mode=Device
PA12.Signal=USB_DP
PA5.Locked=true
PA5.Signal=GPIO_Output
PB10.Locked=true
Expand Down Expand Up @@ -100,7 +107,7 @@ ProjectManager.StackSize=0x1000
ProjectManager.TargetToolchain=STM32CubeIDE
ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=true
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_CAN_Init-CAN-true-HAL-false,4-MX_USART3_UART_Init-USART3-false-LL-true
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_CAN_Init-CAN-true-HAL-false,4-MX_USART3_UART_Init-USART3-false-LL-true,5-MX_USB_PCD_Init-USB-true-HAL-false
RCC.ADC12outputFreq_Value=72000000
RCC.ADC34outputFreq_Value=72000000
RCC.AHBFreq_Value=72000000
Expand All @@ -120,14 +127,14 @@ RCC.HSI_VALUE=8000000
RCC.I2C1Freq_Value=8000000
RCC.I2C2Freq_Value=8000000
RCC.I2SClocksFreq_Value=72000000
RCC.IPParameters=ADC12outputFreq_Value,ADC34outputFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSEPLLFreq_Value,HSE_VALUE,HSIPLLFreq_Value,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2SClocksFreq_Value,LSE_VALUE,LSI_VALUE,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,PLLSourceVirtual,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSourceVirtual,TIM1Freq_Value,TIM2Freq_Value,TIM8Freq_Value,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOOutput2Freq_Value
RCC.IPParameters=ADC12outputFreq_Value,ADC34outputFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSEPLLFreq_Value,HSE_VALUE,HSIPLLFreq_Value,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2SClocksFreq_Value,LSE_VALUE,LSI_VALUE,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,PRESCALERUSB,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSourceVirtual,TIM1Freq_Value,TIM2Freq_Value,TIM8Freq_Value,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOOutput2Freq_Value
RCC.LSE_VALUE=32768
RCC.LSI_VALUE=40000
RCC.MCOFreq_Value=72000000
RCC.PLLCLKFreq_Value=72000000
RCC.PLLMCOFreq_Value=36000000
RCC.PLLMUL=RCC_PLL_MUL9
RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE
RCC.PRESCALERUSB=RCC_USBCLKSOURCE_PLL_DIV1_5
RCC.RTCFreq_Value=40000
RCC.RTCHSEDivFreq_Value=250000
RCC.SYSCLKFreq_VALUE=72000000
Expand All @@ -140,7 +147,7 @@ RCC.UART5Freq_Value=36000000
RCC.USART1Freq_Value=72000000
RCC.USART2Freq_Value=36000000
RCC.USART3Freq_Value=36000000
RCC.USBFreq_Value=72000000
RCC.USBFreq_Value=48000000
RCC.VCOOutput2Freq_Value=8000000
USART3.BaudRate=57600
USART3.IPParameters=VirtualMode-Asynchronous,BaudRate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ extern "C" {
/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);
void MX_CAN_Init(void);
void MX_USB_PCD_Init(void);

/* USER CODE BEGIN EFP */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
/*#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_GPIO_MODULE_ENABLED
#define HAL_EXTI_MODULE_ENABLED
/* #define HAL_CAN_LEGACY_MODULE_ENABLED */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
/* Private variables ---------------------------------------------------------*/
CAN_HandleTypeDef hcan;

PCD_HandleTypeDef hpcd_USB_FS;

/* USER CODE BEGIN PV */

/* USER CODE END PV */
Expand Down Expand Up @@ -148,6 +150,7 @@ void SystemClock_Config(void)
Error_Handler();
}
LL_RCC_SetUSARTClockSource(LL_RCC_USART3_CLKSOURCE_PCLK1);
LL_RCC_SetUSBClockSource(LL_RCC_USB_CLKSOURCE_PLL_DIV_1_5);
}

/**
Expand Down Expand Up @@ -243,6 +246,39 @@ static void MX_USART3_UART_Init(void)

}

/**
* @brief USB Initialization Function
* @param None
* @retval None
*/
void MX_USB_PCD_Init(void)
{

/* USER CODE BEGIN USB_Init 0 */
/* Note that this function is generated but not actually used. The bootloader handles
* the USB initialization.
*/
/* USER CODE END USB_Init 0 */

/* USER CODE BEGIN USB_Init 1 */

/* USER CODE END USB_Init 1 */
hpcd_USB_FS.Instance = USB;
hpcd_USB_FS.Init.dev_endpoints = 8;
hpcd_USB_FS.Init.speed = PCD_SPEED_FULL;
hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
hpcd_USB_FS.Init.low_power_enable = DISABLE;
hpcd_USB_FS.Init.battery_charging_enable = DISABLE;
if (HAL_PCD_Init(&hpcd_USB_FS) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USB_Init 2 */

/* USER CODE END USB_Init 2 */

}

/**
* @brief GPIO Initialization Function
* @param None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,71 @@ void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan)

}

/**
* @brief PCD MSP Initialization
* This function configures the hardware resources used in this example
* @param hpcd: PCD handle pointer
* @retval None
*/
void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hpcd->Instance==USB)
{
/* USER CODE BEGIN USB_MspInit 0 */

/* USER CODE END USB_MspInit 0 */

__HAL_RCC_GPIOA_CLK_ENABLE();
/**USB GPIO Configuration
PA11 ------> USB_DM
PA12 ------> USB_DP
*/
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF14_USB;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/* Peripheral clock enable */
__HAL_RCC_USB_CLK_ENABLE();
/* USER CODE BEGIN USB_MspInit 1 */

/* USER CODE END USB_MspInit 1 */
}

}

/**
* @brief PCD MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hpcd: PCD handle pointer
* @retval None
*/
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
{
if(hpcd->Instance==USB)
{
/* USER CODE BEGIN USB_MspDeInit 0 */

/* USER CODE END USB_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_USB_CLK_DISABLE();

/**USB GPIO Configuration
PA11 ------> USB_DM
PA12 ------> USB_DP
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);

/* USER CODE BEGIN USB_MspDeInit 1 */

/* USER CODE END USB_MspDeInit 1 */
}

}

/* USER CODE BEGIN 1 */
/**
* De-Initializes the Global MSP.
Expand Down
Loading

0 comments on commit f05796b

Please sign in to comment.