Skip to content

Commit 6af55c5

Browse files
author
Alrik Vidstrom
committed
Fix interrupt bug in SDCardBlockDevice::open()
An extra check is necessary when the SDCardBlockDevice object is destroyed and created again. With only the FSP_INVALID_VECTOR fix, multiple interrupt vector entries will be created in this particular case. Worse, the SDCARD interrupts will be reenabled after R_SDHI_Close() but before R_SDHI_Open(), which will cause sdhimmc_accs_isr() inside the Renesas FSP to send an invalid context pointer to r_sdhi_access_irq_process(), causing a hard fault. Former-commit-id: 525fdef
1 parent c7238d8 commit 6af55c5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

libraries/BlockDevices/SDCardBlockDevice.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,21 @@ int SDCardBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t _si
232232
int SDCardBlockDevice::open() {
233233
fsp_err_t rv = FSP_SUCCESS;
234234

235-
IRQManager::getInstance().addPeripheral(IRQ_SDCARD,&cfg);
235+
// This check is necessary when the SDCardBlockDevice object is destroyed and
236+
// created again. With only the FSP_INVALID_VECTOR fix, multiple interrupt
237+
// vector entries will be created in this particular case. Worse, the SDCARD
238+
// interrupts will be reenabled after R_SDHI_Close() but before R_SDHI_Open(),
239+
// which will cause sdhimmc_accs_isr() inside the Renesas FSP to send an invalid
240+
// context pointer to r_sdhi_access_irq_process(), causing a hard fault.
241+
// -->
242+
static bool wasOpenedBefore = false;
243+
if (false == wasOpenedBefore)
244+
{
245+
IRQManager::getInstance().addPeripheral(IRQ_SDCARD,&cfg);
246+
wasOpenedBefore = true;
247+
}
248+
// <--
249+
236250
#ifdef USE_DMAC
237251
IRQManager::getInstance().addDMA(g_transfer0_extend);
238252
#endif

0 commit comments

Comments
 (0)