?? hw_config.c
字號:
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name : hw_config.c
* Author : MCD Application Team
* Version : V2.2.0
* Date : 06/13/2008
* 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 "sys.h"
#include "hw_config.h"
#include "platform_config.h"
#include "mass_mal.h"
#include "usb_desc.h"
#include "usb_pwr.h"
#include "led.h"
//配置USB時鐘,USBclk=48Mhz
void Set_USBClock(void)
{
RCC->CFGR&=~(1<<22); //USBclk=PLLclk/1.5=48Mhz
RCC->APB1ENR|=1<<23; //USB時鐘使能
}
/*******************************************************************************
* Function Name : Enter_LowPowerMode
* Description : Power-off system clocks and power while entering suspend mode
* Input : None.
* Return : None.
*******************************************************************************/
void Enter_LowPowerMode(void)
{
bDeviceState = SUSPENDED;
}
/*******************************************************************************
* Function Name : Leave_LowPowerMode
* Description : Restores system clocks and power while exiting suspend mode
* Input : 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;
}
}
//USB中斷配置
void USB_Interrupts_Config(void)
{
EXTI->IMR|=1<<18;// 開啟線18上的中斷
EXTI->RTSR|=1<<18;//line 18上事件上升降沿觸發
MY_NVIC_Init(1,0,USB_LP_CAN_RX0_IRQChannel,2);//組2,優先級次之
MY_NVIC_Init(0,0,USBWakeUp_IRQChannel,2); //組2,優先級最高
}
/*******************************************************************************
* Function Name : Led_RW_ON
* Description : Turn ON the Read/Write LEDs.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void Led_RW_ON(void)
{
LED1=0;
}
/*******************************************************************************
* Function Name : Led_RW_OFF
* Description : Turn off the Read/Write LEDs.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void Led_RW_OFF(void)
{
LED1=1;
}
/*******************************************************************************
* Function Name : USB_Configured_LED
* Description : Turn ON the Read/Write LEDs.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void USB_Configured_LED(void)
{
//GPIO_SetBits(USB_LED_PORT, GPIO_Pin_6);
}
/*******************************************************************************
* Function Name : USB_NotConfigured_LED
* Description : Turn off the Read/Write LEDs.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void USB_NotConfigured_LED(void)
{
//GPIO_ResetBits(USB_LED_PORT, GPIO_Pin_6);
}
/*******************************************************************************
* Function Name : USB_Cable_Config
* Description : Software Connection/Disconnection of USB Cable.
* Input : None.
* Return : Status
*******************************************************************************/
void USB_Cable_Config (FunctionalState NewState)
{
if (NewState != DISABLE)
{
LED1=1;
}
else
{
LED1=0;
}
}
/*******************************************************************************
* Function Name : Get_SerialNum.
* Description : Create the serial number string descriptor.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void Get_SerialNum(void)
{
u32 Device_Serial0, Device_Serial1, Device_Serial2;
Device_Serial0 = *(vu32*)(0x1FFFF7E8);
Device_Serial1 = *(vu32*)(0x1FFFF7EC);
Device_Serial2 = *(vu32*)(0x1FFFF7F0);
if (Device_Serial0 != 0)
{
MASS_StringSerial[2] = (u8)(Device_Serial0 & 0x000000FF);
MASS_StringSerial[4] = (u8)((Device_Serial0 & 0x0000FF00) >> 8);
MASS_StringSerial[6] = (u8)((Device_Serial0 & 0x00FF0000) >> 16);
MASS_StringSerial[8] = (u8)((Device_Serial0 & 0xFF000000) >> 24);
MASS_StringSerial[10] = (u8)(Device_Serial1 & 0x000000FF);
MASS_StringSerial[12] = (u8)((Device_Serial1 & 0x0000FF00) >> 8);
MASS_StringSerial[14] = (u8)((Device_Serial1 & 0x00FF0000) >> 16);
MASS_StringSerial[16] = (u8)((Device_Serial1 & 0xFF000000) >> 24);
MASS_StringSerial[18] = (u8)(Device_Serial2 & 0x000000FF);
MASS_StringSerial[20] = (u8)((Device_Serial2 & 0x0000FF00) >> 8);
MASS_StringSerial[22] = (u8)((Device_Serial2 & 0x00FF0000) >> 16);
MASS_StringSerial[24] = (u8)((Device_Serial2 & 0xFF000000) >> 24);
}
}
/*******************************************************************************
* Function Name : MAL_Config
* Description : MAL_layer configuration
* Input : None.
* Return : None.
*******************************************************************************/
void MAL_Config(void)
{
MAL_Init(0);
}
/*******************************************************************************
* Function Name : USB_Disconnect_Config
* Description : Disconnect pin configuration
* Input : None.
* Return : None.
*******************************************************************************/
void USB_Disconnect_Config(void)
{
// GPIO_InitTypeDef GPIO_InitStructure;
//
// /* Enable USB_DISCONNECT GPIO clock */
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_DISCONNECT, ENABLE);
//
// /* USB_DISCONNECT_PIN used as 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);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -