@@ -76,6 +76,21 @@ uint32_t HAL_HCD_HC_GetType(HCD_HandleTypeDef *hhcd, uint8_t chnum)
76
76
return hhcd->hc [chnum].ep_type ;
77
77
}
78
78
79
+ // The urb_state parameter can be one of the following according to the ST documentation, but the explanations
80
+ // that follow are the result of an analysis of the ST HAL / LL source code, the Reference Manual for the
81
+ // STM32H747 microcontroller, and the source code of this library:
82
+ //
83
+ // - URB_ERROR = various serious errors that may be hard or impossible to recover from without pulling
84
+ // the thumb drive out and putting it back in again, but we will try
85
+ // - URB_IDLE = set by a call to HAL_HCD_HC_SubmitRequest(), but never used by this library
86
+ // - URB_NYET = never actually used by the ST HAL / LL at the time of writing, nor by this library
87
+ // - URB_STALL = a stall response from the device - but it is never handled by the library and will end up
88
+ // as a timeout at a higher layer, because of an ep_queue.get() timeout, which will activate
89
+ // error recovery indirectly
90
+ // - URB_DONE = the transfer completed normally without errrors
91
+ // - URB_NOTREADY = a NAK, NYET, or not more than a couple of repeats of some of the errors that will
92
+ // become URB_ERROR if they repeat several times in a row
93
+ //
79
94
void HAL_HCD_HC_NotifyURBChange_Callback (HCD_HandleTypeDef *hhcd, uint8_t chnum, HCD_URBStateTypeDef urb_state)
80
95
{
81
96
USBHALHost_Private_t *priv = (USBHALHost_Private_t *)(hhcd->pData );
@@ -107,14 +122,11 @@ void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum,
107
122
}
108
123
break ;
109
124
case URB_NOTREADY:
110
- /* try again */
111
- /* abritary limit , to avoid dead lock if other error than
112
- * slow response is */
113
125
#if defined(MAX_NOTREADY_RETRY)
114
126
if (td->retry < MAX_NOTREADY_RETRY) {
115
- /* increment retry counter */
116
127
td->retry ++;
117
128
#endif
129
+ // Submit the same request again, because the device wasn't ready to accept the last one
118
130
length = td->size <= max_size ? td->size : max_size;
119
131
HAL_HCD_HC_SubmitRequest (hhcd, chnum, dir, type, !td->setup , (uint8_t *) td->currBufPtr , length, 0 );
120
132
HAL_HCD_EnableInt (hhcd, chnum);
@@ -138,6 +150,9 @@ void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum,
138
150
td->state = USB_TYPE_IDLE;
139
151
}
140
152
else if (urb_state == URB_ERROR) {
153
+ // While USB_TYPE_ERROR in the endpoint state is used to activate error recovery, this value is actually never used.
154
+ // Going here will lead to a timeout at a higher layer, because of ep_queue.get() timeout, which will activate error
155
+ // recovery indirectly.
141
156
td->state = USB_TYPE_ERROR;
142
157
} else {
143
158
td->state = USB_TYPE_PROCESSING;
0 commit comments