AnsweredAssumed Answered

Bug report in stm32f1xx_hal_pcd.c Accessing incorrect field during initialization

Question asked by Sven Almgren on Aug 11, 2017

In stm32f1xx_hal_pcd.c (for STM32F1) line 201.

 

There are two loops initializing end-point data, IN_ep and OUT_ep. The structs contain a field called tx_fifo_num which according to comments ain't used.

 

The first loop initialize IN_ep, the second OUT_ep. When looping over OUT_ep, line 203, the loop instead refer to a field in IN_ep.

 

Line 183-207:

 

/* Init endpoints structures */
for (index = 0U; index < 15U ; index++)
{
/* Init ep structure */
hpcd->IN_ep[index].is_in = 1U;
hpcd->IN_ep[index].num = index;
hpcd->IN_ep[index].tx_fifo_num = index;
/* Control until ep is actvated */
hpcd->IN_ep[index].type = EP_TYPE_CTRL;
hpcd->IN_ep[index].maxpacket = 0U;
hpcd->IN_ep[index].xfer_buff = 0U;
hpcd->IN_ep[index].xfer_len = 0U;
}

for (index = 0U; index < 15U ; index++)
{
hpcd->OUT_ep[index].is_in = 0U;
hpcd->OUT_ep[index].num = index;
hpcd->IN_ep[index].tx_fifo_num = index;
/* Control until ep is activated */
hpcd->OUT_ep[index].type = EP_TYPE_CTRL;
hpcd->OUT_ep[index].maxpacket = 0U;
hpcd->OUT_ep[index].xfer_buff = 0U;
hpcd->OUT_ep[index].xfer_len = 0U;
}

This probably doesn't case any real issues, but it's still incorrect.

Outcomes