Skip to content

Commit fdd2f0e

Browse files
committed
Using CMSIS AIRCR defines in swd_host.c if available.
- Wrapped defines in #if so that CMSIS-Core defines are used if they are available, otherwise use the local copy (for CM0/+).
1 parent 5f98ede commit fdd2f0e

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

source/daplink/interface/swd_host.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "DAP_config.h"
2929
#include "DAP.h"
3030
#include "target_family.h"
31+
#include "device.h"
3132

3233
// Default NVIC and Core debug base addresses
3334
// TODO: Read these addresses from ROM.
@@ -45,8 +46,11 @@
4546
#define MAX_SWD_RETRY 100//10
4647
#define MAX_TIMEOUT 1000000 // Timeout for syscalls on target
4748

48-
#define SCB_AIRCR_PRIGROUP_Pos 8 /*!< SCB AIRCR: PRIGROUP Position */
49+
// Use the CMSIS-Core definition if available.
50+
#if !defined(SCB_AIRCR_PRIGROUP_Pos)
51+
#define SCB_AIRCR_PRIGROUP_Pos 8U /*!< SCB AIRCR: PRIGROUP Position */
4952
#define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP Mask */
53+
#endif
5054

5155
typedef struct {
5256
uint32_t select;
@@ -709,7 +713,7 @@ uint8_t swd_flash_syscall_exec(const program_syscall_t *sysCallParam, uint32_t e
709713
if (!swd_read_core_register(0, &state.r[0])) {
710714
return 0;
711715
}
712-
716+
713717
//remove the C_MASKINTS
714718
if (!swd_write_word(DBG_HCSR, DBGKEY | C_DEBUGEN | C_HALT)) {
715719
return 0;
@@ -795,7 +799,7 @@ uint8_t swd_init_debug(void)
795799
// init dap state with fake values
796800
dap_state.select = 0xffffffff;
797801
dap_state.csw = 0xffffffff;
798-
802+
799803
int8_t retries = 4;
800804
int8_t do_abort = 0;
801805
do {
@@ -829,9 +833,9 @@ uint8_t swd_init_debug(void)
829833
if (!swd_write_dp(DP_SELECT, 0)) {
830834
do_abort = 1;
831835
continue;
832-
836+
833837
}
834-
838+
835839
// Power up
836840
if (!swd_write_dp(DP_CTRL_STAT, CSYSPWRUPREQ | CDBGPWRUPREQ)) {
837841
do_abort = 1;
@@ -870,11 +874,11 @@ uint8_t swd_init_debug(void)
870874
do_abort = 1;
871875
continue;
872876
}
873-
877+
874878
return 1;
875-
879+
876880
} while (--retries > 0);
877-
881+
878882
return 0;
879883
}
880884

@@ -904,10 +908,10 @@ uint8_t swd_set_target_state_hw(TARGET_RESET_STATE state)
904908
if (!swd_init_debug()) {
905909
return 0;
906910
}
907-
911+
908912
if (reset_connect == CONNECT_UNDER_RESET) {
909913
// Assert reset
910-
swd_set_target_reset(1);
914+
swd_set_target_reset(1);
911915
osDelay(2);
912916
}
913917

@@ -926,17 +930,17 @@ uint8_t swd_set_target_state_hw(TARGET_RESET_STATE state)
926930
if (!swd_write_word(DBG_EMCR, VC_CORERESET)) {
927931
return 0;
928932
}
929-
933+
930934
if (reset_connect == CONNECT_NORMAL) {
931935
// Assert reset
932-
swd_set_target_reset(1);
936+
swd_set_target_reset(1);
933937
osDelay(2);
934938
}
935-
939+
936940
// Deassert reset
937941
swd_set_target_reset(0);
938942
osDelay(2);
939-
943+
940944
do {
941945
if (!swd_read_word(DBG_HCSR, &val)) {
942946
return 0;

0 commit comments

Comments
 (0)