├── .gitignore ├── doc ├── benchmarks.ods ├── board_schematic.fzz ├── png │ ├── board_schematic_bb.png │ ├── Screenshot_20230103_074404.png │ ├── Screenshot_20230106_153629.png │ └── Screenshot_20230124_140906.png ├── optimizations.adoc ├── TODO.adoc ├── hardware.adoc └── benchmarks.adoc ├── assets ├── wiring-rp-pico.png └── wiring-seeed-xiao.png ├── .gitmodules ├── src ├── daplink-pico │ ├── hic_hal │ │ └── raspberry │ │ │ └── rp2040 │ │ │ ├── cmsis_os2.h │ │ │ └── daplink_addr.h │ ├── board │ │ └── rp2040 │ │ │ ├── program_flash_generic.h │ │ │ ├── pico_target_utils.h │ │ │ └── pico_target_utils.c │ └── family │ │ └── raspberry │ │ └── target_rp2040.h ├── daplink │ ├── README.adoc │ ├── daplink │ │ ├── drag-n-drop │ │ │ ├── flash_manager.h │ │ │ ├── flash_intf.h │ │ │ └── virtual_fs.h │ │ ├── cortex_m.h │ │ ├── settings │ │ │ ├── settings_rom_stub.c │ │ │ └── settings.h │ │ ├── compiler.h │ │ ├── interface │ │ │ └── swd_host.h │ │ ├── error.h │ │ ├── daplink.h │ │ ├── util.h │ │ ├── util.c │ │ └── cmsis-dap │ │ │ └── debug_cm.h │ ├── hic_hal │ │ ├── device.h │ │ └── flash_blob.h │ ├── family │ │ └── renesas │ │ │ ├── rza1lu │ │ │ ├── target.c │ │ │ └── flash_blob.c │ │ │ └── target_reset_rza1lu.c │ └── target │ │ ├── target_board.c │ │ ├── target_config.h │ │ ├── target_board.h │ │ ├── target_family.c │ │ └── target_family.h ├── cdc_debug.h ├── get_serial.h ├── pico-sigrok │ ├── sigrok.h │ ├── cdc_sigrok.h │ ├── sigrok_int.c │ ├── sigrok.pio │ └── sigrok_int.h ├── probe.h ├── rtt_console.h ├── sw_lock.h ├── cdc_uart.h ├── dap_util.h ├── msc │ └── msc_utils.h ├── get_serial.c ├── led.h ├── probe.pio ├── sw_lock.c └── misc_utils.c ├── README.md ├── include ├── picoprobe_config.h ├── boards │ ├── pico_debug_probe.h │ ├── pico.h │ ├── qt_py_rp2040.h │ ├── seeed_rp2040.h │ └── pico_w.h ├── lwipopts.h ├── tusb_config.h └── FreeRTOSConfig.h ├── pico_sdk_import.cmake ├── FreeRTOS_Kernel_import.cmake ├── Makefile └── CMakeLists.txt /.gitignore: -------------------------------------------------------------------------------- 1 | build/** 2 | generated/** 3 | .vscode/** 4 | pico-sdk/** 5 | images/** 6 | -------------------------------------------------------------------------------- /doc/benchmarks.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/litui/delugeprobe/HEAD/doc/benchmarks.ods -------------------------------------------------------------------------------- /assets/wiring-rp-pico.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/litui/delugeprobe/HEAD/assets/wiring-rp-pico.png -------------------------------------------------------------------------------- /doc/board_schematic.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/litui/delugeprobe/HEAD/doc/board_schematic.fzz -------------------------------------------------------------------------------- /assets/wiring-seeed-xiao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/litui/delugeprobe/HEAD/assets/wiring-seeed-xiao.png -------------------------------------------------------------------------------- /doc/png/board_schematic_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/litui/delugeprobe/HEAD/doc/png/board_schematic_bb.png -------------------------------------------------------------------------------- /doc/png/Screenshot_20230103_074404.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/litui/delugeprobe/HEAD/doc/png/Screenshot_20230103_074404.png -------------------------------------------------------------------------------- /doc/png/Screenshot_20230106_153629.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/litui/delugeprobe/HEAD/doc/png/Screenshot_20230106_153629.png -------------------------------------------------------------------------------- /doc/png/Screenshot_20230124_140906.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/litui/delugeprobe/HEAD/doc/png/Screenshot_20230124_140906.png -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "CMSIS_5"] 2 | path = CMSIS_5 3 | url = https://github.com/ARM-software/CMSIS_5 4 | [submodule "freertos"] 5 | path = freertos 6 | url = https://github.com/FreeRTOS/FreeRTOS-Kernel 7 | -------------------------------------------------------------------------------- /src/daplink-pico/hic_hal/raspberry/rp2040/cmsis_os2.h: -------------------------------------------------------------------------------- 1 | #ifndef _CMSIS_OS2_H 2 | #define _CMSIS_OS2_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | 11 | void osDelay(uint32_t ticks); 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/daplink-pico/board/rp2040/program_flash_generic.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #ifndef _PROGRAM_FLASH_GENERIC_H 8 | #define _PROGRAM_FLASH_GENERIC_H 9 | 10 | #include 11 | #include 12 | 13 | uint32_t target_rp2040_get_external_flash_size(void); 14 | 15 | #endif // _PROGRAM_FLASH_GENERIC_H_ 16 | -------------------------------------------------------------------------------- /src/daplink/README.adoc: -------------------------------------------------------------------------------- 1 | [NOTE] 2 | ==== 3 | These are more or less unmodified (but selected) files from 4 | https://github.com/ARMmbed/DAPLink[DAPLink]. 5 | 6 | If the files should be refreshed due to changes in DAPLink, some care has to be taken 7 | not to revert those changes unintentionally. 8 | 9 | Extendening YAPicoprobes capabilites with new targets (aka DAPLink files) should be 10 | straight forward. Check the nRF52 files in the DAPLink source tree. + 11 | Additionally auto-detect code in pico_prerun_board_config() has to be adopted 12 | accordingly. 13 | ==== 14 | -------------------------------------------------------------------------------- /doc/optimizations.adoc: -------------------------------------------------------------------------------- 1 | :imagesdir: png 2 | :source-highlighter: rouge 3 | :toc: 4 | :toclevels: 5 5 | 6 | 7 | 8 | 9 | ## Optimizations 10 | 11 | ### SWD / PIO 12 | Several PIO optimizations has been implemented. Main idea of PIO control has 13 | been taken from https://github.com/essele/pico_debug/blob/main/swd.pio[pico_debug]. 14 | 15 | To monitor the progress between the several versions, 16 | https://sigrok.org/wiki/PulseView[PulseView] has been used. LA probe was 17 | https://github.com/pico-coder/sigrok-pico[sigrok-pico]. 18 | 19 | #### First Version (03.01.2023 - e2b4a67) 20 | image::Screenshot_20230103_074404.png[First Version] 21 | 22 | #### (Currently) Final Version (06.01.2023 - 28fd8db) 23 | image::Screenshot_20230106_153629.png[06.01.2023] 24 | 25 | #### Explanation / Conclusion 26 | The plots above were taken at SWCLK=15MHz. Absolute time of the four command sequences 27 | shrunk from ~25us to 18us. Not bad. 28 | 29 | Nevertheless there are still gaps which may give more optimization opportunities. 30 | Switching times between read / write and the gap between two commands are 31 | candidates. Note that moving code into RAM did not really help (and 32 | optimization is still a non/slow-working mystery). 33 | 34 | -------------------------------------------------------------------------------- /doc/TODO.adoc: -------------------------------------------------------------------------------- 1 | :imagesdir: doc/png 2 | :source-highlighter: rouge 3 | :toc: 4 | :toclevels: 5 5 | 6 | 7 | 8 | 9 | ## TODOs 10 | 11 | ### Features 12 | * Wireless with PicoW 13 | ** USBIP 14 | *** https://usbip.sourceforge.net/ 15 | *** https://github.com/thevoidnn/esp8266-wifi-cmsis-dap 16 | *** https://github.com/windowsair/wireless-esp8266-dap 17 | ** https://arm-software.github.io/CMSIS_5/Driver/html/group__wifi__interface__gr.html[CMSIS WiFi interface] 18 | * semihosting? But actually what can the probe do in this case? 19 | 20 | 21 | ### Bugs 22 | ** check the benchmark "miracle" with the NDEBUG version 23 | ** if `configTICK_RATE_HZ` is around 100, SWD IF no longer works 24 | * TODO 25 | ** voltage of SWD IF is VDD 26 | ** DAP_PACKET_SIZE: how to increase? 27 | ** description of the several COM ports 28 | ** MSD/MSC commands just like in DAPLink 29 | * tests 30 | ** Reset line between probe and target have to be reviewed 31 | ** Win10 (tools) compatibility 32 | 33 | ### Internals 34 | 35 | * parts of the code (at the moment just few) are in a somewhat transition to WiFi. 36 | These parts are surrounded often by `TARGET_BOARD_PICO_W`, so easy identifiable. 37 | Image for PicoW can be build by setting the board in CMakeLists.txt 38 | -------------------------------------------------------------------------------- /src/daplink/daplink/drag-n-drop/flash_manager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file flash_manager.h 3 | * @brief Handling of file steam decode and prep for writing 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2019, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef FLASH_MANAGER_H 23 | #define FLASH_MANAGER_H 24 | 25 | #include 26 | #include 27 | #include "flash_intf.h" 28 | #include "error.h" 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | error_t flash_manager_init(const flash_intf_t *flash_intf); 35 | error_t flash_manager_data(uint32_t addr, const uint8_t *data, uint32_t size); 36 | error_t flash_manager_uninit(void); 37 | void flash_manager_set_page_erase(bool enabled); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/cdc_debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #ifndef CDC_DEBUG_H 27 | #define CDC_DEBUG_H 28 | 29 | #include 30 | #include 31 | 32 | void cdc_debug_init(uint32_t task_prio); 33 | void cdc_debug_line_state_cb(bool dtr, bool rts); 34 | void cdc_debug_tx_complete_cb(void); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/get_serial.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Federico Zuccardi Merli 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #ifndef GET_SERIAL_H_ 27 | #define GET_SERIAL_H_ 28 | 29 | /* Contains unique serial number string (NUL terminated) after call to init_usb_serial */ 30 | extern char usb_serial[]; 31 | 32 | /* Fills unique_serial with the flash unique id */ 33 | extern void usb_serial_init(void); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/pico-sigrok/sigrok.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #ifndef _SIGROK_H 27 | #define _SIGROK_H 28 | 29 | 30 | #include 31 | #include 32 | 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | 39 | void sigrok_init(uint32_t task_prio); 40 | 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/probe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #ifndef PROBE_H_ 27 | #define PROBE_H_ 28 | 29 | void probe_set_swclk_freq(uint32_t freq_khz); 30 | void probe_write_bits(uint bit_count, uint32_t data); 31 | uint32_t probe_read_bits(uint bit_count, bool push, bool pull); 32 | 33 | void probe_gpio_init(void); 34 | void probe_init(void); 35 | void probe_deinit(void); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/rtt_console.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #ifndef _RTT_CONSOLE_H 27 | #define _RTT_CONSOLE_H 28 | 29 | 30 | #include 31 | 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | 38 | void rtt_console_init(uint32_t task_prio); 39 | void rtt_console_send_byte(uint8_t ch); 40 | bool rtt_console_cb_exists(void); 41 | 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/daplink/daplink/cortex_m.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file cortex_m.h 3 | * @brief ARM Cortex-Mx cpu state helper functions 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef CORTEX_M_H 23 | #define CORTEX_M_H 24 | 25 | #include 26 | #include 27 | #include "device.h" 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | typedef uint32_t cortex_int_state_t; 34 | 35 | __STATIC_FORCEINLINE cortex_int_state_t cortex_int_get_and_disable(void) 36 | { 37 | cortex_int_state_t state; 38 | state = __get_PRIMASK(); 39 | __disable_irq(); 40 | return state; 41 | } 42 | 43 | __STATIC_FORCEINLINE void cortex_int_restore(cortex_int_state_t state) 44 | { 45 | __set_PRIMASK(state); 46 | } 47 | 48 | __STATIC_FORCEINLINE bool cortex_in_isr(void) 49 | { 50 | return (__get_xPSR() & 0x1F) != 0; 51 | } 52 | 53 | extern void SystemReset(void); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/sw_lock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #ifndef _SW_LOCK_H 27 | #define _SW_LOCK_H 28 | 29 | 30 | #include 31 | #include 32 | 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | 39 | void sw_lock_init(void); 40 | bool sw_lock(const char *who, bool wait_just_some_ms); 41 | void sw_unlock(const char *who); 42 | bool sw_unlock_requested(void); 43 | 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/cdc_uart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #ifndef CDC_UART_H 27 | #define CDC_UART_H 28 | 29 | #include 30 | #include 31 | #include "tusb.h" 32 | 33 | void cdc_uart_write(const uint8_t *buf, uint32_t cnt); 34 | void cdc_uart_init(uint32_t task_prio); 35 | 36 | #if CFG_TUD_CDC_UART 37 | void cdc_uart_line_state_cb(bool dtr, bool rts); 38 | void cdc_uart_line_coding_cb(cdc_line_coding_t const* line_coding); 39 | void cdc_uart_tx_complete_cb(void); 40 | void cdc_uart_rx_cb(void); 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/dap_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #ifndef DAP_UTIL_H 27 | #define DAP_UTIL_H 28 | 29 | #include 30 | 31 | 32 | typedef enum { 33 | E_DAPTOOL_UNKNOWN, 34 | E_DAPTOOL_OPENOCD, 35 | E_DAPTOOL_PYOCD 36 | } daptool_t; 37 | 38 | 39 | static const uint32_t DAP_CHECK_ABORT = 99999999; 40 | 41 | uint32_t DAP_GetCommandLength(const uint8_t *request_data, uint32_t request_len); 42 | daptool_t DAP_FingerprintTool(const uint8_t *request, uint32_t request_len); 43 | bool DAP_OfflineCommand(const uint8_t *request_data); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/daplink/hic_hal/device.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file cmsis.h 3 | * @brief 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2019, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef DEVICE_H 23 | #define DEVICE_H 24 | 25 | #if defined (INTERFACE_K20D5) \ 26 | || defined (INTERFACE_K26F) \ 27 | || defined (INTERFACE_KL26Z) \ 28 | || defined (INTERFACE_KL27Z) \ 29 | || defined (INTERFACE_LPC55XX) 30 | #include "fsl_device_registers.h" 31 | #elif defined (INTERFACE_LPC11U35) 32 | #include "LPC11Uxx.h" 33 | #elif defined (INTERFACE_LPC4322) 34 | #include "LPC43xx.h" 35 | #elif defined (INTERFACE_MAX32620) 36 | #include "max32620.h" 37 | #elif defined (INTERFACE_MAX32625) 38 | #include "max32625.h" 39 | #elif defined (INTERFACE_SAM3U2C) 40 | #include "sam3u2c.h" 41 | #elif defined (INTERFACE_STM32F103XB) 42 | #include "stm32f1xx.h" 43 | #elif defined (INTERFACE_M48SSIDAE) 44 | #include "M480.h" 45 | #elif defined (INTERFACE_NRF52820) 46 | #include "nrf52820.h" 47 | #elif defined (INTERFACE_RP2040) 48 | //#include "rp2040.h" 49 | #else 50 | #error "CMSIS core headers needed" 51 | #endif 52 | 53 | #endif // DEVICE_H 54 | -------------------------------------------------------------------------------- /src/pico-sigrok/cdc_sigrok.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #ifndef CDC_SIGROK_H 27 | #define CDC_SIGROK_H 28 | 29 | #include 30 | #include 31 | 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | 38 | void cdc_sigrok_init(uint32_t task_prio); 39 | void cdc_sigrok_write(const char *buf, int length); 40 | void cdc_sigrok_rx_cb(void); 41 | void cdc_sigrok_tx_complete_cb(void); 42 | void cdc_sigrok_line_state_cb(bool dtr, bool rts); 43 | 44 | void core1_code(); 45 | 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/daplink/family/renesas/rza1lu/target.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file target.c 3 | * @brief Target information for the RZA1LU based on the GR-LYCHEE profile 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2019, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #include "target_config.h" 23 | 24 | // The file flash_blob.c must only be included in target.c 25 | #include "flash_blob.c" 26 | 27 | // target information 28 | target_cfg_t target_device_rza1lu = { 29 | .version = kTargetConfigVersion, 30 | .sectors_info = sectors_info_rza1lu, 31 | .sector_info_length = (sizeof(sectors_info_rza1lu))/(sizeof(sector_info_t)), 32 | .flash_regions[0].start = flash_start_rza1lu, 33 | .flash_regions[0].end = flash_size_rza1lu, 34 | .flash_regions[0].flags = kRegionIsDefault, 35 | .flash_regions[0].flash_algo = (program_target_t *) &flash_rza1lu, 36 | .ram_regions[0].start = 0x20000000, 37 | .ram_regions[0].end = 0x20300000, 38 | .erase_reset = 1, 39 | .target_vendor = "Renesas", 40 | .target_part_number = "r7s7210xx" 41 | }; -------------------------------------------------------------------------------- /src/daplink-pico/family/raspberry/target_rp2040.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | /** 27 | * This module holds some additional SWD functions. 28 | */ 29 | 30 | #ifndef _TARGET_RP2040_H 31 | #define _TARGET_RP2040_H 32 | 33 | 34 | #include 35 | 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | 42 | // required for linking of \a g_board_info.target_cfg and \a g_raspberry_rp2040_family 43 | #define TARGET_RP2040_FAMILY_ID CREATE_FAMILY_ID(127, 1) 44 | 45 | 46 | bool target_core_is_halted(void); 47 | bool target_core_halt(void); 48 | bool target_core_unhalt(void); 49 | bool target_core_unhalt_with_masked_ints(void); 50 | 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/daplink/daplink/settings/settings_rom_stub.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file settings_rom_stub.c 3 | * @brief Implementation of settings.h 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #include "settings.h" 23 | 24 | void config_rom_init() 25 | { 26 | // Do nothing 27 | } 28 | 29 | void config_set_auto_rst(bool on) 30 | { 31 | // Do nothing 32 | } 33 | 34 | void config_set_automation_allowed(bool on) 35 | { 36 | // Do nothing 37 | } 38 | 39 | void config_set_overflow_detect(bool on) 40 | { 41 | // Do nothing 42 | } 43 | 44 | void config_set_detect_incompatible_target(bool on) 45 | { 46 | // Do nothing 47 | } 48 | 49 | bool config_get_auto_rst() 50 | { 51 | return false; 52 | } 53 | 54 | bool config_get_automation_allowed() 55 | { 56 | return true; 57 | } 58 | 59 | bool config_get_overflow_detect() 60 | { 61 | return false; 62 | } 63 | 64 | bool config_get_detect_incompatible_target() 65 | { 66 | return false; 67 | } 68 | 69 | bool config_ram_get_assert(char *buf, uint16_t buf_size, uint16_t *line, assert_source_t *source) 70 | { 71 | return true; 72 | } 73 | 74 | void config_ram_set_assert(const char *file, uint16_t line) 75 | { 76 | } 77 | 78 | void config_ram_set_page_erase(bool on) 79 | { 80 | } 81 | -------------------------------------------------------------------------------- /src/msc/msc_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #ifndef _MSC_UTILS_H 27 | #define _MSC_UTILS_H 28 | 29 | 30 | #include 31 | #include 32 | 33 | #include "boot/uf2.h" // this is the Pico variant of the UF2 header 34 | 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | 41 | bool msc_target_connect(bool write_mode); 42 | bool msc_target_write_memory(const struct uf2_block *uf2); 43 | bool msc_target_read_memory(struct uf2_block *uf2, uint32_t target_addr, uint32_t block_no, uint32_t num_blocks); 44 | bool msc_target_is_writable(void); 45 | 46 | bool msc_is_uf2_record(const void *sector, uint32_t sector_size); 47 | 48 | void msc_init(uint32_t task_prio); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/daplink/family/renesas/target_reset_rza1lu.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file target_reset.c 3 | * @brief Target reset for the rza1h 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #include "DAP_config.h" 23 | #include "target_family.h" 24 | #include "target_board.h" 25 | #include "swd_host.h" 26 | 27 | static uint8_t target_set_state_rza1lu(target_state_t state) 28 | { 29 | return swd_set_target_state_hw(state); 30 | } 31 | 32 | #define BINARY_DETECTION (0xE59FF000) 33 | 34 | static uint8_t validate_bin_nvic_rza1lu(const uint8_t *buf) 35 | { 36 | // Very dirty hacking here for ARMv7-A (non Cortex-M) binary detection 37 | // This returns validated result when start instrunction 38 | // of the buffer is BINARY_DETECTION (LDR PC, Label) 39 | // Compared with the high-order 3byte 40 | if ((buf[1] == ((BINARY_DETECTION >> 8) & 0xFF)) 41 | && (buf[2] == ((BINARY_DETECTION >> 16) & 0xFF)) 42 | && (buf[3] == ((BINARY_DETECTION >> 24) & 0xFF))) { 43 | return 1; 44 | } else { 45 | return 0; 46 | } 47 | } 48 | 49 | static uint8_t validate_hexfile_rza1lu(const uint8_t *buf) 50 | { 51 | return 0; 52 | } 53 | 54 | const target_family_descriptor_t g_renesas_family = { 55 | .family_id = kRenesas_FamilyID, 56 | .target_set_state = target_set_state_rza1lu, 57 | .validate_bin_nvic = validate_bin_nvic_rza1lu, 58 | .validate_hexfile = validate_hexfile_rza1lu, 59 | }; 60 | 61 | -------------------------------------------------------------------------------- /src/get_serial.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Federico Zuccardi Merli 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #include 27 | #include "pico.h" 28 | #include "pico/unique_id.h" 29 | #include "get_serial.h" 30 | 31 | /* C string for iSerialNumber in USB Device Descriptor, two chars per byte + terminating NUL */ 32 | char usb_serial[PICO_UNIQUE_BOARD_ID_SIZE_BYTES * 2 + 1]; 33 | 34 | /* Why a uint8_t[8] array inside a struct instead of an uint64_t an inquiring mind might wonder */ 35 | static pico_unique_board_id_t uID; 36 | 37 | void usb_serial_init(void) 38 | { 39 | pico_get_unique_board_id(&uID); 40 | 41 | for (int i = 0; i < PICO_UNIQUE_BOARD_ID_SIZE_BYTES * 2; i++) 42 | { 43 | /* Byte index inside the uid array */ 44 | int bi = i / 2; 45 | /* Use high nibble first to keep memory order (just cosmetics) */ 46 | uint8_t nibble = (uID.id[bi] >> 4) & 0x0F; 47 | uID.id[bi] <<= 4; 48 | /* Binary to hex digit */ 49 | usb_serial[i] = nibble < 10 ? nibble + '0' : nibble + 'A' - 10; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/led.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 a-pushkin on GitHub 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #ifndef LED_H 27 | #define LED_H 28 | 29 | 30 | #include 31 | 32 | 33 | typedef enum _led_state { 34 | LS_TARGET_FOUND, // there is a target 35 | LS_NO_TARGET, // no target found 36 | LS_RTT_CB_FOUND, // found an RTT control block on target 37 | LS_RTT_RX_DATA, // RTT data received from target 38 | LS_UART_RX_DATA, // UART data received from target 39 | LS_UART_TX_DATA, // UART data transmitted to target 40 | LS_MSC_CONNECTED, // MSC connected 41 | LS_MSC_DISCONNECTED, // MSC disconnected 42 | LS_DAPV1_CONNECTED, // DAPV1 connected 43 | LS_DAPV1_DISCONNECTED, // DAPV1 disconnected 44 | LS_DAPV2_CONNECTED, // DAPV2 connected 45 | LS_DAPV2_DISCONNECTED, // DAPV2 disconnected 46 | LS_SIGROK_WAIT, // sigrok waits for trigger 47 | LS_SIGROK_RUNNING, // sigrok is running 48 | LS_SIGROK_STOPPED, // sigrok stopped 49 | } led_state_t; 50 | 51 | void led_init(uint32_t task_prio); 52 | void led_state(led_state_t state); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/daplink/hic_hal/flash_blob.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file flash_blob.h 3 | * @brief 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved 7 | * Copyright 2019, Cypress Semiconductor Corporation 8 | * or a subsidiary of Cypress Semiconductor Corporation. 9 | * SPDX-License-Identifier: Apache-2.0 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 12 | * not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 19 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #ifndef FLASH_BLOB_H 25 | #define FLASH_BLOB_H 26 | 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | // Flags for program_target 34 | enum { 35 | kAlgoVerifyReturnsAddress = (1u << 0u), /*!< Verify function returns address if bit set */ 36 | kAlgoSingleInitType = (1u << 1u), /*!< The init function ignores the function code. */ 37 | kAlgoSkipChipErase = (1u << 2u), /*!< Skip region when erase.act action triggers. */ 38 | }; 39 | 40 | typedef struct __attribute__((__packed__)) { 41 | uint32_t breakpoint; 42 | uint32_t static_base; 43 | uint32_t stack_pointer; 44 | } program_syscall_t; 45 | 46 | typedef struct __attribute__((__packed__)) { 47 | const uint32_t init; 48 | const uint32_t uninit; 49 | const uint32_t erase_chip; 50 | const uint32_t erase_sector; 51 | const uint32_t program_page; 52 | const uint32_t verify; 53 | const program_syscall_t sys_call_s; 54 | const uint32_t program_buffer; 55 | const uint32_t algo_start; 56 | const uint32_t algo_size; 57 | const uint32_t *algo_blob; 58 | const uint32_t program_buffer_size; 59 | const uint32_t algo_flags; /*!< Combination of kAlgoVerifyReturnsAddress, kAlgoSingleInitType and kAlgoSkipChipErase*/ 60 | } program_target_t; 61 | 62 | typedef struct __attribute__((__packed__)) { 63 | const uint32_t start; 64 | const uint32_t size; 65 | } sector_info_t; 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /src/daplink/target/target_board.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file target_board.c 3 | * @brief Implementation of target_board.h 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2019, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #include 23 | #include "target_board.h" 24 | #include "compiler.h" 25 | 26 | // Disable optimization of these functions. 27 | // 28 | // This is required because for the "no target" builds, the compiler sees g_board_info fields as 29 | // defined above and will elide entire expressions. However, the board and target info may be 30 | // modified using the post processor script, changing what the code sees at runtime. 31 | 32 | NO_OPTIMIZE_PRE 33 | __WEAK const char * NO_OPTIMIZE_INLINE get_board_id(void) 34 | { 35 | if (g_board_info.target_cfg && g_board_info.target_cfg->rt_board_id) { 36 | return g_board_info.target_cfg->rt_board_id; //flexible board id 37 | } else { 38 | return g_board_info.board_id; 39 | } 40 | } 41 | NO_OPTIMIZE_POST 42 | 43 | NO_OPTIMIZE_PRE 44 | __WEAK uint16_t NO_OPTIMIZE_INLINE get_family_id(void) 45 | { 46 | if (g_board_info.target_cfg && g_board_info.target_cfg->rt_family_id) { 47 | return g_board_info.target_cfg->rt_family_id; //flexible family id 48 | } else { 49 | return g_board_info.family_id; 50 | } 51 | } 52 | NO_OPTIMIZE_POST 53 | 54 | // Disable optimization of this function. 55 | // 56 | // This is required because for the "no target" builds, the compiler sees g_board_info.target_cfg as 57 | // NULL and will elide the entire expression. However, the board and target info may be modified 58 | // using the post processor script, changing what the code sees at runtime. 59 | NO_OPTIMIZE_PRE 60 | __WEAK uint8_t NO_OPTIMIZE_INLINE flash_algo_valid(void) 61 | { 62 | return (g_board_info.target_cfg != 0); 63 | } 64 | NO_OPTIMIZE_POST 65 | -------------------------------------------------------------------------------- /src/daplink/daplink/compiler.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file compiler.h 3 | * @brief Special asserts and macros 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef COMPILER_H 23 | #define COMPILER_H 24 | 25 | #include "cmsis_compiler.h" 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #define COMPILER_CONCAT_(a, b) a##b 32 | #define COMPILER_CONCAT(a, b) COMPILER_CONCAT_(a, b) 33 | 34 | // Divide by zero if the the expression is false. This 35 | // causes an error at compile time. 36 | // 37 | // The special value '__COUNTER__' is used to create a unique value to 38 | // append to 'compiler_assert_' to create a unique token. This prevents 39 | // conflicts resulting from the same enum being declared multiple times. 40 | #define COMPILER_ASSERT(e) enum { COMPILER_CONCAT(compiler_assert_, __COUNTER__) = 1/((e) ? 1 : 0) } 41 | 42 | // Macros to disable optimisation of a function. 43 | #if (defined(__ICCARM__)) 44 | #define NO_OPTIMIZE_PRE _Pragma("optimize = none") 45 | #define NO_OPTIMIZE_INLINE 46 | #define NO_OPTIMIZE_POST 47 | #elif (defined(__CC_ARM)) /* ARMCC */ 48 | #define NO_OPTIMIZE_PRE _Pragma("push") \ 49 | _Pragma("O0") 50 | #define NO_OPTIMIZE_INLINE 51 | #define NO_OPTIMIZE_POST _Pragma("pop") 52 | #define RAM_FUNCTION __attribute__((section("ram_func"))) 53 | #elif (defined(__ARMCC_VERSION)) /* ARMCLANG */ 54 | #define NO_OPTIMIZE_PRE 55 | #define NO_OPTIMIZE_INLINE 56 | #define NO_OPTIMIZE_POST 57 | #define RAM_FUNCTION __attribute__((section("ram_func"))) 58 | #elif (defined(__GNUC__)) 59 | #define NO_OPTIMIZE_PRE 60 | #define NO_OPTIMIZE_INLINE __attribute__((optimize("O0"))) 61 | #define NO_OPTIMIZE_POST 62 | #define RAM_FUNCTION __attribute__((long_call, section(".ram_func"))) 63 | #else 64 | #error "Unknown compiler" 65 | #endif 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /src/daplink/daplink/drag-n-drop/flash_intf.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file flash_intf.h 3 | * @brief Interface for implementing differet ways to write an image into memory 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2019, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef FLASH_INTF_H 23 | #define FLASH_INTF_H 24 | 25 | #include 26 | 27 | #include "error.h" 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | typedef enum { 34 | FLASH_FUNC_NOP, 35 | FLASH_FUNC_ERASE, 36 | FLASH_FUNC_PROGRAM, 37 | FLASH_FUNC_VERIFY 38 | } flash_func_t; 39 | 40 | typedef error_t (*flash_intf_init_cb_t)(void); 41 | typedef error_t (*flash_intf_uninit_cb_t)(void); 42 | typedef error_t (*flash_intf_program_page_cb_t)(uint32_t addr, const uint8_t *buf, uint32_t size); 43 | typedef error_t (*flash_intf_erase_sector_cb_t)(uint32_t sector); 44 | typedef error_t (*flash_intf_erase_chip_cb_t)(void); 45 | typedef uint32_t (*flash_program_page_min_size_cb_t)(uint32_t addr); 46 | typedef uint32_t (*flash_erase_sector_size_cb_t)(uint32_t addr); 47 | typedef uint8_t (*flash_busy_cb_t)(void); 48 | typedef error_t (*flash_algo_set_cb_t)(uint32_t addr); 49 | 50 | typedef struct { 51 | flash_intf_init_cb_t init; 52 | flash_intf_uninit_cb_t uninit; 53 | flash_intf_program_page_cb_t program_page; 54 | flash_intf_erase_sector_cb_t erase_sector; 55 | flash_intf_erase_chip_cb_t erase_chip; 56 | flash_program_page_min_size_cb_t program_page_min_size; 57 | flash_erase_sector_size_cb_t erase_sector_size; 58 | flash_busy_cb_t flash_busy; 59 | flash_algo_set_cb_t flash_algo_set; 60 | } flash_intf_t; 61 | 62 | // All flash interfaces. Unsupported interfaces are NULL. 63 | extern const flash_intf_t *const flash_intf_iap_protected; 64 | extern const flash_intf_t *const flash_intf_target; 65 | extern const flash_intf_t *const flash_intf_target_custom; 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DelugeProbe (Archival Notice) 2 | 3 | **Edit:** As of 2025, this is certainly not the recommended debugging solution for the Synthstrom Deluge. This fork has not been updated and was broken in a couple ways that never saw fixes (my bad). The original repo at [YAPicoprobe](https://github.com/rgrr/yapicoprobe/) has had lots of updates so go check it out! 4 | 5 | # DelugeProbe (Original Documentation) 6 | 7 | Based on [YAPicoprobe](https://github.com/rgrr/yapicoprobe/), DelugeProbe is a CMSIS-DAP debugger and firmware loader tailored to the hardware of the Synthstrom Audible Deluge's Renesas RZ/A1LU (R7S721020) processor. It has been released in anticipation of the June 5, 2023 opening of the Synthstrom Deluge source code as an acceptable substitute for the very expensive ($500-1500 USD) SEGGER JLink debugger. 8 | 9 | While YAPicoprobe is very full-featured, many of those features have been disabled or reworked in DelugeProbe. While the Sigrok code is still present, it has been disabled in release versions for user simplicity and safety of the hardware as the dev boards used do not have logic/line level shifters. If this is a feature you want, feel free to download the source and re-enable it to compile your own version. 10 | 11 | ## Features 12 | 13 | * Processor support for the Renesas RZ/A1LU (used by the Synthstrom Deluge as well as the Renesas GR-LYCHEE development board) ARM Cortex A9 processor 14 | * As a CMSIS-DAP device, it works perfectly in OpenOCD with Renesas e2 Studio (Eclipse), the official (Windows-based) IDE for RZ/A1LU development. The Synthstrom Deluge community repository will include the appropriate Debugger .launch files out-of-the-box. 15 | * Support for debugging in Visual Studio Code using the Cortex-Debug extension. Detail to come... 16 | * Support for running this firmware on various RP2040 devices to ensure you can tailor your debugger to your needs! So far we support: 17 | * Raspberry Pi Pico 18 | * Raspberry Pi Pico W 19 | * Raspberry Pi Pico Debug Probe 20 | * Seeed XIAO RP2040 21 | * Adafruit QT Py RP2040 22 | * and growing... 23 | * Of course, as with the original Picoprobe, the DelugeProbe can be used to debug ARM Cortex M-series devices including the RP2040 itself! 24 | 25 | ## Wiring 26 | 27 | Using an SWD breakout board from Adafruit, here are some Fritzing images showing the default wiring for some of the supported devices: 28 | 29 | ### Raspberry Pi Pico and Pico W 30 | 31 | ![Raspberry Pi Pico / Pico W Wiring](assets/wiring-rp-pico.png) 32 | 33 | ### Seeed XIAO RP2040 34 | 35 | ![Seeed XIAO RP2040 Wiring](assets/wiring-seeed-xiao.png) 36 | -------------------------------------------------------------------------------- /src/daplink/daplink/settings/settings.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file settings.h 3 | * @brief Access to read user configuration settings 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved 7 | * Copyright 2019, Cypress Semiconductor Corporation 8 | * or a subsidiary of Cypress Semiconductor Corporation. 9 | * SPDX-License-Identifier: Apache-2.0 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 12 | * not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 19 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | #ifndef SETTINGS_H 24 | #define SETTINGS_H 25 | 26 | #include 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | typedef enum { 34 | ASSERT_SOURCE_NONE = 0, 35 | ASSERT_SOURCE_BL = 1, 36 | ASSERT_SOURCE_APP = 2 37 | } assert_source_t; 38 | 39 | void config_init(void); 40 | 41 | // Get/set settings residing in flash 42 | void config_set_auto_rst(bool on); 43 | void config_set_automation_allowed(bool on); 44 | void config_set_overflow_detect(bool on); 45 | void config_set_detect_incompatible_target(bool on); 46 | bool config_get_auto_rst(void); 47 | bool config_get_automation_allowed(void); 48 | bool config_get_overflow_detect(void); 49 | bool config_get_detect_incompatible_target(void); 50 | 51 | // Get/set settings residing in shared ram 52 | void config_ram_set_hold_in_bl(bool hold); 53 | void config_ram_set_assert(const char *file, uint16_t line); 54 | void config_ram_clear_assert(void); 55 | bool config_ram_get_hold_in_bl(void); 56 | bool config_ram_get_initial_hold_in_bl(void); 57 | bool config_ram_get_assert(char *buf, uint16_t buf_size, uint16_t *line, assert_source_t *source); 58 | uint8_t config_ram_add_hexdump(uint32_t hexdump); 59 | uint8_t config_ram_get_hexdumps(uint32_t **hexdumps); 60 | void config_ram_set_disable_msd(bool disable_msd); 61 | uint8_t config_ram_get_disable_msd(void); 62 | void config_ram_set_page_erase(bool page_erase_enable); 63 | bool config_ram_get_page_erase(void); 64 | 65 | // Private - should only be called from settings.c 66 | void config_rom_init(void); 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /src/daplink-pico/hic_hal/raspberry/rp2040/daplink_addr.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file daplink_addr.h 3 | * @brief 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef DAPLINK_ADDR_H 23 | #define DAPLINK_ADDR_H 24 | 25 | /* Device sizes */ 26 | 27 | #define DAPLINK_ROM_START 0x10000000 28 | #define DAPLINK_ROM_SIZE 0x00200000 29 | 30 | #define DAPLINK_RAM_START 0x20000000 31 | #define DAPLINK_RAM_SIZE 0x00040000 32 | 33 | /* ROM sizes */ 34 | 35 | #define DAPLINK_ROM_BL_START 0x10000000 36 | #define DAPLINK_ROM_BL_SIZE 0x00000000 37 | 38 | #define DAPLINK_ROM_IF_START 0x10000000 39 | #define DAPLINK_ROM_IF_SIZE 0x00200000 40 | 41 | #define DAPLINK_ROM_CONFIG_USER_START 0x10200000 42 | #define DAPLINK_ROM_CONFIG_USER_SIZE 0x00000000 43 | 44 | /* RAM sizes */ 45 | 46 | #define DAPLINK_RAM_APP_START 0x20000000 47 | #define DAPLINK_RAM_APP_SIZE 0x00040000 48 | 49 | #define DAPLINK_RAM_SHARED_START 0x20040000 50 | #define DAPLINK_RAM_SHARED_SIZE 0x00000000 51 | 52 | /* Flash Programming Info */ 53 | 54 | #define DAPLINK_SECTOR_SIZE 0x00000400 55 | #define DAPLINK_MIN_WRITE_SIZE 0x00000400 56 | 57 | /* Current build */ 58 | 59 | #if defined(DAPLINK_BL) 60 | #define DAPLINK_ROM_APP_START DAPLINK_ROM_BL_START 61 | #define DAPLINK_ROM_APP_SIZE DAPLINK_ROM_BL_SIZE 62 | #define DAPLINK_ROM_UPDATE_START DAPLINK_ROM_IF_START 63 | #define DAPLINK_ROM_UPDATE_SIZE DAPLINK_ROM_IF_SIZE 64 | #elif defined(DAPLINK_IF) 65 | #define DAPLINK_ROM_APP_START DAPLINK_ROM_IF_START 66 | #define DAPLINK_ROM_APP_SIZE DAPLINK_ROM_IF_SIZE 67 | #define DAPLINK_ROM_UPDATE_START DAPLINK_ROM_BL_START 68 | #define DAPLINK_ROM_UPDATE_SIZE DAPLINK_ROM_BL_SIZE 69 | #else 70 | #error "Build must be either bootloader or interface" 71 | #endif 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /src/daplink/daplink/interface/swd_host.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file swd_host.h 3 | * @brief Host driver for accessing the DAP 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2019, ARM Limited, All Rights Reserved 7 | * Copyright 2019, Cypress Semiconductor Corporation 8 | * or a subsidiary of Cypress Semiconductor Corporation. 9 | * SPDX-License-Identifier: Apache-2.0 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 12 | * not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 19 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | */ 23 | 24 | #ifndef SWDHOST_CM_H 25 | #define SWDHOST_CM_H 26 | 27 | #include "flash_blob.h" 28 | #include "target_family.h" 29 | #ifdef TARGET_MCU_CORTEX_A 30 | #include "debug_ca.h" 31 | #else 32 | #include "debug_cm.h" 33 | #endif 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | typedef enum { 40 | CONNECT_NORMAL, 41 | CONNECT_UNDER_RESET, 42 | } SWD_CONNECT_TYPE; 43 | 44 | typedef enum { 45 | FLASHALGO_RETURN_BOOL, 46 | FLASHALGO_RETURN_POINTER 47 | } flash_algo_return_t; 48 | 49 | uint8_t swd_init(void); 50 | uint8_t swd_off(void); 51 | uint8_t swd_init_debug(void); 52 | uint8_t swd_clear_errors(void); 53 | uint8_t swd_read_dp(uint8_t adr, uint32_t *val); 54 | uint8_t swd_write_dp(uint8_t adr, uint32_t val); 55 | uint8_t swd_read_ap(uint32_t adr, uint32_t *val); 56 | uint8_t swd_write_ap(uint32_t adr, uint32_t val); 57 | uint8_t swd_read_word(uint32_t addr, uint32_t *val); 58 | uint8_t swd_write_word(uint32_t addr, uint32_t val); 59 | uint8_t swd_read_byte(uint32_t addr, uint8_t *val); 60 | uint8_t swd_write_byte(uint32_t addr, uint8_t val); 61 | uint8_t swd_read_memory(uint32_t address, uint8_t *data, uint32_t size); 62 | uint8_t swd_write_memory(uint32_t address, uint8_t *data, uint32_t size); 63 | uint8_t swd_read_core_register(uint32_t n, uint32_t *val); 64 | uint8_t swd_write_core_register(uint32_t n, uint32_t val); 65 | 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, flash_algo_return_t return_type); 66 | uint8_t swd_set_target_state_hw(target_state_t state); 67 | uint8_t swd_set_target_state_sw(target_state_t state); 68 | uint8_t swd_transfer_retry(uint32_t req, uint32_t *data); 69 | void int2array(uint8_t *res, uint32_t data, uint8_t len); 70 | void swd_set_reset_connect(SWD_CONNECT_TYPE type); 71 | void swd_set_soft_reset(uint32_t soft_reset_type); 72 | uint8_t JTAG2SWD(void); 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /include/picoprobe_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #ifndef PICOPROBE_H_ 27 | #define PICOPROBE_H_ 28 | 29 | 30 | #define INCLUDE_RTT_CONSOLE 31 | // #define INCLUDE_SIGROK 32 | 33 | 34 | #if !defined(NDEBUG) 35 | #define picoprobe_info_out(format,args...) printf(format, ## args) 36 | #else 37 | #define picoprobe_info_out(format,...) ((void)0) 38 | #endif 39 | 40 | #if !defined(NDEBUG) 41 | #define picoprobe_info(format,args...) printf("(II) " format, ## args) 42 | #else 43 | #define picoprobe_info(format,...) ((void)0) 44 | #endif 45 | 46 | #if 0 && !defined(NDEBUG) 47 | #define picoprobe_debug(format,args...) printf("(DD) " format, ## args) 48 | #else 49 | #define picoprobe_debug(format,...) ((void)0) 50 | #endif 51 | 52 | #if 0 && !defined(NDEBUG) 53 | #define picoprobe_dump(format,args...) printf("(..) " format, ## args) 54 | #else 55 | #define picoprobe_dump(format,...) ((void)0) 56 | #endif 57 | 58 | #if 1 && !defined(NDEBUG) 59 | #define picoprobe_error(format,args...) printf("(EE) " format, ## args) 60 | #else 61 | #define picoprobe_error(format,...) ((void)0) 62 | #endif 63 | 64 | 65 | // Base value of sys_clk in khz. Must be <=125Mhz per RP2040 spec and a multiple of 24Mhz 66 | // to support integer divisors of the PIO clock and ADC clock (for sigrok) 67 | #define PROBE_CPU_CLOCK_KHZ ((120 + 2*24) * 1000) // overclocked, even 264MHz seems to be no problem 68 | 69 | 70 | // pin configurations can be found in include/boards/*.h 71 | 72 | 73 | // optimize a single function 74 | #if 0 75 | // actually no positive effect 76 | #define __TIME_CRITICAL_FUNCTION(func) __attribute__((optimize("O3"))) __time_critical_func(func) 77 | #else 78 | #define __TIME_CRITICAL_FUNCTION(func) func 79 | #endif 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/probe.pio: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | // Output frequency is PIO clock / 6 (therefor the delay [2]) 27 | // PIO clock is set to a high frequency to keep the timing effects of the instructions outside the shift loops small 28 | // BUT take care of maximum frequency / minimum divisor: 29 | // Effective frequency is sysclk/(int + frac/256). Value of 0 is interpreted as 65536. If INT is 0, FRAC must also be 0. 30 | // 31 | // Sideset pin0 is SWDIR, pin1 is SWCLK 32 | 33 | // The following code has been mainly taken from https://github.com/essele/pico_debug/blob/main/swd.pio 34 | 35 | .program probe 36 | 37 | .side_set 2 opt ; side set SWCLK 38 | 39 | 40 | ; The default approach is to just accept jump targets in the FIFO so they effectively 41 | ; become a series of function calls, each function can then process arguments as needed 42 | ; The jump target is 8 bits (the least significant 8) 43 | 44 | public start: 45 | out pc, 8 46 | 47 | 48 | ; // OUTPUT // 49 | 50 | ; Using a single control word sends up to 16 bits (ok, 18) of data. The first 8 will be the jump 51 | ; target (i.e. to here), then 5 to say how many bits, then up to 16 bits of data to send 52 | 53 | public short_output: 54 | out x, 5 55 | set pindirs, 1 side 1 56 | bulk_out_loop: 57 | out pins, 1 side 1 [2] 58 | jmp x--, bulk_out_loop side 3 [2] 59 | set pins, 1 side 1 60 | out NULL, 32 ; clear anything not sent 61 | jmp start 62 | 63 | 64 | ; // INPUT // 65 | 66 | ; Reads in a certain number of bits and pushes the last 32bit into the FIFO 67 | 68 | public input: 69 | out x, 24 70 | public in_jmp: 71 | set pindirs, 0 side 0 72 | bulk_in_loop: 73 | in pins, 1 side 2 [2] 74 | jmp x--, bulk_in_loop side 0 [2] 75 | push 76 | jmp start 77 | -------------------------------------------------------------------------------- /src/daplink/daplink/error.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file error.h 3 | * @brief collection of known errors and accessor for the friendly string 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef ERROR_H 23 | #define ERROR_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | // Keep in sync with the lists error_message and error_type 30 | // New values shold be added to the end of the enum to preserve error codes 31 | typedef enum { 32 | /* Shared errors */ 33 | ERROR_SUCCESS = 0, 34 | ERROR_FAILURE, 35 | ERROR_INTERNAL, 36 | 37 | /* VFS user errors */ 38 | ERROR_ERROR_DURING_TRANSFER, 39 | ERROR_TRANSFER_TIMEOUT, 40 | ERROR_FILE_BOUNDS, 41 | ERROR_OOO_SECTOR, 42 | 43 | /* Target flash errors */ 44 | ERROR_RESET, 45 | ERROR_ALGO_DL, 46 | ERROR_ALGO_MISSING, 47 | ERROR_ALGO_DATA_SEQ, 48 | ERROR_INIT, 49 | ERROR_UNINIT, 50 | ERROR_SECURITY_BITS, 51 | ERROR_UNLOCK, 52 | ERROR_ERASE_SECTOR, 53 | ERROR_ERASE_ALL, 54 | ERROR_WRITE, 55 | ERROR_WRITE_VERIFY, 56 | 57 | /* File stream errors */ 58 | ERROR_SUCCESS_DONE, 59 | ERROR_SUCCESS_DONE_OR_CONTINUE, 60 | ERROR_HEX_CKSUM, 61 | ERROR_HEX_PARSER, 62 | ERROR_HEX_PROGRAM, 63 | ERROR_HEX_INVALID_ADDRESS, 64 | ERROR_HEX_INVALID_APP_OFFSET, 65 | 66 | /* Flash decoder error */ 67 | ERROR_FD_BL_UPDT_ADDR_WRONG, 68 | ERROR_FD_INTF_UPDT_ADDR_WRONG, 69 | ERROR_FD_UNSUPPORTED_UPDATE, 70 | ERROR_FD_INCOMPATIBLE_IMAGE, 71 | 72 | /* Flash IAP interface */ 73 | ERROR_IAP_INIT, 74 | ERROR_IAP_UNINIT, 75 | ERROR_IAP_WRITE, 76 | ERROR_IAP_ERASE_SECTOR, 77 | ERROR_IAP_ERASE_ALL, 78 | ERROR_IAP_OUT_OF_BOUNDS, 79 | ERROR_IAP_UPDT_NOT_SUPPORTED, 80 | ERROR_IAP_UPDT_INCOMPLETE, 81 | ERROR_IAP_NO_INTERCEPT, 82 | ERROR_BL_UPDT_BAD_CRC, 83 | 84 | // Add new values here 85 | 86 | ERROR_COUNT 87 | } error_t; 88 | 89 | const char *error_get_string(error_t error); 90 | 91 | typedef unsigned char error_type_t; 92 | 93 | #define ERROR_TYPE_INTERNAL 0x1 94 | #define ERROR_TYPE_TRANSIENT 0x2 95 | #define ERROR_TYPE_USER 0x4 96 | #define ERROR_TYPE_TARGET 0x8 97 | #define ERROR_TYPE_INTERFACE 0x10 98 | // If you add another error type: 99 | // 1. update error_type_names, used by read_file_fail_txt() 100 | // 2. update ERROR_TYPE_MASK 101 | // 3. make sure that error type bits still fit inside of error_type_t 102 | #define ERROR_TYPE_MASK 0x1F 103 | 104 | error_type_t error_get_type(error_t error); 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /pico_sdk_import.cmake: -------------------------------------------------------------------------------- 1 | # This is a copy of /external/pico_sdk_import.cmake 2 | 3 | # This can be dropped into an external project to help locate this SDK 4 | # It should be include()ed prior to project() 5 | 6 | if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) 7 | set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) 8 | message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") 9 | endif () 10 | 11 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) 12 | set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) 13 | message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") 14 | endif () 15 | 16 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) 17 | set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) 18 | message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") 19 | endif () 20 | 21 | set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") 22 | set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable") 23 | set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") 24 | 25 | if (NOT PICO_SDK_PATH) 26 | if (PICO_SDK_FETCH_FROM_GIT) 27 | include(FetchContent) 28 | set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) 29 | if (PICO_SDK_FETCH_FROM_GIT_PATH) 30 | get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") 31 | endif () 32 | # GIT_SUBMODULES_RECURSE was added in 3.17 33 | if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") 34 | FetchContent_Declare( 35 | pico_sdk 36 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 37 | GIT_TAG master 38 | GIT_SUBMODULES_RECURSE FALSE 39 | ) 40 | else () 41 | FetchContent_Declare( 42 | pico_sdk 43 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 44 | GIT_TAG master 45 | ) 46 | endif () 47 | 48 | if (NOT pico_sdk) 49 | message("Downloading Raspberry Pi Pico SDK") 50 | FetchContent_Populate(pico_sdk) 51 | set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) 52 | endif () 53 | set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) 54 | else () 55 | message(FATAL_ERROR 56 | "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." 57 | ) 58 | endif () 59 | endif () 60 | 61 | get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") 62 | if (NOT EXISTS ${PICO_SDK_PATH}) 63 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") 64 | endif () 65 | 66 | set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) 67 | if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) 68 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") 69 | endif () 70 | 71 | set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) 72 | 73 | include(${PICO_SDK_INIT_CMAKE_FILE}) 74 | -------------------------------------------------------------------------------- /FreeRTOS_Kernel_import.cmake: -------------------------------------------------------------------------------- 1 | # This is a copy of /portable/ThirdParty/GCC/RP2040/FREERTOS_KERNEL_import.cmake 2 | 3 | # This can be dropped into an external project to help locate the FreeRTOS kernel 4 | # It should be include()ed prior to project(). Alternatively this file may 5 | # or the CMakeLists.txt in this directory may be included or added via add_subdirectory 6 | # respectively. 7 | 8 | if (DEFINED ENV{FREERTOS_KERNEL_PATH} AND (NOT FREERTOS_KERNEL_PATH)) 9 | set(FREERTOS_KERNEL_PATH $ENV{FREERTOS_KERNEL_PATH}) 10 | message("Using FREERTOS_KERNEL_PATH from environment ('${FREERTOS_KERNEL_PATH}')") 11 | endif () 12 | 13 | set(FREERTOS_KERNEL_RP2040_RELATIVE_PATH "portable/ThirdParty/GCC/RP2040") 14 | # undo the above 15 | set(FREERTOS_KERNEL_RP2040_BACK_PATH "../../../..") 16 | 17 | if (NOT FREERTOS_KERNEL_PATH) 18 | # check if we are inside the FreeRTOS kernel tree (i.e. this file has been included directly) 19 | get_filename_component(_ACTUAL_PATH ${CMAKE_CURRENT_LIST_DIR} REALPATH) 20 | get_filename_component(_POSSIBLE_PATH ${CMAKE_CURRENT_LIST_DIR}/${FREERTOS_KERNEL_RP2040_BACK_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH} REALPATH) 21 | if (_ACTUAL_PATH STREQUAL _POSSIBLE_PATH) 22 | get_filename_component(FREERTOS_KERNEL_PATH ${CMAKE_CURRENT_LIST_DIR}/${FREERTOS_KERNEL_RP2040_BACK_PATH} REALPATH) 23 | endif() 24 | if (_ACTUAL_PATH STREQUAL _POSSIBLE_PATH) 25 | get_filename_component(FREERTOS_KERNEL_PATH ${CMAKE_CURRENT_LIST_DIR}/${FREERTOS_KERNEL_RP2040_BACK_PATH} REALPATH) 26 | message("Setting FREERTOS_KERNEL_PATH to ${FREERTOS_KERNEL_PATH} based on location of FreeRTOS-Kernel-import.cmake") 27 | elseif (PICO_SDK_PATH AND EXISTS "${PICO_SDK_PATH}/../FreeRTOS-Kernel") 28 | set(FREERTOS_KERNEL_PATH ${PICO_SDK_PATH}/../FreeRTOS-Kernel) 29 | message("Defaulting FREERTOS_KERNEL_PATH as sibling of PICO_SDK_PATH: ${FREERTOS_KERNEL_PATH}") 30 | endif() 31 | endif () 32 | 33 | if (NOT FREERTOS_KERNEL_PATH) 34 | foreach(POSSIBLE_SUFFIX Source FreeRTOS-Kernel FreeRTOS/Source) 35 | # check if FreeRTOS-Kernel exists under directory that included us 36 | set(SEARCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) 37 | get_filename_component(_POSSIBLE_PATH ${SEARCH_ROOT}/${POSSIBLE_SUFFIX} REALPATH) 38 | if (EXISTS ${_POSSIBLE_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}/CMakeLists.txt) 39 | get_filename_component(FREERTOS_KERNEL_PATH ${_POSSIBLE_PATH} REALPATH) 40 | message("Setting FREERTOS_KERNEL_PATH to '${FREERTOS_KERNEL_PATH}' found relative to enclosing project") 41 | break() 42 | endif() 43 | endforeach() 44 | endif() 45 | 46 | if (NOT FREERTOS_KERNEL_PATH) 47 | message(FATAL_ERROR "FreeRTOS location was not specified. Please set FREERTOS_KERNEL_PATH.") 48 | endif() 49 | 50 | set(FREERTOS_KERNEL_PATH "${FREERTOS_KERNEL_PATH}" CACHE PATH "Path to the FreeRTOS Kernel") 51 | 52 | get_filename_component(FREERTOS_KERNEL_PATH "${FREERTOS_KERNEL_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") 53 | if (NOT EXISTS ${FREERTOS_KERNEL_PATH}) 54 | message(FATAL_ERROR "Directory '${FREERTOS_KERNEL_PATH}' not found") 55 | endif() 56 | if (NOT EXISTS ${FREERTOS_KERNEL_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}/CMakeLists.txt) 57 | message(FATAL_ERROR "Directory '${FREERTOS_KERNEL_PATH}' does not contain an RP2040 port here: ${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}") 58 | endif() 59 | set(FREERTOS_KERNEL_PATH ${FREERTOS_KERNEL_PATH} CACHE PATH "Path to the FreeRTOS_KERNEL" FORCE) 60 | 61 | add_subdirectory(${FREERTOS_KERNEL_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH} FREERTOS_KERNEL) -------------------------------------------------------------------------------- /src/daplink/daplink/daplink.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file daplink.h 3 | * @brief Information about different Hardware Interface Circuits the firmware runs 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef DAPLINK_H 23 | #define DAPLINK_H 24 | 25 | #include 26 | #include 27 | 28 | #include "daplink_addr.h" 29 | #include "compiler.h" 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | // Assert that regions are sequential with no gaps 36 | // and that they take up all available space 37 | 38 | // ROM check 39 | COMPILER_ASSERT(DAPLINK_ROM_BL_START == DAPLINK_ROM_START); 40 | COMPILER_ASSERT(DAPLINK_ROM_IF_START + DAPLINK_ROM_IF_SIZE == DAPLINK_ROM_CONFIG_USER_START); 41 | COMPILER_ASSERT(DAPLINK_ROM_CONFIG_USER_START + DAPLINK_ROM_CONFIG_USER_SIZE == DAPLINK_ROM_START + DAPLINK_ROM_SIZE); 42 | 43 | // RAM check 44 | COMPILER_ASSERT(DAPLINK_RAM_APP_START == DAPLINK_RAM_START); 45 | COMPILER_ASSERT(DAPLINK_RAM_APP_START + DAPLINK_RAM_APP_SIZE == DAPLINK_RAM_SHARED_START); 46 | COMPILER_ASSERT(DAPLINK_RAM_SHARED_START + DAPLINK_RAM_SHARED_SIZE == DAPLINK_RAM_START + DAPLINK_RAM_SIZE); 47 | 48 | #define DAPLINK_BUILD_KEY_IF 0x9B939E8F 49 | #define DAPLINK_BUILD_KEY_BL 0x9B939D93 50 | 51 | //! @name HIC IDs 52 | //@{ 53 | #define DAPLINK_HIC_ID_K20DX 0x97969900 54 | #define DAPLINK_HIC_ID_KL26 0x97969901 55 | #define DAPLINK_HIC_ID_LPC11U35 0x97969902 56 | #define DAPLINK_HIC_ID_SAM3U2C 0x97969903 57 | #define DAPLINK_HIC_ID_MAX32620 0x97969904 58 | #define DAPLINK_HIC_ID_LPC4322 0x97969905 59 | #define DAPLINK_HIC_ID_MAX32625 0x97969906 60 | #define DAPLINK_HIC_ID_MAX32550 0x97969907 61 | #define DAPLINK_HIC_ID_STM32F103XB 0x97969908 62 | #define DAPLINK_HIC_ID_K26F 0x97969909 63 | #define DAPLINK_HIC_ID_K22F 0x9796990A 64 | #define DAPLINK_HIC_ID_KL27Z 0x9796990B 65 | #define DAPLINK_HIC_ID_LPC54606 0x9796990C // reserving for future use 66 | #define DAPLINK_HIC_ID_STM32F723IE 0x9796990D // reserving for future use 67 | #define DAPLINK_HIC_ID_LPC55XX 0x4C504355 // 'LPC\x55' 68 | #define DAPLINK_HIC_ID_M48SSIDAE 0x97969921 69 | #define DAPLINK_HIC_ID_PSOC5 0x2E127069 70 | #define DAPLINK_HIC_ID_NRF52820 0x6E052820 // 'n\x05\x28\x20' 71 | #define DAPLINK_HIC_ID_RP2040 0x08154711 72 | //@} 73 | 74 | #define DAPLINK_INFO_OFFSET 0x20 75 | 76 | // Macro with the name of the main application header file. 77 | #if defined(DAPLINK_BL) 78 | #define DAPLINK_MAIN_HEADER "main_bootloader.h" 79 | #elif defined(DAPLINK_IF) 80 | #define DAPLINK_MAIN_HEADER "main_interface.h" 81 | #else 82 | #error "Neither DAPLINK_BL nor DAPLINK_IF are defined!" 83 | #endif 84 | 85 | typedef struct { 86 | uint32_t build_key; 87 | uint32_t hic_id; 88 | uint32_t version; 89 | } daplink_info_t; 90 | 91 | bool daplink_is_bootloader(void); 92 | bool daplink_is_interface(void); 93 | 94 | #ifdef __cplusplus 95 | } 96 | #endif 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /src/sw_lock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #include 27 | 28 | #include "FreeRTOS.h" 29 | #include "semphr.h" 30 | 31 | #include "picoprobe_config.h" 32 | #include "sw_lock.h" 33 | 34 | 35 | static SemaphoreHandle_t sema_lock; 36 | static volatile bool lock_requested; 37 | 38 | 39 | /** 40 | * Lock SW access. Idea is, that DAP/MSC access is exclusive, while the RTT console has a low priority and 41 | * can be superseded by the former. But RTT console tries to have SW as long as possible. 42 | * To allow priority to DAP/MSC, the RTT console has to query sw_unlock_requested() periodically. 43 | * 44 | * \param who name of the caller, just for debugging 45 | * \param wait_just_some_ms do not block the caller permanently 46 | * \return true -> got the lock. Note that false might only happen if \a wait_just_some_ms is true 47 | */ 48 | bool sw_lock(const char *who, bool wait_just_some_ms) 49 | { 50 | BaseType_t r; 51 | 52 | if (wait_just_some_ms) { 53 | // wait just a short period and try to supersede RTT console 54 | lock_requested = true; 55 | picoprobe_debug("sw_lock('%s', %d)...\n", who, wait_just_some_ms); 56 | r = xSemaphoreTake(sema_lock, pdMS_TO_TICKS(1000)); 57 | lock_requested = false; 58 | } 59 | else { 60 | // RTT console: wait until SW is free 61 | r = xSemaphoreTake(sema_lock, portMAX_DELAY); 62 | } 63 | picoprobe_debug("sw_lock('%s', %d) = %ld\n", who, wait_just_some_ms, r); 64 | return (r == pdTRUE) ? true : false; 65 | } // sw_lock 66 | 67 | 68 | 69 | /** 70 | * Free SW access. 71 | */ 72 | void sw_unlock(const char *who) 73 | { 74 | BaseType_t r; 75 | 76 | r = xSemaphoreGive(sema_lock); 77 | (void)r; // suppress warning from compiler 78 | picoprobe_debug("sw_unlock('%s') = %ld\n", who, r); 79 | } // sw_unlock 80 | 81 | 82 | 83 | /** 84 | * Indicate if DAP/MSC want to lock SW. 85 | */ 86 | bool sw_unlock_requested(void) 87 | { 88 | return lock_requested; 89 | } // sw_unlock_request 90 | 91 | 92 | 93 | void sw_lock_init(void) 94 | { 95 | picoprobe_debug("sw_lock_init\n"); 96 | sema_lock = xSemaphoreCreateBinary(); // don't know why, but xSemaphoreCreateMutex() leads to hang on ...Take() 97 | if (sema_lock == NULL) { 98 | panic("sw_lock_init: cannot create sema_lock\n"); 99 | } 100 | xSemaphoreGive(sema_lock); 101 | } // sw_lock_init 102 | -------------------------------------------------------------------------------- /src/daplink/daplink/util.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file util.h 3 | * @brief useful things 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2020, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef UTIL_H 23 | #define UTIL_H 24 | 25 | #include 26 | #include 27 | #include "compiler.h" 28 | 29 | // Protect commonly-defined macros with ifdefs, to prevent conflicts if redefined 30 | // in imported sources (mostly vendor SDKs). 31 | 32 | //! @brief Round up division to nearest number of words. 33 | #define WORDS(s) (((s) + sizeof(uint32_t) - 1) / sizeof(uint32_t)) 34 | 35 | #if !defined(ARRAY_SIZE) 36 | //! @brief Get number of elements in the array. 37 | #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) 38 | #endif 39 | 40 | #if !defined(MIN) 41 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) 42 | #endif 43 | 44 | #if !defined(MAX) 45 | #define MAX(a,b) ((a) > (b) ? (a) : (b)) 46 | #endif 47 | 48 | #define MB(size) ((size) * 1024 * 1024) 49 | 50 | #define KB(size) ((size) * 1024) 51 | 52 | #define ROUND_UP(value, boundary) ((value) + ((boundary) - (value)) % (boundary)) 53 | 54 | #define ROUND_DOWN(value, boundary) ((value) - ((value) % (boundary))) 55 | 56 | #ifdef __cplusplus 57 | extern "C" { 58 | #endif 59 | 60 | // Write the value to the address specified and return the size 61 | uint32_t util_write_hex8(char *str, uint8_t value); 62 | uint32_t util_write_hex16(char *str, uint16_t value); 63 | uint32_t util_write_hex32(char *str, uint32_t value); 64 | uint32_t util_write_uint32(char *str, uint32_t value); 65 | uint32_t util_write_uint32(char *str, uint32_t value); 66 | uint32_t util_write_uint32_zp(char *str, uint32_t value, uint16_t total_size); 67 | uint32_t util_write_string(char *str, const char *data); 68 | 69 | uint32_t util_write_in_region(uint8_t *buf, uint32_t size, uint32_t start, 70 | uint32_t pos, const char *input, uint32_t length); 71 | uint32_t util_write_string_in_region(uint8_t *buf, uint32_t size, uint32_t start, 72 | uint32_t pos, const char *input); 73 | 74 | __STATIC_INLINE uint32_t util_div_round_up(uint32_t dividen, uint32_t divisor) 75 | { 76 | return (dividen + divisor - 1) / divisor; 77 | } 78 | 79 | __STATIC_INLINE uint32_t util_div_round_down(uint32_t dividen, uint32_t divisor) 80 | { 81 | return dividen / divisor; 82 | } 83 | 84 | __STATIC_INLINE uint32_t util_div_round(uint32_t dividen, uint32_t divisor) 85 | { 86 | return (dividen + divisor / 2) / divisor; 87 | } 88 | 89 | #if !(defined(DAPLINK_NO_ASSERT_FILENAMES) && defined(DAPLINK_BL)) 90 | // With the filename enabled. 91 | #define util_assert(expression) _util_assert((expression), __FILE__, __LINE__) 92 | #else 93 | // Filename disabled to save code size. 94 | #define util_assert(expression) _util_assert((expression), "(file)", __LINE__) 95 | #endif 96 | void _util_assert(bool expression, const char *filename, uint16_t line); 97 | 98 | void util_assert_clear(void); 99 | 100 | #ifdef __cplusplus 101 | } 102 | #endif 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /src/pico-sigrok/sigrok_int.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | 27 | #include 28 | #include 29 | 30 | #include "sigrok_int.h" 31 | 32 | 33 | 34 | void sigrok_tx_init(sr_device_t *d) 35 | { 36 | //A reset should have already been called to restart the device. 37 | //An additional one here would clear trigger and other state that had been updated 38 | // reset(d); 39 | d->a_chan_cnt = 0; 40 | for (int i = 0; i < SR_NUM_A_CHAN; i++) { 41 | if (((d->a_mask) >> i) & 1) { 42 | d->a_chan_cnt++; 43 | } 44 | } 45 | //Nibbles per slice controls how PIO digital data is stored 46 | //Only support 0,1,2,4 or 8, which use 0,4,8,16 or 32 bits of PIO fifo data 47 | //per sample clock. 48 | d->d_nps = (d->d_mask & 0xF) ? 1 : 0; 49 | d->d_nps = (d->d_mask & 0xF0) ? (d->d_nps) + 1 : d->d_nps; 50 | d->d_nps = (d->d_mask & 0xFF00) ? (d->d_nps) + 2 : d->d_nps; 51 | d->d_nps = (d->d_mask & 0xFFFF0000) ? (d->d_nps) + 4 : d->d_nps; 52 | //Dealing with samples on a per nibble, rather than per byte basis in non D4 mode 53 | //creates a bunch of annoying special cases, so forcing non D4 mode to always store a minimum 54 | //of 8 bits. 55 | if (d->d_nps == 1 && d->a_chan_cnt > 0) { 56 | d->d_nps = 2; 57 | } 58 | 59 | //Digital channels must enable from D0 and go up, but that is checked by the host 60 | d->d_chan_cnt = 0; 61 | for (int i = 0; i < SR_NUM_D_CHAN; i++) { 62 | if (((d->d_mask) >> i) & 1) { 63 | // Dprintf("i %d inv %d mask %X\n",i,invld,d->d_mask); 64 | d->d_chan_cnt++; 65 | } 66 | } 67 | d->d_tx_bps = (d->d_chan_cnt + 6) / 7; 68 | 69 | d->sample_and_send = true; 70 | } // sigrok_tx_init 71 | 72 | 73 | 74 | // reset as part of init, or on a completed send 75 | void sigrok_reset(sr_device_t *d) 76 | { 77 | d->sample_and_send = false; 78 | d->continuous = false; 79 | d->aborted = false; 80 | d->all_started = false; 81 | d->scnt = 0; 82 | } // sigrok_reset 83 | 84 | 85 | 86 | //initial post reset state 87 | void sigrok_full_reset(sr_device_t *d) 88 | { 89 | sigrok_reset(d); 90 | d->a_mask = 0; 91 | d->d_mask = 0; 92 | d->d_mask_D4 = 0; 93 | d->sample_rate = 5000; 94 | d->num_samples = 10; 95 | d->a_chan_cnt = 0; 96 | d->d_chan_cnt = 0; 97 | d->d_nps = 0; 98 | d->cmdstr_ndx = 0; 99 | } // sigrok_full_reset 100 | -------------------------------------------------------------------------------- /src/pico-sigrok/sigrok.pio: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | // here a frequency 7x higher than the sampling rate is required, so that 27 | // no samples are missed at the trigger point. 28 | // Note that timing of the first three samples is still not correct. 29 | // My main concern was, that no transitions are missed. 30 | // Anyway due to the frequency division 31 | 32 | 33 | .program sigrok_d4_triggered 34 | 35 | public entry_d4: 36 | in pins, 4 [31] ; small start delay to get everything settled 37 | mov isr, null [31] 38 | in pins, 4 ; get start state and save it to X 39 | mov x, isr 40 | mov isr, null 41 | wait_loop: 42 | in pins, 4 ; get current state and save it to Y 43 | mov y, isr 44 | mov isr, null 45 | jmp x != y, triggered 46 | jmp wait_loop 47 | 48 | triggered: ; -> triggered 49 | in x, 4 ; store values of X and Y as first samples into ISR 50 | in y, 4 51 | 52 | .wrap_target 53 | in pins, 4 [6] ; sample 54 | .wrap 55 | 56 | 57 | 58 | .program sigrok_1b_triggered 59 | 60 | public entry_1b: 61 | in pins, 8 [31] ; small start delay to get everything settled 62 | mov isr, null [31] 63 | in pins, 8 ; get start state and save it to X 64 | mov x, isr 65 | mov isr, null 66 | wait_loop: 67 | in pins, 8 ; get current state and save it to Y 68 | mov y, isr 69 | mov isr, null 70 | jmp x != y, triggered 71 | jmp wait_loop 72 | 73 | triggered: ; -> triggered 74 | in x, 8 ; store values of X and Y as first samples into ISR 75 | in y, 8 76 | 77 | .wrap_target 78 | in pins, 8 [6] ; sample 79 | .wrap 80 | 81 | 82 | 83 | .program sigrok_2b_triggered 84 | 85 | public entry_2b: 86 | in pins, 16 [31] ; small start delay to get everything settled 87 | mov isr, null [31] 88 | in pins, 16 ; get start state and save it to X 89 | mov x, isr 90 | mov isr, null 91 | wait_loop: 92 | in pins, 16 ; get current state and save it to Y 93 | mov y, isr 94 | mov isr, null 95 | jmp x != y, triggered 96 | jmp wait_loop 97 | 98 | triggered: ; -> triggered 99 | in x, 16 ; store values of X and Y as first samples into ISR 100 | in y, 16 101 | 102 | .wrap_target 103 | in pins, 16 [6] ; sample 104 | .wrap 105 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile to build YAPicoprobe 2 | # 3 | # ATTENTION: to get the version number & git hash into the image, cmake-create-* has to be invoked. 4 | # 5 | 6 | VERSION_MAJOR := 1 7 | VERSION_MINOR := 2 8 | 9 | BUILD_DIR := build 10 | PROJECT := picoprobe 11 | 12 | 13 | GIT_HASH := $(shell git rev-parse --short HEAD) 14 | 15 | # CMAKE_FLAGS = -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake 16 | CMAKE_FLAGS = -DPICOPROBE_VERSION_MAJOR=$(VERSION_MAJOR) 17 | CMAKE_FLAGS += -DPICOPROBE_VERSION_MINOR=$(VERSION_MINOR) 18 | CMAKE_FLAGS += -DPROJECT=$(PROJECT) 19 | CMAKE_FLAGS += -DGIT_HASH=$(GIT_HASH) 20 | CMAKE_FLAGS += -DCMAKE_EXPORT_COMPILE_COMMANDS=True 21 | 22 | ifeq ($(PICO_BOARD),) 23 | # pico|pico_w|pico_debug_probe 24 | PICO_BOARD := pico 25 | endif 26 | 27 | 28 | 29 | .PHONY: clean 30 | clean: 31 | ninja -C $(BUILD_DIR) -v clean 32 | 33 | 34 | .PHONY: all 35 | all: 36 | ninja -C $(BUILD_DIR) -v all 37 | @echo "--------------------------" 38 | @arm-none-eabi-size -Ax $(BUILD_DIR)/$(PROJECT).elf | awk '{size=strtonum($$2); addr=strtonum($$3); if (addr>=0x20000000 && addr<0x20040000) ram += size; if (addr>=0x10000000 && addr<0x20000000) rom += size; } END {print "Flash: " rom " RAM: " ram}' 39 | @echo "--------------------------" 40 | 41 | 42 | .PHONY: details 43 | details: all 44 | @arm-none-eabi-size -Ax $(BUILD_DIR)/$(PROJECT).elf 45 | 46 | 47 | .PHONY: cmake-create-debug 48 | cmake-create-debug: 49 | cmake -B $(BUILD_DIR) -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DPICO_BOARD=$(PICO_BOARD) $(CMAKE_FLAGS) 50 | # don't know if this is required 51 | @cd $(BUILD_DIR) && sed -i 's/arm-none-eabi-gcc/gcc/' compile_commands.json 52 | 53 | 54 | .PHONY: cmake-create-release 55 | cmake-create-release: 56 | cmake -B $(BUILD_DIR) -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DPICO_BOARD=$(PICO_BOARD) $(CMAKE_FLAGS) 57 | # don't know if this is required 58 | @cd $(BUILD_DIR) && sed -i 's/arm-none-eabi-gcc/gcc/' compile_commands.json 59 | 60 | 61 | .PHONY: clean-build 62 | clean-build: 63 | rm -rf $(BUILD_DIR) 64 | 65 | 66 | .PHONY: flash 67 | flash: all 68 | @echo "Waiting for RPi bootloader..." 69 | @until [ -f /media/pico/INDEX.HTM ]; do sleep 0.1; done; echo "ready!" 70 | cp $(BUILD_DIR)/$(PROJECT).uf2 /media/pico 71 | @echo "ok." 72 | 73 | 74 | .PHONY: create-images 75 | create-images: 76 | $(MAKE) clean-build 77 | $(MAKE) cmake-create-debug PICO_BOARD=pico 78 | $(MAKE) all 79 | mkdir -p images 80 | cp $(BUILD_DIR)/$(PROJECT).uf2 images/delugeprobe-$(shell printf "%02d%02d" $(VERSION_MAJOR) $(VERSION_MINOR))-pico-$(GIT_HASH).uf2 81 | # 82 | $(MAKE) cmake-create-debug PICO_BOARD=pico_w 83 | $(MAKE) all 84 | cp $(BUILD_DIR)/$(PROJECT).uf2 images/delugeprobe-$(shell printf "%02d%02d" $(VERSION_MAJOR) $(VERSION_MINOR))-picow-$(GIT_HASH).uf2 85 | # 86 | $(MAKE) cmake-create-debug PICO_BOARD=pico_debug_probe 87 | $(MAKE) all 88 | cp $(BUILD_DIR)/$(PROJECT).uf2 images/delugeprobe-$(shell printf "%02d%02d" $(VERSION_MAJOR) $(VERSION_MINOR))-picodebugprobe-$(GIT_HASH).uf2 89 | # 90 | $(MAKE) cmake-create-debug PICO_BOARD=seeed_rp2040 91 | $(MAKE) all 92 | cp $(BUILD_DIR)/$(PROJECT).uf2 images/delugeprobe-$(shell printf "%02d%02d" $(VERSION_MAJOR) $(VERSION_MINOR))-seeed_xiao_rp2040-$(GIT_HASH).uf2 93 | # 94 | $(MAKE) cmake-create-debug PICO_BOARD=qt_py_rp2040 95 | $(MAKE) all 96 | cp $(BUILD_DIR)/$(PROJECT).uf2 images/delugeprobe-$(shell printf "%02d%02d" $(VERSION_MAJOR) $(VERSION_MINOR))-qt_py_rp2040-$(GIT_HASH).uf2 97 | 98 | 99 | .PHONY: check-clang 100 | check-clang: 101 | # clang-tidy has its limit if another target is used... 102 | @cd $(BUILD_DIR) && run-clang-tidy -checks='-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling' 103 | -------------------------------------------------------------------------------- /include/boards/pico_debug_probe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | // ----------------------------------------------------- 8 | // NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO 9 | // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES 10 | // ----------------------------------------------------- 11 | 12 | // This header may be included by other board headers as "boards/pico_debug_probe.h". 13 | // But normally this is included via "#include " if PICO_BOARD is set accordingly. 14 | // Schematic: https://datasheets.raspberrypi.com/debug/raspberry-pi-debug-probe-schematics.pdf 15 | 16 | #ifndef _BOARDS_PICO_DEBUG_PROBE_H 17 | #define _BOARDS_PICO_DEBUG_PROBE_H 18 | 19 | // For board detection 20 | #define RASPBERRYPI_PICO_DEBUG_PROBE 21 | 22 | // --- LED --- 23 | #ifndef PICO_DEFAULT_LED_PIN 24 | #define PICO_DEFAULT_LED_PIN 2 25 | #endif 26 | 27 | 28 | // --- FLASH --- 29 | 30 | #define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 31 | 32 | #ifndef PICO_FLASH_SPI_CLKDIV 33 | #define PICO_FLASH_SPI_CLKDIV 2 34 | #endif 35 | 36 | #ifndef PICO_FLASH_SIZE_BYTES 37 | #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) 38 | #endif 39 | 40 | #ifndef PICO_RP2040_B0_SUPPORTED 41 | #define PICO_RP2040_B0_SUPPORTED 0 42 | #endif 43 | 44 | 45 | 46 | // --- Definitions for YAPicoprobe 47 | 48 | #define PICOPROBE_LED PICO_DEFAULT_LED_PIN 49 | #define PICOPROBE_LED_CONNECTED 15 50 | #define PICOPROBE_LED_RUNNING 16 51 | #define PICOPROBE_LED_TARGET_RX 7 // host -> probe -> target UART / RTT data, i.e. target is receiving 52 | #define PICOPROBE_LED_TARGET_TX 8 // target -> probe -> host UART / RTT data, i.e. target is transmitting 53 | 54 | // PIO config 55 | #define PROBE_PIO pio0 56 | #define PROBE_SM 0 57 | #define PROBE_PIN_OFFSET 11 58 | #define PROBE_PIN_COUNT 4 59 | #define PROBE_PIN_SWDIR 11 // not used 60 | #define PROBE_PIN_SWCLK 12 61 | #define PROBE_PIN_SWDIN 13 // dedicated input 62 | #define PROBE_PIN_SWDIO 14 // used as output 63 | #define PROBE_PIN_RESET 17 // Target reset config (not connected) 64 | // #define PROBE_MAX_KHZ now in g_board_info.target_cfg->rt_max_swd_kHz, setup in pico::pico_prerun_board_config() 65 | 66 | // UART config (UART target -> probe) 67 | #define PICOPROBE_UART_TX 4 68 | #define PICOPROBE_UART_RX 5 // or 6 69 | #define PICOPROBE_UART_INTERFACE uart1 70 | #define PICOPROBE_UART_BAUDRATE 115200 71 | 72 | // 73 | // Other pin definitions 74 | // - LED actual handling is done in led.c, pin definition is PICOPROBE_LED / PICO_DEFAULT_LED_PIN 75 | // - sigrok defines are in pico-sigrok/sigrok-int.h 76 | // - Debug used in probe.c 77 | // 78 | 79 | 80 | // sigrok config 81 | #define SIGROK_PIO pio1 82 | #define SIGROK_SM 0 // often hard coded 83 | 84 | // Pin usage, this is from pico/pico_w 85 | // Currently sigrok cannot be used on the debug probe, so move sigrok on unused pins 86 | // GP0 and 1 are reserved for debug uart 87 | // GP2-GP22 are digital inputs 88 | // GP23 controls power supply modes and is not a board input 89 | // GP24-25 are not on the board and not used 90 | // GP26-28 are ADC. 91 | 92 | // number of analog channels 93 | #define SR_NUM_A_CHAN 2 94 | // first digital channel port 95 | #define SR_BASE_D_CHAN 18 96 | // number of digital channels 97 | #define SR_NUM_D_CHAN 8 98 | // Storage size of the DMA buffer. The buffer is split into two halves so that when the first 99 | // buffer fills we can send the trace data serially while the other buffer is DMA'd into. 100 | // 102000 buffer size allows 200000 of D4 samples. 101 | #define SR_DMA_BUF_SIZE 10000 102 | 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /src/misc_utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | /** 27 | * These functions are required because configSUPPORT_STATIC_ALLOCATION is set to one to allow 28 | * performance measurements of FreeRTOS. Code is taken from examples. 29 | */ 30 | 31 | 32 | #include "FreeRTOS.h" 33 | 34 | 35 | 36 | void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, 37 | StackType_t **ppxIdleTaskStackBuffer, 38 | uint32_t *pulIdleTaskStackSize ) 39 | { 40 | /* If the buffers to be provided to the Idle task are declared inside this 41 | function then they must be declared static - otherwise they will be allocated on 42 | the stack and so not exists after this function exits. */ 43 | static StaticTask_t xIdleTaskTCB; 44 | static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ]; 45 | 46 | /* Pass out a pointer to the StaticTask_t structure in which the Idle task's 47 | state will be stored. */ 48 | *ppxIdleTaskTCBBuffer = &xIdleTaskTCB; 49 | 50 | /* Pass out the array that will be used as the Idle task's stack. */ 51 | *ppxIdleTaskStackBuffer = uxIdleTaskStack; 52 | 53 | /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer. 54 | Note that, as the array is necessarily of type StackType_t, 55 | configMINIMAL_STACK_SIZE is specified in words, not bytes. */ 56 | *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; 57 | } // vApplicationGetIdleTaskMemory 58 | 59 | 60 | 61 | /* configSUPPORT_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the 62 | * application must provide an implementation of vApplicationGetTimerTaskMemory() 63 | * to provide the memory that is used by the Timer service task. */ 64 | void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize ) 65 | { 66 | /* If the buffers to be provided to the Timer task are declared inside this 67 | * function then they must be declared static - otherwise they will be allocated on 68 | * the stack and so not exists after this function exits. */ 69 | static StaticTask_t xTimerTaskTCB; 70 | static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ]; 71 | 72 | /* Pass out a pointer to the StaticTask_t structure in which the Timer 73 | task's state will be stored. */ 74 | *ppxTimerTaskTCBBuffer = &xTimerTaskTCB; 75 | 76 | /* Pass out the array that will be used as the Timer task's stack. */ 77 | *ppxTimerTaskStackBuffer = uxTimerTaskStack; 78 | 79 | /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer. 80 | Note that, as the array is necessarily of type StackType_t, 81 | configTIMER_TASK_STACK_DEPTH is specified in words, not bytes. */ 82 | *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; 83 | } // vApplicationGetTimerTaskMemory 84 | 85 | -------------------------------------------------------------------------------- /src/daplink/target/target_config.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file target_config.h 3 | * @brief 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2019, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef TARGET_CONFIG_H 23 | #define TARGET_CONFIG_H 24 | 25 | #include 26 | #include 27 | 28 | #include "flash_blob.h" 29 | #include "util.h" 30 | 31 | //! @brief Current target configuration version. 32 | //! 33 | //! - Version 1: Initial version. 34 | enum _target_config_version { 35 | kTargetConfigVersion = 1, //!< The current board info version. 36 | }; 37 | 38 | //! This can vary from target to target and should be in the structure or flash blob 39 | #define TARGET_AUTO_INCREMENT_PAGE_SIZE (1024) 40 | 41 | //! Additional flash and ram regions 42 | #define MAX_REGIONS (10) 43 | 44 | //! @brief Option flags for memory regions. 45 | enum _region_flags { 46 | kRegionIsDefault = (1 << 0), /*!< Out of bounds regions will use the same flash algo if this is set */ 47 | kRegionIsSecure = (1 << 1), /*!< The region can only be accessed from the secure world. Only applies for TrustZone-enabled targets. */ 48 | }; 49 | 50 | /*! 51 | * @brief Details of a target flash or RAM memory region. 52 | */ 53 | typedef struct __attribute__((__packed__)) region_info { 54 | uint32_t start; /*!< Region start address. */ 55 | uint32_t end; /*!< Region end address. */ 56 | uint32_t flags; /*!< Flags for this region from the #_region_flags enumeration. */ 57 | uint32_t alias_index; /*!< Use with flags; will point to a different index if there is an alias region */ 58 | program_target_t *flash_algo; /*!< A pointer to the flash algorithm structure */ 59 | } region_info_t; 60 | 61 | /*! 62 | * @brief Information required to program target flash. 63 | */ 64 | typedef struct __attribute__((__packed__)) target_cfg { 65 | uint32_t version; /*!< Target configuration version */ 66 | const sector_info_t* sectors_info; /*!< Sector start and length list */ 67 | uint32_t sector_info_length; /*!< Number of entries in the sectors_info array */ 68 | region_info_t flash_regions[MAX_REGIONS]; /*!< Flash regions */ 69 | region_info_t ram_regions[MAX_REGIONS]; /*!< RAM regions */ 70 | const char *rt_board_id; /*!< If assigned, this is a flexible board ID */ 71 | uint16_t rt_family_id; /*!< If assigned, this is a flexible family ID */ 72 | uint8_t erase_reset; /*!< Reset after performing an erase */ 73 | uint8_t pad; 74 | 75 | //! @name CMSIS-DAP v2.1 target strings 76 | //@{ 77 | char *target_vendor; /*!< Must match the Dvendor attribute value of the CMSIS DFP, excluding the 78 | colon and vendor code suffix when present. Maximum 60 characters including 79 | terminal NULL. */ 80 | char *target_part_number; /*!< Part number of the target device. Must match the Dname attribute value 81 | of the device's CMSIS DFP. Maximum 60 characters including terminal NULL. */ 82 | //@} 83 | 84 | uint32_t rt_uf2_id; //!< UF2 identification, see pico.c (rt = remote target?) 85 | uint16_t rt_max_swd_khz; //!< maximum SWD frequency in kHz 86 | uint16_t rt_swd_khz; //!< fair SWD frequency in kHz 87 | } target_cfg_t; 88 | 89 | extern target_cfg_t target_device; 90 | 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /src/daplink-pico/board/rp2040/pico_target_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #ifndef _PICO_TARGET_UTILS_H 27 | #define _PICO_TARGET_UTILS_H 28 | 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | 40 | #define TARGET_RP2040_FLASH_START 0x10000000 41 | #define TARGET_RP2040_FLASH_MAX_SIZE 0x10000000 42 | #define TARGET_RP2040_RAM_START 0x20000000 43 | 44 | #define TARGET_RP2040_STACK (TARGET_RP2040_RAM_START + 0x30800) 45 | 46 | 47 | // pre: flash connected, post: generic XIP active 48 | #define RP2040_FLASH_RANGE_ERASE(OFFS, CNT, BLKSIZE, CMD) \ 49 | do { \ 50 | _flash_exit_xip(); \ 51 | _flash_range_erase((OFFS), (CNT), (BLKSIZE), (CMD)); \ 52 | _flash_flush_cache(); \ 53 | _flash_enter_cmd_xip(); \ 54 | } while (0) 55 | 56 | // pre: flash connected, post: generic XIP active 57 | #define RP2040_FLASH_RANGE_PROGRAM(ADDR, DATA, LEN) \ 58 | do { \ 59 | _flash_exit_xip(); \ 60 | _flash_range_program((ADDR), (DATA), (LEN)); \ 61 | _flash_flush_cache(); \ 62 | _flash_enter_cmd_xip(); \ 63 | } while (0) 64 | 65 | // post: flash connected && fast or generic XIP active 66 | #define RP2040_FLASH_ENTER_CMD_XIP() \ 67 | do { \ 68 | _connect_internal_flash(); \ 69 | _flash_flush_cache(); \ 70 | if (*((uint32_t *)TARGET_RP2040_BOOT2) == 0xffffffff) { \ 71 | _flash_enter_cmd_xip(); \ 72 | } \ 73 | else { \ 74 | ((void (*)(void))TARGET_RP2040_BOOT2+1)(); \ 75 | } \ 76 | } while (0) 77 | 78 | 79 | #define rom_hword_as_ptr(rom_address) (void *)(uintptr_t)(*(uint16_t *)rom_address) 80 | #define fn(a, b) (uint32_t)((b << 8) | a) 81 | typedef void *(*rom_table_lookup_fn)(uint16_t *table, uint32_t code); 82 | 83 | 84 | typedef void *(*rom_void_fn)(void); 85 | typedef void *(*rom_flash_erase_fn)(uint32_t addr, size_t count, uint32_t block_size, uint8_t block_cmd); 86 | typedef void *(*rom_flash_prog_fn)(uint32_t addr, const uint8_t *data, size_t count); 87 | 88 | 89 | uint32_t rp2040_target_find_rom_func(char ch1, char ch2); 90 | bool rp2040_target_call_function(uint32_t addr, uint32_t args[], int argc, uint32_t *result); 91 | 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /include/lwipopts.h: -------------------------------------------------------------------------------- 1 | #ifndef _LWIPOPTS_EXAMPLE_COMMONH_H 2 | #define _LWIPOPTS_EXAMPLE_COMMONH_H 3 | 4 | // Common settings used in most of the pico_w examples 5 | // (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details) 6 | 7 | // allow override in some examples 8 | #ifndef NO_SYS 9 | #define NO_SYS 0 10 | #endif 11 | 12 | // allow override in some examples 13 | #ifndef LWIP_SOCKET 14 | #define LWIP_SOCKET 0 15 | #endif 16 | 17 | #if PICO_CYW43_ARCH_POLL 18 | #define MEM_LIBC_MALLOC 1 19 | #else 20 | // MEM_LIBC_MALLOC is incompatible with non polling versions 21 | #define MEM_LIBC_MALLOC 0 22 | #endif 23 | 24 | #define MEM_ALIGNMENT 4 25 | #define MEM_SIZE 4000 26 | #define MEMP_NUM_TCP_SEG 32 27 | #define MEMP_NUM_ARP_QUEUE 10 28 | #define PBUF_POOL_SIZE 24 29 | #define LWIP_ARP 1 30 | #define LWIP_ETHERNET 1 31 | #define LWIP_ICMP 1 32 | #define LWIP_RAW 1 33 | #define TCP_WND (8 * TCP_MSS) 34 | #define TCP_MSS 1460 35 | #define TCP_SND_BUF (8 * TCP_MSS) 36 | #define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS)) 37 | #define LWIP_NETIF_STATUS_CALLBACK 1 38 | #define LWIP_NETIF_LINK_CALLBACK 1 39 | #define LWIP_NETIF_HOSTNAME 1 40 | #define LWIP_NETCONN 0 41 | #define MEM_STATS 0 42 | #define SYS_STATS 0 43 | #define MEMP_STATS 0 44 | #define LINK_STATS 0 45 | // #define ETH_PAD_SIZE 2 46 | #define LWIP_CHKSUM_ALGORITHM 3 47 | #define LWIP_DHCP 1 48 | #define LWIP_IPV4 1 49 | #define LWIP_TCP 1 50 | #define LWIP_UDP 1 51 | #define LWIP_DNS 1 52 | #define LWIP_TCP_KEEPALIVE 1 53 | #define LWIP_NETIF_TX_SINGLE_PBUF 1 54 | #define DHCP_DOES_ARP_CHECK 0 55 | #define LWIP_DHCP_DOES_ACD_CHECK 0 56 | 57 | #ifndef NDEBUG 58 | #define LWIP_DEBUG 1 59 | #define LWIP_STATS 1 60 | #define LWIP_STATS_DISPLAY 1 61 | #endif 62 | 63 | #define ETHARP_DEBUG LWIP_DBG_OFF 64 | #define NETIF_DEBUG LWIP_DBG_OFF 65 | #define PBUF_DEBUG LWIP_DBG_OFF 66 | #define API_LIB_DEBUG LWIP_DBG_OFF 67 | #define API_MSG_DEBUG LWIP_DBG_OFF 68 | #define SOCKETS_DEBUG LWIP_DBG_OFF 69 | #define ICMP_DEBUG LWIP_DBG_OFF 70 | #define INET_DEBUG LWIP_DBG_OFF 71 | #define IP_DEBUG LWIP_DBG_OFF 72 | #define IP_REASS_DEBUG LWIP_DBG_OFF 73 | #define RAW_DEBUG LWIP_DBG_OFF 74 | #define MEM_DEBUG LWIP_DBG_OFF 75 | #define MEMP_DEBUG LWIP_DBG_OFF 76 | #define SYS_DEBUG LWIP_DBG_OFF 77 | #define TCP_DEBUG LWIP_DBG_OFF 78 | #define TCP_INPUT_DEBUG LWIP_DBG_OFF 79 | #define TCP_OUTPUT_DEBUG LWIP_DBG_OFF 80 | #define TCP_RTO_DEBUG LWIP_DBG_OFF 81 | #define TCP_CWND_DEBUG LWIP_DBG_OFF 82 | #define TCP_WND_DEBUG LWIP_DBG_OFF 83 | #define TCP_FR_DEBUG LWIP_DBG_OFF 84 | #define TCP_QLEN_DEBUG LWIP_DBG_OFF 85 | #define TCP_RST_DEBUG LWIP_DBG_OFF 86 | #define UDP_DEBUG LWIP_DBG_OFF 87 | #define TCPIP_DEBUG LWIP_DBG_OFF 88 | #define PPP_DEBUG LWIP_DBG_OFF 89 | #define SLIP_DEBUG LWIP_DBG_OFF 90 | #define DHCP_DEBUG LWIP_DBG_OFF 91 | 92 | 93 | #if !NO_SYS 94 | #define TCPIP_THREAD_STACKSIZE 1024 95 | #define DEFAULT_THREAD_STACKSIZE 1024 96 | #define DEFAULT_RAW_RECVMBOX_SIZE 8 97 | #define TCPIP_MBOX_SIZE 8 98 | #define LWIP_TIMEVAL_PRIVATE 0 99 | 100 | // not necessary, can be done either way 101 | #define LWIP_TCPIP_CORE_LOCKING_INPUT 1 102 | #endif 103 | 104 | #endif /* __LWIPOPTS_H__ */ 105 | -------------------------------------------------------------------------------- /doc/hardware.adoc: -------------------------------------------------------------------------------- 1 | :imagesdir: png 2 | :source-highlighter: rouge 3 | :toc: 4 | :toclevels: 5 5 | 6 | 7 | 8 | 9 | ## Hardware 10 | 11 | ### Existing Probe Hardware 12 | [%autowidth] 13 | [%header] 14 | |=== 15 | | Name | Comment 16 | 17 | | https://www.raspberrypi.com/products/debug-probe/[Raspberry Pi Debug Probe] 18 | | the "original" 19 | 20 | | https://mcuoneclipse.com/2023/04/08/open-source-picolink-raspberry-pi-rp2040-cmsis-dap-debug-probe/[picoLink] 21 | | Open Source picoLink: Raspberry Pi RP2040 CMSIS-DAP Debug Probe 22 | 23 | | https://github.com/tjko/tiny-picoprobe[tiny-picoprobe] 24 | | small PCB to mount a regular Pico Pi board to work without breadboard 25 | 26 | | https://github.com/Fabien-Chouteau/picoprobe-pcb[Pimoroni Probe PCB] 27 | | converts a Pi Pico into a simple probe (with standard SWD connector) 28 | 29 | | https://github.com/ene9ba/PicoProbeHolder[Pico Probe Holder] 30 | | Adapter which also provides 3.3V and 5V to the target 31 | 32 | | https://github.com/martijnvwezel/pico-probe-programmer[Pico Probe Programmer] 33 | | Another PCB adapter 34 | 35 | |=== 36 | 37 | All unfortunately without level shifters and without the possibility to use 38 | YaPicoprobes sigrok features. So there is some space left for other hardware 39 | (ideas). 40 | 41 | 42 | ### Pin Assignments 43 | 44 | .Pins Assignments Rasberry Pi Pico 45 | [%autowidth] 46 | [%header] 47 | |=== 48 | | Pin | Description 49 | 50 | | GP1 | SWDIR 51 | | GP2 | target SWCLK 52 | | GP3 | target SWDIO 53 | | GP4 | target UART-RX 54 | | GP5 | target UART-TX 55 | | GP6 | target /RESET (RUN) 56 | | GP10..17 | sigrok digital inputs 57 | | GP26/ADC0 | sigrok ADC0 58 | | GP27/ADC1 | sigrok ADC1 59 | | GP28/ADC2 | sigrok ADC2 60 | 61 | |=== 62 | 63 | .Other Pin Assigments Raspberry Pi Pico 64 | [%autowidth] 65 | [%header] 66 | |=== 67 | | Pin | Description | Pico W 68 | 69 | | GPIO0 | spare | 70 | | GPIO7..9 | spare | 71 | | GPIO18 | spare | 72 | | GPIO19..21 | debug pins (for probe debugging) | 73 | | GPIO22 | spare | 74 | | GPIO23 | power supply control | WL_ON 75 | | GPIO24 | USB sense | WL_D 76 | | GPIO25 | LED | WL_CS 77 | | GPIO29/ADC3 | VSYS/3 | WL_CLK 78 | |=== 79 | 80 | 81 | 82 | ### SWDIR / SWDIO 83 | 84 | Level shifter must be used to allow different voltage levels on probe and target. 85 | There are different switching circuits out there, e.g. 86 | 87 | * https://www.ti.com/product/TXS0108E[TXS0108E] (or TXS0102/4E) which 88 | allows 3.3V on probe side and up to 5V on target side for up to 8 signals 89 | * https://www.ti.com/product/SN74LXC1T45[74LXC1T45] which allows the same voltage levels 90 | for a single signal (depending of type) 91 | 92 | Because SWDIO is a bidirectional signal, the level shifter must 93 | switch between input and output. The TXS010xx does this automatically while the 74LXCxT45 94 | requires an SWDIR signal to control direction. 95 | 96 | Drawback of the automatic switching are much lower frequencies (\<=24MHz) which may pass 97 | the component and the condition Vcca\<=Vccb. So the TXS0108E is actually not 98 | recommended for this purpose. 99 | 100 | For a clean implementation SWDIR has been provided to allow support of the 74LXCxT45. The following image 101 | shows the timing of SWDIR, SWCLK and SWDIO. 102 | 103 | image::Screenshot_20230124_140906.png[SWDIR] 104 | 105 | 106 | ### sigrok 107 | 108 | For the sigrok input signals it's also good practice to use level shifter if the target 109 | uses other voltage levels than the probe. 110 | 111 | 112 | 113 | ### Ideas 114 | 115 | The firmware calls for a new hardware. To get a really nice probe, some 116 | level shifters , LEDs and power regulator for target supply would be required. 117 | 118 | Following parts could be used: 119 | 120 | * use 2x https://www.ti.com/product/SN74LXC1T45[74LXC1T45] for the SWD IF, 121 | largest package: 6 pin SOT-23 122 | * 7803 for power supply of target 123 | * https://www.ti.com/product/SN74LVC8T245[74LVC8T245] level shifter for sigrok input, 124 | 24 pin SOIC / _SOP_ packages are visible for soldering 125 | 126 | -------------------------------------------------------------------------------- /include/tusb_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #ifndef _TUSB_CONFIG_H_ 27 | #define _TUSB_CONFIG_H_ 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | //-------------------------------------------------------------------- 34 | // COMMON CONFIGURATION 35 | //-------------------------------------------------------------------- 36 | 37 | // defined by compiler flags for flexibility 38 | #ifndef CFG_TUSB_MCU 39 | #error CFG_TUSB_MCU must be defined 40 | #endif 41 | 42 | #define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE 43 | 44 | // force usage of FreeRTOS, can't be overwritten in CMakeLists.txt / Makefile 45 | #undef CFG_TUSB_OS 46 | #define CFG_TUSB_OS OPT_OS_FREERTOS 47 | 48 | 49 | #ifndef CFG_TUSB_MEM_SECTION 50 | #define CFG_TUSB_MEM_SECTION 51 | #endif 52 | 53 | #ifndef CFG_TUSB_MEM_ALIGN 54 | #define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4))) 55 | #endif 56 | 57 | //-------------------------------------------------------------------- 58 | // DEVICE CONFIGURATION 59 | //-------------------------------------------------------------------- 60 | 61 | #ifndef CFG_TUD_ENDPOINT0_SIZE 62 | #define CFG_TUD_ENDPOINT0_SIZE 64 63 | #endif 64 | 65 | //------------- CLASS -------------// 66 | 67 | //********************************************** 68 | // Functionality can be enabled/disabled here. 69 | // Note that still all modules are compiled. 70 | // This will change in the future. 71 | //********************************************** 72 | 73 | #define CFG_TUD_CDC_UART 1 // CDC for target UART IO 74 | #if !defined(TARGET_BOARD_PICO_DEBUG_PROBE) 75 | #define CFG_TUD_CDC_SIGROK 0 // CDC for sigrok IO 76 | #else 77 | #define CFG_TUD_CDC_SIGROK 0 // no sigrok for debug probe 78 | #endif 79 | #if !defined(NDEBUG) 80 | #define CFG_TUD_CDC_DEBUG 1 // CDC for debug output of the probe 81 | #else 82 | #define CFG_TUD_CDC_DEBUG 0 83 | #endif 84 | 85 | #define CFG_TUD_HID 1 // CMSIS-DAPv1 86 | #define CFG_TUD_VENDOR 1 // CMSIS-DAPv2 87 | #define CFG_TUD_MSC 1 // DAPLink drive 88 | #define CFG_TUD_CDC (CFG_TUD_CDC_UART + CFG_TUD_CDC_SIGROK + CFG_TUD_CDC_DEBUG) 89 | 90 | 91 | // CDC numbering (must go 0.. consecutive) 92 | #define CDC_UART_N (CFG_TUD_CDC_UART - 1) 93 | #define CDC_SIGROK_N (CFG_TUD_CDC_UART + CFG_TUD_CDC_SIGROK - 1) 94 | #define CDC_DEBUG_N (CFG_TUD_CDC_UART + CFG_TUD_CDC_SIGROK + CFG_TUD_CDC_DEBUG - 1) 95 | 96 | //------------- BUFFER SIZES -------------// 97 | 98 | #define CFG_TUD_CDC_RX_BUFSIZE 64 99 | #define CFG_TUD_CDC_TX_BUFSIZE 256 100 | 101 | // these numbers must be in the range 64..1024 (and the same) 102 | #define CFG_TUD_VENDOR_RX_BUFSIZE 1024 103 | #define CFG_TUD_VENDOR_TX_BUFSIZE CFG_TUD_VENDOR_RX_BUFSIZE 104 | 105 | // note: this is optimized for DAPLink write speed 106 | #define CFG_TUD_MSC_EP_BUFSIZE 512 107 | 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | #endif /* _TUSB_CONFIG_H_ */ 114 | -------------------------------------------------------------------------------- /include/boards/pico.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | // ----------------------------------------------------- 8 | // NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO 9 | // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES 10 | // ----------------------------------------------------- 11 | 12 | // This header may be included by other board headers as "boards/pico.h". 13 | // But normally this is included via "#include " if PICO_BOARD is set accordingly. 14 | 15 | #ifndef _BOARDS_PICO_H 16 | #define _BOARDS_PICO_H 17 | 18 | // For board detection 19 | #define RASPBERRYPI_PICO 20 | 21 | // --- UART --- 22 | #ifndef PICO_DEFAULT_UART 23 | #define PICO_DEFAULT_UART 0 24 | #endif 25 | #ifndef PICO_DEFAULT_UART_TX_PIN 26 | #define PICO_DEFAULT_UART_TX_PIN 0 27 | #endif 28 | #ifndef PICO_DEFAULT_UART_RX_PIN 29 | #define PICO_DEFAULT_UART_RX_PIN 1 30 | #endif 31 | 32 | // --- LED --- 33 | #ifndef PICO_DEFAULT_LED_PIN 34 | #define PICO_DEFAULT_LED_PIN 25 35 | #endif 36 | // no PICO_DEFAULT_WS2812_PIN 37 | 38 | // --- I2C --- 39 | #ifndef PICO_DEFAULT_I2C 40 | #define PICO_DEFAULT_I2C 0 41 | #endif 42 | #ifndef PICO_DEFAULT_I2C_SDA_PIN 43 | #define PICO_DEFAULT_I2C_SDA_PIN 4 44 | #endif 45 | #ifndef PICO_DEFAULT_I2C_SCL_PIN 46 | #define PICO_DEFAULT_I2C_SCL_PIN 5 47 | #endif 48 | 49 | // --- SPI --- 50 | #ifndef PICO_DEFAULT_SPI 51 | #define PICO_DEFAULT_SPI 0 52 | #endif 53 | #ifndef PICO_DEFAULT_SPI_SCK_PIN 54 | #define PICO_DEFAULT_SPI_SCK_PIN 18 55 | #endif 56 | #ifndef PICO_DEFAULT_SPI_TX_PIN 57 | #define PICO_DEFAULT_SPI_TX_PIN 19 58 | #endif 59 | #ifndef PICO_DEFAULT_SPI_RX_PIN 60 | #define PICO_DEFAULT_SPI_RX_PIN 16 61 | #endif 62 | #ifndef PICO_DEFAULT_SPI_CSN_PIN 63 | #define PICO_DEFAULT_SPI_CSN_PIN 17 64 | #endif 65 | 66 | // --- FLASH --- 67 | 68 | #define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 69 | 70 | #ifndef PICO_FLASH_SPI_CLKDIV 71 | #define PICO_FLASH_SPI_CLKDIV 2 72 | #endif 73 | 74 | #ifndef PICO_FLASH_SIZE_BYTES 75 | #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) 76 | #endif 77 | 78 | // Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) 79 | #define PICO_SMPS_MODE_PIN 23 80 | 81 | #ifndef PICO_RP2040_B0_SUPPORTED 82 | #define PICO_RP2040_B0_SUPPORTED 1 83 | #endif 84 | 85 | // Pin get VBUS 86 | #ifndef PICO_VBUS_PIN 87 | #define PICO_VBUS_PIN 24 88 | #endif 89 | 90 | // Pin used to monitor VSYS using ADC 91 | #ifndef PICO_VSYS_PIN 92 | #define PICO_VSYS_PIN 29 93 | #endif 94 | 95 | 96 | 97 | // --- Definitions for YAPicoprobe 98 | 99 | #define PICOPROBE_LED PICO_DEFAULT_LED_PIN 100 | 101 | // PIO config 102 | #define PROBE_PIO pio0 103 | #define PROBE_SM 0 104 | #define PROBE_PIN_OFFSET 1 105 | #define PROBE_PIN_COUNT 3 106 | #define PROBE_PIN_SWDIR (PROBE_PIN_OFFSET + 0) // 1 107 | #define PROBE_PIN_SWCLK (PROBE_PIN_OFFSET + 1) // 2 108 | #define PROBE_PIN_SWDIO (PROBE_PIN_OFFSET + 2) // 3 109 | #define PROBE_PIN_RESET 6 // Target reset config 110 | // #define PROBE_MAX_KHZ now in g_board_info.target_cfg->rt_max_swd_kHz, setup in pico::pico_prerun_board_config() 111 | 112 | // UART config (UART target -> probe) 113 | #define PICOPROBE_UART_TX 4 114 | #define PICOPROBE_UART_RX 5 115 | #define PICOPROBE_UART_INTERFACE uart1 116 | #define PICOPROBE_UART_BAUDRATE 115200 117 | 118 | // 119 | // Other pin definitions 120 | // - LED actual handling is done in led.c, pin definition is PICOPROBE_LED / PICO_DEFAULT_LED_PIN 121 | // - sigrok defines are in pico-sigrok/sigrok-int.h 122 | // - Debug used in probe.c 123 | // 124 | 125 | 126 | // sigrok config 127 | #define SIGROK_PIO pio1 128 | #define SIGROK_SM 0 // often hard coded 129 | 130 | //Pin usage 131 | //GP0 and 1 are reserved for debug uart 132 | //GP2-GP22 are digital inputs 133 | //GP23 controls power supply modes and is not a board input 134 | //GP24-25 are not on the board and not used 135 | //GP26-28 are ADC. 136 | 137 | // number of analog channels 138 | #define SR_NUM_A_CHAN 3 139 | // first digital channel port 140 | #define SR_BASE_D_CHAN 10 141 | // number of digital channels 142 | #define SR_NUM_D_CHAN 8 143 | // Storage size of the DMA buffer. The buffer is split into two halves so that when the first 144 | // buffer fills we can send the trace data serially while the other buffer is DMA'd into. 145 | // 102000 buffer size allows 200000 of D4 samples. 146 | #define SR_DMA_BUF_SIZE 102000 147 | 148 | 149 | #endif -------------------------------------------------------------------------------- /src/daplink/daplink/drag-n-drop/virtual_fs.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file virtual_fs.h 3 | * @brief FAT 12/16 filesystem handling 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef VIRTUAL_FS_H 23 | #define VIRTUAL_FS_H 24 | 25 | #include 26 | #include 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #define VFS_CLUSTER_SIZE 0x1000 33 | #define VFS_SECTOR_SIZE 512 34 | #define VFS_INVALID_SECTOR 0xFFFFFFFF 35 | #define VFS_FILE_INVALID 0 36 | #define VFS_MAX_FILES 16 37 | 38 | typedef char vfs_filename_t[11]; 39 | 40 | typedef enum { 41 | VFS_FILE_ATTR_READ_ONLY = (1 << 0), 42 | VFS_FILE_ATTR_HIDDEN = (1 << 1), 43 | VFS_FILE_ATTR_SYSTEM = (1 << 2), 44 | VFS_FILE_ATTR_VOLUME_LABEL = (1 << 3), 45 | VFS_FILE_ATTR_SUB_DIR = (1 << 4), 46 | VFS_FILE_ATTR_ARCHIVE = (1 << 5), 47 | } vfs_file_attr_bit_t; 48 | 49 | typedef enum { 50 | VFS_FILE_CREATED = 0, /*!< A new file was created */ 51 | VFS_FILE_DELETED, /*!< An existing file was deleted */ 52 | VFS_FILE_CHANGED, /*!< Some attribute of the file changed. 53 | Note: when a file is deleted or 54 | created a file changed 55 | notification will also occur*/ 56 | } vfs_file_change_t; 57 | 58 | typedef void *vfs_file_t; 59 | typedef uint32_t vfs_sector_t; 60 | 61 | // Callback for when data is written to a file on the virtual filesystem 62 | typedef void (*vfs_write_cb_t)(uint32_t sector_offset, const uint8_t *data, uint32_t num_sectors); 63 | // Callback for when data is ready from the virtual filesystem 64 | typedef uint32_t (*vfs_read_cb_t)(uint32_t sector_offset, uint8_t *data, uint32_t num_sectors); 65 | // Callback for when a file's attributes are changed on the virtual filesystem. Note that the 'file' parameter 66 | // can be saved and compared to other files to see if they are referencing the same object. The 67 | // same cannot be done with new_file_data since it points to a temporary buffer. 68 | typedef void (*vfs_file_change_cb_t)(const vfs_filename_t filename, vfs_file_change_t change, 69 | vfs_file_t file, vfs_file_t new_file_data); 70 | 71 | // Initialize the filesystem with the given size and name 72 | void vfs_init(const vfs_filename_t drive_name, uint32_t disk_size); 73 | 74 | // Get the total size of the virtual filesystem 75 | uint32_t vfs_get_total_size(void); 76 | 77 | // Add a file to the virtual FS and return a handle to this file. 78 | // This must be called before vfs_read or vfs_write are called. 79 | // Adding a new file after vfs_read or vfs_write have been called results in undefined behavior. 80 | vfs_file_t vfs_create_file(const vfs_filename_t filename, vfs_read_cb_t read_cb, vfs_write_cb_t write_cb, uint32_t len); 81 | 82 | // Set the attributes of a file 83 | void vfs_file_set_attr(vfs_file_t file, vfs_file_attr_bit_t attr); 84 | 85 | // Get the starting sector of this file. 86 | // NOTE - If the file size is 0 there is no starting 87 | // sector so VFS_INVALID_SECTOR will be returned. 88 | vfs_sector_t vfs_file_get_start_sector(vfs_file_t file); 89 | 90 | // Get the size of the file. 91 | uint32_t vfs_file_get_size(vfs_file_t file); 92 | 93 | // Get the attributes of a file 94 | vfs_file_attr_bit_t vfs_file_get_attr(vfs_file_t file); 95 | 96 | // Set the callback when a file is created, deleted or has atributes changed. 97 | void vfs_set_file_change_callback(vfs_file_change_cb_t cb); 98 | 99 | // Read one or more sectors from the virtual filesystem 100 | void vfs_read(uint32_t sector, uint8_t *buf, uint32_t num_of_sectors); 101 | 102 | // Write one or more sectors to the virtual filesystem 103 | void vfs_write(uint32_t sector, const uint8_t *buf, uint32_t num_of_sectors); 104 | 105 | // Validate 8.3 filenames 106 | bool filename_valid(const vfs_filename_t filename); 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /include/boards/qt_py_rp2040.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | // ----------------------------------------------------- 8 | // NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO 9 | // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES 10 | // ----------------------------------------------------- 11 | 12 | // This header may be included by other board headers as "boards/qt_py_rp2040.h". 13 | // But normally this is included via "#include " if PICO_BOARD is set accordingly. 14 | 15 | #ifndef _BOARDS_QT_PY_RP2040 16 | #define _BOARDS_QT_PY_RP2040 17 | 18 | // For board detection 19 | #define QT_PY_RP2040 20 | 21 | // --- UART --- 22 | #ifndef PICO_DEFAULT_UART 23 | #define PICO_DEFAULT_UART 0 24 | #endif 25 | #ifndef PICO_DEFAULT_UART_TX_PIN 26 | #define PICO_DEFAULT_UART_TX_PIN 0 27 | #endif 28 | #ifndef PICO_DEFAULT_UART_RX_PIN 29 | #define PICO_DEFAULT_UART_RX_PIN 1 30 | #endif 31 | 32 | // --- LED --- 33 | #ifndef PICO_DEFAULT_LED_PIN 34 | #define PICO_DEFAULT_LED_PIN 34 35 | #endif 36 | // no PICO_DEFAULT_WS2812_PIN 37 | 38 | // --- I2C --- 39 | #ifndef PICO_DEFAULT_I2C 40 | #define PICO_DEFAULT_I2C 1 41 | #endif 42 | #ifndef PICO_DEFAULT_I2C_SDA_PIN 43 | #define PICO_DEFAULT_I2C_SDA_PIN 22 44 | #endif 45 | #ifndef PICO_DEFAULT_I2C_SCL_PIN 46 | #define PICO_DEFAULT_I2C_SCL_PIN 23 47 | #endif 48 | 49 | // --- SPI --- 50 | #ifndef PICO_DEFAULT_SPI 51 | #define PICO_DEFAULT_SPI 1 52 | #endif 53 | #ifndef PICO_DEFAULT_SPI_SCK_PIN 54 | #define PICO_DEFAULT_SPI_SCK_PIN 14 55 | #endif 56 | #ifndef PICO_DEFAULT_SPI_TX_PIN 57 | #define PICO_DEFAULT_SPI_TX_PIN 15 58 | #endif 59 | #ifndef PICO_DEFAULT_SPI_RX_PIN 60 | #define PICO_DEFAULT_SPI_RX_PIN 16 61 | #endif 62 | #ifndef PICO_DEFAULT_SPI_CSN_PIN 63 | #define PICO_DEFAULT_SPI_CSN_PIN 17 64 | #endif 65 | 66 | // --- FLASH --- 67 | 68 | #define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 69 | 70 | #ifndef PICO_FLASH_SPI_CLKDIV 71 | #define PICO_FLASH_SPI_CLKDIV 2 72 | #endif 73 | 74 | #ifndef PICO_FLASH_SIZE_BYTES 75 | #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) 76 | #endif 77 | 78 | // Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) 79 | #define PICO_SMPS_MODE_PIN -1 80 | 81 | #ifndef PICO_RP2040_B0_SUPPORTED 82 | #define PICO_RP2040_B0_SUPPORTED 1 83 | #endif 84 | 85 | // Pin get VBUS 86 | #ifndef PICO_VBUS_PIN 87 | #define PICO_VBUS_PIN 19 88 | #endif 89 | 90 | // Pin used to monitor VSYS using ADC 91 | #ifndef PICO_VSYS_PIN 92 | #define PICO_VSYS_PIN 15 93 | #endif 94 | 95 | 96 | 97 | // --- Definitions for YAPicoprobe 98 | 99 | #define PICOPROBE_LED PICO_DEFAULT_LED_PIN 100 | 101 | // PIO config 102 | #define PROBE_PIO pio0 103 | #define PROBE_SM 0 104 | #define PROBE_PIN_OFFSET 2 105 | #define PROBE_PIN_COUNT 5 106 | #define PROBE_PIN_SWDIR 2 // ? 107 | // #define PROBE_PIN_SWDIR (PROBE_PIN_OFFSET + 0) // 1 108 | #define PROBE_PIN_SWCLK 6 109 | // #define PROBE_PIN_SWCLK (PROBE_PIN_OFFSET + 1) // 2 110 | #define PROBE_PIN_SWDIO 3 111 | // #define PROBE_PIN_SWDIO (PROBE_PIN_OFFSET + 2) // 3 112 | #define PROBE_PIN_RESET 21 // Target reset config 113 | // #define PROBE_MAX_KHZ now in g_board_info.target_cfg->rt_max_swd_kHz, setup in pico::pico_prerun_board_config() 114 | 115 | // UART config (UART target -> probe) 116 | #define PICOPROBE_UART_TX 20 117 | #define PICOPROBE_UART_RX 5 118 | #define PICOPROBE_UART_INTERFACE uart1 119 | #define PICOPROBE_UART_BAUDRATE 115200 120 | 121 | // 122 | // Other pin definitions 123 | // - LED actual handling is done in led.c, pin definition is PICOPROBE_LED / PICO_DEFAULT_LED_PIN 124 | // - sigrok defines are in pico-sigrok/sigrok-int.h 125 | // - Debug used in probe.c 126 | // 127 | 128 | 129 | // sigrok config 130 | #define SIGROK_PIO pio1 131 | #define SIGROK_SM 0 // often hard coded 132 | 133 | //Pin usage 134 | //GP0 and 1 are reserved for debug uart 135 | //GP2-GP22 are digital inputs 136 | //GP23 controls power supply modes and is not a board input 137 | //GP24-25 are not on the board and not used 138 | //GP26-28 are ADC. 139 | 140 | // number of analog channels 141 | #define SR_NUM_A_CHAN 4 142 | // first digital channel port 143 | #define SR_BASE_D_CHAN 24 144 | // number of digital channels 145 | #define SR_NUM_D_CHAN 2 146 | // Storage size of the DMA buffer. The buffer is split into two halves so that when the first 147 | // buffer fills we can send the trace data serially while the other buffer is DMA'd into. 148 | // 102000 buffer size allows 200000 of D4 samples. 149 | #define SR_DMA_BUF_SIZE 102000 150 | 151 | 152 | #endif 153 | -------------------------------------------------------------------------------- /include/boards/seeed_rp2040.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | // ----------------------------------------------------- 8 | // NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO 9 | // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES 10 | // ----------------------------------------------------- 11 | 12 | // This header may be included by other board headers as "boards/seeed_rp2040.h". 13 | // But normally this is included via "#include " if PICO_BOARD is set accordingly. 14 | 15 | #ifndef _BOARDS_SEEED_RP2040 16 | #define _BOARDS_SEEED_RP2040 17 | 18 | // For board detection 19 | #define SEEED_RP2040 20 | 21 | // --- UART --- 22 | #ifndef PICO_DEFAULT_UART 23 | #define PICO_DEFAULT_UART 0 24 | #endif 25 | #ifndef PICO_DEFAULT_UART_TX_PIN 26 | #define PICO_DEFAULT_UART_TX_PIN 0 27 | #endif 28 | #ifndef PICO_DEFAULT_UART_RX_PIN 29 | #define PICO_DEFAULT_UART_RX_PIN 1 30 | #endif 31 | 32 | // --- LED --- 33 | #ifndef PICO_DEFAULT_LED_PIN 34 | #define PICO_DEFAULT_LED_PIN 17 35 | #endif 36 | // no PICO_DEFAULT_WS2812_PIN 37 | 38 | // --- I2C --- 39 | #ifndef PICO_DEFAULT_I2C 40 | #define PICO_DEFAULT_I2C 1 41 | #endif 42 | #ifndef PICO_DEFAULT_I2C_SDA_PIN 43 | #define PICO_DEFAULT_I2C_SDA_PIN 22 44 | #endif 45 | #ifndef PICO_DEFAULT_I2C_SCL_PIN 46 | #define PICO_DEFAULT_I2C_SCL_PIN 23 47 | #endif 48 | 49 | // --- SPI --- 50 | #ifndef PICO_DEFAULT_SPI 51 | #define PICO_DEFAULT_SPI 0 52 | #endif 53 | #ifndef PICO_DEFAULT_SPI_SCK_PIN 54 | #define PICO_DEFAULT_SPI_SCK_PIN 18 55 | #endif 56 | #ifndef PICO_DEFAULT_SPI_TX_PIN 57 | #define PICO_DEFAULT_SPI_TX_PIN 19 58 | #endif 59 | #ifndef PICO_DEFAULT_SPI_RX_PIN 60 | #define PICO_DEFAULT_SPI_RX_PIN 20 61 | #endif 62 | #ifndef PICO_DEFAULT_SPI_CSN_PIN 63 | #define PICO_DEFAULT_SPI_CSN_PIN 21 64 | #endif 65 | 66 | // --- FLASH --- 67 | 68 | #define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 69 | 70 | #ifndef PICO_FLASH_SPI_CLKDIV 71 | #define PICO_FLASH_SPI_CLKDIV 2 72 | #endif 73 | 74 | #ifndef PICO_FLASH_SIZE_BYTES 75 | #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) 76 | #endif 77 | 78 | // Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads) 79 | #define PICO_SMPS_MODE_PIN -1 80 | 81 | #ifndef PICO_RP2040_B0_SUPPORTED 82 | #define PICO_RP2040_B0_SUPPORTED 1 83 | #endif 84 | 85 | // Pin get VBUS 86 | #ifndef PICO_VBUS_PIN 87 | #define PICO_VBUS_PIN 19 88 | #endif 89 | 90 | // Pin used to monitor VSYS using ADC 91 | #ifndef PICO_VSYS_PIN 92 | #define PICO_VSYS_PIN 15 93 | #endif 94 | 95 | 96 | 97 | // --- Definitions for YAPicoprobe 98 | 99 | #define PICOPROBE_LED PICO_DEFAULT_LED_PIN 100 | 101 | // PIO config 102 | #define PROBE_PIO pio0 103 | #define PROBE_SM 0 104 | #define PROBE_PIN_OFFSET 1 105 | #define PROBE_PIN_COUNT 3 106 | #define PROBE_PIN_SWDIR 1 // ? 107 | // #define PROBE_PIN_SWDIR (PROBE_PIN_OFFSET + 0) // 1 108 | #define PROBE_PIN_SWCLK 2 109 | // #define PROBE_PIN_SWCLK (PROBE_PIN_OFFSET + 1) // 2 110 | #define PROBE_PIN_SWDIO 3 111 | // #define PROBE_PIN_SWDIO (PROBE_PIN_OFFSET + 2) // 3 112 | #define PROBE_PIN_RESET 29 // Target reset config 113 | // #define PROBE_MAX_KHZ now in g_board_info.target_cfg->rt_max_swd_kHz, setup in pico::pico_prerun_board_config() 114 | 115 | // UART config (UART target -> probe) 116 | #define PICOPROBE_UART_TX 0 117 | #define PICOPROBE_UART_RX 1 118 | #define PICOPROBE_UART_INTERFACE uart0 119 | #define PICOPROBE_UART_BAUDRATE 115200 120 | 121 | // 122 | // Other pin definitions 123 | // - LED actual handling is done in led.c, pin definition is PICOPROBE_LED / PICO_DEFAULT_LED_PIN 124 | // - sigrok defines are in pico-sigrok/sigrok-int.h 125 | // - Debug used in probe.c 126 | // 127 | 128 | 129 | // sigrok config 130 | #define SIGROK_PIO pio1 131 | #define SIGROK_SM 0 // often hard coded 132 | 133 | //Pin usage 134 | //GP0 and 1 are reserved for debug uart 135 | //GP2-GP22 are digital inputs 136 | //GP23 controls power supply modes and is not a board input 137 | //GP24-25 are not on the board and not used 138 | //GP26-28 are ADC. 139 | 140 | // number of analog channels 141 | #define SR_NUM_A_CHAN 4 142 | // first digital channel port 143 | #define SR_BASE_D_CHAN 24 144 | // number of digital channels 145 | #define SR_NUM_D_CHAN 2 146 | // Storage size of the DMA buffer. The buffer is split into two halves so that when the first 147 | // buffer fills we can send the trace data serially while the other buffer is DMA'd into. 148 | // 102000 buffer size allows 200000 of D4 samples. 149 | #define SR_DMA_BUF_SIZE 102000 150 | 151 | 152 | #endif 153 | -------------------------------------------------------------------------------- /doc/benchmarks.adoc: -------------------------------------------------------------------------------- 1 | :imagesdir: png 2 | :source-highlighter: rouge 3 | :toc: 4 | :toclevels: 5 5 | 6 | 7 | 8 | 9 | ## Benchmarks 10 | 11 | ### SWD / Benchmarking 12 | Benchmarking is done with an image with a size around 400KByte. Command lines are as follows: 13 | 14 | * **cp**: `time cp firmware.uf2 /media/picoprobe/` 15 | * **OpenOCD 0.12.0-rc2** (CMSIS-DAP)v2: `time openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 25000" -c "program {firmware.elf} verify reset; shutdown;"` 16 | * **OpenOCD 0.12.0-rc2** (CMSIS-DAP)v1: `time openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "cmsis_dap_backend hid; adapter speed 25000" -c "program {firmware.elf} verify reset; shutdown;"` 17 | * **pyOCD 0.34.3**: `time pyocd flash -f 25000000 -t rp2040 firmware.elf`, pyOCD ignores silently "-O cmsis_dap.prefer_v1=true", except for the "list" option 18 | 19 | Note that benchmarking takes place under Linux. Surprisingly OpenOCD and pyOCD behave differently under Windows. 20 | DAPv2 is always used, because DAPv1 does not run under Linux(?). 21 | 22 | .CMSIS-DAP Benchmarks 23 | [%header] 24 | |=== 25 | |command / version | cp | OpenOCD DAPv1 | OpenOCD DAPv2 | pyOCD DAPv2 | comment 26 | 27 | | very early version | - | - | 10.4s | - | 28 | 29 | | v1.00 | 6.4s | - | 8.1s | 16.5s | 30 | 31 | | git-3120a90 | 5.7s | - | 7.8s | 15.4s | 32 | 33 | | - same but NDEBUG -| 7.3s | - | 9.5s | 16.6s 34 | | a bad miracle... to make things worse, pyOCD is very instable 35 | 36 | | git-bd8c41f | 5.7s | 28.6s | 7.7s | 19.9s 37 | | there was a python update :-/ 38 | 39 | | git-0d6c6a8 | 5.7s | 28.5s | 6.8s | 20.2s | 40 | 41 | | - same but optimized for OpenOCD | 5.7s | 28.5s | 6.1s | - | pyOCD crashes 42 | 43 | | git-0eba8bf | 4.9s | 28.6s | 6.5s | 13.8s | cp shows sometimes 5.4s 44 | 45 | | - same but optimized for OpenOCD | 4.9s | 28.6s | 5.8s | - | pyOCD crashes 46 | 47 | | git-e38fa52 | 4.8s | 28.6s | 6.6s | 14.0s | cp shows sometimes 5.4s 48 | 49 | | - same but optimized for OpenOCD | 4.8s | 28.6s | 5.9s | - | pyOCD crashes 50 | 51 | | git-28fd8db | 4.1s | 28.6s | 6.2s | 13.9s | cp shows sometimes 4.6s, SWCLK tuned to 25MHz 52 | 53 | | - same but optimized for OpenOCD | 4.1s | 28.6s | 5.7s | - | pyOCD crashes 54 | |=== 55 | 56 | ### Comparison with picoprobe and automated_test.py of pyOCD 57 | 58 | There is a good benchmark (actually the functional tests) in pyOCD: 59 | `automated_test.py`. For configuration check https://github.com/pyocd/pyOCD/blob/main/docs/automated_tests.md 60 | 61 | Comparing the original picoprobe firmware (running on the official Raspi Pico Debug Probe) 62 | and YAPicoprobe shows the following picture: 63 | 64 | .Benchmarking with automated_test.py 65 | [%header] 66 | |=== 67 | | Probe HW | Probe FW | Target | 1.1MHz | 2MHz | 4MHz | 6MHz | 8MHz 68 | 69 | | Debug Probe 70 | | Original Picoprobe (https://github.com/raspberrypi/picoprobe/releases/latest/download/debugprobe.uf2[download]) 71 | | nRF52840 dongle 72 | | 586s 73 | | 583s 74 | | 580s 75 | | 581s 76 | | (-) 77 | 78 | | Debug Probe 79 | | YAPicoprobe 80 | | nRF52840 dongle 81 | | 327s 82 | | 236s 83 | | 192s 84 | | 171s (*) 85 | | (-) 86 | 87 | | Pi Pico W 88 | | YAPicoprobe 89 | | nRF52840 dongle 90 | | 332s 91 | | 234s 92 | | 192s 93 | | 177s 94 | | (-) 95 | 96 | |||||||| 97 | 98 | | Debug Probe 99 | | Original Picoprobe (https://github.com/raspberrypi/picoprobe/releases/latest/download/debugprobe.uf2[download]) 100 | | PCA10056 101 | | 586s 102 | | 582s 103 | | 581s 104 | | 580s 105 | | 580s 106 | 107 | | Debug Probe 108 | | YAPicoprobe 109 | | PCA10056 110 | | 322s 111 | | 233s 112 | | 189s 113 | | 183s 114 | | 244s 115 | 116 | | Pi Pico W 117 | | YAPicoprobe 118 | | PCA10056 119 | | 120 | | 237s 121 | | 193s 122 | | 178s 123 | | 173s 124 | 125 | |=== 126 | 127 | (*) unexpected error only observed in conjuntion with the nRF52840 dongle. 128 | 129 | 130 | Tests were performed with the following configuration: 131 | 132 | ```yaml 133 | probes: 134 | : 135 | frequency: [12468]000000 136 | target_override: nrf52840 137 | test_binary: l1_nrf52840-dk.bin 138 | ``` 139 | 140 | Findings are not completely clear: 141 | 142 | * the original probe firmware is very slow, no clue about the actual reason. Weird is that runtime with the 143 | original firmware is not frequency dependant 144 | 145 | * there seems to be a frequency limit of the debug probe HW 146 | at around 6MHz due to its in-series resistors (runtime increase from 6 to 8MHz) 147 | 148 | * the nRF52840 dongle has problems with >=6MHz as well. Either a PCB or a nRF52840 part problem. 149 | Max frequency of 4MHz should be used 150 | 151 | * good setups are 152 | ** YAPicoprobe + PCA10056 @ 6MHz 153 | ** YAPicoprobe + nRF52840 dongle @ 4MHz 154 | 155 | -------------------------------------------------------------------------------- /include/boards/pico_w.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | // ----------------------------------------------------- 8 | // NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO 9 | // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES 10 | // ----------------------------------------------------- 11 | 12 | // This header may be included by other board headers as "boards/pico.h". 13 | // But normally this is included via "#include " if PICO_BOARD is set accordingly. 14 | 15 | #ifndef _BOARDS_PICO_W_H 16 | #define _BOARDS_PICO_W_H 17 | 18 | // For board detection 19 | #define RASPBERRYPI_PICO_W 20 | 21 | // --- UART --- 22 | #ifndef PICO_DEFAULT_UART 23 | #define PICO_DEFAULT_UART 0 24 | #endif 25 | #ifndef PICO_DEFAULT_UART_TX_PIN 26 | #define PICO_DEFAULT_UART_TX_PIN 0 27 | #endif 28 | #ifndef PICO_DEFAULT_UART_RX_PIN 29 | #define PICO_DEFAULT_UART_RX_PIN 1 30 | #endif 31 | 32 | // --- LED --- 33 | // no PICO_DEFAULT_LED_PIN - LED is on Wireless chip 34 | // no PICO_DEFAULT_WS2812_PIN 35 | 36 | // --- I2C --- 37 | #ifndef PICO_DEFAULT_I2C 38 | #define PICO_DEFAULT_I2C 0 39 | #endif 40 | #ifndef PICO_DEFAULT_I2C_SDA_PIN 41 | #define PICO_DEFAULT_I2C_SDA_PIN 4 42 | #endif 43 | #ifndef PICO_DEFAULT_I2C_SCL_PIN 44 | #define PICO_DEFAULT_I2C_SCL_PIN 5 45 | #endif 46 | 47 | // --- SPI --- 48 | #ifndef PICO_DEFAULT_SPI 49 | #define PICO_DEFAULT_SPI 0 50 | #endif 51 | #ifndef PICO_DEFAULT_SPI_SCK_PIN 52 | #define PICO_DEFAULT_SPI_SCK_PIN 18 53 | #endif 54 | #ifndef PICO_DEFAULT_SPI_TX_PIN 55 | #define PICO_DEFAULT_SPI_TX_PIN 19 56 | #endif 57 | #ifndef PICO_DEFAULT_SPI_RX_PIN 58 | #define PICO_DEFAULT_SPI_RX_PIN 16 59 | #endif 60 | #ifndef PICO_DEFAULT_SPI_CSN_PIN 61 | #define PICO_DEFAULT_SPI_CSN_PIN 17 62 | #endif 63 | 64 | // --- FLASH --- 65 | 66 | #define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 67 | 68 | #ifndef PICO_FLASH_SPI_CLKDIV 69 | #define PICO_FLASH_SPI_CLKDIV 2 70 | #endif 71 | 72 | #ifndef PICO_FLASH_SIZE_BYTES 73 | #define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024) 74 | #endif 75 | 76 | // note the SMSP mode pin is on WL_GPIO1 77 | // #define PICO_SMPS_MODE_PIN 78 | 79 | #ifndef PICO_RP2040_B0_SUPPORTED 80 | #define PICO_RP2040_B0_SUPPORTED 0 81 | #endif 82 | 83 | #ifndef PICO_RP2040_B1_SUPPORTED 84 | #define PICO_RP2040_B1_SUPPORTED 0 85 | #endif 86 | 87 | #ifndef CYW43_PIN_WL_HOST_WAKE 88 | #define CYW43_PIN_WL_HOST_WAKE 24 89 | #endif 90 | 91 | #ifndef CYW43_PIN_WL_REG_ON 92 | #define CYW43_PIN_WL_REG_ON 23 93 | #endif 94 | 95 | #ifndef CYW43_WL_GPIO_COUNT 96 | #define CYW43_WL_GPIO_COUNT 3 97 | #endif 98 | 99 | #ifndef CYW43_WL_GPIO_LED_PIN 100 | #define CYW43_WL_GPIO_LED_PIN 0 101 | #endif 102 | 103 | // CYW43 GPIO to get VBUS 104 | #ifndef CYW43_WL_GPIO_VBUS_PIN 105 | #define CYW43_WL_GPIO_VBUS_PIN 2 106 | #endif 107 | 108 | // VSYS pin is shared with CYW43 109 | #ifndef CYW43_USES_VSYS_PIN 110 | #define CYW43_USES_VSYS_PIN 1 111 | #endif 112 | 113 | // Pin used to monitor VSYS using ADC 114 | #ifndef PICO_VSYS_PIN 115 | #define PICO_VSYS_PIN 29 116 | #endif 117 | 118 | 119 | // --- Definitions for YAPicoprobe 120 | 121 | // PIO config 122 | #define PROBE_PIO pio0 123 | #define PROBE_SM 0 124 | #define PROBE_PIN_OFFSET 1 125 | #define PROBE_PIN_COUNT 3 126 | #define PROBE_PIN_SWDIR (PROBE_PIN_OFFSET + 0) // 1 127 | #define PROBE_PIN_SWCLK (PROBE_PIN_OFFSET + 1) // 2 128 | #define PROBE_PIN_SWDIO (PROBE_PIN_OFFSET + 2) // 3 129 | #define PROBE_PIN_RESET 6 // Target reset config 130 | // #define PROBE_MAX_KHZ now in g_board_info.target_cfg->rt_max_swd_kHz, setup in pico::pico_prerun_board_config() 131 | 132 | // UART config (UART target -> probe) 133 | #define PICOPROBE_UART_TX 4 134 | #define PICOPROBE_UART_RX 5 135 | #define PICOPROBE_UART_INTERFACE uart1 136 | #define PICOPROBE_UART_BAUDRATE 115200 137 | 138 | // 139 | // Other pin definitions 140 | // - LED actual handling is done in led.c, pin definition is PICOPROBE_LED / PICO_DEFAULT_LED_PIN 141 | // - sigrok defines are in pico-sigrok/sigrok-int.h 142 | // - Debug used in probe.c 143 | // 144 | 145 | 146 | // sigrok config 147 | #define SIGROK_PIO pio1 148 | #define SIGROK_SM 0 // often hard coded 149 | 150 | //Pin usage 151 | //GP0 and 1 are reserved for debug uart 152 | //GP2-GP22 are digital inputs 153 | //GP24-25 are not on the board and not used 154 | //GP26-28 are ADC. 155 | 156 | // number of analog channels 157 | #define SR_NUM_A_CHAN 3 158 | // first digital channel port 159 | #define SR_BASE_D_CHAN 10 160 | // number of digital channels 161 | #define SR_NUM_D_CHAN 8 162 | // Storage size of the DMA buffer. The buffer is split into two halves so that when the first 163 | // buffer fills we can send the trace data serially while the other buffer is DMA'd into. 164 | // 102000 buffer size allows 200000 of D4 samples. 165 | #define SR_DMA_BUF_SIZE 62000 166 | 167 | 168 | #endif 169 | -------------------------------------------------------------------------------- /src/pico-sigrok/sigrok_int.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #ifndef SIGROK_INT_H 27 | #define SIGROK_INT_H 28 | 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | 40 | //Pin usage 41 | //GP0 and 1 are reserved for debug uart 42 | //GP2-GP22 are digital inputs 43 | //GP23 controls power supply modes and is not a board input 44 | //GP24-25 are not on the board and not used 45 | //GP26-28 are ADC. 46 | #if !defined(SR_NUM_A_CHAN) 47 | #warning "sigrok: reverting to a default configuration" 48 | #define SR_NUM_A_CHAN 3 49 | // first digital channel port 50 | #define SR_BASE_D_CHAN 2 51 | // number of digital channels 52 | #define SR_NUM_D_CHAN 21 53 | // Storage size of the DMA buffer. The buffer is split into two halves so that when the first 54 | // buffer fills we can send the trace data serially while the other buffer is DMA'd into 55 | #define SR_DMA_BUF_SIZE 220000 56 | #endif 57 | 58 | // Mask for the digital channels fetched from PIO 59 | #define SR_PIO_D_MASK ((1 << (SR_NUM_D_CHAN)) - 1) 60 | 61 | // Mask for the digital channels at GPIO level 62 | #define SR_GPIO_D_MASK (((1 << (SR_NUM_D_CHAN)) - 1) << (SR_BASE_D_CHAN)) 63 | 64 | // Mask for analog channels 65 | #define SR_ADC_A_MASK (((1 << (SR_NUM_A_CHAN)) - 1)) 66 | 67 | 68 | #if 1 && !defined(NDEBUG) 69 | #define Dprintf(format,args...) printf("(SR) " format, ## args) 70 | #else 71 | #define Dprintf(format,...) ((void)0) 72 | #endif 73 | 74 | 75 | typedef struct sr_device { 76 | uint32_t sample_rate; 77 | uint32_t num_samples; 78 | uint32_t a_mask; //!< enable mask for analog channels (bit 0..(SR_NUM_A_CHAN-1)) 79 | uint32_t d_mask; //!< enable mask for digital channels (bit 0..(SR_NUM_D_CHAN-1)) 80 | uint32_t d_mask_D4; //!< enable mask for send_slices_D4() operation 81 | uint32_t samples_per_half; //!< number of samples for one of the 4 dma target arrays 82 | uint8_t a_chan_cnt; //!< count of enabled analog channels 83 | uint8_t d_chan_cnt; //!< count of enabled digital channels 84 | uint8_t d_tx_bps; //Digital Transmit bytes per slice 85 | //Pins sampled by the PIO - 4,8,16 or 32 86 | uint8_t pin_count; 87 | uint8_t d_nps; //digital nibbles per slice from a PIO/DMA perspective. 88 | uint32_t scnt; //number of samples sent 89 | uint32_t d_size,a_size; //size of each of the two data buffers for each of a& d 90 | uint32_t dbuf0_start,dbuf1_start,abuf0_start,abuf1_start; //starting memory pointers of adc buffers 91 | 92 | uint32_t cmdstr_ndx; //!< index into \a cmdstr 93 | char cmdstr[30]; //!< used for parsing input 94 | char rspstr[30]; //!< response string of a \a cmdstr 95 | 96 | // mark key control variables volatile since multiple cores might access them 97 | volatile bool all_started; //!< sampling and transmission has been started (incl initialization) 98 | volatile bool sample_and_send; //!< sample and send data 99 | volatile bool continuous; //!< continuous sample mode 100 | volatile bool aborted; //!< abort sampling and transmission (due to host command or overflow) 101 | volatile bool send_resp; //!< send the response string contained in \a rspstr 102 | } sr_device_t; 103 | 104 | 105 | // 106 | // shared between modules 107 | // 108 | extern sr_device_t sr_dev; 109 | 110 | void sigrok_tx_init(sr_device_t *d); 111 | void sigrok_reset(sr_device_t *d); 112 | void sigrok_full_reset(sr_device_t *d); 113 | 114 | void sigrok_notify(void); 115 | 116 | #ifdef __cplusplus 117 | } 118 | #endif 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /src/daplink/daplink/util.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file util.c 3 | * @brief Implementation of util.h 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #include 23 | 24 | #include "util.h" 25 | #include "settings.h" 26 | #include "cortex_m.h" 27 | 28 | //remove dependency from vfs_manager 29 | __WEAK void vfs_mngr_fs_remount(void) {} 30 | 31 | uint32_t util_write_hex8(char *str, uint8_t value) 32 | { 33 | static const char nybble_chars[] = "0123456789abcdef"; 34 | *(str + 0) = nybble_chars[(value >> 4) & 0x0F ]; 35 | *(str + 1) = nybble_chars[(value >> 0) & 0x0F ]; 36 | return 2; 37 | } 38 | 39 | uint32_t util_write_hex16(char *str, uint16_t value) 40 | { 41 | uint32_t pos = 0; 42 | pos += util_write_hex8(str + pos, (value >> 8) & 0xFF); 43 | pos += util_write_hex8(str + pos, (value >> 0) & 0xFF); 44 | return pos; 45 | } 46 | 47 | uint32_t util_write_hex32(char *str, uint32_t value) 48 | { 49 | uint32_t pos = 0; 50 | pos += util_write_hex8(str + pos, (value >> 0x18) & 0xFF); 51 | pos += util_write_hex8(str + pos, (value >> 0x10) & 0xFF); 52 | pos += util_write_hex8(str + pos, (value >> 0x08) & 0xFF); 53 | pos += util_write_hex8(str + pos, (value >> 0x00) & 0xFF); 54 | return pos; 55 | } 56 | 57 | uint32_t util_write_uint32(char *str, uint32_t value) 58 | { 59 | uint32_t temp_val; 60 | uint64_t digits; 61 | uint32_t i; 62 | // Count the number of digits 63 | digits = 0; 64 | temp_val = value; 65 | 66 | while (temp_val > 0) { 67 | temp_val /= 10; 68 | digits += 1; 69 | } 70 | 71 | if (digits <= 0) { 72 | digits = 1; 73 | } 74 | 75 | // Write the number 76 | for (i = 0; i < digits; i++) { 77 | str[digits - i - 1] = '0' + (value % 10); 78 | value /= 10; 79 | } 80 | 81 | return digits; 82 | } 83 | 84 | uint32_t util_write_uint32_zp(char *str, uint32_t value, uint16_t total_size) 85 | { 86 | uint32_t size; 87 | // Get the size of value 88 | size = util_write_uint32(str, value); 89 | 90 | if (size >= total_size) { 91 | return size; 92 | } 93 | 94 | // Zero fill 95 | memset(str, '0', total_size); 96 | // Write value 97 | util_write_uint32(str + (total_size - size), value); 98 | return total_size; 99 | } 100 | 101 | uint32_t util_write_string(char *str, const char *data) 102 | { 103 | uint32_t pos = 0; 104 | 105 | while (0 != data[pos]) { 106 | str[pos] = data[pos]; 107 | pos++; 108 | } 109 | 110 | return pos; 111 | } 112 | 113 | uint32_t util_write_string_in_region(uint8_t *buf, uint32_t size, uint32_t start, uint32_t pos, const char *input) { 114 | return util_write_in_region(buf, size, start, pos, input, strlen(input)); 115 | } 116 | 117 | uint32_t util_write_in_region(uint8_t *buf, uint32_t size, uint32_t start, uint32_t pos, const char *input, uint32_t length) { 118 | if (buf != NULL) { 119 | // Check if there is something to copy 120 | if (((pos + length) >= start) && (pos <= (start + size))) { 121 | uint32_t i_off = 0; 122 | uint32_t o_off = 0; 123 | uint32_t l = length; 124 | if (pos < start) { 125 | i_off = start - pos; 126 | l -= i_off; 127 | } else { 128 | o_off = pos - start; 129 | } 130 | if ((pos + length) > (start + size)) { 131 | l -= (pos + length) - (start + size); 132 | } 133 | memcpy(buf + o_off, input + i_off, l); 134 | } 135 | } 136 | 137 | return length; 138 | } 139 | 140 | void _util_assert(bool expression, const char *filename, uint16_t line) 141 | { 142 | bool assert_set; 143 | cortex_int_state_t int_state; 144 | 145 | if (expression) { 146 | return; 147 | } 148 | 149 | int_state = cortex_int_get_and_disable(); 150 | // Only write the assert if there is not already one 151 | assert_set = config_ram_get_assert(0, 0, 0, 0); 152 | 153 | if (!assert_set) { 154 | config_ram_set_assert(filename, line); 155 | } 156 | 157 | cortex_int_restore(int_state); 158 | 159 | // Start a remount if this is the first assert 160 | // Do not call vfs_mngr_fs_remount from an ISR! 161 | if (!assert_set && !cortex_in_isr()) { 162 | vfs_mngr_fs_remount(); 163 | } 164 | } 165 | 166 | void util_assert_clear() 167 | { 168 | cortex_int_state_t int_state; 169 | int_state = cortex_int_get_and_disable(); 170 | config_ram_clear_assert(); 171 | cortex_int_restore(int_state); 172 | } 173 | -------------------------------------------------------------------------------- /src/daplink/target/target_board.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file target_board.h 3 | * @brief 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2018-2019, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef TARGET_BOARD_H 23 | #define TARGET_BOARD_H 24 | 25 | #include 26 | #include "target_config.h" 27 | #include "target_family.h" 28 | #include "virtual_fs.h" 29 | 30 | //! @brief Current board info version. 31 | //! 32 | //! - Version 1: Initial version. 33 | enum _board_info_version { 34 | kBoardInfoVersion = 1, //!< The current board info version. 35 | }; 36 | 37 | //! @brief Flags for board_info 38 | enum _board_info_flags { 39 | kEnablePageErase = (1 << 0), /*!< Enable page programming and sector erase for drag and drop */ 40 | kEnableUnderResetConnect = (1 << 1), /*!< Enable under reset connection when enabling debug mode */ 41 | }; 42 | 43 | /*! 44 | * @brief Board customization info. 45 | * 46 | * Each board must have a unique 4-character Board ID. For Mbed OS targets, the Board ID is the same 47 | * as the Mbed Platform ID. These IDs are nominally allocated by Arm in order to guarantee there are 48 | * no conflicts between boards. Please see the DAPLink documentation for more. 49 | * 50 | * The family_id member tells DAPLink which device family the on-board target belongs to. This then 51 | * determines certain behaviours, such as how to reset the target. Family IDs are defined in the 52 | * #family_id_t enumeration. 53 | * 54 | * The board initialization function pointers allow the board to override the routines defined 55 | * by the device family. 56 | */ 57 | typedef struct board_info { 58 | uint16_t info_version; /*!< Version number of the board info */ 59 | uint16_t family_id; /*!< Use to select or identify target family from defined target family or custom ones */ 60 | char board_id[5]; /*!< 4-char board ID plus null terminator */ 61 | uint8_t _padding[3]; 62 | uint32_t flags; /*!< Flags from #_board_info_flags */ 63 | target_cfg_t *target_cfg; /*!< Specific chip configuration for the target and enables MSD when non-NULL */ 64 | 65 | //! @name MSD customization 66 | //@{ 67 | vfs_filename_t daplink_url_name; /*!< Customize the URL file name */ 68 | vfs_filename_t daplink_drive_name; /*!< Customize the MSD DAPLink drive name */ 69 | char daplink_target_url[64]; /*!< Customize the target url in DETAILS.TXT */ 70 | //@} 71 | 72 | //! @name Board initialization customization 73 | //@{ 74 | void (*prerun_board_config)(void); /*!< Specific board debug/ID related initialization */ 75 | void (*swd_set_target_reset)(uint8_t asserted); /*!< Boards can customize how to send reset to the target with precedence over target family */ 76 | uint8_t (*target_set_state)(target_state_t state); /*!< Boards can customize target debug states with precedence over target family */ 77 | uint32_t soft_reset_type; /*!< Boards can override software reset type to VECTRESET or SYSRESETREQ */ 78 | //@} 79 | 80 | //! @name CMSIS-DAP v2.1 board strings 81 | //@{ 82 | char *board_vendor; //!< Board vendor. Maximum 60 characters including terminal NULL. 83 | char *board_name; //!< Board name. Maximum 60 characters including terminal NULL. 84 | //@} 85 | } board_info_t; 86 | 87 | //! @brief Information describing the board on which DAPLink is running. 88 | extern const board_info_t g_board_info; 89 | 90 | #ifdef __cplusplus 91 | extern "C" { 92 | #endif 93 | 94 | //! @brief Returns the 4-char ID of the board used by the running firmware. 95 | //! 96 | //! For firmware with no board, the board ID is "0000". 97 | const char * get_board_id(void); 98 | 99 | //! @brief Returns the family ID for the target associated with the board. 100 | //! 101 | //! The family ID will be 0 if there is no board. 102 | uint16_t get_family_id(void); 103 | 104 | //! @brief Whether the board has a valid flash algo. 105 | uint8_t flash_algo_valid(void); 106 | 107 | //! @brief Returns the MSD HTML help filename or a default. 108 | static inline const char * get_daplink_url_name ( void ) { return ((g_board_info.daplink_url_name[0] != 0) ? g_board_info.daplink_url_name : "MBED HTM"); } 109 | 110 | //! @brief Returns the MSD volume name or a default. 111 | static inline const char * get_daplink_drive_name ( void ) { return ((g_board_info.daplink_drive_name[0] != 0) ? g_board_info.daplink_drive_name : "DAPLINK "); } 112 | 113 | //! @brief Returns the target information URL or a default. 114 | static inline const char * get_daplink_target_url ( void ) { return ((g_board_info.daplink_target_url[0] != 0) ? g_board_info.daplink_target_url : "https://mbed.org/device/?code=@U?version=@V?target_id=@T"); } 115 | 116 | #ifdef __cplusplus 117 | } 118 | #endif 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /src/daplink/target/target_family.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file target_family.c 3 | * @brief Implementation of target_family.h 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2019, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #include 23 | #include "daplink.h" 24 | #include "DAP_config.h" 25 | #include "swd_host.h" 26 | #include "target_family.h" 27 | #include "target_board.h" 28 | 29 | // Stub families 30 | const target_family_descriptor_t g_hw_reset_family = { 31 | .family_id = kStub_HWReset_FamilyID, 32 | .default_reset_type = kHardwareReset, 33 | }; 34 | 35 | const target_family_descriptor_t g_sw_vectreset_family = { 36 | .family_id = kStub_SWVectReset_FamilyID, 37 | .default_reset_type = kSoftwareReset, 38 | .soft_reset_type = VECTRESET, 39 | }; 40 | 41 | const target_family_descriptor_t g_sw_sysresetreq_family = { 42 | .family_id = kStub_SWSysReset_FamilyID, 43 | .default_reset_type = kSoftwareReset, 44 | .soft_reset_type = SYSRESETREQ, 45 | }; 46 | 47 | // Weak references to family definitions. 48 | __WEAK const target_family_descriptor_t g_nxp_kinetis_kseries = {0}; 49 | __WEAK const target_family_descriptor_t g_nxp_kinetis_lseries = {0}; 50 | __WEAK const target_family_descriptor_t g_nxp_kinetis_k32w_series = {0}; 51 | __WEAK const target_family_descriptor_t g_nxp_mimxrt = {0}; 52 | __WEAK const target_family_descriptor_t g_nxp_rapid_iot = {0}; 53 | __WEAK const target_family_descriptor_t g_nxp_lpc55xx_series = {0}; 54 | __WEAK const target_family_descriptor_t g_nordic_nrf51 = {0}; 55 | __WEAK const target_family_descriptor_t g_nordic_nrf52 = {0}; 56 | __WEAK const target_family_descriptor_t g_realtek_rtl8195am = {0}; 57 | __WEAK const target_family_descriptor_t g_renesas_family = {0}; 58 | __WEAK const target_family_descriptor_t g_toshiba_tz_family = {0}; 59 | __WEAK const target_family_descriptor_t g_ambiq_ama3b1kk = {0}; 60 | __WEAK const target_family_descriptor_t g_maxim_max3262x_family = {0}; 61 | __WEAK const target_family_descriptor_t g_maxim_max3266x_family = {0}; 62 | __WEAK const target_family_descriptor_t g_raspberry_rp2040_family = {0}; 63 | 64 | //! @brief Terminator value for g_families list. 65 | //! 66 | //! This terminator value is chosen so that weak references to the family descriptors that 67 | //! resolve to NULL at link time do not terminate the list early. 68 | #define FAMILY_LIST_TERMINATOR ((const target_family_descriptor_t *)(0xffffffff)) 69 | 70 | //! @brief Default list of family descriptors. 71 | //! 72 | //! init_family() scans this list searching for a family descriptor with an ID that matches 73 | //! the family ID set in the board info or target config structs. Because each of the family 74 | //! descriptors has a weak reference defined above, the entry in this list for a family whose 75 | //! descriptor is not included in the link will resolve to NULL and init_family() can skip it. 76 | __WEAK 77 | const target_family_descriptor_t *g_families[] = { 78 | &g_hw_reset_family, 79 | &g_sw_vectreset_family, 80 | &g_sw_sysresetreq_family, 81 | &g_nxp_kinetis_kseries, 82 | &g_nxp_kinetis_lseries, 83 | &g_nxp_kinetis_k32w_series, 84 | &g_nxp_lpc55xx_series, 85 | &g_nxp_mimxrt, 86 | &g_nxp_rapid_iot, 87 | &g_nordic_nrf51, 88 | &g_nordic_nrf52, 89 | &g_realtek_rtl8195am, 90 | &g_toshiba_tz_family, 91 | &g_renesas_family, 92 | &g_ambiq_ama3b1kk, 93 | &g_maxim_max3262x_family, 94 | &g_maxim_max3266x_family, 95 | &g_raspberry_rp2040_family, 96 | FAMILY_LIST_TERMINATOR // list terminator 97 | }; 98 | 99 | __WEAK 100 | const target_family_descriptor_t *g_target_family = NULL; 101 | 102 | 103 | void init_family(void) 104 | { 105 | // Check if the family is already set. 106 | if (g_target_family != NULL) { 107 | return; 108 | } 109 | 110 | // Scan families table looking for matching family ID. 111 | uint8_t index = 0; 112 | uint16_t family_id = get_family_id(); 113 | 114 | while (g_families[index] != FAMILY_LIST_TERMINATOR) { 115 | if ((g_families[index] != NULL) && (g_families[index]->family_id == family_id)) { 116 | g_target_family = g_families[index]; 117 | break; 118 | } 119 | index++; 120 | } 121 | 122 | // Last resort is to use a default family. 123 | if (g_target_family == NULL) { 124 | g_target_family = &g_hw_reset_family; 125 | } 126 | } 127 | 128 | uint8_t target_set_state(target_state_t state) 129 | { 130 | if (g_board_info.target_set_state) { //target specific 131 | g_board_info.target_set_state(state); 132 | } 133 | if (g_target_family) { 134 | if (g_target_family->target_set_state) { 135 | //customize target state 136 | return g_target_family->target_set_state(state); 137 | } else { 138 | if (g_target_family->default_reset_type == kHardwareReset) { 139 | return swd_set_target_state_hw(state); 140 | } else if (g_target_family->default_reset_type == kSoftwareReset) { 141 | if (g_board_info.soft_reset_type) { //board has precedence 142 | swd_set_soft_reset(g_board_info.soft_reset_type); 143 | } else if (g_target_family->soft_reset_type) { 144 | swd_set_soft_reset(g_target_family->soft_reset_type); 145 | } 146 | return swd_set_target_state_sw(state); 147 | } else { 148 | return 1; 149 | } 150 | } 151 | } else { 152 | return 0; 153 | } 154 | } 155 | 156 | void swd_set_target_reset(uint8_t asserted) 157 | { 158 | // printf("swd_set_target_reset(%d), %p %p\n", asserted, g_target_family, g_target_family == NULL ? NULL : g_target_family->swd_set_target_reset); 159 | if (g_target_family && g_target_family->swd_set_target_reset) { 160 | g_target_family->swd_set_target_reset(asserted); 161 | } else { 162 | (asserted) ? PIN_nRESET_OUT(0) : PIN_nRESET_OUT(1); 163 | } 164 | } 165 | 166 | uint32_t target_get_apsel() 167 | { 168 | if (g_target_family && g_target_family->apsel) { 169 | return g_target_family->apsel; 170 | } else { 171 | return 0; 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /include/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS V202107.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * http://www.FreeRTOS.org 23 | * http://aws.amazon.com/freertos 24 | * 25 | * 1 tab == 4 spaces! 26 | */ 27 | 28 | #ifndef FREERTOS_CONFIG_H 29 | #define FREERTOS_CONFIG_H 30 | 31 | /*----------------------------------------------------------- 32 | * Application specific definitions. 33 | * 34 | * These definitions should be adjusted for your particular hardware and 35 | * application requirements. 36 | * 37 | * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE 38 | * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. 39 | * 40 | * See http://www.freertos.org/a00110.html 41 | *----------------------------------------------------------*/ 42 | 43 | /* Scheduler Related */ 44 | #define configUSE_PREEMPTION 1 45 | #define configUSE_TICKLESS_IDLE 1 46 | #define configUSE_IDLE_HOOK 0 47 | #define configUSE_TICK_HOOK 0 48 | 49 | // TODO I guess this should be smaller than 1000 (and also a divisor of 1000) 50 | // otherwise in portmacro.h (in FreeRTOS), definition of portTICK_PERIOD_MS is questionable... 51 | // TODO values around 100 lead to errors in target communication!? 52 | #define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) 53 | 54 | #define configMAX_PRIORITIES 32 55 | #define configMINIMAL_STACK_SIZE ((configSTACK_DEPTH_TYPE) 1024) 56 | #define configUSE_16_BIT_TICKS 0 57 | 58 | #define configIDLE_SHOULD_YIELD 1 59 | 60 | #define configUSE_TASK_NOTIFICATIONS 1 61 | 62 | /* Synchronization Related */ 63 | #define configUSE_MUTEXES 1 64 | #define configUSE_RECURSIVE_MUTEXES 1 65 | #define configUSE_APPLICATION_TASK_TAG 0 66 | #define configUSE_COUNTING_SEMAPHORES 0 67 | #define configQUEUE_REGISTRY_SIZE 8 68 | #define configUSE_QUEUE_SETS 1 69 | #define configUSE_TIME_SLICING 1 70 | #define configUSE_NEWLIB_REENTRANT 0 71 | #define configENABLE_BACKWARD_COMPATIBILITY 1 72 | #define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5 73 | 74 | /* System */ 75 | #define configSTACK_DEPTH_TYPE uint32_t 76 | #define configMESSAGE_BUFFER_LENGTH_TYPE size_t 77 | 78 | /* Memory allocation related definitions. */ 79 | #define configSUPPORT_STATIC_ALLOCATION 1 80 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 81 | #define configTOTAL_HEAP_SIZE (105*1024) 82 | #define configAPPLICATION_ALLOCATED_HEAP 0 83 | 84 | /* Hook function related definitions. */ 85 | #define configCHECK_FOR_STACK_OVERFLOW 0 86 | #define configUSE_MALLOC_FAILED_HOOK 1 87 | #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 88 | 89 | /* Run time and task stats gathering related definitions. */ 90 | #define configUSE_TRACE_FACILITY 0 // switch on task status output 91 | #define configGENERATE_RUN_TIME_STATS configUSE_TRACE_FACILITY 92 | #define configUSE_STATS_FORMATTING_FUNCTIONS 0 93 | 94 | #if configUSE_TRACE_FACILITY 95 | #define TF_TIMER_BASE _u(0x40054000) 96 | #define TF_TIMER_TIMERAWL_OFFSET _u(0x00000028) 97 | 98 | #warning "configUSE_TRACE_FACILITY is set" 99 | #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() do {} while( 0 ) 100 | #define portALT_GET_RUN_TIME_COUNTER_VALUE( dest ) ( dest = *((uint32_t *)(TF_TIMER_BASE + TF_TIMER_TIMERAWL_OFFSET)) ) 101 | #endif 102 | 103 | /* Co-routine related definitions. */ 104 | #define configUSE_CO_ROUTINES 0 105 | #define configMAX_CO_ROUTINE_PRIORITIES 1 106 | 107 | /* Software timer related definitions. */ 108 | #define configUSE_TIMERS 1 109 | #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) 110 | #define configTIMER_QUEUE_LENGTH 10 111 | #define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE 112 | 113 | /* Interrupt nesting behaviour configuration. */ 114 | /* 115 | #define configKERNEL_INTERRUPT_PRIORITY [dependent of processor] 116 | #define configMAX_SYSCALL_INTERRUPT_PRIORITY [dependent on processor and application] 117 | #define configMAX_API_CALL_INTERRUPT_PRIORITY [dependent on processor and application] 118 | */ 119 | 120 | /* SMP port only */ 121 | #define configNUM_CORES 2 122 | #define configTICK_CORE 1 123 | #define configRUN_MULTIPLE_PRIORITIES 1 124 | #define configUSE_CORE_AFFINITY 1 125 | 126 | /* RP2040 specific */ 127 | #define configSUPPORT_PICO_SYNC_INTEROP 1 128 | #define configSUPPORT_PICO_TIME_INTEROP 1 129 | 130 | #include 131 | /* Define to trap errors during development. */ 132 | #define configASSERT(x) assert(x) 133 | 134 | /* Set the following definitions to 1 to include the API function, or zero 135 | to exclude the API function. */ 136 | #define INCLUDE_vTaskPrioritySet 0 137 | #define INCLUDE_uxTaskPriorityGet 0 138 | #define INCLUDE_vTaskDelete 1 139 | #define INCLUDE_vTaskSuspend 1 140 | #define INCLUDE_vTaskDelayUntil 0 141 | #define INCLUDE_vTaskDelay 1 142 | #define INCLUDE_xTaskGetSchedulerState 0 143 | #define INCLUDE_xTaskGetCurrentTaskHandle 0 144 | #define INCLUDE_uxTaskGetStackHighWaterMark 0 145 | #define INCLUDE_xTaskGetIdleTaskHandle 0 146 | #define INCLUDE_eTaskGetState 0 147 | #define INCLUDE_xTimerPendFunctionCall 1 148 | #define INCLUDE_xTaskAbortDelay 0 149 | #define INCLUDE_xTaskGetHandle 0 150 | #define INCLUDE_xTaskResumeFromISR 0 151 | #define INCLUDE_xQueueGetMutexHolder 1 152 | 153 | /* A header file that defines trace macro can be included here. */ 154 | 155 | #endif /* FREERTOS_CONFIG_H */ 156 | 157 | -------------------------------------------------------------------------------- /src/daplink-pico/board/rp2040/pico_target_utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | */ 25 | 26 | #include 27 | 28 | #include "pico_target_utils.h" 29 | 30 | #include "swd_host.h" 31 | #include "target_rp2040.h" 32 | 33 | 34 | 35 | // Read 16-bit word from target memory. 36 | static uint8_t swd_read_word16(uint32_t addr, uint16_t *val) 37 | { 38 | uint8_t v1, v2; 39 | 40 | if ( !swd_read_byte(addr+0, &v1)) 41 | return 0; 42 | if ( !swd_read_byte(addr+1, &v2)) 43 | return 0; 44 | 45 | *val = ((uint16_t)v2 << 8) + v1; 46 | return 1; 47 | } // swd_read_word16 48 | 49 | 50 | 51 | // this is 'M' 'u', 1 (version) 52 | #define RP2040_BOOTROM_MAGIC 0x01754d 53 | #define RP2040_BOOTROM_MAGIC_ADDR 0x00000010 54 | 55 | 56 | // 57 | // find a function in the bootrom, see RP2040 datasheet, chapter 2.8 58 | // 59 | uint32_t rp2040_target_find_rom_func(char ch1, char ch2) 60 | { 61 | uint16_t tag = (ch2 << 8) | ch1; 62 | 63 | // First read the bootrom magic value... 64 | uint32_t magic; 65 | 66 | if ( !swd_read_word(RP2040_BOOTROM_MAGIC_ADDR, &magic)) 67 | return 0; 68 | if ((magic & 0x00ffffff) != RP2040_BOOTROM_MAGIC) 69 | return 0; 70 | 71 | // Now find the start of the table... 72 | uint16_t v; 73 | uint32_t tabaddr; 74 | if ( !swd_read_word16(RP2040_BOOTROM_MAGIC_ADDR+4, &v)) 75 | return 0; 76 | tabaddr = v; 77 | 78 | // Now try to find our function... 79 | uint16_t value; 80 | do { 81 | if ( !swd_read_word16(tabaddr, &value)) 82 | return 0; 83 | if (value == tag) { 84 | if ( !swd_read_word16(tabaddr+2, &value)) 85 | return 0; 86 | return (uint32_t)value; 87 | } 88 | tabaddr += 4; 89 | } while (value != 0); 90 | return 0; 91 | } // rp2040_target_find_rom_func 92 | 93 | 94 | 95 | /// 96 | /// Call function on the target device at address \a addr. 97 | /// Arguments are in \a args[] / \a argc, result of the called function (from r0) will be 98 | /// put to \a *result (if != NULL). 99 | /// 100 | /// \pre 101 | /// - target MCU must be connected 102 | /// - code must be already uploaded to target 103 | /// 104 | /// \note 105 | /// The called function could end with __breakpoint(), but with the help of the used trampoline 106 | /// functions in ROM, the functions can be fetched. 107 | /// 108 | bool rp2040_target_call_function(uint32_t addr, uint32_t args[], int argc, uint32_t *result) 109 | { 110 | static uint32_t trampoline_addr = 0; // trampoline is fine to get the return value of the callee 111 | static uint32_t trampoline_end; 112 | 113 | if ( !target_core_halt()) 114 | return false; 115 | 116 | assert(argc <= 4); 117 | 118 | // First get the trampoline address... (actually not required, because the functions reside in RAM...) 119 | if (trampoline_addr == 0) { 120 | trampoline_addr = rp2040_target_find_rom_func('D', 'T'); 121 | trampoline_end = rp2040_target_find_rom_func('D', 'E'); 122 | if (trampoline_addr == 0 || trampoline_end == 0) 123 | return false; 124 | } 125 | 126 | // Set the registers for the trampoline call... 127 | // function in r7, args in r0, r1, r2, and r3, end in lr? 128 | for (int i = 0; i < argc; ++i) { 129 | if ( !swd_write_core_register(i, args[i])) 130 | return false; 131 | } 132 | if ( !swd_write_core_register(7, addr)) 133 | return false; 134 | 135 | // Set the stack pointer to something sensible... (MSP) 136 | if ( !swd_write_core_register(13, TARGET_RP2040_STACK)) 137 | return false; 138 | 139 | // Now set the PC to go to our address 140 | if ( !swd_write_core_register(15, trampoline_addr)) 141 | return false; 142 | 143 | // Set xPSR for the thumb thingy... 144 | if ( !swd_write_core_register(16, (1 << 24))) 145 | return false; 146 | 147 | if ( !target_core_halt()) 148 | return false; 149 | 150 | #if DEBUG_MODULE 151 | for (int i = 0; i < 18; ++i) 152 | display_reg(i); 153 | #endif 154 | 155 | // start execution 156 | // picoprobe_info(".................... execute\n"); 157 | if ( !target_core_unhalt_with_masked_ints()) 158 | return false; 159 | 160 | // check status 161 | { 162 | uint32_t status; 163 | 164 | if (!swd_read_dp(DP_CTRL_STAT, &status)) { 165 | return false; 166 | } 167 | if (status & (STICKYERR | WDATAERR)) { 168 | return false; 169 | } 170 | } 171 | 172 | // Wait until core is halted (again) 173 | { 174 | const uint32_t timeout_us = 5000000; 175 | bool interrupted = false; 176 | uint32_t start_us = time_us_32(); 177 | 178 | while ( !target_core_is_halted()) { 179 | uint32_t dt_us = time_us_32() - start_us; 180 | 181 | if (dt_us > timeout_us) { 182 | target_core_halt(); 183 | picoprobe_error("rp2040_target_call_function: execution timed out after %lu ms\n", dt_us / 1000); 184 | interrupted = true; 185 | } 186 | } 187 | if ( !interrupted) { 188 | uint32_t dt_ms = (time_us_32() - start_us) / 1000; 189 | if (dt_ms > 10) { 190 | picoprobe_debug("rp2040_target_call_function: execution finished after %lu ms\n", dt_ms); 191 | } 192 | } 193 | } 194 | 195 | #if DEBUG_MODULE 196 | for (int i = 0; i < 18; ++i) 197 | display_reg(i); 198 | #endif 199 | 200 | if (result != NULL) { 201 | // fetch result of function (r0) 202 | if ( !swd_read_core_register(0, result)) 203 | return false; 204 | } 205 | 206 | { 207 | uint32_t r15; 208 | 209 | if ( !swd_read_core_register(15, &r15)) { 210 | return false; 211 | } 212 | 213 | if (r15 != (trampoline_end & 0xfffffffe)) { 214 | picoprobe_error("rp2040_target_call_function: invoked target function did not run til end: 0x%0lx != 0x%0lx\n", r15, trampoline_end); 215 | return false; 216 | } 217 | } 218 | return true; 219 | } // rp2040_target_call_function 220 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | 3 | # set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/toolchain.cmake) 4 | 5 | # 6 | # board definition: pico or pico_w, default is pico 7 | # 8 | if(PICO_BOARD STREQUAL "") 9 | set(PICO_BOARD pico) 10 | endif() 11 | set(PICO_STDIO_UART 0) 12 | 13 | # 14 | # below order is important 15 | # 16 | include(pico_sdk_import.cmake) 17 | 18 | # set(CMAKE_SYSTEM_NAME Generic) 19 | 20 | set(FREERTOS_KERNEL_PATH ${CMAKE_CURRENT_LIST_DIR}/freertos) 21 | include(FreeRTOS_Kernel_import.cmake) 22 | 23 | set(PICO_BOARD_HEADER_DIRS ${CMAKE_CURRENT_LIST_DIR}/include/boards) 24 | pico_sdk_init() 25 | 26 | # set(CMAKE_C_COMPILER_FORCED TRUE) 27 | # set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") 28 | # set(CMAKE_C_COMPILER_WORKS TRUE) 29 | #set(CMAKE_CXX_COMPILER_WORKS TRUE) 30 | 31 | project(${PROJECT} "C" "CXX") 32 | 33 | string(TOUPPER ${PICO_BOARD} PICO_BOARD_UPPER) 34 | 35 | # 36 | # set some project specifica 37 | # 38 | add_definitions( 39 | -DPICO_CORE1_STACK_SIZE=0x400 40 | -DPICO_HEAP_SIZE=0x0 41 | -DPICO_STACK_SIZE=0x400 42 | -DTARGET_BOARD_${PICO_BOARD_UPPER} 43 | -DCMAKE_SYSTEM_NAME=Generic 44 | ) 45 | 46 | # 47 | # set some things inherited from Makefile / command line 48 | # 49 | if (PICOPROBE_VERSION_MAJOR) 50 | add_definitions(-DPICOPROBE_VERSION_MAJOR=${PICOPROBE_VERSION_MAJOR}) 51 | else() 52 | set(PICOPROBE_VERSION_MAJOR 0) 53 | endif() 54 | if (PICOPROBE_VERSION_MINOR) 55 | add_definitions(-DPICOPROBE_VERSION_MINOR=${PICOPROBE_VERSION_MINOR}) 56 | else() 57 | set(PICOPROBE_VERSION_MINOR 0) 58 | endif() 59 | 60 | # set version string to "x.yy" 61 | # there are perhaps smarter ways... 62 | if (PICOPROBE_VERSION_MINOR LESS "10") 63 | add_definitions(-DPICOPROBE_VERSION_STRING="${PICOPROBE_VERSION_MAJOR}.0${PICOPROBE_VERSION_MINOR}") 64 | else() 65 | add_definitions(-DPICOPROBE_VERSION_STRING="${PICOPROBE_VERSION_MAJOR}.${PICOPROBE_VERSION_MINOR}") 66 | endif() 67 | 68 | if (GIT_HASH) 69 | add_definitions(-DGIT_HASH="${GIT_HASH}") 70 | endif() 71 | 72 | 73 | ######################################################################################################################## 74 | 75 | 76 | add_executable(${PROJECT} 77 | src/cdc_uart.c 78 | src/dap_util.c 79 | src/get_serial.c 80 | src/led.c 81 | src/main.c 82 | src/misc_utils.c 83 | src/probe.c 84 | src/rtt_console.c 85 | src/sw_dp_pio.c 86 | src/sw_lock.c 87 | src/usb_descriptors.c 88 | ) 89 | 90 | if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") 91 | target_sources(${PROJECT} PRIVATE 92 | src/cdc_debug.c 93 | ) 94 | endif() 95 | 96 | target_sources(${PROJECT} PRIVATE 97 | CMSIS_5/CMSIS/DAP/Firmware/Source/DAP.c 98 | CMSIS_5/CMSIS/DAP/Firmware/Source/JTAG_DP.c 99 | CMSIS_5/CMSIS/DAP/Firmware/Source/DAP_vendor.c 100 | CMSIS_5/CMSIS/DAP/Firmware/Source/SWO.c 101 | ) 102 | 103 | target_include_directories(${PROJECT} PRIVATE 104 | CMSIS_5/CMSIS/DAP/Firmware/Include/ 105 | CMSIS_5/CMSIS/Core/Include/ 106 | include/ 107 | ) 108 | 109 | #-------------------------------------------------------------------------------------------------- 110 | # 111 | # this is for MSC/DAPLink operation 112 | # 113 | target_sources(${PROJECT} PRIVATE 114 | src/msc/msc_drive.c 115 | src/msc/msc_utils.c 116 | src/daplink/daplink/util.c 117 | src/daplink/daplink/drag-n-drop/flash_manager.c 118 | src/daplink/daplink/interface/swd_host.c 119 | src/daplink/daplink/interface/target_flash.c 120 | src/daplink/daplink/settings/settings_rom_stub.c 121 | src/daplink/family/renesas/target_reset_rza1lu.c 122 | src/daplink/family/renesas/rza1lu/target.c 123 | src/daplink/target/target_board.c 124 | src/daplink/target/target_family.c 125 | src/daplink-pico/board/rp2040/pico.c 126 | src/daplink-pico/board/rp2040/pico_target_utils.c 127 | src/daplink-pico/board/rp2040/program_flash_generic.c 128 | src/daplink-pico/family/raspberry/rp2040/target_reset_rp2040.c 129 | ) 130 | 131 | target_include_directories(${PROJECT} PRIVATE 132 | src/daplink/daplink 133 | src/daplink/daplink/cmsis-dap 134 | src/daplink/daplink/drag-n-drop 135 | src/daplink/daplink/interface 136 | src/daplink/daplink/settings 137 | src/daplink/hic_hal 138 | src/daplink/target 139 | src/daplink-pico/board/rp2040 140 | src/daplink-pico/family/raspberry 141 | src/daplink-pico/hic_hal/raspberry/rp2040 142 | $ENV{PICO_SDK_PATH}/src/common/boot_uf2/include 143 | ) 144 | 145 | # Both are actually dummies to prevent the DAPLink files from throwing errors 146 | # Actually not required because picoprobes structure is different 147 | add_compile_definitions(INTERFACE_RP2040=1 148 | DAPLINK_IF=1) 149 | 150 | # not sure if this is still required, but this equals to DAPLINK_HIC_ID_RP2040 in daplink.h 151 | add_compile_definitions(DAPLINK_HIC_ID=0x08154711) 152 | 153 | # required to get required DAPLink functions 154 | add_compile_definitions(DRAG_N_DROP_SUPPORT=1) 155 | 156 | # required for Renesas drag n drop 157 | add_compile_definitions(TARGET_MCU_CORTEX_A=1) 158 | 159 | #-------------------------------------------------------------------------------------------------- 160 | # 161 | # this is for SIGROK operation (taken from https://github.com/pico-coder/sigrok-pico) 162 | # 163 | target_sources(${PROJECT} PRIVATE 164 | src/pico-sigrok/cdc_sigrok.c 165 | src/pico-sigrok/sigrok.c 166 | src/pico-sigrok/sigrok_int.c 167 | ) 168 | 169 | target_link_libraries(${PROJECT} PRIVATE 170 | hardware_adc 171 | hardware_dma 172 | ) 173 | 174 | pico_generate_pio_header(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}/src/pico-sigrok/sigrok.pio) 175 | 176 | #-------------------------------------------------------------------------------------------------- 177 | 178 | target_compile_options(${PROJECT} PRIVATE -Wall) 179 | 180 | if(DEFINED ENV{PICOPROBE_LED}) 181 | message("PICOPROBE_LED is defined as " $ENV{PICOPROBE_LED}) 182 | target_compile_definitions(${PROJECT} PRIVATE PICOPROBE_LED=$ENV{PICOPROBE_LED}) 183 | endif() 184 | 185 | set(DBG_PIN_COUNT=4) 186 | 187 | pico_generate_pio_header(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}/src/probe.pio) 188 | 189 | target_include_directories(${PROJECT} PRIVATE src) 190 | 191 | target_compile_definitions (${PROJECT} PRIVATE 192 | PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1 193 | PICO_RP2040_USB_DEVICE_UFRAME_FIX=1 194 | ) 195 | 196 | target_link_libraries(${PROJECT} PRIVATE 197 | pico_multicore 198 | pico_stdlib 199 | pico_unique_id 200 | tinyusb_device 201 | tinyusb_board 202 | hardware_pio 203 | FreeRTOS-Kernel 204 | FreeRTOS-Kernel-Heap4 205 | ) 206 | 207 | if(PICO_BOARD STREQUAL "pico_w") 208 | target_link_libraries(${PROJECT} PRIVATE 209 | #pico_cyw43_arch_lwip_sys_freertos 210 | #pico_lwip_iperf 211 | pico_cyw43_arch_none 212 | ) 213 | endif() 214 | 215 | 216 | # 217 | # code resides in flash (in former versions it was in RAM) 218 | # if you want to force single functions into RAM, use "__no_inline_not_in_flash_func()" from platform.h 219 | # 220 | pico_set_binary_type(${PROJECT} default) 221 | 222 | pico_add_extra_outputs(${PROJECT}) 223 | -------------------------------------------------------------------------------- /src/daplink/target/target_family.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file target_family.h 3 | * @brief 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2018-2019, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef TARGET_FAMILY_H 23 | #define TARGET_FAMILY_H 24 | 25 | #include 26 | #include 27 | 28 | //! @brief Creates a family ID from a vendor ID and family index within that vendor. 29 | #define CREATE_FAMILY_ID(vendor, family) ((vendor) << 8 | (family)) 30 | 31 | //! @brief States into which the target can be placed. 32 | //! 33 | //! These enums are passed to target_set_state() and indicate the desired state into which 34 | //! the target should be reset. 35 | typedef enum _target_state { 36 | RESET_HOLD, //!< Hold target in reset 37 | RESET_PROGRAM, //!< Reset target and setup for flash programming 38 | RESET_RUN, //!< Reset target and run normally 39 | NO_DEBUG, //!< Disable debug on running target 40 | DEBUG, //!< Enable debug on running target 41 | HALT, //!< Halt the target without resetting it 42 | RUN, //!< Resume the target without resetting it 43 | POST_FLASH_RESET, //!< Reset target after flash programming 44 | POWER_ON, //!< Poweron the target 45 | SHUTDOWN, //!< Poweroff the target 46 | ATTACH, 47 | } target_state_t; 48 | 49 | //! @brief Options for reset. 50 | typedef enum _reset_type { 51 | kHardwareReset = 1, 52 | kSoftwareReset, 53 | } reset_type_t; 54 | 55 | //! @brief Unique IDs for vendors. 56 | //! 57 | //! The vendor IDs are the same as those used for the _DeviceVendorEnum_ defined for the PDSC file 58 | //! format from CMSIS-Packs. See the [DeviceVendorEnum 59 | //! documentation](https://arm-software.github.io/CMSIS_5/Pack/html/pdsc_family_pg.html#DeviceVendorEnum) 60 | //! for the list of ID values. 61 | enum _vendor_ids { 62 | kStub_VendorID = 0, 63 | kNXP_VendorID = 11, 64 | kTI_VendorID = 16, 65 | kMaxim_VendorID = 23, 66 | kNordic_VendorID = 54, 67 | kToshiba_VendorID = 92, 68 | kRenesas_VendorID = 117, 69 | kRealtek_VendorID = 124, 70 | kAmbiq_VendorID = 120, 71 | }; 72 | 73 | //! @brief Unique IDs for device families supported by DAPLink. 74 | //! 75 | //! The values of these enums are created with the CREATE_FAMILY_ID() macro. Vendor IDs come from 76 | //! the #_vendor_ids enumeration. The family index for each ID is simply an integer that is unique 77 | //! within the family. 78 | //! 79 | //! There are several "stub" families defined with a stub vendor. These families are meant to be 80 | //! used for devices that do not require any customized behaviour in order to be successfully 81 | //! controlled by DAPLink. The individual stub families provide some options for what reset type 82 | //! should be used, either hardware or software. 83 | //! 84 | //! To add a new family, first determine if you can simply use one of the stub families. For many 85 | //! devices, the stub families are sufficient and using them reduces complexity. 86 | //! 87 | //! If you do need a new family ID, first check if the vendor is present in #_vendor_ids. If not, 88 | //! add the vendor ID to that enum (see its documentation for the source of vendor ID values). 89 | //! Then pick a unique family index by adding 1 to the highest existing family index within that 90 | //! vendor. For a family with a new vendor, the family index should be 1. 91 | typedef enum _family_id { 92 | kStub_HWReset_FamilyID = CREATE_FAMILY_ID(kStub_VendorID, 1), 93 | kStub_SWVectReset_FamilyID = CREATE_FAMILY_ID(kStub_VendorID, 2), 94 | kStub_SWSysReset_FamilyID = CREATE_FAMILY_ID(kStub_VendorID, 3), 95 | kNXP_KinetisK_FamilyID = CREATE_FAMILY_ID(kNXP_VendorID, 1), 96 | kNXP_KinetisL_FamilyID = CREATE_FAMILY_ID(kNXP_VendorID, 2), 97 | kNXP_Mimxrt_FamilyID = CREATE_FAMILY_ID(kNXP_VendorID, 3), 98 | kNXP_RapidIot_FamilyID = CREATE_FAMILY_ID(kNXP_VendorID, 4), 99 | kNXP_KinetisK32W_FamilyID = CREATE_FAMILY_ID(kNXP_VendorID, 5), 100 | kNXP_LPC55xx_FamilyID = CREATE_FAMILY_ID(kNXP_VendorID, 6), 101 | kNordic_Nrf51_FamilyID = CREATE_FAMILY_ID(kNordic_VendorID, 1), 102 | kNordic_Nrf52_FamilyID = CREATE_FAMILY_ID(kNordic_VendorID, 2), 103 | kRealtek_Rtl8195am_FamilyID = CREATE_FAMILY_ID(kRealtek_VendorID, 1), 104 | kTI_Cc3220sf_FamilyID = CREATE_FAMILY_ID(kTI_VendorID, 1), 105 | kToshiba_Tz_FamilyID = CREATE_FAMILY_ID(kToshiba_VendorID, 1), 106 | kRenesas_FamilyID = CREATE_FAMILY_ID(kRenesas_VendorID, 1), 107 | kAmbiq_ama3b1kk_FamilyID = CREATE_FAMILY_ID(kAmbiq_VendorID, 1), 108 | kMaxim_MAX3262X_FamilyID = CREATE_FAMILY_ID(kMaxim_VendorID, 1), 109 | kMaxim_MAX3266X_FamilyID = CREATE_FAMILY_ID(kMaxim_VendorID, 2), 110 | } family_id_t; 111 | 112 | //! @brief Defines all characteristics of a device family. 113 | typedef struct target_family_descriptor { 114 | uint16_t family_id; /*!< Use to select or identify target family from defined target family or custom ones */ 115 | reset_type_t default_reset_type; /*!< Target family can select predefined reset from kHardwareReset and kSoftwareReset */ 116 | uint32_t soft_reset_type; /*!< Families can override software reset type to VECTRESET or SYSRESETREQ */ 117 | void (*target_before_init_debug)(void); /*!< Target dependant function before debug initialization */ 118 | void (*prerun_target_config)(void); /*!< Target specific initialization */ 119 | uint8_t (*target_unlock_sequence)(void); /*!< Unlock targets that can enter lock state */ 120 | uint8_t (*security_bits_set)(uint32_t addr, uint8_t *data, uint32_t size); /*!< Check security bits in the programmable flash region */ 121 | uint8_t (*target_set_state)(target_state_t state); /*!< Families can customize target debug states */ 122 | void (*swd_set_target_reset)(uint8_t asserted); /*!< Families can customize how to send reset to the target */ 123 | uint8_t (*validate_bin_nvic)(const uint8_t *buf); /*!< Validate a bin file to be flash by drag and drop */ 124 | uint8_t (*validate_hexfile)(const uint8_t *buf); /*!< Validate a hex file to be flash by drag and drop */ 125 | uint32_t apsel; /*!< APSEL for the family */ 126 | } target_family_descriptor_t; 127 | 128 | //! @brief The active family used by the board. 129 | //! 130 | //! This global is initialized by init_family() just after DAPLink boots. Normally it matches 131 | //! the family specified by the #board_info_t::family_id field of #g_board_info. 132 | extern const target_family_descriptor_t *g_target_family; 133 | 134 | #ifdef __cplusplus 135 | extern "C" { 136 | #endif 137 | 138 | //! @brief Initialize g_target_family. 139 | void init_family(void); 140 | 141 | //! @brief Reset the target into a new state. 142 | //! 143 | //! Used to prepare the target for some operation, or release it for user control. 144 | uint8_t target_set_state(target_state_t state); 145 | 146 | //! @brief Controls reset of the target. 147 | void swd_set_target_reset(uint8_t asserted); 148 | 149 | //! @brief Get the APSEL for the AHB-AP to use for controlling the target. 150 | uint32_t target_get_apsel(void); 151 | 152 | #ifdef __cplusplus 153 | } 154 | #endif 155 | 156 | #endif 157 | -------------------------------------------------------------------------------- /src/daplink/family/renesas/rza1lu/flash_blob.c: -------------------------------------------------------------------------------- 1 | /* Flash OS Routines (Automagically Generated) 2 | * Copyright (c) 2009-2019 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | static const uint32_t rza1lu_flash_algo[] = { 18 | 0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2, 19 | 0x41f0e92d, 0x4efe4604, 0xf0106830, 0xd07d0f01, 0x4ffb6961, 0xf44f220e, 0x3f184380, 0xf0004638, 20 | 0x4df7fb08, 0x087ff44f, 0x3d246960, 0xf894b160, 0x22101046, 0x46284643, 0xfafbf000, 0x06bb6821, 21 | 0x4638221e, 0xfaf5f000, 0x220c69a1, 0x5380f44f, 0xf0004638, 0x69a0faee, 0xf894b168, 0x23ff1047, 22 | 0x46282200, 0xfae5f000, 0x221c6861, 0x5340f04f, 0xf0004638, 0x69e1fade, 0xf44f2208, 0x46386370, 23 | 0xfad7f000, 0xb17069e0, 0x220048dd, 0xf04f6ca1, 0x382033ff, 0xfacdf000, 0x221868a1, 0x7340f04f, 24 | 0xf0004638, 0x6a21fac6, 0x220423f0, 0xf0004638, 0x6a20fac0, 0xf814b328, 0x22181f4c, 0xf04f4dd0, 25 | 0x3d1c437f, 0xf0004628, 0x7861fab4, 0x46432210, 0xf0004628, 0x78a1faae, 0xf44f2208, 0x4628437f, 26 | 0xfaa7f000, 0x23ff78e1, 0x46282200, 0xfaa1f000, 0x1c40f854, 0x3c4c2214, 0x1340f44f, 0xf0004638, 27 | 0x220ffa98, 0x4300f44f, 0xe0004638, 0x6b61e027, 0xfa8ff000, 0xf44f6b60, 0xb1783840, 0x1044f894, 28 | 0x4db72210, 0x35184643, 0xf0004628, 0xf894fa82, 0x23071045, 0x46282200, 0xfa7bf000, 0x230f6a61, 29 | 0x46382200, 0xfa75f000, 0x6a604dad, 0xb1d83d48, 0xd0072808, 0xd00a280c, 0xd00d280f, 0x2001e00e, 30 | 0x81f0e8bd, 0x0058f894, 0x0040f885, 0xf8b4e006, 0xf8a50058, 0xe0010040, 0x64286da0, 0x69212210, 31 | 0x46384643, 0xfa55f000, 0x8274f8df, 0x7780f44f, 0x22086aa1, 0xf1a8463b, 0x46400828, 0xfa49f000, 32 | 0x23046ae1, 0x46402202, 0xfa43f000, 0x23026b21, 0x46402201, 0xfa3df000, 0x4f91463b, 0x22086ba1, 33 | 0x4638371c, 0xfa35f000, 0x23106be1, 0x46382204, 0xfa2ff000, 0x23016c21, 0x46382200, 0xfa29f000, 34 | 0x22002301, 0x46404619, 0xfa23f000, 0xf0106830, 0xd0fb0f01, 0x28086a60, 0x280cd004, 0x280fd005, 35 | 0xe006d005, 0x0038f895, 0x8f28e002, 0x6ba8e000, 0x20006520, 0x2100e7a4, 0x60016141, 0x1046f880, 36 | 0x60416181, 0x1047f880, 0x638161c1, 0x64816081, 0x63c16201, 0xf88060c1, 0xf880104c, 0xf880104d, 37 | 0xf880104e, 0x6341104f, 0x1044f880, 0x1045f880, 0x64016241, 0x62816101, 0x630162c1, 0xb5704770, 38 | 0x48684605, 0x4448460c, 0xffd5f7ff, 0x23004a65, 0x444a2001, 0x61506013, 0x5046f882, 0x300ae9c2, 39 | 0x20086310, 0x61136413, 0x46106250, 0x4316e9c2, 0x4070e8bd, 0xb570e6b4, 0x485a4606, 0x4448460d, 40 | 0xffb9f7ff, 0x22004c57, 0x444c2001, 0x61606022, 0x6046f884, 0x200ae9c4, 0x20086320, 0x61226422, 41 | 0x65e265a2, 0x46206260, 0xfe9af7ff, 0xd1022800, 0x1050f894, 0xbd707029, 0x2000494b, 0x1e42b510, 42 | 0x1c40c104, 0xdbfb2810, 0x48482101, 0x68006001, 0x0035f241, 0x82084946, 0x4946200f, 0x48458008, 43 | 0x78013030, 0x0108f021, 0x78007001, 0x483c2200, 0x46112301, 0xf000383c, 0x4c39f98c, 0x6ca13c48, 44 | 0xd4fc0789, 0x23032200, 0x46204611, 0xf981f000, 0xf8b14939, 0xf0400210, 0xf8a100fc, 0x49370210, 45 | 0x0310f8b1, 0x00fcf020, 0x0310f8a1, 0x88014834, 0x01fcf041, 0x48338001, 0xf0218801, 0x800101fc, 46 | 0x88014831, 0x01fcf021, 0x48308001, 0xf0418801, 0x800101fc, 0x492e6820, 0x60204308, 0xf0206820, 47 | 0xf0400078, 0x60200020, 0x492a6860, 0x60604008, 0xf2406de0, 0x43881111, 0x68a065e0, 0x7103f64f, 48 | 0xf4404388, 0x60a07000, 0xf94af000, 0x2001b108, 0x221fbd10, 0xf04f2101, 0x46204300, 0xf939f000, 49 | 0x20006820, 0xb510bd10, 0x4c0d221f, 0xf04f2100, 0x3c484300, 0xf0004620, 0x2100f92c, 0x221060e1, 50 | 0x21eb4807, 0x037ff44f, 0xf0003838, 0x4804f922, 0x22002307, 0x38342101, 0xf91bf000, 0x0000e01c, 51 | 0x3fefa048, 0x00000004, 0xe8201180, 0x3fffff80, 0xfcfe0000, 0xfcfe0408, 0xfcfe7000, 0xfcfe3000, 52 | 0xfcfe3510, 0xfcfe3610, 0xfcfe3a10, 0xfcfe3410, 0x00fff300, 0xfffcfcfc, 0x7103f64f, 0x200061e1, 53 | 0xb510bd10, 0xf93cf000, 0xd1142800, 0x444848a5, 0xfee1f7ff, 0x210148a3, 0x61414448, 0x60012100, 54 | 0xf88021c7, 0xf7ff1046, 0x2800fdcb, 0xe8bdd103, 0xf0004010, 0xbd10b919, 0x4604b510, 0xf920f000, 55 | 0xd1192800, 0x44484897, 0xfec5f7ff, 0x21014895, 0x44482220, 0x21006141, 0xf8806001, 0x22072046, 56 | 0x64846381, 0x608161c2, 0xfdaaf7ff, 0xd1032800, 0x4010e8bd, 0xb8f8f000, 0xe92dbd10, 0x000c47f0, 57 | 0x46054616, 0xf000d056, 0x2800f8fb, 0x4885d152, 0xf7ff4448, 0x4f83fea0, 0x0a00f04f, 0x0801f04f, 58 | 0x444f2202, 0xf8c74638, 0xf8c7a000, 0xf8878014, 0x22072046, 0xa038f8c7, 0xa008f8c7, 0x8028f8c7, 59 | 0x61fa64bd, 0xfd7cf7ff, 0xd1332800, 0xf7ff4638, 0xf8c7fe82, 0xf8c78028, 0x46d08030, 0xa010f8c7, 60 | 0xa040f8c7, 0x2c04e020, 0x200fd305, 0x25046278, 0x65b86830, 0x2c02e00c, 0x200cd305, 0x25026278, 61 | 0x65b88830, 0x2008e004, 0x62782501, 0x65b87830, 0xd80142ac, 0x8028f8c7, 0x44484862, 0xfd50f7ff, 62 | 0xd1072800, 0x442e1b64, 0xd1dc2c00, 0x47f0e8bd, 0xb89af000, 0x87f0e8bd, 0x47f0e92d, 0x48594682, 63 | 0x460d4616, 0xf7ff4448, 0x4f56fe46, 0x0800f04f, 0x21032401, 0x4638444f, 0x8000f8c7, 0xf887617c, 64 | 0x21071046, 0x8038f8c7, 0xa048f8c7, 0x8008f8c7, 0x61f962bc, 0xfd24f7ff, 0x4638bb98, 0xfe2bf7ff, 65 | 0xf8c762bc, 0xf8c78010, 0x62fc8040, 0x2d04e02d, 0x200fd303, 0x62782404, 0x2d02e008, 0x200cd303, 66 | 0x62782402, 0x2008e002, 0x62782401, 0xd80142a5, 0x8028f8c7, 0x4448483b, 0xfd02f7ff, 0xd1b92800, 67 | 0xd0052c04, 0xd0062c02, 0x0050f897, 0xe0067831, 0x68316d38, 0xf8b7e003, 0x88310050, 0x4288b280, 68 | 0x2001d001, 0x1b2de7a6, 0x2d004426, 0x2000d1cf, 0xb510e7a0, 0x40916804, 0x430c439c, 0xbd106004, 69 | 0x2000b508, 0xf88d4669, 0x20050000, 0xfe23f7ff, 0xf89db9e8, 0xf0200000, 0x2001011c, 0x1000f88d, 70 | 0xfdfdf7ff, 0x46692035, 0xfe15f7ff, 0xf89db978, 0xf0200000, 0xf0400039, 0x20310102, 0x1000f88d, 71 | 0xfdedf7ff, 0x46692015, 0xfe05f7ff, 0x2001b108, 0xf89dbd08, 0xf0200000, 0x20110104, 0x1000f88d, 72 | 0xfdddf7ff, 0xbd082000, 0x2005b508, 0xf7ff4669, 0x2800fdf2, 0xf89dd103, 0x07c91000, 0xbd08d1f5, 73 | 0xb5104808, 0xf7ff4448, 0x4806fda6, 0x44482101, 0x21006141, 0x21066001, 0x1046f880, 0x4010e8bd, 74 | 0x0000e48e, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 75 | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 76 | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 77 | 0x00000000, 0x00000000, 0x00000000 78 | }; 79 | 80 | // Start address of flash 81 | static const uint32_t flash_start_rza1lu = 0x18000000; 82 | // Size of flash 83 | static const uint32_t flash_size_rza1lu = 0x00800000; 84 | 85 | /** 86 | * List of start and size for each size of flash sector 87 | * The size will apply to all sectors between the listed address and the next address 88 | * in the list. 89 | * The last pair in the list will have sectors starting at that address and ending 90 | * at address start + size. 91 | */ 92 | static const sector_info_t sectors_info_rza1lu[] = { 93 | {0, 4096}, 94 | }; 95 | 96 | static const program_target_t flash_rza1lu = { 97 | .init = 0x200202f9, 98 | .uninit = 0x200203e7, 99 | .erase_chip = 0x20020463, 100 | .erase_sector = 0x20020499, 101 | .program_page = 0x200204db, 102 | .verify = 0x20020599, 103 | { 104 | .breakpoint = 0x20020001, 105 | .static_base = 0x20020708, 106 | .stack_pointer = 0x20020a00 107 | }, 108 | .program_buffer = 0x20020000 + 0x00004000, 109 | .algo_start = 0x20020000, 110 | .algo_size = sizeof(rza1lu_flash_algo), 111 | .algo_blob = rza1lu_flash_algo, 112 | .program_buffer_size = 0x00000100 113 | }; 114 | -------------------------------------------------------------------------------- /src/daplink/daplink/cmsis-dap/debug_cm.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file debug_cm.h 3 | * @brief Access to ARM DAP (Cortex-M) using CMSIS-DAP protocol 4 | * 5 | * DAPLink Interface Firmware 6 | * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved 7 | * SPDX-License-Identifier: Apache-2.0 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 | * not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | #ifndef DEBUG_CM_H 23 | #define DEBUG_CM_H 24 | 25 | #include "DAP_config.h" 26 | #include "DAP.h" 27 | 28 | // SWD register access 29 | #define SWD_REG_AP (1) 30 | #define SWD_REG_DP (0) 31 | #define SWD_REG_R (1<<1) 32 | #define SWD_REG_W (0<<1) 33 | #define SWD_REG_ADR(a) (a & 0x0c) 34 | 35 | // Abort Register definitions 36 | #define DAPABORT 0x00000001 // DAP Abort 37 | #define STKCMPCLR 0x00000002 // Clear STICKYCMP Flag (SW Only) 38 | #define STKERRCLR 0x00000004 // Clear STICKYERR Flag (SW Only) 39 | #define WDERRCLR 0x00000008 // Clear WDATAERR Flag (SW Only) 40 | #define ORUNERRCLR 0x00000010 // Clear STICKYORUN Flag (SW Only) 41 | 42 | // Debug Control and Status definitions 43 | #define ORUNDETECT 0x00000001 // Overrun Detect 44 | #define STICKYORUN 0x00000002 // Sticky Overrun 45 | #define TRNMODE 0x0000000C // Transfer Mode Mask 46 | #define TRNNORMAL 0x00000000 // Transfer Mode: Normal 47 | #define TRNVERIFY 0x00000004 // Transfer Mode: Pushed Verify 48 | #define TRNCOMPARE 0x00000008 // Transfer Mode: Pushed Compare 49 | #define STICKYCMP 0x00000010 // Sticky Compare 50 | #define STICKYERR 0x00000020 // Sticky Error 51 | #define READOK 0x00000040 // Read OK (SW Only) 52 | #define WDATAERR 0x00000080 // Write Data Error (SW Only) 53 | #define MASKLANE 0x00000F00 // Mask Lane Mask 54 | #define MASKLANE0 0x00000100 // Mask Lane 0 55 | #define MASKLANE1 0x00000200 // Mask Lane 1 56 | #define MASKLANE2 0x00000400 // Mask Lane 2 57 | #define MASKLANE3 0x00000800 // Mask Lane 3 58 | #define TRNCNT 0x001FF000 // Transaction Counter Mask 59 | #define CDBGRSTREQ 0x04000000 // Debug Reset Request 60 | #define CDBGRSTACK 0x08000000 // Debug Reset Acknowledge 61 | #define CDBGPWRUPREQ 0x10000000 // Debug Power-up Request 62 | #define CDBGPWRUPACK 0x20000000 // Debug Power-up Acknowledge 63 | #define CSYSPWRUPREQ 0x40000000 // System Power-up Request 64 | #define CSYSPWRUPACK 0x80000000 // System Power-up Acknowledge 65 | 66 | // Debug Select Register definitions 67 | #define CTRLSEL 0x00000001 // CTRLSEL (SW Only) 68 | #define APBANKSEL 0x000000F0 // APBANKSEL Mask 69 | #define APSEL 0xFF000000 // APSEL Mask 70 | 71 | // Access Port Register Addresses 72 | #define AP_CSW 0x00 // Control and Status Word 73 | #define AP_TAR 0x04 // Transfer Address 74 | #define AP_DRW 0x0C // Data Read/Write 75 | #define AP_BD0 0x10 // Banked Data 0 76 | #define AP_BD1 0x14 // Banked Data 1 77 | #define AP_BD2 0x18 // Banked Data 2 78 | #define AP_BD3 0x1C // Banked Data 3 79 | #define AP_ROM 0xF8 // Debug ROM Address 80 | #define AP_IDR 0xFC // Identification Register 81 | 82 | // AP Control and Status Word definitions 83 | #define CSW_SIZE 0x00000007 // Access Size: Selection Mask 84 | #define CSW_SIZE8 0x00000000 // Access Size: 8-bit 85 | #define CSW_SIZE16 0x00000001 // Access Size: 16-bit 86 | #define CSW_SIZE32 0x00000002 // Access Size: 32-bit 87 | #define CSW_ADDRINC 0x00000030 // Auto Address Increment Mask 88 | #define CSW_NADDRINC 0x00000000 // No Address Increment 89 | #define CSW_SADDRINC 0x00000010 // Single Address Increment 90 | #define CSW_PADDRINC 0x00000020 // Packed Address Increment 91 | #define CSW_DBGSTAT 0x00000040 // Debug Status 92 | #define CSW_TINPROG 0x00000080 // Transfer in progress 93 | #define CSW_HPROT 0x02000000 // User/Privilege Control 94 | #define CSW_MSTRTYPE 0x20000000 // Master Type Mask 95 | #define CSW_MSTRCORE 0x00000000 // Master Type: Core 96 | #define CSW_MSTRDBG 0x20000000 // Master Type: Debug 97 | #define CSW_RESERVED 0x01000000 // Reserved Value 98 | 99 | // Core Debug Register Address Offsets 100 | #define DBG_OFS 0x0DF0 // Debug Register Offset inside NVIC 101 | #define DBG_HCSR_OFS 0x00 // Debug Halting Control & Status Register 102 | #define DBG_CRSR_OFS 0x04 // Debug Core Register Selector Register 103 | #define DBG_CRDR_OFS 0x08 // Debug Core Register Data Register 104 | #define DBG_EMCR_OFS 0x0C // Debug Exception & Monitor Control Register 105 | 106 | // Core Debug Register Addresses 107 | #define DBG_HCSR (DBG_Addr + DBG_HCSR_OFS) 108 | #define DBG_CRSR (DBG_Addr + DBG_CRSR_OFS) 109 | #define DBG_CRDR (DBG_Addr + DBG_CRDR_OFS) 110 | #define DBG_EMCR (DBG_Addr + DBG_EMCR_OFS) 111 | 112 | // Debug Halting Control and Status Register definitions 113 | #define C_DEBUGEN 0x00000001 // Debug Enable 114 | #define C_HALT 0x00000002 // Halt 115 | #define C_STEP 0x00000004 // Step 116 | #define C_MASKINTS 0x00000008 // Mask Interrupts 117 | #define C_SNAPSTALL 0x00000020 // Snap Stall 118 | #define S_REGRDY 0x00010000 // Register R/W Ready Flag 119 | #define S_HALT 0x00020000 // Halt Flag 120 | #define S_SLEEP 0x00040000 // Sleep Flag 121 | #define S_LOCKUP 0x00080000 // Lockup Flag 122 | #define S_RETIRE_ST 0x01000000 // Sticky Retire Flag 123 | #define S_RESET_ST 0x02000000 // Sticky Reset Flag 124 | #define DBGKEY 0xA05F0000 // Debug Key 125 | 126 | // Debug Exception and Monitor Control Register definitions 127 | #define VC_CORERESET 0x00000001 // Reset Vector Catch 128 | #define VC_MMERR 0x00000010 // Debug Trap on MMU Fault 129 | #define VC_NOCPERR 0x00000020 // Debug Trap on No Coprocessor Fault 130 | #define VC_CHKERR 0x00000040 // Debug Trap on Checking Error Fault 131 | #define VC_STATERR 0x00000080 // Debug Trap on State Error Fault 132 | #define VC_BUSERR 0x00000100 // Debug Trap on Bus Error Fault 133 | #define VC_INTERR 0x00000200 // Debug Trap on Interrupt Error Fault 134 | #define VC_HARDERR 0x00000400 // Debug Trap on Hard Fault 135 | #define MON_EN 0x00010000 // Monitor Enable 136 | #define MON_PEND 0x00020000 // Monitor Pend 137 | #define MON_STEP 0x00040000 // Monitor Step 138 | #define MON_REQ 0x00080000 // Monitor Request 139 | #define TRCENA 0x01000000 // Trace Enable (DWT, ITM, ETM, TPIU) 140 | 141 | // NVIC: Interrupt Controller Type Register 142 | #define NVIC_ICT (NVIC_Addr + 0x0004) 143 | #define INTLINESNUM 0x0000001F // Interrupt Line Numbers 144 | 145 | // NVIC: CPUID Base Register 146 | #define NVIC_CPUID (NVIC_Addr + 0x0D00) 147 | #define CPUID_PARTNO 0x0000FFF0 // Part Number Mask 148 | #define CPUID_REVISION 0x0000000F // Revision Mask 149 | #define CPUID_VARIANT 0x00F00000 // Variant Mask 150 | 151 | // NVIC: Application Interrupt/Reset Control Register 152 | #define NVIC_AIRCR (NVIC_Addr + 0x0D0C) 153 | #define VECTRESET 0x00000001 // Reset Cortex-M (except Debug) 154 | #define VECTCLRACTIVE 0x00000002 // Clear Active Vector Bit 155 | #define SYSRESETREQ 0x00000004 // Reset System (except Debug) 156 | #define VECTKEY 0x05FA0000 // Write Key 157 | 158 | // NVIC: Debug Fault Status Register 159 | #define NVIC_DFSR (NVIC_Addr + 0x0D30) 160 | #define HALTED 0x00000001 // Halt Flag 161 | #define BKPT 0x00000002 // BKPT Flag 162 | #define DWTTRAP 0x00000004 // DWT Match 163 | #define VCATCH 0x00000008 // Vector Catch Flag 164 | #define EXTERNAL 0x00000010 // External Debug Request 165 | 166 | // Data Watchpoint and Trace unit 167 | #define DWT_PCSR 0xe000101c // DWT PC Sampling Register 168 | 169 | #endif 170 | --------------------------------------------------------------------------------