mirror of
https://github.com/candle-usb/candleLight_fw.git
synced 2025-01-28 06:02:52 +08:00
workaround usb bug, when bulk out packages are not received any more
This commit is contained in:
parent
af487b2344
commit
b3c89ee20b
@ -10,3 +10,4 @@ uint8_t USBD_GS_CAN_Init(USBD_HandleTypeDef *pdev, queue_t *q_frame_pool, queue_
|
||||
void USBD_GS_CAN_SetChannel(USBD_HandleTypeDef *pdev, uint8_t channel, CAN_HandleTypeDef* handle);
|
||||
bool USBD_GS_CAN_TxReady(USBD_HandleTypeDef *pdev);
|
||||
uint8_t USBD_GS_CAN_Transmit(USBD_HandleTypeDef *pdev, uint8_t *buf, uint16_t len);
|
||||
uint8_t USBD_GS_CAN_PrepareReceive(USBD_HandleTypeDef *pdev);
|
||||
|
@ -23,7 +23,7 @@ queue_t *q_to_host;
|
||||
bool send_to_host_or_enqueue(struct gs_host_frame *frame)
|
||||
{
|
||||
bool retval = false;
|
||||
if (USBD_GS_CAN_Transmit(&hUSB, (uint8_t*)frame, sizeof(struct gs_host_frame))==USBD_OK) {
|
||||
if ( USBD_GS_CAN_Transmit(&hUSB, (uint8_t*)frame, sizeof(struct gs_host_frame)) == USBD_OK ) {
|
||||
queue_push_back(q_frame_pool, frame);
|
||||
retval = true;
|
||||
} else {
|
||||
@ -68,6 +68,7 @@ int main(void)
|
||||
|
||||
struct gs_host_frame *frame = queue_pop_front(q_from_host);
|
||||
if (frame != 0) { // send can message from host
|
||||
USBD_GS_CAN_PrepareReceive(&hUSB);
|
||||
|
||||
if (can_send(&hCAN, frame)) {
|
||||
send_to_host_or_enqueue(frame);
|
||||
|
@ -71,7 +71,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
|
||||
__HAL_RCC_USB_CLK_ENABLE();
|
||||
|
||||
/* Peripheral interrupt init */
|
||||
HAL_NVIC_SetPriority(USB_IRQn, 0, 0);
|
||||
HAL_NVIC_SetPriority(USB_IRQn, 1, 0);
|
||||
HAL_NVIC_EnableIRQ(USB_IRQn);
|
||||
/* USER CODE BEGIN USB_MspInit 1 */
|
||||
|
||||
|
@ -30,6 +30,10 @@ typedef struct {
|
||||
|
||||
CAN_HandleTypeDef *channels[NUM_CAN_CHANNEL];
|
||||
|
||||
uint32_t out_requests;
|
||||
uint32_t out_requests_fail;
|
||||
uint32_t out_requests_no_buf;
|
||||
|
||||
} USBD_GS_CAN_HandleTypeDef __attribute__ ((aligned (4)));
|
||||
|
||||
static uint8_t USBD_GS_CAN_Start(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
@ -40,8 +44,6 @@ static uint8_t USBD_GS_CAN_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t *USBD_GS_CAN_GetCfgDesc(uint16_t *len);
|
||||
static uint8_t USBD_GS_CAN_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_GS_CAN_PrepareReceive(USBD_HandleTypeDef *pdev);
|
||||
|
||||
/* CAN interface class callbacks structure */
|
||||
USBD_ClassTypeDef USBD_GS_CAN = {
|
||||
USBD_GS_CAN_Start,
|
||||
@ -319,14 +321,18 @@ static uint8_t USBD_GS_CAN_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) {
|
||||
|
||||
USBD_GS_CAN_HandleTypeDef *hcan = (USBD_GS_CAN_HandleTypeDef*)pdev->pClassData;
|
||||
|
||||
hcan->out_requests++;
|
||||
|
||||
uint32_t rxlen = USBD_LL_GetRxDataSize(pdev, epnum);
|
||||
if (rxlen >= sizeof(struct gs_host_frame)) {
|
||||
queue_push_back_i(hcan->q_from_host, hcan->from_host_buf);
|
||||
hcan->from_host_buf = queue_pop_front_i(hcan->q_frame_pool);
|
||||
if (hcan->from_host_buf==0) {
|
||||
// TODO handle buffers full condition - how?
|
||||
}
|
||||
retval = USBD_OK;
|
||||
}
|
||||
|
||||
USBD_GS_CAN_PrepareReceive(pdev);
|
||||
//USBD_GS_CAN_PrepareReceive(pdev);
|
||||
return retval;
|
||||
}
|
||||
|
||||
@ -336,10 +342,10 @@ static uint8_t *USBD_GS_CAN_GetCfgDesc(uint16_t *len)
|
||||
return USBD_GS_CAN_CfgDesc;
|
||||
}
|
||||
|
||||
static uint8_t USBD_GS_CAN_PrepareReceive(USBD_HandleTypeDef *pdev)
|
||||
inline uint8_t USBD_GS_CAN_PrepareReceive(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_GS_CAN_HandleTypeDef *hcan = (USBD_GS_CAN_HandleTypeDef*)pdev->pClassData;
|
||||
return USBD_LL_PrepareReceive(pdev, GSUSB_ENDPOINT_OUT, hcan->from_host_buf, sizeof(struct gs_host_frame));
|
||||
return USBD_LL_PrepareReceive(pdev, GSUSB_ENDPOINT_OUT, (uint8_t*)hcan->from_host_buf, sizeof(struct gs_host_frame));
|
||||
}
|
||||
|
||||
bool USBD_GS_CAN_TxReady(USBD_HandleTypeDef *pdev)
|
||||
@ -358,5 +364,4 @@ uint8_t USBD_GS_CAN_Transmit(USBD_HandleTypeDef *pdev, uint8_t *buf, uint16_t le
|
||||
} else {
|
||||
return USBD_BUSY;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user