Skip to content
Closed
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
327 changes: 173 additions & 154 deletions source/daplink/interface/swd_host.c

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions source/daplink/interface/swd_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,29 @@ extern "C" {
uint8_t swd_init(void);
uint8_t swd_off(void);
uint8_t swd_init_debug(void);
uint8_t swd_debug_deinit(void);
uint8_t swd_read_dp(uint8_t adr, uint32_t *val);
uint8_t swd_write_dp(uint8_t adr, uint32_t val);
uint8_t swd_read_ap(uint32_t adr, uint32_t *val);
uint8_t swd_write_ap(uint32_t adr, uint32_t val);
uint8_t swd_read_memory(uint32_t address, uint8_t *data, uint32_t size);
uint8_t swd_write_memory(uint32_t address, uint8_t *data, uint32_t size);
uint8_t swd_flash_syscall_exec(const program_syscall_t *sysCallParam, uint32_t entry, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4);
void swd_set_target_reset(uint8_t asserted);
uint8_t swd_set_target_state_hw(TARGET_RESET_STATE state);
uint8_t swd_set_target_state_sw(TARGET_RESET_STATE state);
uint8_t swd_set_target_reset(uint8_t asserted);

static uint8_t target_debug_enable(void);
static uint8_t target_debug_halt(void);
static uint8_t target_debug_halt_on_reset_enable(void);
static uint8_t target_debug_halt_on_reset_disable(void);
static uint8_t target_debug_halt_check(void);
static uint8_t target_reset_sw(void);
static uint8_t target_reset_hw(void);
static uint8_t target_reset_hw_assert(uint8_t asserted);

uint8_t target_quirk_reset_pre_program(void *param);
uint8_t target_quirk_reset_post_program(void *param);
uint8_t target_quirk_reset_pre_run(void *param);
uint8_t target_quirk_reset_post_run(void *param);

#ifdef __cplusplus
}
Expand Down
19 changes: 17 additions & 2 deletions source/daplink/interface/swd_host_ca.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @brief Implementation of swd_host.h
*
* DAPLink Interface Firmware
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
* Copyright (c) 2009-2018, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand Down Expand Up @@ -777,9 +777,10 @@ uint8_t swd_uninit_debug(void)
return 1;
}

__attribute__((weak)) void swd_set_target_reset(uint8_t asserted)
__attribute__((weak)) uint8_t swd_set_target_reset(uint8_t asserted)
{
(asserted) ? PIN_nRESET_OUT(0) : PIN_nRESET_OUT(1);
return 1;
}

uint8_t swd_set_target_state_hw(TARGET_RESET_STATE state)
Expand Down Expand Up @@ -865,6 +866,7 @@ uint8_t swd_set_target_state_hw(TARGET_RESET_STATE state)
return 1;
}

// NOTE: This function does not work on Reneas R7S Cortex-A Target.
uint8_t swd_set_target_state_sw(TARGET_RESET_STATE state)
{
uint32_t val;
Expand Down Expand Up @@ -951,4 +953,17 @@ uint8_t swd_set_target_state_sw(TARGET_RESET_STATE state)
return 1;
}

// TODO: Align this code with Cortex-M when deidcated Target code is ready.
uint8_t target_set_state(TARGET_RESET_STATE state)
{
uint8_t res;
// This kind of fallback causes UMS flashing to fail on GR-PEACH!
// Reset works with HW/SW but RESET_HALT works only for HW.
//res = swd_set_target_state_sw(state);
//if (!res) {
res = swd_set_target_state_hw(state);
//}
return res;
}

