2017-01-21 03:58 PM
Hello,
I just started a mini project using USB CDC with STM32CubeMX and while trying to figure out how to use CDC driver i found this piece of code.
I think there is code duplication (copy-paste) in STM32Cube_FW_L0_V1.8.0/Drivers/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_pcd.c
In function PCD_EP_ISR_Handler(),
In section /* Decode and service non control endpoints interrupt */ for Correct Transfer for transmission,
from /* IN double Buffering*/ to /*multi-packet on the NON control OUT endpoint*/.Code in above described section wrongly writes data to PMA memory.
The later call to HAL_PCD_EP_Transmit() writes right data to PMA memory and sends it.
Possible side effect with duplicated code in PCD_EP_ISR_Handler() can be a calling of function PCD_FreeUserBuffer() twice in case of ep->doublebuffer != 0U.
#stm32l0xx2018-03-16 07:21 AM
Hello,
I found same necessaries memory copies USB_WritePMA in PCD_EP_ISR_Handler
at file stm32l4xx_hal_pcd.c
Project was generated with CubeX v4.24, STM32L4 package version 1.11.0
static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd)
{
......................
if ((wEPVal & USB_EP_CTR_TX) != 0)
{ ep = &hpcd->IN_ep[epindex]; /* clear int flag */ PCD_CLEAR_TX_EP_CTR(hpcd->Instance, epindex); /* IN double Buffering*/ if (ep->doublebuffer == 0) {/* necessaries memory copies (copy paste problem from RX part?)
ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num);
if (ep->xfer_count != 0)
{
USB_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, ep->xfer_count);
}*/
} else {
//If double buffer not
incomprehensible code in red. Maybe stm software engineers or guru can explain it?
if (PCD_GET_ENDPOINT(hpcd->Instance, ep->num) & USB_EP_DTOG_TX)
{ /*read from endpoint BUF0Addr buffer*/ ep->xfer_count = PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num); if (ep->xfer_count != 0) { USB_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, ep->xfer_count); } } else { /*read from endpoint BUF1Addr buffer*/ ep->xfer_count = PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num); if (ep->xfer_count != 0) { USB_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, ep->xfer_count); } } PCD_FreeUserBuffer(hpcd->Instance, ep->num, PCD_EP_DBUF_IN); } /*multi-packet on the NON control IN endpoint*/ ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num); ep->xfer_buff+=ep->xfer_count; /* Zero Length Packet? */ if (ep->xfer_len == 0) { /* TX COMPLETE */ HAL_PCD_DataInStageCallback(hpcd, ep->num); } else { HAL_PCD_EP_Transmit(hpcd, ep->num, ep->xfer_buff, ep->xfer_len); } }............
}
BR.
Darius Babrauskas