static int8_t tunnelInit(void)
{
    doubleBuffer_init(&usbReceiveBuffer, usbRecvData, sizeof(usbRecvData));

    USBD_CDC_SetRxBuffer(&USBD_Device, usbRecvData);
    return USBD_OK;
}
/**
  * @brief  Initializes the CDC media low layer      
  * @param  None
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Itf_Init(void)
{
  /*##-6- Enable TIM peripherals Clock #######################################*/
  USBCDCTIMx_CLK_ENABLE();

  /*##-7- Configure the NVIC for TIMx ########################################*/
  /* Set Interrupt Group Priority */
  HAL_NVIC_SetPriority(USBCDCTIMx_IRQn, 6, 0);

  /* Enable the TIMx global Interrupt */
  HAL_NVIC_EnableIRQ(USBCDCTIMx_IRQn);
  /*##-3- Configure the TIM Base generation  #################################*/
  TIM_Config();
  
  /*##-4- Start the TIM Base generation in interrupt mode ####################*/
  /* Start Channel1 */
  if(HAL_TIM_Base_Start_IT(&USBCDCTimHandle) != HAL_OK)
  {
    /* Starting Error */
    Error_Handler();
  }
  
  /*##-5- Set Application Buffers ############################################*/
  USBD_CDC_SetTxBuffer(&usb_cdc_dev_param, UserTxBuffer, 0);
  USBD_CDC_SetRxBuffer(&usb_cdc_dev_param, UserRxBuffer);
  
  return (USBD_OK);
}
/**
  * @brief  CDC_Itf_Init
  *         Initializes the CDC media low layer
  * @param  None
  * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Itf_Init(void)
{
#if 0
  /*##-1- Configure the UART peripheral ######################################*/
  /* Put the USART peripheral in the Asynchronous mode (UART Mode) */
  /* USART configured as follow:
      - Word Length = 8 Bits
      - Stop Bit    = One Stop bit
      - Parity      = No parity
      - BaudRate    = 115200 baud
      - Hardware flow control disabled (RTS and CTS signals) */
  UartHandle.Instance        = USARTx;
  UartHandle.Init.BaudRate   = 115200;
  UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
  UartHandle.Init.StopBits   = UART_STOPBITS_1;
  UartHandle.Init.Parity     = UART_PARITY_NONE;
  UartHandle.Init.HwFlowCtl  = UART_HWCONTROL_NONE;
  UartHandle.Init.Mode       = UART_MODE_TX_RX;
  
  if(HAL_UART_Init(&UartHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }
  
  /*##-2- Put UART peripheral in IT reception process ########################*/
  /* Any data received will be stored in "UserTxBuffer" buffer  */
  if(HAL_UART_Receive_IT(&UartHandle, (uint8_t *)UserTxBuffer, 1) != HAL_OK)
  {
    /* Transfer error in reception process */
    Error_Handler();
  }
  
  /*##-3- Configure the TIM Base generation  #################################*/
  now done in HAL_MspInit
  TIM_Config();
#endif
  
    /*##-4- Start the TIM Base generation in interrupt mode ####################*/
    /* Start Channel1 */
    __HAL_TIM_ENABLE_IT(&TIM3_Handle, TIM_IT_UPDATE);
  
    /*##-5- Set Application Buffers ############################################*/
    USBD_CDC_SetTxBuffer(&hUSBDDevice, UserTxBuffer, 0);
    USBD_CDC_SetRxBuffer(&hUSBDDevice, UserRxBuffer);

    UserRxBufCur = 0;
    UserRxBufLen = 0;
  
    /* NOTE: we cannot reset these here, because USBD_CDC_SetInterrupt
     * may be called before this init function to set these values.
     * This can happen if the USB enumeration occurs after the call to
     * USBD_CDC_SetInterrupt.
    user_interrupt_char = VCP_CHAR_NONE;
    user_interrupt_data = NULL;
    */

    return (USBD_OK);
}
Beispiel #4
0
/**
  * @brief  CDC_Init_FS
  *         Initializes the CDC media low layer over the FS USB IP
  * @param  None
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Init_FS(void)
{
  hUsbDevice_0 = &hUsbDeviceFS;
  USBD_CDC_SetRxBuffer(hUsbDevice_0, ReceiveBuffer);
  USBD_CDC_ReceivePacket(hUsbDevice_0);

  return (USBD_OK);
}
Beispiel #5
0
/**
  * @brief  CDC_Receive_FS
  *         Data received over USB OUT endpoint are sent over CDC interface 
  *         through this function.
  *           
  *         @note
  *         This function will block any OUT packet reception on USB endpoint 
  *         untill exiting this function. If you exit this function before transfer
  *         is complete on CDC interface (ie. using DMA controller) it will result 
  *         in receiving more data while previous ones are still not sent.
  *                 
  * @param  Buf: Buffer of data to be received
  * @param  Len: Number of data received (in bytes)
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
{
  /* USER CODE BEGIN 6 */
  USBD_CDC_SetRxBuffer(hUsbDevice_0, &Buf[0]);
  USBD_CDC_ReceivePacket(hUsbDevice_0);
  return (USBD_OK);
  /* USER CODE END 6 */ 
}
/**
  * @brief  CDC_Itf_Init
  *         Initializes the CDC media low layer
  * @param  None
  * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Itf_Init(void)
{
  //  USBD_CDC_SetTxBuffer(&hUSBDDevice, NULL, 0);
  USBD_CDC_SetRxBuffer(&hUSBDDevice, UserRxBuffer);


  return (USBD_OK);
}
/**
  * @brief  CDC_Itf_DataRx
  *         Data received over USB OUT endpoint is processed here.
  * @param  Buf: Buffer of data received
  * @param  Len: Number of data received (in bytes)
  * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
  * @note   The buffer we are passed here is just UserRxBuffer, so we are
  *         free to modify it.
  */
