Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix software reset by writing in SYSRESETQ register when a reset is requested #73

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading