It turns out that the pyocd.core.exceptions.TransferFaultError: SWD/JTAG Transfer Fault
issue was not caused by Mbed Studio 1.3.1, but by the choice of the program to debug, namely the regular Blinky Mbed OS example, unmodified, using the Debug
build profile. More specifically, it was the use of ThisThread::sleep_for()
that was breaking everything.
Adding the following lines at the beginning of main()
fixed the issue:
#ifdef MBED_DEBUG
HAL_DBGMCU_EnableDBGSleepMode();
#endif
This function sets a bit required on this target to make the debug mode work properly with the WFI
instruction:
/**
* @brief Enable the Debug Module during SLEEP mode.
* @retval None
*/
void HAL_DBGMCU_EnableDBGSleepMode(void)
{
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
}
The fact that this change is required in Mbed Studio does not seem normal to me, for two reasons:
- One would expect to be able to run or debug this example on all Mbed-OS-supported platforms without having to modify it. It would be more natural if this bit were set by Mbed Studio (using Mbed OS or pyOCD) either if the
Debug
build profile is selected or when the debugger is started. - According to this page of the Mbed documentation, the sleep mode is supposed to be disabled for the
Debug
build profile, but this is actually not the case: thembed-os-example-blinky\BUILD\NUCLEO_L476RG\ARMC6\.profile*
files setDEVICE_SLEEP=1
for this build profile.
This hardware requirement applies to many other Cortex-M targets supported by Mbed OS. I don’t know how Mbed Studio handles it for these other targets.
I will edit the title of this topic to reflect my latest findings.