static int8_t CDC_Itf_Receive(uint8_t* Buf, uint32_t *Len) {
#if 0
    // this sends the data over the UART using DMA
    HAL_UART_Transmit_DMA(&UartHandle, Buf, *Len);
#endif

    // TODO improve this function to implement a circular buffer

    // if we have processed all the characters, reset the buffer counters
    if (UserRxBufCur > 0 && UserRxBufCur >= UserRxBufLen) {
        memmove(UserRxBuffer, UserRxBuffer + UserRxBufLen, *Len);
        UserRxBufCur = 0;
        UserRxBufLen = 0;
    }

    uint32_t delta_len;

    if (user_interrupt_char == -1) {
        // no special interrupt character
        delta_len = *Len;

    } else {
        // filter out special interrupt character from the buffer
        bool char_found = false;
        uint8_t *dest = Buf;
        uint8_t *src = Buf;
        uint8_t *buf_top = Buf + *Len;
        for (; src < buf_top; src++) {
            if (*src == user_interrupt_char) {
                char_found = true;
                // raise exception when interrupts are finished
                pendsv_nlr_jump(user_interrupt_data);
            } else {
                if (char_found) {
                    *dest = *src;
                }
                dest++;
            }
        }

        // length of remaining characters
        delta_len = dest - Buf;
    }

    if (UserRxBufLen + delta_len + CDC_DATA_FS_MAX_PACKET_SIZE > APP_RX_DATA_SIZE) {
        // if we keep this data then the buffer can overflow on the next USB rx
        // so we don't increment the length, and throw this data away
    } else {
        // data fits, leaving room for another CDC_DATA_FS_OUT_PACKET_SIZE
        UserRxBufLen += delta_len;
    }

    // initiate next USB packet transfer, to append to existing data in buffer
    USBD_CDC_SetRxBuffer(&hUSBDDevice, UserRxBuffer + UserRxBufLen);
    USBD_CDC_ReceivePacket(&hUSBDDevice);

    return USBD_OK;
}
Beispiel #8
0
/**
  * @brief  CDC_Receive_FS
  *         Data received over USB OUT endpoint are sent over CDC interface 
  *         through this function.
  *           
  *         @note
  *         This function will block any OUT packet reception on USB endpoint 
  *         untill exiting this function. If you exit this function before transfer
  *         is complete on CDC interface (ie. using DMA controller) it will result 
  *         in receiving more data while previous ones are still not sent.
  *                 
  * @param  Buf: Buffer of data to be received
  * @param  Len: Number of data received (in bytes)
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
{
  /* USER CODE BEGIN 6 */
  USBD_CDC_SetRxBuffer(hUsbDevice_0, &Buf[0]);
  USBD_CDC_ReceivePacket(hUsbDevice_0);
	HAL_UART_Transmit_IT(&huart2, Buf, *Len);
  return (USBD_OK);
  /* USER CODE END 6 */ 
}
Beispiel #9
0
/**
  * @brief  CDC_Init_FS
  *         Initializes the CDC media low layer over the FS USB IP
  * @param  None
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Init_FS(void)
{ 
  /* USER CODE BEGIN 3 */ 
  /* Set Application Buffers */
  USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0);
  USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS);
  return (USBD_OK);
  /* USER CODE END 3 */ 
}
Beispiel #10
0
/**
  * @brief  CDC_Receive_FS
  *         Data received over USB OUT endpoint are sent over CDC interface 
  *         through this function.
  *           
  *         @note
  *         This function will block any OUT packet reception on USB endpoint 
  *         untill exiting this function. If you exit this function before transfer
  *         is complete on CDC interface (ie. using DMA controller) it will result 
  *         in receiving more data while previous ones are still not sent.
  *                 
  * @param  Buf: Buffer of data to be received
  * @param  Len: Number of data received (in bytes)
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
{
  /* USER CODE BEGIN 6 */
  USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
  USBD_CDC_ReceivePacket(&hUsbDeviceFS);
  CDC_RX_Data = &Buf[0];
  return (USBD_OK);
  /* USER CODE END 6 */ 
}
Beispiel #11
0
/**
  * @brief  CDC_Itf_Init
  *         Initializes the CDC media low layer
  * @param  None
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Itf_Init(void)
{
  
  /*##-5- Set Application Buffers ############################################*/
  USBD_CDC_SetTxBuffer(&USBD_Device, UserTxBuffer, 0);
  USBD_CDC_SetRxBuffer(&USBD_Device, UserRxBuffer);
  
  return (USBD_OK);
}
Beispiel #12
0
/**
  * @brief  CDC_Init_HS
  *         Initializes the CDC media low layer over the USB HS IP
  * @param  None
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Init_HS(void)
{
  hUsbDevice_1 = &hUsbDeviceHS;
  /* USER CODE BEGIN 8 */ 
  /* Set Application Buffers */
  USBD_CDC_SetTxBuffer(hUsbDevice_1, UserTxBufferHS, 0);
  USBD_CDC_SetRxBuffer(hUsbDevice_1, UserRxBufferHS);
  return (USBD_OK);
  /* USER CODE END 8 */ 
}
Beispiel #13
0
/**
  * @brief  CDC_Init_FS
  *         Initializes the CDC media low layer over the FS USB IP
  * @param  None
  * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Init_FS(void)
{
  hUsbDevice_0 = &hUsbDeviceFS;
  /* USER CODE BEGIN 4 */ 
  /* Set Application Buffers */
  USBD_CDC_SetTxBuffer(hUsbDevice_0, UserTxBuffer, 0);
  USBD_CDC_SetRxBuffer(hUsbDevice_0, UserRxBuffer);
  return (USBD_OK);
  /* USER CODE END 4 */ 
}
Beispiel #14
0
/**
  * @brief  CDC_Receive_FS
  *         Callback. Data received over USB OUT endpoint are sent over CDC interface
  *         through this function.
  *
  *         @note
  *         This function will block any OUT packet reception on USB endpoint
  *         untill exiting this function. If you exit this function before transfer
  *         is complete on CDC interface (ie. using DMA controller) it will result
  *         in receiving more data while previous ones are still not sent.
  *
  * @param  Buf: Buffer of data to be received
  * @param  Len: Number of data received (in bytes)
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Receive_FS (uint8_t* buf, uint32_t *len)
{
  if(len == 0)
    return USBD_OK; /* not sure if this ever happens but it might */

  /* Push the buffer we just received into the HAL UART TX quee */
  HAL_StatusTypeDef r;
  while((r = HAL_UART_Transmit_IT(&huart2, buf, *len)) == HAL_BUSY) {
    // We could go into STOP mode here, but USB is connected so who cares about power?
    // UART, transmit timer are both higher priority interrupts so will interrupt us here
  }

  /* Swap the buffer that we'll receive next CDC packet into */
  if(buf == cdc2usart_buf_a)
    USBD_CDC_SetRxBuffer(husb, cdc2usart_buf_b);
  else
    USBD_CDC_SetRxBuffer(husb, cdc2usart_buf_a);

  USBD_CDC_ReceivePacket(husb);
  return r == HAL_OK ? USBD_OK : USBD_FAIL;
}
/**
  * @brief  CDC_Itf_Init
  *         Initializes the CDC media low layer
  * @param  None
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Itf_Init(void)
{
#if 0
  /*##-1- Configure the UART peripheral ######################################*/
  /* Put the USART peripheral in the Asynchronous mode (UART Mode) */
  /* USART configured as follow:
      - Word Length = 8 Bits
      - Stop Bit    = One Stop bit
      - Parity      = No parity
      - BaudRate    = 115200 baud
      - Hardware flow control disabled (RTS and CTS signals) */
  UartHandle.Instance          = USARTx;
  UartHandle.Init.BaudRate     = 115200;
  UartHandle.Init.WordLength   = UART_WORDLENGTH_8B;
  UartHandle.Init.StopBits     = UART_STOPBITS_1;
  UartHandle.Init.Parity       = UART_PARITY_NONE;
  UartHandle.Init.HwFlowCtl    = UART_HWCONTROL_NONE;
  UartHandle.Init.Mode         = UART_MODE_TX_RX;
  UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
    
  if(HAL_UART_Init(&UartHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }
  
  /*##-2- Put UART peripheral in IT reception process ########################*/
  /* Any data received will be stored in "UserTxBuffer" buffer  */
  if(HAL_UART_Receive_IT(&UartHandle, (uint8_t *)UserTxBuffer, 1) != HAL_OK)
  {
    /* Transfer error in reception process */
    Error_Handler();
  }
  
#endif

  /*##-3- Configure the TIM Base generation  #################################*/
  TIM_Config();
  
  /*##-4- Start the TIM Base generation in interrupt mode ####################*/
  /* Start Channel1 */
  if(HAL_TIM_Base_Start_IT(&TimHandle) != HAL_OK)
  {
    /* Starting Error */
    Error_Handler();
  }
  
  /*##-5- Set Application Buffers ############################################*/
  USBD_CDC_SetTxBuffer(&USBD_Device, UserTxBuffer, 0);
  USBD_CDC_SetRxBuffer(&USBD_Device, UserRxBuffer);
  
  return (USBD_OK);
}
/* initializes the CDC media low level layer */
static int8_t CDC_Itf_Init(void)
{
	TIM_Config();

	if (HAL_TIM_Base_Start_IT(&TimHandle) != HAL_OK) {
		Error_Handler();
	}

	USBD_CDC_SetTxBuffer(&USBD_Device, UserTxBuffer, 0);
	USBD_CDC_SetRxBuffer(&USBD_Device, UserRxBuffer);

	return USBD_OK;
}
Beispiel #17
0
/**
  * @brief  CDC_Init_FS
  *         Initializes the CDC media low layer over the FS USB IP
  * @param  None
  * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Init_FS(void)
{
  hUsbDevice_0 = &hUsbDeviceFS;
  /* USER CODE BEGIN 4 */ 
  /* Set Application Buffers */
  USBD_CDC_SetTxBuffer(hUsbDevice_0, UserLowLevelTxBufferFS, 0);
  USBD_CDC_SetRxBuffer(hUsbDevice_0, UserLowLevelRxBufferFS);
  AppRxBufferHeadIndex = 0;
  AppRxBufferTailIndex = 0;
  if ( hUsbDevice_0 == NULL ) return USBD_FAIL;
  usb_init_count++;
  return (USBD_OK);
  /* USER CODE END 4 */ 
}
Beispiel #18
0
/**
 * @brief  CDC_Receive_FS
 *         Data received over USB OUT endpoint are sent over CDC interface
 *         through this function.
 *
 *         @note
 *         This function will block any OUT packet reception on USB endpoint
 *         untill exiting this function. If you exit this function before transfer
 *         is complete on CDC interface (ie. using DMA controller) it will result
 *         in receiving more data while previous ones are still not sent.
 *
 * @param  Buf: Buffer of data to be received
 * @param  Len: Number of data received (in bytes)
 * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
 */
