| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- // SPDX-License-Identifier: BSD-3-Clause
- // Copyright (c) 2022, Alex Taradov <alex@taradov.com>. All rights reserved.
- #ifndef _DAP_CONFIG_H_
- #define _DAP_CONFIG_H_
- /*- Includes ----------------------------------------------------------------*/
- #include "rp2040.h"
- #include "hal_config.h"
- /*- Definitions -------------------------------------------------------------*/
- #define DAP_CONFIG_ENABLE_JTAG
- #define DAP_CONFIG_DEFAULT_PORT DAP_PORT_SWD
- #define DAP_CONFIG_DEFAULT_CLOCK 1000000 // Hz
- #define DAP_CONFIG_PACKET_SIZE 64
- #define DAP_CONFIG_PACKET_COUNT 1
- #define DAP_CONFIG_JTAG_DEV_COUNT 8
- // DAP_CONFIG_PRODUCT_STR must contain "CMSIS-DAP" to be compatible with the standard
- #define DAP_CONFIG_VENDOR_STR "Alex Taradov"
- #define DAP_CONFIG_PRODUCT_STR "Generic CMSIS-DAP Adapter"
- #define DAP_CONFIG_SER_NUM_STR usb_serial_number
- #define DAP_CONFIG_CMSIS_DAP_VER_STR "2.0.0"
- //#define DAP_CONFIG_RESET_TARGET_FN target_specific_reset_function
- //#define DAP_CONFIG_VENDOR_FN vendor_command_handler_function
- // Attribute to use for performance-critical functions
- #define DAP_CONFIG_PERFORMANCE_ATTR
- // A value at which dap_clock_test() produces 1 kHz output on the SWCLK pin
- #define DAP_CONFIG_DELAY_CONSTANT 20000
- // A threshold for switching to fast clock (no added delays)
- // This is the frequency produced by dap_clock_test(1) on the SWCLK pin
- #define DAP_CONFIG_FAST_CLOCK 8550000 // Hz
- /*- Prototypes --------------------------------------------------------------*/
- extern char usb_serial_number[16];
- /*- Implementations ---------------------------------------------------------*/
- //-----------------------------------------------------------------------------
- static inline void DAP_CONFIG_SWCLK_TCK_write(int value)
- {
- HAL_GPIO_SWCLK_TCK_write(value);
- }
- //-----------------------------------------------------------------------------
- static inline void DAP_CONFIG_SWDIO_TMS_write(int value)
- {
- HAL_GPIO_SWDIO_TMS_write(value);
- }
- //-----------------------------------------------------------------------------
- static inline void DAP_CONFIG_TDI_write(int value)
- {
- #ifdef DAP_CONFIG_ENABLE_JTAG
- HAL_GPIO_TDI_write(value);
- #else
- (void)value;
- #endif
- }
- //-----------------------------------------------------------------------------
- static inline void DAP_CONFIG_TDO_write(int value)
- {
- #ifdef DAP_CONFIG_ENABLE_JTAG
- HAL_GPIO_TDO_write(value);
- #else
- (void)value;
- #endif
- }
- //-----------------------------------------------------------------------------
- static inline void DAP_CONFIG_nTRST_write(int value)
- {
- (void)value;
- }
- //-----------------------------------------------------------------------------
- static inline void DAP_CONFIG_nRESET_write(int value)
- {
- HAL_GPIO_nRESET_write(value);
- }
- //-----------------------------------------------------------------------------
- static inline int DAP_CONFIG_SWCLK_TCK_read(void)
- {
- return HAL_GPIO_SWCLK_TCK_read();
- }
- //-----------------------------------------------------------------------------
- static inline int DAP_CONFIG_SWDIO_TMS_read(void)
- {
- return HAL_GPIO_SWDIO_TMS_read();
- }
- //-----------------------------------------------------------------------------
- static inline int DAP_CONFIG_TDO_read(void)
- {
- #ifdef DAP_CONFIG_ENABLE_JTAG
- return HAL_GPIO_TDO_read();
- #else
- return 0;
- #endif
- }
- //-----------------------------------------------------------------------------
- static inline int DAP_CONFIG_TDI_read(void)
- {
- #ifdef DAP_CONFIG_ENABLE_JTAG
- return HAL_GPIO_TDI_read();
- #else
- return 0;
- #endif
- }
- //-----------------------------------------------------------------------------
- static inline int DAP_CONFIG_nTRST_read(void)
- {
- return 0;
- }
- //-----------------------------------------------------------------------------
- static inline int DAP_CONFIG_nRESET_read(void)
- {
- return HAL_GPIO_nRESET_read();
- }
- //-----------------------------------------------------------------------------
- static inline void DAP_CONFIG_SWCLK_TCK_set(void)
- {
- HAL_GPIO_SWCLK_TCK_set();
- }
- //-----------------------------------------------------------------------------
- static inline void DAP_CONFIG_SWCLK_TCK_clr(void)
- {
- HAL_GPIO_SWCLK_TCK_clr();
- }
- //-----------------------------------------------------------------------------
- static inline void DAP_CONFIG_SWDIO_TMS_in(void)
- {
- HAL_GPIO_SWDIO_TMS_in();
- }
- //-----------------------------------------------------------------------------
- static inline void DAP_CONFIG_SWDIO_TMS_out(void)
- {
- HAL_GPIO_SWDIO_TMS_out();
- }
- //-----------------------------------------------------------------------------
- static inline void DAP_CONFIG_SETUP(void)
- {
- HAL_GPIO_SWCLK_TCK_in();
- HAL_GPIO_SWDIO_TMS_in();
- HAL_GPIO_nRESET_in();
- #ifdef DAP_CONFIG_ENABLE_JTAG
- HAL_GPIO_TDO_in();
- HAL_GPIO_TDI_in();
- #endif
- }
- //-----------------------------------------------------------------------------
- static inline void DAP_CONFIG_DISCONNECT(void)
- {
- HAL_GPIO_SWCLK_TCK_in();
- HAL_GPIO_SWDIO_TMS_in();
- HAL_GPIO_nRESET_in();
- #ifdef DAP_CONFIG_ENABLE_JTAG
- HAL_GPIO_TDO_in();
- HAL_GPIO_TDI_in();
- #endif
- }
- //-----------------------------------------------------------------------------
- static inline void DAP_CONFIG_CONNECT_SWD(void)
- {
- HAL_GPIO_SWDIO_TMS_out();
- HAL_GPIO_SWDIO_TMS_set();
- HAL_GPIO_SWCLK_TCK_out();
- HAL_GPIO_SWCLK_TCK_set();
- HAL_GPIO_nRESET_out();
- HAL_GPIO_nRESET_set();
- #ifdef DAP_CONFIG_ENABLE_JTAG
- HAL_GPIO_TDO_in();
- HAL_GPIO_TDI_in();
- #endif
- }
- //-----------------------------------------------------------------------------
- static inline void DAP_CONFIG_CONNECT_JTAG(void)
- {
- HAL_GPIO_SWDIO_TMS_out();
- HAL_GPIO_SWDIO_TMS_set();
- HAL_GPIO_SWCLK_TCK_out();
- HAL_GPIO_SWCLK_TCK_set();
- HAL_GPIO_nRESET_out();
- HAL_GPIO_nRESET_set();
- #ifdef DAP_CONFIG_ENABLE_JTAG
- HAL_GPIO_TDO_in();
- HAL_GPIO_TDI_out();
- HAL_GPIO_TDI_set();
- #endif
- }
- //-----------------------------------------------------------------------------
- static inline void DAP_CONFIG_LED(int index, int state)
- {
- (void)index;
- (void)state;
- }
- //-----------------------------------------------------------------------------
- __attribute__((always_inline))
- static inline void DAP_CONFIG_DELAY(uint32_t cycles)
- {
- asm volatile (
- "1: sub %[cycles], %[cycles], #1 \n"
- " bne 1b \n"
- : [cycles] "+l"(cycles)
- );
- }
- #endif // _DAP_CONFIG_H_
|