Skip to content

Commit

Permalink
fix(usb): disable ICACHE
Browse files Browse the repository at this point in the history
When USB is used on STM32H5 and ICACHE enable it does not
work so disable it.

Signed-off-by: Frederic Pillon <[email protected]>
  • Loading branch information
fpistm committed May 31, 2023
1 parent 757e359 commit a36188b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cores/arduino/stm32/usb/cdc/usbd_cdc_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ USBD_HandleTypeDef hUSBD_Device_CDC;

static bool CDC_initialized = false;
static bool CDC_DTR_enabled = true;
static bool icache_enabled = false;

/* Received Data over USB are stored in this buffer */
CDC_TransmitQueue_TypeDef TransmitQueue;
Expand Down Expand Up @@ -270,6 +271,15 @@ static int8_t USBD_CDC_TransmitCplt(uint8_t *Buf, uint32_t *Len, uint8_t epnum)

void CDC_init(void)
{
#if defined(ICACHE) && defined (HAL_ICACHE_MODULE_ENABLED) && !defined(HAL_ICACHE_MODULE_DISABLED)
if (HAL_ICACHE_IsEnabled() == 1) {
icache_enabled = true;
/* Disable instruction cache prior to internal cacheable memory update */
if (HAL_ICACHE_Disable() != HAL_OK) {
Error_Handler();
}
}
#endif /* ICACHE && HAL_ICACHE_MODULE_ENABLED && !HAL_ICACHE_MODULE_DISABLED */
if (!CDC_initialized) {
/* Init Device Library */
if (USBD_Init(&hUSBD_Device_CDC, &USBD_Desc, 0) == USBD_OK) {
Expand All @@ -294,6 +304,14 @@ void CDC_deInit(void)
USBD_DeInit(&hUSBD_Device_CDC);
CDC_initialized = false;
}
#if defined(ICACHE) && defined (HAL_ICACHE_MODULE_ENABLED) && !defined(HAL_ICACHE_MODULE_DISABLED)
if (icache_enabled) {
/* Re-enable instruction cache */
if (HAL_ICACHE_Enable() != HAL_OK) {
Error_Handler();
}
}
#endif /* ICACHE && HAL_ICACHE_MODULE_ENABLED && !HAL_ICACHE_MODULE_DISABLED */
}

bool CDC_connected()
Expand Down
18 changes: 18 additions & 0 deletions cores/arduino/stm32/usb/hid/usbd_hid_composite_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ USBD_HandleTypeDef hUSBD_Device_HID;

static bool HID_keyboard_initialized = false;
static bool HID_mouse_initialized = false;
static bool icache_enabled = false;

/**
* @brief Initialize USB devices
Expand All @@ -36,6 +37,15 @@ static bool HID_mouse_initialized = false;
*/
void HID_Composite_Init(HID_Interface device)
{
#if defined(ICACHE) && defined (HAL_ICACHE_MODULE_ENABLED) && !defined(HAL_ICACHE_MODULE_DISABLED)
if (HAL_ICACHE_IsEnabled() == 1) {
icache_enabled = true;
/* Disable instruction cache prior to internal cacheable memory update */
if (HAL_ICACHE_Disable() != HAL_OK) {
Error_Handler();
}
}
#endif /* ICACHE && HAL_ICACHE_MODULE_ENABLED && !HAL_ICACHE_MODULE_DISABLED */
if (IS_HID_INTERFACE(device) &&
!HID_keyboard_initialized && !HID_mouse_initialized) {
/* Init Device Library */
Expand Down Expand Up @@ -72,6 +82,14 @@ void HID_Composite_DeInit(HID_Interface device)
/* DeInit Device Library */
USBD_DeInit(&hUSBD_Device_HID);
}
#if defined(ICACHE) && defined (HAL_ICACHE_MODULE_ENABLED) && !defined(HAL_ICACHE_MODULE_DISABLED)
if (icache_enabled) {
/* Re-enable instruction cache */
if (HAL_ICACHE_Enable() != HAL_OK) {
Error_Handler();
}
}
#endif /* ICACHE && HAL_ICACHE_MODULE_ENABLED && !HAL_ICACHE_MODULE_DISABLED */
if (device == HID_KEYBOARD) {
HID_keyboard_initialized = false;
}
Expand Down

0 comments on commit a36188b

Please sign in to comment.