static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
{
	uint32_t i;
	/* USER CODE BEGIN 7 */
	for (i = 0; i < *Len; i++)
		UserTxBufferFS[i] = UserRxBufferFS[i];

	USBD_CDC_SetTxBuffer(&hUsbDeviceFS, &UserTxBufferFS[0], *Len);
	USBD_CDC_TransmitPacket(&hUsbDeviceFS);

	USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &UserRxBufferFS[0]);
	USBD_CDC_ReceivePacket(&hUsbDeviceFS);
	return (USBD_OK);
	/* USER CODE END 7 */
}
static int8_t CDC_Itf_Init(void)
{
    tx_wr = 0;
    tx_rd = 0;
    tx_overflow = 0;
    rx_wr = 0;
    rx_rd = 0;
    rx_overflow = 0;

    USBD_CDC_SetTxBuffer(&hUSBDDevice, tx_fifo, 0);
    USBD_CDC_SetRxBuffer(&hUSBDDevice, rx_buffer);

    cdc_timer_start();

    return USBD_OK;
}
Beispiel #20
0
/**
  * @brief  CDC_Init_FS
  *         Initializes the CDC media low layer over the FS USB IP
  * @param  None
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Init_FS(void)
{
  husb = &hUsbDeviceFS;

  /* Configure the USART with some sensible defaults

     TODO: If possible, don't drive TX high while CDC is "closed"?
   */
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 115200;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  huart2.Init.OneBitSampling = UART_ONEBIT_SAMPLING_DISABLED ;
  huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  HAL_UART_Init(&huart2);

  /* Enable USART2 in NVIC, set priority to high */
  NVIC_SetPriority(USART2_IRQn, USART_IRQ_PRIORITY);
  NVIC_EnableIRQ(USART2_IRQn);

  /* UART2 receives data to the CDC transmit buffer, byte at a time :( */
  if(HAL_UART_Receive_IT(&huart2, usart2cdc_rx, 1) != HAL_OK)
    return USBD_FAIL;

  /* Configure USB transmit timer */
  husbtimer.Instance = TIM3;
  husbtimer.Init.Period = 10000 - 1; /* approx 10ms, I think... */
  husbtimer.Init.Prescaler = 48-1;
  husbtimer.Init.ClockDivision = 0;
  husbtimer.Init.CounterMode = TIM_COUNTERMODE_UP;
  if(HAL_TIM_Base_Init(&husbtimer) != HAL_OK)
    return USBD_FAIL;

  __TIM3_CLK_ENABLE();
  NVIC_SetPriority(TIM3_IRQn, USB_TIMER_IRQ_PRIORITY);
  NVIC_EnableIRQ(TIM3_IRQn);

  /* Set Application USB Buffers */
  USBD_CDC_SetTxBuffer(husb, usart2cdc_tx, 0); /* don't send anything now */
  USBD_CDC_SetRxBuffer(husb, cdc2usart_buf_a);     /* read into here if CDC data comes */

  return USBD_OK;
}
Beispiel #21
0
/**
  * @brief  CDC_Receive_FS
  *         Data received over USB OUT endpoint are sent over CDC interface 
  *         through this function.
  *           
  *         @note
  *         This function will block any OUT packet reception on USB endpoint 
  *         untill exiting this function. If you exit this function before transfer
  *         is complete on CDC interface (ie. using DMA controller) it will result 
  *         in receiving more data while previous ones are still not sent.
  *                 
  * @param  Buf: Buffer of data to be received
  * @param  Len: Number of data received (in bytes)
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
{
  /* USER CODE BEGIN 7 */ 
