Skip to content

Commit a36188b

Browse files
committed
fix(usb): disable ICACHE
When USB is used on STM32H5 and ICACHE enable it does not work so disable it. Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 757e359 commit a36188b

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

cores/arduino/stm32/usb/cdc/usbd_cdc_if.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ USBD_HandleTypeDef hUSBD_Device_CDC;
4848

4949
static bool CDC_initialized = false;
5050
static bool CDC_DTR_enabled = true;
51+
static bool icache_enabled = false;
5152

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

271272
void CDC_init(void)
272273
{
274+
#if defined(ICACHE) && defined (HAL_ICACHE_MODULE_ENABLED) && !defined(HAL_ICACHE_MODULE_DISABLED)
275+
if (HAL_ICACHE_IsEnabled() == 1) {
276+
icache_enabled = true;
277+
/* Disable instruction cache prior to internal cacheable memory update */
278+
if (HAL_ICACHE_Disable() != HAL_OK) {
279+
Error_Handler();
280+
}
281+
}
282+
#endif /* ICACHE && HAL_ICACHE_MODULE_ENABLED && !HAL_ICACHE_MODULE_DISABLED */
273283
if (!CDC_initialized) {
274284
/* Init Device Library */
275285
if (USBD_Init(&hUSBD_Device_CDC, &USBD_Desc, 0) == USBD_OK) {
@@ -294,6 +304,14 @@ void CDC_deInit(void)
294304
USBD_DeInit(&hUSBD_Device_CDC);
295305
CDC_initialized = false;
296306
}
307+
#if defined(ICACHE) && defined (HAL_ICACHE_MODULE_ENABLED) && !defined(HAL_ICACHE_MODULE_DISABLED)
308+
if (icache_enabled) {
309+
/* Re-enable instruction cache */
310+
if (HAL_ICACHE_Enable() != HAL_OK) {
311+
Error_Handler();
312+
}
313+
}
314+
#endif /* ICACHE && HAL_ICACHE_MODULE_ENABLED && !HAL_ICACHE_MODULE_DISABLED */
297315
}
298316

299317
bool CDC_connected()

cores/arduino/stm32/usb/hid/usbd_hid_composite_if.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ USBD_HandleTypeDef hUSBD_Device_HID;
2828

2929
static bool HID_keyboard_initialized = false;
3030
static bool HID_mouse_initialized = false;
31+
static bool icache_enabled = false;
3132

3233
/**
3334
* @brief Initialize USB devices
@@ -36,6 +37,15 @@ static bool HID_mouse_initialized = false;
3637
*/
3738
void HID_Composite_Init(HID_Interface device)
3839
{
40+
#if defined(ICACHE) && defined (HAL_ICACHE_MODULE_ENABLED) && !defined(HAL_ICACHE_MODULE_DISABLED)
41+
if (HAL_ICACHE_IsEnabled() == 1) {
42+
icache_enabled = true;
43+
/* Disable instruction cache prior to internal cacheable memory update */
44+
if (HAL_ICACHE_Disable() != HAL_OK) {
45+
Error_Handler();
46+
}
47+
}
48+
#endif /* ICACHE && HAL_ICACHE_MODULE_ENABLED && !HAL_ICACHE_MODULE_DISABLED */
3949
if (IS_HID_INTERFACE(device) &&
4050
!HID_keyboard_initialized && !HID_mouse_initialized) {
4151
/* Init Device Library */
@@ -72,6 +82,14 @@ void HID_Composite_DeInit(HID_Interface device)
7282
/* DeInit Device Library */
7383
USBD_DeInit(&hUSBD_Device_HID);
7484
}
85+
#if defined(ICACHE) && defined (HAL_ICACHE_MODULE_ENABLED) && !defined(HAL_ICACHE_MODULE_DISABLED)
86+
if (icache_enabled) {
87+
/* Re-enable instruction cache */
88+
if (HAL_ICACHE_Enable() != HAL_OK) {
89+
Error_Handler();
90+
}
91+
}
92+
#endif /* ICACHE && HAL_ICACHE_MODULE_ENABLED && !HAL_ICACHE_MODULE_DISABLED */
7593
if (device == HID_KEYBOARD) {
7694
HID_keyboard_initialized = false;
7795
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy