snickerdoodle Platform Controller
firmware for STM32F0 platform controller
usbd_conf.c File Reference

: This file implements the board support package for the USB device library More...

#include "stm32f0xx.h"
#include "stm32f0xx_hal.h"
#include "usbd_def.h"
#include "usbd_core.h"
#include "usbd_cdc.h"

Functions

static void SystemClockConfig_Resume (void)
 Configures system clock after wake-up from USB Resume CallBack: enable HSI, PLL and select PLL as system clock source. More...
 
void HAL_PCDEx_SetConnectionState (PCD_HandleTypeDef *hpcd, uint8_t state)
 Software Device Connection. More...
 
void HAL_PCD_MspInit (PCD_HandleTypeDef *hpcd)
 
void HAL_PCD_MspDeInit (PCD_HandleTypeDef *hpcd)
 
void HAL_PCD_SetupStageCallback (PCD_HandleTypeDef *hpcd)
 Setup Stage callback. More...
 
void HAL_PCD_DataOutStageCallback (PCD_HandleTypeDef *hpcd, uint8_t epnum)
 Data Out Stage callback. More...
 
void HAL_PCD_DataInStageCallback (PCD_HandleTypeDef *hpcd, uint8_t epnum)
 Data In Stage callback.. More...
 
void HAL_PCD_SOFCallback (PCD_HandleTypeDef *hpcd)
 SOF callback. More...
 
void HAL_PCD_ResetCallback (PCD_HandleTypeDef *hpcd)
 Reset callback. More...
 
void HAL_PCD_SuspendCallback (PCD_HandleTypeDef *hpcd)
 Suspend callback. When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) More...
 
void HAL_PCD_ResumeCallback (PCD_HandleTypeDef *hpcd)
 Resume callback. When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) More...
 
void HAL_PCD_ISOOUTIncompleteCallback (PCD_HandleTypeDef *hpcd, uint8_t epnum)
 ISOOUTIncomplete callback. More...
 
void HAL_PCD_ISOINIncompleteCallback (PCD_HandleTypeDef *hpcd, uint8_t epnum)
 ISOINIncomplete callback. More...
 
void HAL_PCD_ConnectCallback (PCD_HandleTypeDef *hpcd)
 ConnectCallback callback. More...
 
void HAL_PCD_DisconnectCallback (PCD_HandleTypeDef *hpcd)
 Disconnect callback. More...
 
USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev)
 Initializes the Low Level portion of the Device driver. More...
 
USBD_StatusTypeDef USBD_LL_DeInit (USBD_HandleTypeDef *pdev)
 De-Initializes the Low Level portion of the Device driver. More...
 
USBD_StatusTypeDef USBD_LL_Start (USBD_HandleTypeDef *pdev)
 Starts the Low Level portion of the Device driver. More...
 
USBD_StatusTypeDef USBD_LL_Stop (USBD_HandleTypeDef *pdev)
 Stops the Low Level portion of the Device driver. More...
 
USBD_StatusTypeDef USBD_LL_OpenEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps)
 Opens an endpoint of the Low Level Driver. More...
 
USBD_StatusTypeDef USBD_LL_CloseEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
 Closes an endpoint of the Low Level Driver. More...
 
USBD_StatusTypeDef USBD_LL_FlushEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
 Flushes an endpoint of the Low Level Driver. More...
 
USBD_StatusTypeDef USBD_LL_StallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
 Sets a Stall condition on an endpoint of the Low Level Driver. More...
 
USBD_StatusTypeDef USBD_LL_ClearStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
 Clears a Stall condition on an endpoint of the Low Level Driver. More...
 
uint8_t USBD_LL_IsStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
 Returns Stall condition. More...
 
USBD_StatusTypeDef USBD_LL_SetUSBAddress (USBD_HandleTypeDef *pdev, uint8_t dev_addr)
 Assigns a USB address to the device. More...
 
USBD_StatusTypeDef USBD_LL_Transmit (USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size)
 Transmits data over an endpoint. More...
 
USBD_StatusTypeDef USBD_LL_PrepareReceive (USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size)
 Prepares an endpoint for reception. More...
 
