Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 9 | ||
---|---|---|---|
Line 15... | Line 15... | ||
15 | * the License. You may obtain a copy of the License at: |
15 | * the License. You may obtain a copy of the License at: |
16 | * www.st.com/SLA0044 |
16 | * www.st.com/SLA0044 |
17 | * |
17 | * |
18 | ****************************************************************************** |
18 | ****************************************************************************** |
19 | */ |
19 | */ |
20 | /* USER CODE END Header */ |
20 | /* USER CODE END Header */ |
21 | 21 | ||
22 | /* Includes ------------------------------------------------------------------*/ |
22 | /* Includes ------------------------------------------------------------------*/ |
23 | #include "stm32f1xx.h" |
23 | #include "stm32f1xx.h" |
24 | #include "stm32f1xx_hal.h" |
24 | #include "stm32f1xx_hal.h" |
25 | #include "usbd_def.h" |
25 | #include "usbd_def.h" |
Line 56... | Line 56... | ||
56 | /* USER CODE BEGIN 1 */ |
56 | /* USER CODE BEGIN 1 */ |
57 | 57 | ||
58 | /* USER CODE END 1 */ |
58 | /* USER CODE END 1 */ |
59 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
59 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
60 | static void PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state); |
60 | static void PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state); |
61 | else |
61 | #else |
62 | void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state); |
62 | void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state); |
63 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
63 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
64 | 64 | ||
65 | /******************************************************************************* |
65 | /******************************************************************************* |
66 | LL Driver Callbacks (PCD -> USB Device Library) |
66 | LL Driver Callbacks (PCD -> USB Device Library) |
Line 175... | Line 175... | ||
175 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
175 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
176 | static void PCD_ResetCallback(PCD_HandleTypeDef *hpcd) |
176 | static void PCD_ResetCallback(PCD_HandleTypeDef *hpcd) |
177 | #else |
177 | #else |
178 | void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) |
178 | void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) |
179 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
179 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
180 | { |
180 | { |
181 | USBD_SpeedTypeDef speed = USBD_SPEED_FULL; |
181 | USBD_SpeedTypeDef speed = USBD_SPEED_FULL; |
182 | 182 | ||
183 | if ( hpcd->Init.speed != PCD_SPEED_FULL) |
183 | if ( hpcd->Init.speed != PCD_SPEED_FULL) |
184 | { |
184 | { |
185 | Error_Handler(); |
185 | Error_Handler(); |
Line 356... | Line 356... | ||
356 | USBD_StatusTypeDef usb_status = USBD_OK; |
356 | USBD_StatusTypeDef usb_status = USBD_OK; |
357 | 357 | ||
358 | hal_status = HAL_PCD_DeInit(pdev->pData); |
358 | hal_status = HAL_PCD_DeInit(pdev->pData); |
359 | 359 | ||
360 | usb_status = USBD_Get_USB_Status(hal_status); |
360 | usb_status = USBD_Get_USB_Status(hal_status); |
361 | 361 | ||
362 | return usb_status; |
362 | return usb_status; |
363 | } |
363 | } |
364 | 364 | ||
365 | /** |
365 | /** |
366 | * @brief Starts the low level portion of the device driver. |
366 | * @brief Starts the low level portion of the device driver. |
367 | * @param pdev: Device handle |
367 | * @param pdev: Device handle |
Line 369... | Line 369... | ||
369 | */ |
369 | */ |
370 | USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) |
370 | USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) |
371 | { |
371 | { |
372 | HAL_StatusTypeDef hal_status = HAL_OK; |
372 | HAL_StatusTypeDef hal_status = HAL_OK; |
373 | USBD_StatusTypeDef usb_status = USBD_OK; |
373 | USBD_StatusTypeDef usb_status = USBD_OK; |
374 | 374 | ||
375 | hal_status = HAL_PCD_Start(pdev->pData); |
375 | hal_status = HAL_PCD_Start(pdev->pData); |
376 | 376 | ||
377 | usb_status = USBD_Get_USB_Status(hal_status); |
377 | usb_status = USBD_Get_USB_Status(hal_status); |
378 | 378 | ||
379 | return usb_status; |
379 | return usb_status; |
380 | } |
380 | } |
381 | 381 | ||
382 | /** |
382 | /** |
383 | * @brief Stops the low level portion of the device driver. |
383 | * @brief Stops the low level portion of the device driver. |
Line 390... | Line 390... | ||
390 | USBD_StatusTypeDef usb_status = USBD_OK; |
390 | USBD_StatusTypeDef usb_status = USBD_OK; |
391 | 391 | ||
392 | hal_status = HAL_PCD_Stop(pdev->pData); |
392 | hal_status = HAL_PCD_Stop(pdev->pData); |
393 | 393 | ||
394 | usb_status = USBD_Get_USB_Status(hal_status); |
394 | usb_status = USBD_Get_USB_Status(hal_status); |
395 | 395 | ||
396 | return usb_status; |
396 | return usb_status; |
397 | } |
397 | } |
398 | 398 | ||
399 | /** |
399 | /** |
400 | * @brief Opens an endpoint of the low level driver. |
400 | * @brief Opens an endpoint of the low level driver. |
Line 410... | Line 410... | ||
410 | USBD_StatusTypeDef usb_status = USBD_OK; |
410 | USBD_StatusTypeDef usb_status = USBD_OK; |
411 | 411 | ||
412 | hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type); |
412 | hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type); |
413 | 413 | ||
414 | usb_status = USBD_Get_USB_Status(hal_status); |
414 | usb_status = USBD_Get_USB_Status(hal_status); |
415 | 415 | ||
416 | return usb_status; |
416 | return usb_status; |
417 | } |
417 | } |
418 | 418 | ||
419 | /** |
419 | /** |
420 | * @brief Closes an endpoint of the low level driver. |
420 | * @brief Closes an endpoint of the low level driver. |
Line 424... | Line 424... | ||
424 | */ |
424 | */ |
425 | USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) |
425 | USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) |
426 | { |
426 | { |
427 | HAL_StatusTypeDef hal_status = HAL_OK; |
427 | HAL_StatusTypeDef hal_status = HAL_OK; |
428 | USBD_StatusTypeDef usb_status = USBD_OK; |
428 | USBD_StatusTypeDef usb_status = USBD_OK; |
429 | 429 | ||
430 | hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr); |
430 | hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr); |
431 | 431 | ||
432 | usb_status = USBD_Get_USB_Status(hal_status); |
432 | usb_status = USBD_Get_USB_Status(hal_status); |
433 | 433 | ||
434 | return usb_status; |
434 | return usb_status; |
435 | } |
435 | } |
436 | 436 | ||
437 | /** |
437 | /** |
438 | * @brief Flushes an endpoint of the Low Level Driver. |
438 | * @brief Flushes an endpoint of the Low Level Driver. |
439 | * @param pdev: Device handle |
439 | * @param pdev: Device handle |
Line 442... | Line 442... | ||
442 | */ |
442 | */ |
443 | USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) |
443 | USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) |
444 | { |
444 | { |
445 | HAL_StatusTypeDef hal_status = HAL_OK; |
445 | HAL_StatusTypeDef hal_status = HAL_OK; |
446 | USBD_StatusTypeDef usb_status = USBD_OK; |
446 | USBD_StatusTypeDef usb_status = USBD_OK; |
447 | 447 | ||
448 | hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr); |
448 | hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr); |
449 | 449 | ||
450 | usb_status = USBD_Get_USB_Status(hal_status); |
450 | usb_status = USBD_Get_USB_Status(hal_status); |
451 | 451 | ||
452 | return usb_status; |
452 | return usb_status; |
453 | } |
453 | } |
454 | 454 | ||
455 | /** |
455 | /** |
456 | * @brief Sets a Stall condition on an endpoint of the Low Level Driver. |
456 | * @brief Sets a Stall condition on an endpoint of the Low Level Driver. |
457 | * @param pdev: Device handle |
457 | * @param pdev: Device handle |
Line 460... | Line 460... | ||
460 | */ |
460 | */ |
461 | USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) |
461 | USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) |
462 | { |
462 | { |
463 | HAL_StatusTypeDef hal_status = HAL_OK; |
463 | HAL_StatusTypeDef hal_status = HAL_OK; |
464 | USBD_StatusTypeDef usb_status = USBD_OK; |
464 | USBD_StatusTypeDef usb_status = USBD_OK; |
465 | 465 | ||
466 | hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr); |
466 | hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr); |
467 | 467 | ||
468 | usb_status = USBD_Get_USB_Status(hal_status); |
468 | usb_status = USBD_Get_USB_Status(hal_status); |
469 | 469 | ||
470 | return usb_status; |
470 | return usb_status; |
471 | } |
471 | } |
472 | 472 | ||
473 | /** |
473 | /** |
474 | * @brief Clears a Stall condition on an endpoint of the Low Level Driver. |
474 | * @brief Clears a Stall condition on an endpoint of the Low Level Driver. |
475 | * @param pdev: Device handle |
475 | * @param pdev: Device handle |
Line 478... | Line 478... | ||
478 | */ |
478 | */ |
479 | USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) |
479 | USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) |
480 | { |
480 | { |
481 | HAL_StatusTypeDef hal_status = HAL_OK; |
481 | HAL_StatusTypeDef hal_status = HAL_OK; |
482 | USBD_StatusTypeDef usb_status = USBD_OK; |
482 | USBD_StatusTypeDef usb_status = USBD_OK; |
483 | 483 | ||
484 | hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr); |
484 | hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr); |
485 | 485 | ||
486 | usb_status = USBD_Get_USB_Status(hal_status); |
486 | usb_status = USBD_Get_USB_Status(hal_status); |
487 | 487 | ||
488 | return usb_status; |
488 | return usb_status; |
489 | } |
489 | } |
490 | 490 | ||
491 | /** |
491 | /** |
492 | * @brief Returns Stall condition. |
492 | * @brief Returns Stall condition. |
493 | * @param pdev: Device handle |
493 | * @param pdev: Device handle |
Line 495... | Line 495... | ||
495 | * @retval Stall (1: Yes, 0: No) |
495 | * @retval Stall (1: Yes, 0: No) |
496 | */ |
496 | */ |
497 | uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) |
497 | uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) |
498 | { |
498 | { |
499 | PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData; |
499 | PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData; |
500 | 500 | ||
501 | if((ep_addr & 0x80) == 0x80) |
501 | if((ep_addr & 0x80) == 0x80) |
502 | { |
502 | { |
503 | return hpcd->IN_ep[ep_addr & 0x7F].is_stall; |
503 | return hpcd->IN_ep[ep_addr & 0x7F].is_stall; |
504 | } |
504 | } |
505 | else |
505 | else |
506 | { |
506 | { |
507 | return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; |
507 | return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; |
508 | } |
508 | } |
509 | } |
509 | } |
510 | 510 | ||
511 | /** |
511 | /** |
512 | * @brief Assigns a USB address to the device. |
512 | * @brief Assigns a USB address to the device. |
Line 516... | Line 516... | ||
516 | */ |
516 | */ |
517 | USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr) |
517 | USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr) |
518 | { |
518 | { |
519 | HAL_StatusTypeDef hal_status = HAL_OK; |
519 | HAL_StatusTypeDef hal_status = HAL_OK; |
520 | USBD_StatusTypeDef usb_status = USBD_OK; |
520 | USBD_StatusTypeDef usb_status = USBD_OK; |
521 | 521 | ||
522 | hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr); |
522 | hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr); |
523 | 523 | ||
524 | usb_status = USBD_Get_USB_Status(hal_status); |
524 | usb_status = USBD_Get_USB_Status(hal_status); |
525 | 525 | ||
526 | return usb_status; |
526 | return usb_status; |
527 | } |
527 | } |
528 | 528 | ||
529 | /** |
529 | /** |
530 | * @brief Transmits data over an endpoint. |
530 | * @brief Transmits data over an endpoint. |
531 | * @param pdev: Device handle |
531 | * @param pdev: Device handle |
532 | * @param ep_addr: Endpoint number |
532 | * @param ep_addr: Endpoint number |
533 | * @param pbuf: Pointer to data to be sent |
533 | * @param pbuf: Pointer to data to be sent |
534 | * @param size: Data size |
534 | * @param size: Data size |
535 | * @retval USBD status |
535 | * @retval USBD status |
536 | */ |
536 | */ |
537 | USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size) |
537 | USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size) |
538 | { |
538 | { |
539 | HAL_StatusTypeDef hal_status = HAL_OK; |
539 | HAL_StatusTypeDef hal_status = HAL_OK; |
540 | USBD_StatusTypeDef usb_status = USBD_OK; |
540 | USBD_StatusTypeDef usb_status = USBD_OK; |
541 | 541 | ||
542 | hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size); |
542 | hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size); |
543 | 543 | ||
544 | usb_status = USBD_Get_USB_Status(hal_status); |
544 | usb_status = USBD_Get_USB_Status(hal_status); |
545 | 545 | ||
546 | return usb_status; |
546 | return usb_status; |
547 | } |
547 | } |
548 | 548 | ||
549 | /** |
549 | /** |
550 | * @brief Prepares an endpoint for reception. |
550 | * @brief Prepares an endpoint for reception. |
551 | * @param pdev: Device handle |
551 | * @param pdev: Device handle |
Line 558... | Line 558... | ||
558 | { |
558 | { |
559 | HAL_StatusTypeDef hal_status = HAL_OK; |
559 | HAL_StatusTypeDef hal_status = HAL_OK; |
560 | USBD_StatusTypeDef usb_status = USBD_OK; |
560 | USBD_StatusTypeDef usb_status = USBD_OK; |
561 | 561 | ||
562 | hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size); |
562 | hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size); |
563 | 563 | ||
564 | usb_status = USBD_Get_USB_Status(hal_status); |
564 | usb_status = USBD_Get_USB_Status(hal_status); |
565 | 565 | ||
566 | return usb_status; |
566 | return usb_status; |
567 | } |
567 | } |
568 | 568 | ||
569 | /** |
569 | /** |
570 | * @brief Returns the last transfered packet size. |
570 | * @brief Returns the last transfered packet size. |
571 | * @param pdev: Device handle |
571 | * @param pdev: Device handle |