Skip to content

Commit

Permalink
Improve error handling and turn off dma
Browse files Browse the repository at this point in the history
DMA is currently very unreliable, it doesn't work at
all with the Arturia Beatstep Pro. Turning it off for
now to allow further testing.

Signed-off-by: Greg Burns <[email protected]>
  • Loading branch information
GregBurns committed Feb 26, 2024
1 parent 81cdee4 commit a2aca08
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ typedef enum {
MIDI_IDLE,
MIDI_RX,
MIDI_RX_POLL,
MIDI_FAIL
MIDI_RX_ERROR,
MIDI_FATAL_ERROR
} MIDI_StateTypeDef;

typedef enum {
Expand Down
33 changes: 19 additions & 14 deletions Middlewares/ST/STM32_USB_Host_Library/Class/MIDI/Src/usbh_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ static USBH_StatusTypeDef USBH_MIDI_InterfaceDeInit(USBH_HandleTypeDef *phost)
static USBH_StatusTypeDef USBH_MIDI_ClassRequest(USBH_HandleTypeDef *phost)
{
phost->pUser(phost, HOST_CLASS_REQUEST);
USBH_UsrLog("Speed=%d", USBH_LL_GetSpeed(phost));
return USBH_OK;
}

Expand Down Expand Up @@ -166,31 +165,36 @@ static USBH_StatusTypeDef USBH_MIDI_Process(USBH_HandleTypeDef *phost)
hMidi->state = MIDI_RX;
break;
case MIDI_RX:
error = USBH_BulkReceiveData(phost, hMidi->rxBuffer, hMidi->InEpSize, hMidi->InPipe);
if (error == USBH_OK) {
hMidi->state = MIDI_RX_POLL;
} else {
USBH_UsrLog("BulkReceiveData->%d", error);
hMidi->state = MIDI_FAIL;
error = USBH_FAIL;
}
// Always returns USBH_OK, call USBH_LL_GetURBState() for status
USBH_BulkReceiveData(phost, hMidi->rxBuffer, hMidi->InEpSize, hMidi->InPipe);
hMidi->state = MIDI_RX_POLL;
break;
case MIDI_RX_POLL:
rxStatus = USBH_LL_GetURBState(phost, hMidi->InPipe);
if (rxStatus == USBH_URB_DONE) {
if (rxStatus == USBH_URB_NOTREADY || rxStatus == USBH_URB_IDLE) {
hMidi->state = MIDI_RX_POLL;
} else if (rxStatus == USBH_URB_DONE) {
size_t sz = USBH_LL_GetLastXferSize(phost, hMidi->InPipe);
hMidi->state = MIDI_RX;
if (hMidi->callback) {
hMidi->callback(hMidi->rxBuffer, sz, hMidi->pUser);
}
} else if (rxStatus == USBH_URB_ERROR || rxStatus == USBH_URB_STALL) {
hMidi->state = MIDI_FAIL;
} else {
hMidi->state = MIDI_RX_ERROR;
error = USBH_FAIL;
}
break;
case MIDI_FAIL:
hMidi->state = MIDI_IDLE;
case MIDI_RX_ERROR:
error = USBH_ClrFeature(phost, hMidi->InEp);
if (error == USBH_FAIL) {
USBH_MIDI_InterfaceDeInit(phost);
hMidi->state = MIDI_FATAL_ERROR;
} else {
hMidi->state = MIDI_IDLE;
}
break;
case MIDI_FATAL_ERROR:
return USBH_FAIL;
}
return error;
}
Expand Down Expand Up @@ -228,6 +232,7 @@ MIDI_ErrorTypeDef USBH_MIDI_Transmit(USBH_HandleTypeDef *phost, uint8_t* data, s
{
if(txStatus == USBH_URB_ERROR || txStatus == USBH_URB_STALL)
{
USBH_ClrFeature(phost, hMidi->OutEp);
return MIDI_ERROR;
}
if(numUrbs == 0)
Expand Down
4 changes: 3 additions & 1 deletion src/usbh/usbh_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,16 @@ USBH_StatusTypeDef USBH_LL_Init(USBH_HandleTypeDef *phost)
/* Init USB_IP */
if(phost->id == HOST_HS)
{
memset(&hhcd_USB_OTG_HS, 0, sizeof(hhcd_USB_OTG_HS));

/* Link the driver to the stack. */
hhcd_USB_OTG_HS.pData = phost;
phost->pData = &hhcd_USB_OTG_HS;

hhcd_USB_OTG_HS.Instance = USB_OTG_HS;
hhcd_USB_OTG_HS.Init.Host_channels = 16;
hhcd_USB_OTG_HS.Init.speed = HCD_SPEED_FULL;
hhcd_USB_OTG_HS.Init.dma_enable = ENABLE;
hhcd_USB_OTG_HS.Init.dma_enable = DISABLE;
hhcd_USB_OTG_HS.Init.phy_itface = USB_OTG_EMBEDDED_PHY;
hhcd_USB_OTG_HS.Init.Sof_enable = DISABLE;
hhcd_USB_OTG_HS.Init.low_power_enable = DISABLE;
Expand Down

0 comments on commit a2aca08

Please sign in to comment.