Skip to content

Commit

Permalink
fix software reset by writing in SYSRESETQ register when a reset is r…
Browse files Browse the repository at this point in the history
…equested (#73)

Some debugger software (e.g. Keil) does not perform a software reset when
resetting the target. When this option enabled, a soft reset is attempted
when DAP_ResetTarget() is performed. This is done by writing to the
SYSRESETREQ field of the AIRCR register in the Cortex-M architecture.

This should work for ARMv6-m, ARMv7-m and ARMv8-m architecture. However,
there is no guarantee that the reset operation will be executed correctly.

Only available for SWD.

Links: #73
---------

Co-authored-by: windowsair <[email protected]>
  • Loading branch information
kerms and windowsair authored May 7, 2024
1 parent adfecf1 commit 2dc7bd6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
18 changes: 17 additions & 1 deletion components/DAP/source/DAP.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,22 @@ static uint32_t DAP_Disconnect(uint8_t *response) {
// return: number of bytes in response
static uint32_t DAP_ResetTarget(uint8_t *response) {

#if (USE_FORCE_SYSRESETREQ_AFTER_FLASH)
if (DAP_Data.debug_port == DAP_PORT_SWD) {
/* Workaround for software reset when nRESET is not connected */
uint8_t ack;
uint32_t AIRCR_REG_ADDR = 0xE000ED0C;
uint32_t AIRCR_RESET_VAL = 0x05FA << 16 | 1 << 2; /* Vector key | SYSRESETREQ bit */
uint8_t req = DAP_TRANSFER_APnDP | 0 | DAP_TRANSFER_A2 | 0;
ack = SWD_Transfer(req,&AIRCR_REG_ADDR);
if (ack == DAP_TRANSFER_OK) {
dap_os_delay(2);
req = DAP_TRANSFER_APnDP | 0 | DAP_TRANSFER_A2 | DAP_TRANSFER_A3;
SWD_Transfer(req,&AIRCR_RESET_VAL);
}
}
#endif

*(response+1) = RESET_TARGET();
*(response+0) = DAP_OK;
return (2U);
Expand Down Expand Up @@ -1850,4 +1866,4 @@ void DAP_Setup(void) {
void dap_os_delay(int ms)
{
vTaskDelay(pdMS_TO_TICKS(ms));
}
}
15 changes: 15 additions & 0 deletions main/dap_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,20 @@
#define DAP_PACKET_SIZE 255U // 255 for USB HID
#endif

/**
* @brief Enable this option to force a software reset when resetting the device
*
* Some debugger software (e.g. Keil) does not perform a software reset when
* resetting the target. When this option enabled, a soft reset is attempted
* when DAP_ResetTarget() is performed. This is done by writing to the
* SYSRESETREQ field of the AIRCR register in the Cortex-M architecture.
*
* This should work for ARMv6-m, ARMv7-m and ARMv8-m architecture. However,
* there is no guarantee that the reset operation will be executed correctly.
*
* Only available for SWD.
*
*/
#define USE_FORCE_SYSRESETREQ_AFTER_FLASH 0

#endif

0 comments on commit 2dc7bd6

Please sign in to comment.