Skip to content

Commit dce6bdc

Browse files
author
Alrik Vidstrom
committed
Fix incorrect device address at error recovery
The device address was incorrectly hard-coded as 0 when the channel was re-initialized after recovery of a USB_TYPE_ERROR.
1 parent f1d0a22 commit dce6bdc

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/targets/TARGET_STM/USBEndpoint_STM.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#include "USBHost/dbg.h"
2222
#include "USBHost/USBEndpoint.h"
23+
#include "USBHost/USBDeviceConnected.h"
24+
2325
extern uint32_t HAL_HCD_HC_GetMaxPacket(HCD_HandleTypeDef *hhcd, uint8_t chn_num);
2426
extern uint32_t HAL_HCD_HC_GetType(HCD_HandleTypeDef *hhcd, uint8_t chn_num);
2527
extern void HAL_HCD_DisableInt(HCD_HandleTypeDef *hhcd, uint8_t chn_num);
@@ -115,13 +117,13 @@ void USBEndpoint::setState(USB_TYPE st)
115117
if (st == USB_TYPE_ERROR) {
116118
HAL_HCD_HC_Halt((HCD_HandleTypeDef *)hced->hhcd, hced->ch_num);
117119
HAL_HCD_DisableInt((HCD_HandleTypeDef *)hced->hhcd, hced->ch_num);
118-
119-
}
120-
if (st == USB_TYPE_ERROR) {
121120
uint8_t hcd_speed = HCD_SPEED_FULL;
122121
/* small speed device with hub not supported
123122
if (this->speed) hcd_speed = HCD_SPEED_LOW;*/
124-
HAL_HCD_HC_Init((HCD_HandleTypeDef *)hced->hhcd, hced->ch_num, address, 0, hcd_speed, type, size);
123+
124+
// Notice that dev->getAddress() must be used instead of device_address, because the latter will contain
125+
// incorrect values in certain cases
126+
HAL_HCD_HC_Init((HCD_HandleTypeDef *)hced->hhcd, hced->ch_num, address, dev->getAddress(), hcd_speed, type, size);
125127
}
126128
}
127129

0 commit comments

Comments
 (0)