// uncomment this for you know what	
//#define CDCecho
#ifdef CDCecho	
  for (int i = 0; i < *Len; i++)
     UserTxBufferFS[i] = UserRxBufferFS[i];
   
  USBD_CDC_SetTxBuffer(&hUsbDeviceFS, &UserTxBufferFS[0], *Len);
  USBD_CDC_TransmitPacket(&hUsbDeviceFS);
   
  USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &UserRxBufferFS[0]);
  USBD_CDC_ReceivePacket(&hUsbDeviceFS);
#endif
  return (USBD_OK);
  /* USER CODE END 7 */ 
}
Beispiel #22
0
/**
  * @brief  CDC_Itf_Init
  *         Initializes the CDC media low layer
  * @param  None
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Itf_Init(void)
{
  /*##-3- Configure the TIM Base generation  #################################*/
  TIM_Config();
  
  /*##-4- Start the TIM Base generation in interrupt mode ####################*/
  /* Start Channel1 */
  if(HAL_TIM_Base_Start_IT(&TimHandle) != HAL_OK)
  {
    /* Starting Error */
    Error_Handler();
  }
  
  /*##-5- Set Application Buffers ############################################*/
  USBD_CDC_SetTxBuffer(&USBD_Device, UserTxBuffer, 0);
  USBD_CDC_SetRxBuffer(&USBD_Device, UserRxBuffer);
  
  return (USBD_OK);
}
Beispiel #23
0
/**
  * @brief  CDC_Receive_FS
  *         Data received over USB OUT endpoint are sent over CDC interface 
  *         through this function.
  *           
  *         @note
  *         This function will block any OUT packet reception on USB endpoint 
  *         untill exiting this function. If you exit this function before transfer
  *         is complete on CDC interface (ie. using DMA controller) it will result 
  *         in receiving more data while previous ones are still not sent.
  *                 
  * @param  Buf: Buffer of data to be received
  * @param  Len: Number of data received (in bytes)
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
{
  /* USER CODE BEGIN 6 */
  uint8_t result = USBD_OK;
	static uint8_t buff_RX[512];
	static uint8_t buff_TX[512];
	
	int i = 0;
	for (i = 0; i < *Len; i++)
		buff_TX[i] = buff_RX[i];
	
	USBD_CDC_SetTxBuffer(hUsbDevice_0, &buff_TX[0], *Len);
	USBD_CDC_TransmitPacket(hUsbDevice_0);
	
	USBD_CDC_SetRxBuffer(hUsbDevice_0, &buff_RX[0]);
  USBD_CDC_ReceivePacket(hUsbDevice_0);
  return (result);
  /* USER CODE END 6 */ 
}
Beispiel #24
0
/**
  * @brief  CDC_Init_FS
  *         Initializes the CDC media low layer over the FS USB IP
  * @param  None
  * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Init_FS(void)
{
  hUsbDevice_0 = &hUsbDeviceFS;
  /* USER CODE BEGIN 4 */ 
  /* Set Application Buffers */
  USBD_CDC_SetTxBuffer(hUsbDevice_0, UserLowLevelTxBufferFS, 0);
  USBD_CDC_SetRxBuffer(hUsbDevice_0, UserLowLevelRxBufferFS);
  AppRxBufferHeadIndex = 0;
  AppRxBufferTailIndex = 0;
  if ( hUsbDevice_0 == NULL ) return USBD_FAIL;
  USBD_CDC_HandleTypeDef *pCDC =
          (USBD_CDC_HandleTypeDef *)hUsbDevice_0->pClassData;
  if ( pCDC->TxState != 0 ) {
      pCDC->TxState = 0;
      //pCDC->RxState = 0;
  }
  return (USBD_OK);
  /* USER CODE END 4 */ 
}
static int8_t CDC_Itf_Receive(uint8_t* pbuf, uint32_t *Len)
{
    uint32_t n = *Len;
    uint32_t i;

    // Write the received buffer to the Rx fifo.
    for (i = 0; i < n; i ++) {
        uint32_t rx_wr_inc = (rx_wr == (RX_FIFO_SIZE - 1)) ? 0 : rx_wr + 1;
        if (rx_wr_inc != rx_rd) {
            rx_fifo[rx_wr] = pbuf[i];
            rx_wr = rx_wr_inc;
        } else {
            rx_overflow += 1;
        }
    }

    USBD_CDC_SetRxBuffer(&hUSBDDevice, rx_buffer);
    USBD_CDC_ReceivePacket(&hUSBDDevice);
    return USBD_OK;
}
Beispiel #26
0
/**
  * @brief  CDC_Receive_FS
  *         Data received over USB OUT endpoint are sent over CDC interface 
  *         through this function.
  *           
  *         @note
  *         This function will block any OUT packet reception on USB endpoint 
  *         untill exiting this function. If you exit this function before transfer
  *         is complete on CDC interface (ie. using DMA controller) it will result 
  *         in receiving more data while previous ones are still not sent.
  *                 
  * @param  Buf: Buffer of data to be received
  * @param  Len: Number of data received (in bytes)
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
{
    uint8_t i;

    for( i = 0; i < *Len; i++ )
    {
        if( IsFifoFull( &UartObj->FifoRx ) == false )
        {
            // Read one byte from the receive data register
            FifoPush( &UartObj->FifoRx, Buf[i] );
        }
    }
    if( UartObj->IrqNotify != NULL )
    {
        UartObj->IrqNotify( UART_NOTIFY_RX );
    }
    USBD_CDC_SetRxBuffer(hUsbDevice_0, Buf);
    USBD_CDC_ReceivePacket(hUsbDevice_0);
    return (USBD_OK);
}
Beispiel #27
0
/**
  * @brief  CDC_Receive_FS
  *         Data received over USB OUT endpoint are sent over CDC interface 
  *         through this function.
  *           
  *         @note
  *         This function will block any OUT packet reception on USB endpoint 
  *         untill exiting this function. If you exit this function before transfer
  *         is complete on CDC interface (ie. using DMA controller) it will result 
  *         in receiving more data while previous ones are still not sent.
  *                 
  * @param  Buf: Buffer of data to be received
  * @param  Len: Number of data received (in bytes)
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
{
  /* USER CODE BEGIN 6 */
  memcpy(User_Data, Buf, *Len);
  
  