uint32_t USBD_LL_GetRxDataSize (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
 Returns the last transfered packet size. More...
 
void USBD_LL_Delay (uint32_t Delay)
 Delays routine for the USB Device Library. More...
 
void * USBD_static_malloc (uint32_t size)
 static single allocation. More...
 
void USBD_static_free (void *p)
 Dummy memory free. More...
 

Variables

PCD_HandleTypeDef hpcd_USB_FS
 

Detailed Description

: This file implements the board support package for the USB device library

Version
: v1.0_Cube COPYRIGHT(c) 2016 STMicroelectronics

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of STMicroelectronics nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

◆ HAL_PCD_ConnectCallback()

void HAL_PCD_ConnectCallback ( PCD_HandleTypeDef *  hpcd)

ConnectCallback callback.

Parameters
hpcdPCD handle
Return values
None
237 {
238  USBD_LL_DevConnected(hpcd->pData);

◆ HAL_PCD_DataInStageCallback()

void HAL_PCD_DataInStageCallback ( PCD_HandleTypeDef *  hpcd,
uint8_t  epnum 
)

Data In Stage callback..

Parameters
hpcdPCD handle
epnumEndpoint Number
Return values
None
129 {
130  USBD_LL_DataInStage(hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff);

◆ HAL_PCD_DataOutStageCallback()

void HAL_PCD_DataOutStageCallback ( PCD_HandleTypeDef *  hpcd,
uint8_t  epnum 
)

Data Out Stage callback.

Parameters
hpcdPCD handle
epnumEndpoint Number
Return values
None
118 {
119  USBD_LL_DataOutStage(hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff);

◆ HAL_PCD_DisconnectCallback()

void HAL_PCD_DisconnectCallback ( PCD_HandleTypeDef *  hpcd)

Disconnect callback.

Parameters
hpcdPCD handle
Return values
None
247 {
248  USBD_LL_DevDisconnected(hpcd->pData);

◆ HAL_PCD_ISOINIncompleteCallback()

void HAL_PCD_ISOINIncompleteCallback ( PCD_HandleTypeDef *  hpcd,
uint8_t  epnum 
)

ISOINIncomplete callback.

Parameters
hpcdPCD handle
epnumEndpoint Number
Return values
None
227 {
228  USBD_LL_IsoINIncomplete(hpcd->pData, epnum);

◆ HAL_PCD_ISOOUTIncompleteCallback()

void HAL_PCD_ISOOUTIncompleteCallback ( PCD_HandleTypeDef *  hpcd,
uint8_t  epnum 
)

ISOOUTIncomplete callback.

Parameters
hpcdPCD handle
epnumEndpoint Number
Return values
None
216 {
217  USBD_LL_IsoOUTIncomplete(hpcd->pData, epnum);

◆ HAL_PCD_ResetCallback()

void HAL_PCD_ResetCallback ( PCD_HandleTypeDef *  hpcd)

Reset callback.

Parameters
hpcdPCD handle
Return values
None
149 {
150  USBD_SpeedTypeDef speed = USBD_SPEED_FULL;
151 
152  /*Set USB Current Speed*/
153  switch (hpcd->Init.speed)
154  {
155  case PCD_SPEED_FULL:
156  speed = USBD_SPEED_FULL;
157  break;
158 
159  default:
160  speed = USBD_SPEED_FULL;
161  break;
162  }
163  USBD_LL_SetSpeed(hpcd->pData, speed);
164 
165  /*Reset Device*/
166  USBD_LL_Reset(hpcd->pData);

◆ HAL_PCD_ResumeCallback()

void HAL_PCD_ResumeCallback ( PCD_HandleTypeDef *  hpcd)

Resume callback. When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)

Parameters
hpcdPCD handle
Return values
None
196 {
197  /* USER CODE BEGIN 3 */
198  if (hpcd->Init.low_power_enable)
199  {
200  /* Reset SLEEPDEEP bit of Cortex System Control Register */
201  SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
203  }
204  /* USER CODE END 3 */
205  USBD_LL_Resume(hpcd->pData);
206 
static void SystemClockConfig_Resume(void)
Configures system clock after wake-up from USB Resume CallBack: enable HSI, PLL and select PLL as sys...
Definition: usbd_conf.c:506

◆ HAL_PCD_SetupStageCallback()

void HAL_PCD_SetupStageCallback ( PCD_HandleTypeDef *  hpcd)

Setup Stage callback.

Parameters
hpcdPCD handle
Return values
None
107 {
108  USBD_LL_SetupStage(hpcd->pData, (uint8_t *)hpcd->Setup);

◆ HAL_PCD_SOFCallback()

void HAL_PCD_SOFCallback ( PCD_HandleTypeDef *  hpcd)

SOF callback.

Parameters
hpcdPCD handle
Return values
None
139 {
140  USBD_LL_SOF(hpcd->pData);

◆ HAL_PCD_SuspendCallback()

void HAL_PCD_SuspendCallback ( PCD_HandleTypeDef *  hpcd)

Suspend callback. When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)

Parameters
hpcdPCD handle
Return values
None
176 {
177  /* Inform USB library that core enters in suspend Mode */
178  USBD_LL_Suspend(hpcd->pData);
179  /*Enter in STOP mode */
180  /* USER CODE BEGIN 2 */
181  if (hpcd->Init.low_power_enable)
182  {
183  /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register */
184  SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
185  }
186  /* USER CODE END 2 */

◆ HAL_PCDEx_SetConnectionState()

void HAL_PCDEx_SetConnectionState ( PCD_HandleTypeDef *  hpcd,
uint8_t  state 
)

Software Device Connection.

Parameters
hpcdPCD handle
stateconnection state (0 : disconnected / 1: connected)
Return values
None
520 {
521 /* USER CODE BEGIN 6 */
522  if (state == 1)
523  {
524  /* Configure Low Connection State */
525 
526  }
527  else
528  {
529  /* Configure High Connection State */
530 
531  }
532 /* USER CODE END 6 */
enum sd_buff_state state
Definition: sd_buffer.h:108

◆ SystemClockConfig_Resume()

static void SystemClockConfig_Resume ( void  )
static

Configures system clock after wake-up from USB Resume CallBack: enable HSI, PLL and select PLL as system clock source.

Parameters
None
Return values
None
508 {
void SystemClock_Config(void)
System Clock Configuration Configure and initialize the main, systick, timer and peripheral clocks...
Definition: main.c:206

◆ USBD_LL_ClearStallEP()

USBD_StatusTypeDef USBD_LL_ClearStallEP ( USBD_HandleTypeDef *  pdev,
uint8_t  ep_addr 
)

Clears a Stall condition on an endpoint of the Low Level Driver.

Parameters
pdevDevice handle
ep_addrEndpoint Number
Return values
USBDStatus
384 {
385 
386  HAL_PCD_EP_ClrStall(pdev->pData, ep_addr);
387  return USBD_OK;

◆ USBD_LL_CloseEP()

USBD_StatusTypeDef USBD_LL_CloseEP ( USBD_HandleTypeDef *  pdev,
uint8_t  ep_addr 
)

Closes an endpoint of the Low Level Driver.

Parameters
pdevDevice handle
ep_addrEndpoint Number
Return values
USBDStatus
345 {
346 
347  HAL_PCD_EP_Close(pdev->pData, ep_addr);
348  return USBD_OK;

◆ USBD_LL_DeInit()

USBD_StatusTypeDef USBD_LL_DeInit ( USBD_HandleTypeDef *  pdev)

De-Initializes the Low Level portion of the Device driver.

Parameters
pdevDevice handle
Return values
USBDStatus
289 {
290  HAL_PCD_DeInit(pdev->pData);
291  return USBD_OK;

◆ USBD_LL_Delay()

void USBD_LL_Delay ( uint32_t  Delay)

Delays routine for the USB Device Library.

Parameters
DelayDelay in ms
Return values
None
475 {
476  HAL_Delay(Delay);

◆ USBD_LL_FlushEP()

USBD_StatusTypeDef USBD_LL_FlushEP ( USBD_HandleTypeDef *  pdev,
uint8_t  ep_addr 
)

Flushes an endpoint of the Low Level Driver.

Parameters
pdevDevice handle
ep_addrEndpoint Number
Return values
USBDStatus
358 {
359 
360  HAL_PCD_EP_Flush(pdev->pData, ep_addr);
361  return USBD_OK;

◆ USBD_LL_GetRxDataSize()

uint32_t USBD_LL_GetRxDataSize ( USBD_HandleTypeDef *  pdev,
uint8_t  ep_addr 
)

Returns the last transfered packet size.

Parameters
pdevDevice handle
ep_addrEndpoint Number
Return values
RecivedData Size
465 {
466  return HAL_PCD_EP_GetRxCount(pdev->pData, ep_addr);

◆ USBD_LL_Init()

USBD_StatusTypeDef USBD_LL_Init ( USBD_HandleTypeDef *  pdev)

Initializes the Low Level portion of the Device driver.

Parameters
pdevDevice handle
Return values
USBDStatus
260 {
261  /* Init USB_IP */
262  /* Link The driver to the stack */
263  hpcd_USB_FS.pData = pdev;
264  pdev->pData = &hpcd_USB_FS;
265 
266  hpcd_USB_FS.Instance = USB;
267  hpcd_USB_FS.Init.dev_endpoints = 5;
268  hpcd_USB_FS.Init.speed = PCD_SPEED_FULL;
269  hpcd_USB_FS.Init.ep0_mps = DEP0CTL_MPS_8;
270  hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
271  hpcd_USB_FS.Init.low_power_enable = DISABLE;
272  hpcd_USB_FS.Init.battery_charging_enable = DISABLE;
273  HAL_PCD_Init(&hpcd_USB_FS);
274 
275  HAL_PCDEx_PMAConfig(pdev->pData , 0x00 , PCD_SNG_BUF, 0x18);
276  HAL_PCDEx_PMAConfig(pdev->pData , 0x80 , PCD_SNG_BUF, 0x58);
277  HAL_PCDEx_PMAConfig(pdev->pData , 0x81 , PCD_SNG_BUF, 0xC0);
278  HAL_PCDEx_PMAConfig(pdev->pData , 0x01 , PCD_SNG_BUF, 0x110);
279  HAL_PCDEx_PMAConfig(pdev->pData , 0x82 , PCD_SNG_BUF, 0x100);
280  return USBD_OK;

◆ USBD_LL_IsStallEP()

uint8_t USBD_LL_IsStallEP ( USBD_HandleTypeDef *  pdev,
uint8_t  ep_addr 
)

Returns Stall condition.

Parameters
pdevDevice handle
ep_addrEndpoint Number
Return values
Stall(1: Yes, 0: No)
397 {
398  PCD_HandleTypeDef *hpcd = pdev->pData;
399 
400  if((ep_addr & 0x80) == 0x80)
401  {
402  return hpcd->IN_ep[ep_addr & 0x7F].is_stall;
403  }
404  else
405  {
406  return hpcd->OUT_ep[ep_addr & 0x7F].is_stall;
407  }

◆ USBD_LL_OpenEP()

USBD_StatusTypeDef USBD_LL_OpenEP ( USBD_HandleTypeDef *  pdev,
uint8_t  ep_addr,
uint8_t  ep_type,
uint16_t  ep_mps 
)

Opens an endpoint of the Low Level Driver.

Parameters
pdevDevice handle
ep_addrEndpoint Number
ep_typeEndpoint Type
ep_mpsEndpoint Max Packet Size
Return values
USBDStatus
328 {
329 
330  HAL_PCD_EP_Open(pdev->pData,
331  ep_addr,
332  ep_mps,
333  ep_type);
334 
335  return USBD_OK;

◆ USBD_LL_PrepareReceive()

USBD_StatusTypeDef USBD_LL_PrepareReceive ( USBD_HandleTypeDef *  pdev,
uint8_t  ep_addr,
uint8_t *  pbuf,
uint16_t  size 
)

Prepares an endpoint for reception.

Parameters
pdevDevice handle
ep_addrEndpoint Number
pbufPointer to data to be received
sizeData size
Return values
USBDStatus
452 {
453 
454  HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size);
455  return USBD_OK;
uint32_t size
Definition: sd_buffer.h:107

◆ USBD_LL_SetUSBAddress()

USBD_StatusTypeDef USBD_LL_SetUSBAddress ( USBD_HandleTypeDef *  pdev,
uint8_t  dev_addr 
)

Assigns a USB address to the device.

Parameters
pdevDevice handle
ep_addrEndpoint Number
Return values
USBDStatus
416 {
417 
418  HAL_PCD_SetAddress(pdev->pData, dev_addr);
419  return USBD_OK;

◆ USBD_LL_StallEP()

USBD_StatusTypeDef USBD_LL_StallEP ( USBD_HandleTypeDef *  pdev,
uint8_t  ep_addr 
)

Sets a Stall condition on an endpoint of the Low Level Driver.

Parameters
pdevDevice handle
ep_addrEndpoint Number
Return values
USBDStatus
371 {
372 
373  HAL_PCD_EP_SetStall(pdev->pData, ep_addr);
374  return USBD_OK;

◆ USBD_LL_Start()

USBD_StatusTypeDef USBD_LL_Start ( USBD_HandleTypeDef *  pdev)

Starts the Low Level portion of the Device driver.

Parameters
pdevDevice handle
Return values
USBDStatus
300 {
301  HAL_PCD_Start(pdev->pData);
302  return USBD_OK;

◆ USBD_LL_Stop()

USBD_StatusTypeDef USBD_LL_Stop ( USBD_HandleTypeDef *  pdev)

Stops the Low Level portion of the Device driver.

Parameters
pdevDevice handle
Return values
USBDStatus
311 {
312  HAL_PCD_Stop(pdev->pData);
313  return USBD_OK;

◆ USBD_LL_Transmit()

USBD_StatusTypeDef USBD_LL_Transmit ( USBD_HandleTypeDef *  pdev,
uint8_t  ep_addr,
uint8_t *  pbuf,
uint16_t  size 
)

Transmits data over an endpoint.

Parameters
pdevDevice handle
ep_addrEndpoint Number
pbufPointer to data to be sent
sizeData size
Return values
USBDStatus
434 {
435 
436  HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size);
437  return USBD_OK;
uint32_t size
Definition: sd_buffer.h:107