#endif
9 changes: 9 additions & 0 deletions source/hic_hal/target_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ extern "C" {
// This can vary from target to target and should be in the structure or flash blob
#define TARGET_AUTO_INCREMENT_PAGE_SIZE (1024)

/* TARGET RESET RELATED DEFINES */
#define TARGET_DELAY_RESET 1 // How long do we wait after reset.
#define TARGET_DELAY_RETRY 100 // How long do we wait with retries.
enum TARGET_RESET_TYPES { // Enumerate available reset types.
TARGET_RESET_NONE=0, // No reset is also an option.
TARGET_RESET_HARDWARE=1, // Hardware reset using GPIO.
TARGET_RESET_SOFTWARE=2 // Software reset using AIRCR.
};

/**
@struct target_cfg_t
@brief The firmware configuration struct has unique about the chip its running on.
Expand Down
4 changes: 2 additions & 2 deletions source/hic_hal/target_reset.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ extern "C" {
#endif

typedef enum {
RESET_HOLD, // Hold target in reset
RESET_HOLD, // Hold target under reset asserted. TODO: Reset-Halt?
RESET_PROGRAM, // Reset target and setup for flash programming.
RESET_RUN, // Reset target and run normally
NO_DEBUG, // Disable debug on running target
DEBUG // Enable debug on running target
DEBUG, // Enable debug on running target
} TARGET_RESET_STATE;

void target_before_init_debug(void);
Expand Down
13 changes: 7 additions & 6 deletions source/target/freescale/target_reset_Kseries.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @brief Target reset for the Kinetis K series
*
* DAPLink Interface Firmware
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
* Copyright (c) 2009-2017, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand All @@ -30,7 +30,6 @@

void target_before_init_debug(void)
{
swd_set_target_reset(1);
}

void prerun_target_config(void)
Expand All @@ -55,6 +54,12 @@ void board_init(void)
{
}

/**
* Unlock Sequence clears out the Security Bits and Flash Memory.
* NOTE: This leaves Hardware Reset line asserted on exit until halt!
* NOTE: During the unlock sequence the hardware reset must be asserted to
* ensure device code cannot execute / interfere with the unlocking procedure.
*/
uint8_t target_unlock_sequence(void)
{
uint32_t val;
Expand Down Expand Up @@ -150,7 +155,3 @@ uint8_t security_bits_set(uint32_t addr, uint8_t *data, uint32_t size)
return 0;
}

uint8_t target_set_state(TARGET_RESET_STATE state)
{
return swd_set_target_state_hw(state);
}
6 changes: 1 addition & 5 deletions source/target/freescale/target_reset_Lseries.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @brief Target reset for the Kinetis L series
*
* DAPLink Interface Firmware
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
* Copyright (c) 2009-2017, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand Down Expand Up @@ -136,7 +136,3 @@ uint8_t security_bits_set(uint32_t addr, uint8_t *data, uint32_t size)
return 0;
}

uint8_t target_set_state(TARGET_RESET_STATE state)
{
return swd_set_target_state_hw(state);
}
10 changes: 3 additions & 7 deletions source/target/nordic/target_reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @brief Target reset for the nrf51
*
* DAPLink Interface Firmware
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
* Copyright (c) 2009-2017, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand Down Expand Up @@ -38,12 +38,8 @@ uint8_t security_bits_set(uint32_t addr, uint8_t *data, uint32_t size)
return 0;
}

uint8_t target_set_state(TARGET_RESET_STATE state)
{
return swd_set_target_state_sw(state);
}

