mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-04 12:24:11 +01:00
a688b95eb6
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1235 ebee16cc-31ac-478f-84a7-5cbb03baadba
310 lines
10 KiB
C
310 lines
10 KiB
C
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
|
|
* File Name : hw_config.c
|
|
* Author : MCD Application Team
|
|
* Version : V3.2.1
|
|
* Date : 07/05/2010
|
|
* Description : Hardware Configuration & Setup
|
|
********************************************************************************
|
|
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
|
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
|
|
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
|
|
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
|
|
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
|
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
|
*******************************************************************************/
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "stm32f10x.h"
|
|
#include "spi_flash.h"
|
|
#include "hw_config.h"
|
|
#include "dfu_mal.h"
|
|
#include "usb_lib.h"
|
|
#include "usb_desc.h"
|
|
#include "platform_config.h"
|
|
#include "usb_pwr.h"
|
|
#include "stm32_eval.h"
|
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
/* Private define ------------------------------------------------------------*/
|
|
/* Private macro -------------------------------------------------------------*/
|
|
/* Private variables ---------------------------------------------------------*/
|
|
ErrorStatus HSEStartUpStatus;
|
|
/* Extern variables ----------------------------------------------------------*/
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len);
|
|
/* Private functions ---------------------------------------------------------*/
|
|
/*******************************************************************************
|
|
* Function Name : Set_System.
|
|
* Description : Configures Main system clocks & power.
|
|
* Input : None.
|
|
* Output : None.
|
|
* Return : None.
|
|
*******************************************************************************/
|
|
void Set_System(void)
|
|
{
|
|
#ifndef USE_STM3210C_EVAL
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
#endif /* USE_STM3210C_EVAL */
|
|
|
|
/* Unlock the internal flash */
|
|
FLASH_Unlock();
|
|
|
|
#ifdef STM32F10X_HD
|
|
/* Enable the FSMC Clock */
|
|
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
|
|
#endif /* STM32F10X_HD */
|
|
|
|
#ifndef USE_STM3210C_EVAL
|
|
/* Enable "DISCONNECT" GPIO clock */
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_DISCONNECT, ENABLE);
|
|
|
|
/* Configure USB pull-up */
|
|
GPIO_InitStructure.GPIO_Pin = USB_DISCONNECT_PIN;
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
|
|
GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure);
|
|
|
|
USB_Cable_Config(DISABLE);
|
|
#endif /* USE_STM3210C_EVAL */
|
|
|
|
/* Init the media interface */
|
|
MAL_Init();
|
|
|
|
#ifndef USE_STM3210C_EVAL
|
|
USB_Cable_Config(ENABLE);
|
|
#endif /* USE_STM3210C_EVAL */
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* Function Name : Set_USBClock.
|
|
* Description : Configures USB Clock input (48MHz).
|
|
* Input : None.
|
|
* Output : None.
|
|
* Return : None.
|
|
*******************************************************************************/
|
|
void Set_USBClock(void)
|
|
{
|
|
#ifdef STM32F10X_CL
|
|
/* Select USBCLK source */
|
|
RCC_OTGFSCLKConfig(RCC_OTGFSCLKSource_PLLVCO_Div3);
|
|
|
|
/* Enable the USB clock */
|
|
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_OTG_FS, ENABLE) ;
|
|
#else
|
|
/* Select USBCLK source */
|
|
RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
|
|
|
|
/* Enable the USB clock */
|
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
|
|
#endif /* STM32F10X_CL */
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* Function Name : Enter_LowPowerMode.
|
|
* Description : Power-off system clocks and power while entering suspend mode.
|
|
* Input : None.
|
|
* Output : None.
|
|
* Return : None.
|
|
*******************************************************************************/
|
|
void Enter_LowPowerMode(void)
|
|
{
|
|
/* Set the device state to suspend */
|
|
bDeviceState = SUSPENDED;
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* Function Name : Leave_LowPowerMode.
|
|
* Description : Restores system clocks and power while exiting suspend mode.
|
|
* Input : None.
|
|
* Output : None.
|
|
* Return : None.
|
|
*******************************************************************************/
|
|
void Leave_LowPowerMode(void)
|
|
{
|
|
DEVICE_INFO *pInfo = &Device_Info;
|
|
|
|
/* Set the device state to the correct state */
|
|
if (pInfo->Current_Configuration != 0)
|
|
{
|
|
/* Device configured */
|
|
bDeviceState = CONFIGURED;
|
|
}
|
|
else
|
|
{
|
|
bDeviceState = ATTACHED;
|
|
}
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* Function Name : USB_Cable_Config.
|
|
* Description : Software Connection/Disconnection of USB Cable.
|
|
* Input : NewState: new state.
|
|
* Output : None.
|
|
* Return : None.
|
|
*******************************************************************************/
|
|
void USB_Cable_Config (FunctionalState NewState)
|
|
{
|
|
#ifdef USE_STM3210C_EVAL
|
|
if (NewState != DISABLE)
|
|
{
|
|
USB_DevConnect();
|
|
}
|
|
else
|
|
{
|
|
USB_DevDisconnect();
|
|
}
|
|
#else /* USE_STM3210B_EVAL or USE_STM3210E_EVAL */
|
|
if (NewState != DISABLE)
|
|
{
|
|
GPIO_ResetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);
|
|
}
|
|
else
|
|
{
|
|
GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);
|
|
}
|
|
#endif /* USE_STM3210C_EVAL */
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* Function Name : DFU_Button_Config.
|
|
* Description : Configures the DFU selector Button to enter DFU Mode.
|
|
* Input : None.
|
|
* Output : None.
|
|
* Return : None.
|
|
*******************************************************************************/
|
|
void DFU_Button_Config(void)
|
|
{
|
|
/* Configure "DFU enter" button */
|
|
// STM_EVAL_PBInit(Button_KEY, Mode_GPIO);
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* Function Name : DFU_Button_Read.
|
|
* Description : Reads the DFU selector Button to enter DFU Mode.
|
|
* Input : None.
|
|
* Output : None.
|
|
* Return : Status
|
|
*******************************************************************************/
|
|
uint8_t DFU_Button_Read (void)
|
|
{
|
|
return 0;//STM_EVAL_PBGetState(Button_KEY);
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* Function Name : USB_Interrupts_Config.
|
|
* Description : Configures the USB interrupts.
|
|
* Input : None.
|
|
* Output : None.
|
|
* Return : None.
|
|
*******************************************************************************/
|
|
void USB_Interrupts_Config(void)
|
|
{
|
|
NVIC_InitTypeDef NVIC_InitStructure;
|
|
|
|
#ifdef STM32F10X_CL
|
|
/* Enable the USB Interrupts */
|
|
NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn;
|
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
|
NVIC_Init(&NVIC_InitStructure);
|
|
#else
|
|
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
|
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
|
NVIC_Init(&NVIC_InitStructure);
|
|
#endif /* STM32F10X_CL */
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* Function Name : Reset_Device.
|
|
* Description : Reset the device.
|
|
* Input : None.
|
|
* Output : None.
|
|
* Return : None.
|
|
*******************************************************************************/
|
|
void Reset_Device(void)
|
|
{
|
|
USB_Cable_Config(DISABLE);
|
|
NVIC_SystemReset();
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* Function Name : Get_SerialNum.
|
|
* Description : Create the serial number string descriptor.
|
|
* Input : None.
|
|
* Output : None.
|
|
* Return : None.
|
|
*******************************************************************************/
|
|
void Get_SerialNum(void)
|
|
{
|
|
uint32_t Device_Serial0, Device_Serial1, Device_Serial2;
|
|
|
|
Device_Serial0 = *(__IO uint32_t*)(0x1FFFF7E8);
|
|
Device_Serial1 = *(__IO uint32_t*)(0x1FFFF7EC);
|
|
Device_Serial2 = *(__IO uint32_t*)(0x1FFFF7F0);
|
|
|
|
Device_Serial0 += Device_Serial2;
|
|
|
|
if (Device_Serial0 != 0)
|
|
{
|
|
IntToUnicode (Device_Serial0, &DFU_StringSerial[2] , 8);
|
|
IntToUnicode (Device_Serial1, &DFU_StringSerial[18], 4);
|
|
}
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* Function Name : HexToChar.
|
|
* Description : Convert Hex 32Bits value into char.
|
|
* Input : None.
|
|
* Output : None.
|
|
* Return : None.
|
|
*******************************************************************************/
|
|
static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
|
{
|
|
uint8_t idx = 0;
|
|
|
|
for( idx = 0 ; idx < len ; idx ++)
|
|
{
|
|
if( ((value >> 28)) < 0xA )
|
|
{
|
|
pbuf[ 2* idx] = (value >> 28) + '0';
|
|
}
|
|
else
|
|
{
|
|
pbuf[2* idx] = (value >> 28) + 'A' - 10;
|
|
}
|
|
|
|
value = value << 4;
|
|
|
|
pbuf[ 2* idx + 1] = 0;
|
|
}
|
|
}
|
|
#ifdef STM32F10X_CL
|
|
/*******************************************************************************
|
|
* Function Name : USB_OTG_BSP_uDelay.
|
|
* Description : provide delay (usec).
|
|
* Input : None.
|
|
* Output : None.
|
|
* Return : None.
|
|
*******************************************************************************/
|
|
void USB_OTG_BSP_uDelay (const uint32_t usec)
|
|
{
|
|
RCC_ClocksTypeDef RCC_Clocks;
|
|
|
|
/* Configure HCLK clock as SysTick clock source */
|
|
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
|
|
|
|
RCC_GetClocksFreq(&RCC_Clocks);
|
|
|
|
SysTick_Config(usec * (RCC_Clocks.HCLK_Frequency / 1000000));
|
|
|
|
SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk ;
|
|
|
|
while (!(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk));
|
|
}
|
|
#endif
|
|
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
|