//   if(User_Data[1] == 0) {
//    temp = atoi(&User_Data[0]);
//   }
//   else {
//     UiData[temp - 1] = atoi(&User_Data[0]);
//     memset(User_Data, 0, sizeof(User_Data));
//   }
  
  
  if(temp == 0) {
    temp = atoi(&User_Data[0]);
  }
  else {
  
    UiData[temp - 1] = atoi(&User_Data[0]);
    temp = 0;
    memset(User_Data, 0, sizeof(User_Data));
  }
  
  
   
  //a = atoi((const char *) User_Data[0]);
  //UiData[a] = 
  //UiData[atoi(User_Data[0])] = atoi(User_Data[1]);
  
  
  
  USBD_CDC_SetRxBuffer(hUsbDevice_0, &Buf[0]);
  USBD_CDC_ReceivePacket(hUsbDevice_0);
  return (USBD_OK);
  /* USER CODE END 6 */ 
}
Beispiel #28
0
void USB_Handler(uint8_t* Buf, uint32_t *Len)
{
	int sz;
	RTC_DateTypeDef sDate;
	RTC_TimeTypeDef sTime;
	if (UserRxBufferFS[0] == 0xAB)
	{
		settingsPacket.startByte = UserRxBufferFS[0];
		settingsPacket.command = UserRxBufferFS[1];
		for (int i = 0; i < 16; i++)
			settingsPacket.data[i] = UserRxBufferFS[i + 2];
		switch (settingsPacket.command)
		{
			case READ_ID:
				settingsPacket.data[0] = 1;
				strcpy((char *) &settingsPacket.data[1],
						(char *) &device.settings->firmware.VERSION);
				break;
			case SET_TIME:
				sDate.Year = settingsPacket.data[0];
				sDate.Month = settingsPacket.data[1];
				sDate.Date = settingsPacket.data[2];
				sTime.Hours = settingsPacket.data[3];
				sTime.Minutes = settingsPacket.data[4];
				sTime.Seconds = settingsPacket.data[5];
				settingsPacket.data[0] = 1;
#ifdef __RTC__
				HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN);
				HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN);

#endif
				break;
			case GET_DOOR_EVENT:
				settingsPacket.data[0] = 1;
				HAL_I2C_Mem_Read(&hi2c1, EEPROM_CODE, INIT_EEPROM + 4, I2C_MEMADD_SIZE_8BIT,
						(uint8_t*) device.door, sizeof(DOOR_T), 1000);
				device.door->STATUS = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_3);
				settingsPacket.data[1] = device.door->STATUS;
