Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
target_reset.c
00001 /** 00002 * @file target_reset.c 00003 * @brief Target reset for the lpc812 00004 * 00005 * DAPLink Interface Firmware 00006 * Copyright (c) 2009-2019, ARM Limited, All Rights Reserved 00007 * SPDX-License-Identifier: Apache-2.0 00008 * 00009 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00010 * not use this file except in compliance with the License. 00011 * You may obtain a copy of the License at 00012 * 00013 * http://www.apache.org/licenses/LICENSE-2.0 00014 * 00015 * Unless required by applicable law or agreed to in writing, software 00016 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00017 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00018 * See the License for the specific language governing permissions and 00019 * limitations under the License. 00020 */ 00021 #include "target_family.h" 00022 #include "swd_host.h" 00023 #include "cmsis_os2.h" 00024 00025 #define DBG_Addr (0xE000EDF0) 00026 #define DWT_COMP0 (0xE0001020) 00027 #define DWT_FUNCTION0 (0xE0001028) 00028 #define DWT_FUNCTION_MATCH (0x4 << 0) 00029 #define DWT_FUNCTION_ACTION (0x1 << 4) 00030 #define DWT_FUNCTION_DATAVSIZE (0x2 << 10) 00031 00032 /* Debug mailbox AP registers */ 00033 #define DEBUGMB_CSW 0x02000000 00034 #define DEBUGMB_REQ 0x02000004 00035 #define DEBUGMB_RET 0x02000008 00036 #define DEBUGMB_ID 0x020000FC 00037 00038 static uint8_t lpc55s6x_target_set_state(target_state_t state) 00039 { 00040 uint32_t val; 00041 int8_t ap_retries = 2; 00042 00043 if (state == RESET_PROGRAM) { 00044 if (!swd_init_debug()) { 00045 return 0; 00046 } 00047 00048 // Enable debug 00049 while(swd_write_word(DBG_HCSR, DBGKEY | C_DEBUGEN) == 0) { 00050 if( --ap_retries <=0 ) 00051 return 0; 00052 // Target is in invalid state? 00053 swd_set_target_reset(1); 00054 osDelay(2); 00055 swd_set_target_reset(0); 00056 osDelay(2); 00057 } 00058 00059 // Set Trace Enable bit 00060 if (!swd_read_word(DBG_EMCR, &val)) { 00061 return 0; 00062 } 00063 00064 if (!swd_write_word(DBG_EMCR, val | TRCENA)) { 00065 return 0; 00066 } 00067 00068 // Clear the comparator function register 00069 if (!swd_write_word(DWT_FUNCTION0, 0x0)) { 00070 return 0; 00071 } 00072 00073 // Set the address 00074 if (!swd_write_word(DWT_COMP0, 0x50000040)) { 00075 return 0; 00076 } 00077 00078 // Update the comparator function register 00079 if (!swd_write_word(DWT_FUNCTION0, (DWT_FUNCTION_MATCH | DWT_FUNCTION_ACTION | DWT_FUNCTION_DATAVSIZE))) { 00080 return 0; 00081 } 00082 00083 // Reset using the debug mailbox 00084 if (!swd_write_ap(DEBUGMB_CSW, 0x20)) { 00085 return 0; 00086 } 00087 00088 osDelay(5); 00089 00090 do { 00091 if (!swd_read_word(DBG_HCSR, &val)) { 00092 return 0; 00093 } 00094 } while ((val & S_HALT) == 0); 00095 00096 // Disable halt on reset 00097 if (!swd_write_word(DBG_EMCR, 0)) { 00098 return 0; 00099 } 00100 00101 return 1; 00102 00103 } else { 00104 return swd_set_target_state_sw(state); 00105 } 00106 } 00107 00108 const target_family_descriptor_t g_target_family_lpc55S6X = { 00109 .family_id = VENDOR_TO_FAMILY(kNXP_VendorID, 0), //ID not maching the predefined family ids 00110 .target_set_state = lpc55s6x_target_set_state, 00111 }; 00112 00113 const target_family_descriptor_t *g_target_family = &g_target_family_lpc55S6X;
Generated on Tue Jul 12 2022 15:37:25 by