void swd_set_target_reset(uint8_t asserted)
// TODO: REMOVE THAT FUNCTION AFTER GLOBAL WAS INTRODUCED UNWEAK, VERIFY!
void nrf_swd_set_target_reset(uint8_t asserted)
{
if (asserted) {
swd_init_debug();
Expand Down
11 changes: 5 additions & 6 deletions source/target/nordic/target_reset_nrf5x_sam3u2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,26 @@
#include "DAP_config.h"
#include "info.h"

// For nRF chips CxxxPWRUPREQ is required, which is part of swd_init_debug().
void target_before_init_debug(void)
{
return;
}

// TODO: Memory unlock routines can be added here for locked chips.
uint8_t target_unlock_sequence(void)
{
return 1;
}

// TODO: Memory lock routines can be added here to lock the chip.
uint8_t security_bits_set(uint32_t addr, uint8_t *data, uint32_t size)
{
return 0;
}

uint8_t target_set_state(TARGET_RESET_STATE state)
{
return swd_set_target_state_sw(state);
}

void swd_set_target_reset(uint8_t asserted)
// TODO: Take the debug disable quirk from here..
void nrf_swd_set_target_reset(uint8_t asserted)
{
const char *board_id;
board_id = info_get_board_id();
Expand Down
32 changes: 16 additions & 16 deletions source/target/nxp/lpc4088/target_reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @brief Target reset for the lpc4088
*
* DAPLink Interface Firmware
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
* Copyright (c) 2009-2017, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand Down Expand Up @@ -59,22 +59,22 @@ uint8_t target_unlock_sequence(void)
return 1;
}

uint8_t target_set_state(TARGET_RESET_STATE state)
uint8_t target_quirk_reset_pre_program(void *param)
{
//return swd_set_target_state_hw(state);
uint8_t res;
if (state == RESET_PROGRAM)
{
gpio_set_isp_pin(0);
res = swd_set_target_state_hw(state);
gpio_set_isp_pin(1);
}
else
{
gpio_set_isp_pin(1);
res = swd_set_target_state_hw(state);
}
return res;
gpio_set_isp_pin(0);
return 1;
}

uint8_t target_quirk_reset_post_program(void *param)
{
gpio_set_isp_pin(1);
return 1;
}

uint8_t target_quirk_reset_pre_run(void *param)
{
gpio_set_isp_pin(1);
return 1;
}

uint8_t security_bits_set(uint32_t addr, uint8_t *data, uint32_t size)
Expand Down
7 changes: 1 addition & 6 deletions source/target/nxp/target_reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @brief Target reset for the lpc812
*
* DAPLink Interface Firmware
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
* Copyright (c) 2009-2017, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand Down Expand Up @@ -32,11 +32,6 @@ uint8_t target_unlock_sequence(void)
return 1;
}

uint8_t target_set_state(TARGET_RESET_STATE state)
{
return swd_set_target_state_hw(state);
}

uint8_t security_bits_set(uint32_t addr, uint8_t *data, uint32_t size)
{
return 0;
Expand Down
7 changes: 1 addition & 6 deletions source/target/onsemi/ncs36510/target_reset.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* CMSIS-DAP Interface Firmware
* Copyright (c) 2009-2013 ARM Limited
* Copyright (c) 2009-2017 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,11 +27,6 @@ uint8_t target_unlock_sequence(void) {
return 1;
}

uint8_t target_set_state(TARGET_RESET_STATE state) {
/* sw reset preferred because hardware (pin) reset also resets debug logic */
return swd_set_target_state_sw(state);
}

uint8_t security_bits_set(uint32_t addr, uint8_t *data, uint32_t size) {
return 0;
}
7 changes: 1 addition & 6 deletions source/target/renesas/target_reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @brief Target reset for the rza1h
*
* DAPLink Interface Firmware
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
* Copyright (c) 2009-2017, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand Down Expand Up @@ -32,11 +32,6 @@ uint8_t target_unlock_sequence(void)
return 1;
}

uint8_t target_set_state(TARGET_RESET_STATE state)
{
return swd_set_target_state_hw(state);
}

uint8_t security_bits_set(uint32_t addr, uint8_t *data, uint32_t size)
{
return 0;
Expand Down
7 changes: 1 addition & 6 deletions source/target/siliconlabs/target_reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @brief Target reset for the efm32gg
*
* DAPLink Interface Firmware
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
* Copyright (c) 2009-2017, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand Down Expand Up @@ -32,11 +32,6 @@ uint8_t target_unlock_sequence(void)
return 1;
}

uint8_t target_set_state(TARGET_RESET_STATE state)
{
return swd_set_target_state_sw(state);
}

uint8_t security_bits_set(uint32_t addr, uint8_t *data, uint32_t size)
{
return 0;
Expand Down
5 changes: 0 additions & 5 deletions source/target/st/nz32_sc151/target_reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ uint8_t target_unlock_sequence(void)
return 1;
}

uint8_t target_set_state(TARGET_RESET_STATE state)
{
return swd_set_target_state_hw(state);
}

uint8_t security_bits_set(uint32_t addr, uint8_t *data, uint32_t size)
{
return 0;
Expand Down
6 changes: 1 addition & 5 deletions source/target/st/target_reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @brief Target reset for the stm32f407
*
* DAPLink Interface Firmware
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
* Copyright (c) 2009-2017, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand Down Expand Up @@ -37,7 +37,3 @@ uint8_t security_bits_set(uint32_t addr, uint8_t *data, uint32_t size)
return 0;
}

uint8_t target_set_state(TARGET_RESET_STATE state)
{
return swd_set_target_state_hw(state);
}
Loading