#ifdef __DEDUG__
				printf("door->STATUS %u\n", device.door->STATUS);
#endif

				settingsPacket.data[2] = device.door->COUNT;
				settingsPacket.data[3] = device.door->TIME.Hours;
				settingsPacket.data[4] = device.door->TIME.Minutes;
				settingsPacket.data[5] = device.door->TIME.Seconds;
				settingsPacket.data[6] = device.door->DATE.Date;
				settingsPacket.data[7] = device.door->DATE.Month;
				settingsPacket.data[8] = device.door->DATE.Year;

				break;

			case READ_VERSION:
				settingsPacket.data[0] = 1;
				strcpy(&settingsPacket.data[1], &device.settings->firmware.VERSION[0]);
				break;

			case RESET_DOOR_EVENT:
				memset(device.door, 0, sizeof(DOOR_T));
				HAL_I2C_Mem_Write(&hi2c1, EEPROM_CODE, INIT_EEPROM + 4, I2C_MEMADD_SIZE_8BIT,
						(uint8_t*) device.door, sizeof(DOOR_T), 1000);
//				HAL_I2C_Mem_Read(&hi2c1, EEPROM_CODE, INIT_EEPROM + 4, I2C_MEMADD_SIZE_8BIT,
//						(uint8_t*) device.door, sizeof(DOOR_T), 1000);

							break;
		}

