Files
@ 2a5ab412b8d9
Branch filter:
Location: therm/hw_config.c - annotation
2a5ab412b8d9
10.2 KiB
text/plain
Swap out to HAL library and new USB library
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 6f724d71c0ec 675c16cde5b1 675c16cde5b1 6f724d71c0ec 6f724d71c0ec 6f724d71c0ec 6f724d71c0ec 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 6f724d71c0ec 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 675c16cde5b1 | /**
******************************************************************************
* @file hw_config.c
* @author MCD Application Team
* @version V4.0.0
* @date 21-January-2013
* @brief Hardware Configuration & Setup
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32_it.h"
#include "usb_lib.h"
#include "usb_prop.h"
#include "usb_desc.h"
#include "hw_config.h"
#include "usb_pwr.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
ErrorStatus HSEStartUpStatus;
EXTI_InitTypeDef EXTI_InitStructure;
extern __IO uint32_t packet_sent;
extern __IO uint8_t Send_Buffer[VIRTUAL_COM_PORT_DATA_SIZE] ;
extern __IO uint32_t packet_receive;
extern __IO uint8_t Receive_length;
uint8_t Receive_Buffer[64];
uint32_t Send_length;
static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len);
/* Extern variables ----------------------------------------------------------*/
extern LINE_CODING linecoding;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : Set_System
* Description : Configures Main system clocks & power
* Input : None.
* Return : None.
*******************************************************************************/
void Set_System(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
#if defined(USB_USE_EXTERNAL_PULLUP)
GPIO_InitTypeDef GPIO_InitStructure;
#endif /* USB_USE_EXTERNAL_PULLUP */
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file
*/
/* Enable the SYSCFG module clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
/* Enable USB_DISCONNECT GPIO clock */
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_DISCONNECT, ENABLE);
/* Configure USB pull-up pin */
//GPIO_InitStructure.GPIO_Pin = USB_DISCONNECT_PIN;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
//GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure);
#if defined(USB_USE_EXTERNAL_PULLUP)
/* Enable the USB disconnect GPIO clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIO_DISCONNECT, ENABLE);
/* USB_DISCONNECT used as USB pull-up */
GPIO_InitStructure.GPIO_Pin = USB_DISCONNECT_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure);
#endif /* USB_USE_EXTERNAL_PULLUP */
/* Configure the EXTI line 18 connected internally to the USB IP */
EXTI_ClearITPendingBit(EXTI_Line18);
EXTI_InitStructure.EXTI_Line = EXTI_Line18;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
/*******************************************************************************
* Function Name : Set_USBClock
* Description : Configures USB Clock input (48MHz)
* Input : None.
* Return : None.
*******************************************************************************/
void Set_USBClock(void)
{
/* Enable USB clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
}
/*******************************************************************************
* Function Name : Enter_LowPowerMode
* Description : Power-off system clocks and power while entering suspend mode
* Input : 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.
* 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;
}
/*Enable SystemCoreClock*/
SystemInit();
}
/*******************************************************************************
* Function Name : USB_Interrupts_Config
* Description : Configures the USB interrupts
* Input : None.
* Return : None.
*******************************************************************************/
void USB_Interrupts_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* 2 bit for pre-emption priority, 2 bits for subpriority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
/* Enable the USB interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable the USB Wake-up interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USB_FS_WKUP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/*******************************************************************************
* 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)
{
STM32L15_USB_CONNECT;
}
else
{
STM32L15_USB_DISCONNECT;
}
}
/*******************************************************************************
* 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 = *(uint32_t*)ID1;
Device_Serial1 = *(uint32_t*)ID2;
Device_Serial2 = *(uint32_t*)ID3;
Device_Serial0 += Device_Serial2;
if (Device_Serial0 != 0)
{
IntToUnicode (Device_Serial0, &Virtual_Com_Port_StringSerial[2] , 8);
IntToUnicode (Device_Serial1, &Virtual_Com_Port_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;
}
}
/*******************************************************************************
* Function Name : Send DATA .
* Description : send the data received from the STM32 to the PC through USB
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
uint32_t CDC_Send_DATA (uint8_t *ptrBuffer, uint8_t Send_length)
{
/*if max buffer is Not reached*/
if(Send_length < VIRTUAL_COM_PORT_DATA_SIZE)
{
/*Sent flag*/
packet_sent = 0;
/* send packet to PMA*/
UserToPMABufferCopy((unsigned char*)ptrBuffer, ENDP1_TXADDR, Send_length);
SetEPTxCount(ENDP1, Send_length);
SetEPTxValid(ENDP1);
}
else
{
return 0;
}
return 1;
}
/*******************************************************************************
* Function Name : Receive DATA .
* Description : receive the data from the PC to STM32 and send it through USB
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
uint32_t CDC_Receive_DATA(void)
{
/*Receive flag*/
packet_receive = 0;
SetEPRxValid(ENDP3);
return 1 ;
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|