I'm trying to port GRBL 1.1 to the STM32F746 chip. Tell me the solution, thanks.

Committer:
Sergunb
Date:
Mon Sep 04 12:05:05 2017 +0000
Revision:
0:9dcf85d9b2f3
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sergunb 0:9dcf85d9b2f3 1 /******************** (C) COPYRIGHT 2011 STMicroelectronics ********************
Sergunb 0:9dcf85d9b2f3 2 * File Name : usb_endp.c
Sergunb 0:9dcf85d9b2f3 3 * Author : MCD Application Team
Sergunb 0:9dcf85d9b2f3 4 * Version : V3.3.0
Sergunb 0:9dcf85d9b2f3 5 * Date : 21-March-2011
Sergunb 0:9dcf85d9b2f3 6 * Description : Endpoint routines
Sergunb 0:9dcf85d9b2f3 7 ********************************************************************************
Sergunb 0:9dcf85d9b2f3 8 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
Sergunb 0:9dcf85d9b2f3 9 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
Sergunb 0:9dcf85d9b2f3 10 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
Sergunb 0:9dcf85d9b2f3 11 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
Sergunb 0:9dcf85d9b2f3 12 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
Sergunb 0:9dcf85d9b2f3 13 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
Sergunb 0:9dcf85d9b2f3 14 *******************************************************************************/
Sergunb 0:9dcf85d9b2f3 15
Sergunb 0:9dcf85d9b2f3 16 #include "usb_lib.h"
Sergunb 0:9dcf85d9b2f3 17 #include "usb_desc.h"
Sergunb 0:9dcf85d9b2f3 18 #include "usb_mem.h"
Sergunb 0:9dcf85d9b2f3 19 #include "hw_config.h"
Sergunb 0:9dcf85d9b2f3 20 #include "usb_istr.h"
Sergunb 0:9dcf85d9b2f3 21 #include "usb_pwr.h"
Sergunb 0:9dcf85d9b2f3 22 #include "serial.h"
Sergunb 0:9dcf85d9b2f3 23 uint8_t USB_Rx_Buffer[VIRTUAL_COM_PORT_DATA_SIZE];
Sergunb 0:9dcf85d9b2f3 24
Sergunb 0:9dcf85d9b2f3 25 extern uint8_t serial_tx_buffer[];
Sergunb 0:9dcf85d9b2f3 26 extern uint8_t serial_tx_buffer_head;
Sergunb 0:9dcf85d9b2f3 27 extern volatile uint8_t serial_tx_buffer_tail;
Sergunb 0:9dcf85d9b2f3 28
Sergunb 0:9dcf85d9b2f3 29 void EP3_OUT_Callback(void)
Sergunb 0:9dcf85d9b2f3 30 {
Sergunb 0:9dcf85d9b2f3 31 uint16_t USB_Rx_Cnt;
Sergunb 0:9dcf85d9b2f3 32
Sergunb 0:9dcf85d9b2f3 33 /* Get the received data buffer and update the counter */
Sergunb 0:9dcf85d9b2f3 34 USB_Rx_Cnt = USB_SIL_Read(EP3_OUT, USB_Rx_Buffer);
Sergunb 0:9dcf85d9b2f3 35
Sergunb 0:9dcf85d9b2f3 36 /* USB data will be immediately processed, this allow next USB traffic being
Sergunb 0:9dcf85d9b2f3 37 NAKed till the end of the USART Xfer */
Sergunb 0:9dcf85d9b2f3 38
Sergunb 0:9dcf85d9b2f3 39 OnUsbDataRx(USB_Rx_Buffer, USB_Rx_Cnt);
Sergunb 0:9dcf85d9b2f3 40
Sergunb 0:9dcf85d9b2f3 41 /* Enable the receive of data on EP3 */
Sergunb 0:9dcf85d9b2f3 42 SetEPRxValid(ENDP3);
Sergunb 0:9dcf85d9b2f3 43 }
Sergunb 0:9dcf85d9b2f3 44 void EP1_IN_Callback (void)
Sergunb 0:9dcf85d9b2f3 45 {
Sergunb 0:9dcf85d9b2f3 46 if (serial_tx_buffer_head != serial_tx_buffer_tail && (_GetEPTxStatus(ENDP1) == EP_TX_NAK))
Sergunb 0:9dcf85d9b2f3 47 {
Sergunb 0:9dcf85d9b2f3 48 uint16_t USB_Tx_length;
Sergunb 0:9dcf85d9b2f3 49
Sergunb 0:9dcf85d9b2f3 50 if (serial_tx_buffer_head > serial_tx_buffer_tail)
Sergunb 0:9dcf85d9b2f3 51 USB_Tx_length = serial_tx_buffer_head - serial_tx_buffer_tail;
Sergunb 0:9dcf85d9b2f3 52 else
Sergunb 0:9dcf85d9b2f3 53 {
Sergunb 0:9dcf85d9b2f3 54 USB_Tx_length = TX_BUFFER_SIZE - serial_tx_buffer_tail + serial_tx_buffer_head;
Sergunb 0:9dcf85d9b2f3 55 }
Sergunb 0:9dcf85d9b2f3 56
Sergunb 0:9dcf85d9b2f3 57 if (USB_Tx_length != 0)
Sergunb 0:9dcf85d9b2f3 58 {
Sergunb 0:9dcf85d9b2f3 59 if (USB_Tx_length > 64)
Sergunb 0:9dcf85d9b2f3 60 USB_Tx_length = 64;
Sergunb 0:9dcf85d9b2f3 61
Sergunb 0:9dcf85d9b2f3 62 // UserToPMABufferCopy(&serial_tx_buffer[serial_tx_buffer_tail], ENDP1_TXADDR, USB_Tx_length);
Sergunb 0:9dcf85d9b2f3 63 {
Sergunb 0:9dcf85d9b2f3 64 uint8_t *pbUsrBuf = serial_tx_buffer + serial_tx_buffer_tail;
Sergunb 0:9dcf85d9b2f3 65 uint32_t n = (USB_Tx_length + 1) >> 1; /* n = (wNBytes + 1) / 2 */
Sergunb 0:9dcf85d9b2f3 66 uint32_t i, temp1;
Sergunb 0:9dcf85d9b2f3 67 uint16_t *pdwVal;
Sergunb 0:9dcf85d9b2f3 68 pdwVal = (uint16_t *)(ENDP1_TXADDR * 2 + PMAAddr);
Sergunb 0:9dcf85d9b2f3 69 for (i = n; i != 0; i--)
Sergunb 0:9dcf85d9b2f3 70 {
Sergunb 0:9dcf85d9b2f3 71 temp1 = (uint16_t) * pbUsrBuf;
Sergunb 0:9dcf85d9b2f3 72 pbUsrBuf++;
Sergunb 0:9dcf85d9b2f3 73 if (pbUsrBuf - serial_tx_buffer == TX_BUFFER_SIZE)
Sergunb 0:9dcf85d9b2f3 74 pbUsrBuf = serial_tx_buffer;
Sergunb 0:9dcf85d9b2f3 75
Sergunb 0:9dcf85d9b2f3 76 *pdwVal++ = temp1 | (uint16_t) * pbUsrBuf << 8;
Sergunb 0:9dcf85d9b2f3 77 pdwVal++;
Sergunb 0:9dcf85d9b2f3 78 pbUsrBuf++;
Sergunb 0:9dcf85d9b2f3 79 if (pbUsrBuf - serial_tx_buffer == TX_BUFFER_SIZE)
Sergunb 0:9dcf85d9b2f3 80 pbUsrBuf = serial_tx_buffer;
Sergunb 0:9dcf85d9b2f3 81 }
Sergunb 0:9dcf85d9b2f3 82 }
Sergunb 0:9dcf85d9b2f3 83
Sergunb 0:9dcf85d9b2f3 84 SetEPTxCount(ENDP1, USB_Tx_length);
Sergunb 0:9dcf85d9b2f3 85 SetEPTxValid(ENDP1);
Sergunb 0:9dcf85d9b2f3 86
Sergunb 0:9dcf85d9b2f3 87 serial_tx_buffer_tail += USB_Tx_length;
Sergunb 0:9dcf85d9b2f3 88 if (serial_tx_buffer_tail >= TX_BUFFER_SIZE)
Sergunb 0:9dcf85d9b2f3 89 serial_tx_buffer_tail -= TX_BUFFER_SIZE;
Sergunb 0:9dcf85d9b2f3 90 }
Sergunb 0:9dcf85d9b2f3 91 }
Sergunb 0:9dcf85d9b2f3 92 }
Sergunb 0:9dcf85d9b2f3 93
Sergunb 0:9dcf85d9b2f3 94
Sergunb 0:9dcf85d9b2f3 95 /* \brief Start Of Frame (SOF) callback
Sergunb 0:9dcf85d9b2f3 96 */
Sergunb 0:9dcf85d9b2f3 97 void SOF_Callback(void)
Sergunb 0:9dcf85d9b2f3 98 {
Sergunb 0:9dcf85d9b2f3 99 if(bDeviceState == CONFIGURED)
Sergunb 0:9dcf85d9b2f3 100 {
Sergunb 0:9dcf85d9b2f3 101 /* Check the data to be sent through IN pipe */
Sergunb 0:9dcf85d9b2f3 102 EP1_IN_Callback();
Sergunb 0:9dcf85d9b2f3 103 }
Sergunb 0:9dcf85d9b2f3 104 }
Sergunb 0:9dcf85d9b2f3 105 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
Sergunb 0:9dcf85d9b2f3 106