//	for (int i = 0; i < *Len; i++)
//		UserTxBufferFS[i] = UserRxBufferFS[i];
//
//	USBD_CDC_SetTxBuffer(&hUsbDeviceFS, &UserTxBufferFS[0], *Len);
		USBD_CDC_SetTxBuffer(&hUsbDeviceFS, (uint8_t*) &settingsPacket, sizeof(settingsPacket));
		USBD_CDC_TransmitPacket(&hUsbDeviceFS);

		USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &UserRxBufferFS[0]);
		USBD_CDC_ReceivePacket(&hUsbDeviceFS);
	}
	else
	{
		settingsPacket.startByte = UserRxBufferFS[0];
		USBD_CDC_SetTxBuffer(&hUsbDeviceFS, (uint8_t*) &settingsPacket, 1);
		USBD_CDC_TransmitPacket(&hUsbDeviceFS);
		USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &UserRxBufferFS[0]);
		USBD_CDC_ReceivePacket(&hUsbDeviceFS);
	}
}
Beispiel #29
0
/**
  * @brief  VCP_Init
  *         Initializes the CDC media low layer
  * @param  None
  * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t VCP_Init(void)
{
    USBD_CDC_SetRxBuffer(&hUSBDDevice, s_RxBuffer.Buffer);
    g_VCPInitialized = 1;
    return (0);
}
/**
  * @brief  CDC_Itf_Init
  *         Initializes the CDC media low layer
  * @param  None
  * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Itf_Init(void)
{
	USBD_CDC_SetRxBuffer(&USBD_Device, USBRxBuffer);
  return (USBD_OK);
}