From 11c278e368611d9ede1c136422d3f11f52f3f3b0 Mon Sep 17 00:00:00 2001 From: Samuel Date: Sat, 27 Sep 2025 10:05:21 +0200 Subject: [PATCH] Debug fonctionnel sans le plugin --- .gitignore | 2 +- .vscode/c_cpp_properties.json | 22 ------- .vscode/cmake-kits.json | 15 ----- .vscode/extensions.json | 9 --- .vscode/launch.json | 36 ++--------- .vscode/settings.json | 43 ++------------ .vscode/tasks.json | 109 +++++----------------------------- CMakeLists.txt | 16 ----- communication.c | 24 ++++++-- main.c | 12 +++- messagerie.h | 2 +- pico_sdk_import.cmake | 63 +------------------- 12 files changed, 57 insertions(+), 296 deletions(-) delete mode 100644 .vscode/c_cpp_properties.json delete mode 100644 .vscode/cmake-kits.json delete mode 100644 .vscode/extensions.json diff --git a/.gitignore b/.gitignore index 57c1469..b65c12a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ build/ -build-dbg/ \ No newline at end of file +debug/ \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json deleted file mode 100644 index a1f2032..0000000 --- a/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "configurations": [ - { - "name": "Pico", - "includePath": [ - "${workspaceFolder}/**", - "${userHome}/.pico-sdk/sdk/2.2.0/**" - ], - "forcedInclude": [ - "${userHome}/.pico-sdk/sdk/2.2.0/src/common/pico_base_headers/include/pico.h", - "${workspaceFolder}/build/generated/pico_base/pico/config_autogen.h" - ], - "defines": [], - "compilerPath": "${userHome}/.pico-sdk/toolchain/14_2_Rel1/bin/arm-none-eabi-gcc", - "compileCommands": "${workspaceFolder}/build/compile_commands.json", - "cStandard": "c17", - "cppStandard": "c++14", - "intelliSenseMode": "linux-gcc-arm" - } - ], - "version": 4 -} diff --git a/.vscode/cmake-kits.json b/.vscode/cmake-kits.json deleted file mode 100644 index b0f3815..0000000 --- a/.vscode/cmake-kits.json +++ /dev/null @@ -1,15 +0,0 @@ -[ - { - "name": "Pico", - "compilers": { - "C": "${command:raspberry-pi-pico.getCompilerPath}", - "CXX": "${command:raspberry-pi-pico.getCxxCompilerPath}" - }, - "environmentVariables": { - "PATH": "${command:raspberry-pi-pico.getEnvPath};${env:PATH}" - }, - "cmakeSettings": { - "Python3_EXECUTABLE": "${command:raspberry-pi-pico.getPythonPath}" - } - } -] \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index a940d7c..0000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "recommendations": [ - "marus25.cortex-debug", - "ms-vscode.cpptools", - "ms-vscode.cpptools-extension-pack", - "ms-vscode.vscode-serial-monitor", - "raspberry-pi.raspberry-pi-pico" - ] -} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 424aa71..185d9b8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,49 +1,23 @@ { "version": "0.2.0", "configurations": [ - { - "name": "Pico Debug (Cortex-Debug)", - "cwd": "${userHome}/.pico-sdk/openocd/0.12.0+dev/scripts", - "executable": "${command:raspberry-pi-pico.launchTargetPath}", - "request": "launch", - "type": "cortex-debug", - "servertype": "openocd", - "serverpath": "${userHome}/.pico-sdk/openocd/0.12.0+dev/openocd.exe", - "gdbPath": "${command:raspberry-pi-pico.getGDBPath}", - "device": "${command:raspberry-pi-pico.getChipUppercase}", - "configFiles": [ - "interface/cmsis-dap.cfg", - "target/${command:raspberry-pi-pico.getTarget}.cfg" - ], - "svdFile": "${userHome}/.pico-sdk/sdk/2.2.0/src/${command:raspberry-pi-pico.getChip}/hardware_regs/${command:raspberry-pi-pico.getChipUppercase}.svd", - "runToEntryPoint": "main", - // Fix for no_flash binaries, where monitor reset halt doesn't do what is expected - // Also works fine for flash binaries - "overrideLaunchCommands": [ - "monitor reset init", - "load \"${command:raspberry-pi-pico.launchTargetPath}\"" - ], - "openOCDLaunchCommands": [ - "adapter speed 5000" - ] - }, { "name": "Pico Debug (Cortex-Debug with external OpenOCD)", "cwd": "${workspaceRoot}", - "executable": "${command:raspberry-pi-pico.launchTargetPath}", + "executable": "debug/Modele_RPiPico.elf", "request": "launch", "type": "cortex-debug", "servertype": "external", "gdbTarget": "localhost:3333", - "gdbPath": "${command:raspberry-pi-pico.getGDBPath}", - "device": "${command:raspberry-pi-pico.getChipUppercase}", - "svdFile": "${userHome}/.pico-sdk/sdk/2.2.0/src/${command:raspberry-pi-pico.getChip}/hardware_regs/${command:raspberry-pi-pico.getChipUppercase}.svd", + "gdbPath": "gdb-multiarch", + "device": "RP2040", + "svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/RP2040.svd", "runToEntryPoint": "main", // Fix for no_flash binaries, where monitor reset halt doesn't do what is expected // Also works fine for flash binaries "overrideLaunchCommands": [ "monitor reset init", - "load \"${command:raspberry-pi-pico.launchTargetPath}\"" + "load debug/Modele_RPiPico.elf" ] }, ] diff --git a/.vscode/settings.json b/.vscode/settings.json index b6c0f55..4217d5b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,40 +1,5 @@ { - "cmake.showSystemKits": false, - "cmake.options.statusBarVisibility": "hidden", - "cmake.options.advanced": { - "build": { - "statusBarVisibility": "hidden" - }, - "launch": { - "statusBarVisibility": "hidden" - }, - "debug": { - "statusBarVisibility": "hidden" - } - }, - "cmake.configureOnEdit": true, - "cmake.automaticReconfigure": true, - "cmake.configureOnOpen": true, - "cmake.generator": "Ninja", - "cmake.cmakePath": "${userHome}/.pico-sdk/cmake/v3.31.5/bin/cmake", - "C_Cpp.debugShortcut": false, - "terminal.integrated.env.windows": { - "PICO_SDK_PATH": "${env:USERPROFILE}/.pico-sdk/sdk/2.2.0", - "PICO_TOOLCHAIN_PATH": "${env:USERPROFILE}/.pico-sdk/toolchain/14_2_Rel1", - "Path": "${env:USERPROFILE}/.pico-sdk/toolchain/14_2_Rel1/bin;${env:USERPROFILE}/.pico-sdk/picotool/2.2.0/picotool;${env:USERPROFILE}/.pico-sdk/cmake/v3.31.5/bin;${env:USERPROFILE}/.pico-sdk/ninja/v1.12.1;${env:PATH}" - }, - "terminal.integrated.env.osx": { - "PICO_SDK_PATH": "${env:HOME}/.pico-sdk/sdk/2.2.0", - "PICO_TOOLCHAIN_PATH": "${env:HOME}/.pico-sdk/toolchain/14_2_Rel1", - "PATH": "${env:HOME}/.pico-sdk/toolchain/14_2_Rel1/bin:${env:HOME}/.pico-sdk/picotool/2.2.0/picotool:${env:HOME}/.pico-sdk/cmake/v3.31.5/bin:${env:HOME}/.pico-sdk/ninja/v1.12.1:${env:PATH}" - }, - "terminal.integrated.env.linux": { - "PICO_SDK_PATH": "${env:HOME}/.pico-sdk/sdk/2.2.0", - "PICO_TOOLCHAIN_PATH": "${env:HOME}/.pico-sdk/toolchain/14_2_Rel1", - "PATH": "${env:HOME}/.pico-sdk/toolchain/14_2_Rel1/bin:${env:HOME}/.pico-sdk/picotool/2.2.0/picotool:${env:HOME}/.pico-sdk/cmake/v3.31.5/bin:${env:HOME}/.pico-sdk/ninja/v1.12.1:${env:PATH}" - }, - "raspberry-pi-pico.cmakeAutoConfigure": false, - "raspberry-pi-pico.useCmakeTools": true, - "raspberry-pi-pico.cmakePath": "${HOME}/.pico-sdk/cmake/v3.31.5/bin/cmake", - "raspberry-pi-pico.ninjaPath": "${HOME}/.pico-sdk/ninja/v1.12.1/ninja" -} + "files.associations": { + "string.h": "c" + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index f427bf0..2f9adff 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,102 +1,25 @@ { - "version": "2.0.0", "tasks": [ { - "label": "Compile Project", - "type": "process", - "isBuildCommand": true, - "command": "${userHome}/.pico-sdk/ninja/v1.12.1/ninja", - "args": ["-C", "${workspaceFolder}/build"], - "group": "build", - "presentation": { - "reveal": "always", - "panel": "dedicated" - }, - "problemMatcher": "$gcc", - "windows": { - "command": "${env:USERPROFILE}/.pico-sdk/ninja/v1.12.1/ninja.exe" + "type": "shell", + "command": "cd build; cmake ../; make Flash", + "label": "CMake & Make & Flash", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true } }, { - "label": "Run Project", - "type": "process", - "command": "${env:HOME}/.pico-sdk/picotool/2.2.0/picotool/picotool", - "args": [ - "load", - "${command:raspberry-pi-pico.launchTargetPath}", - "-fx" - ], - "presentation": { - "reveal": "always", - "panel": "dedicated" - }, + "type": "shell", + "command": "cd debug; cmake -DCMAKE_BUILD_TYPE=Debug ../; make Flash", + "label": "Flash Debug", "problemMatcher": [], - "windows": { - "command": "${env:USERPROFILE}/.pico-sdk/picotool/2.2.0/picotool/picotool.exe" - } - }, - { - "label": "Flash", - "type": "process", - "command": "${userHome}/.pico-sdk/openocd/0.12.0+dev/openocd.exe", - "args": [ - "-s", - "${userHome}/.pico-sdk/openocd/0.12.0+dev/scripts", - "-f", - "interface/cmsis-dap.cfg", - "-f", - "target/${command:raspberry-pi-pico.getTarget}.cfg", - "-c", - "adapter speed 5000; program \"${command:raspberry-pi-pico.launchTargetPath}\" verify reset exit" - ], - "problemMatcher": [], - "windows": { - "command": "${env:USERPROFILE}/.pico-sdk/openocd/0.12.0+dev/openocd.exe", - } - }, - { - "label": "Rescue Reset", - "type": "process", - "command": "${userHome}/.pico-sdk/openocd/0.12.0+dev/openocd.exe", - "args": [ - "-s", - "${userHome}/.pico-sdk/openocd/0.12.0+dev/scripts", - "-f", - "interface/cmsis-dap.cfg", - "-f", - "target/${command:raspberry-pi-pico.getChip}-rescue.cfg", - "-c", - "adapter speed 5000; reset halt; exit" - ], - "problemMatcher": [], - "windows": { - "command": "${env:USERPROFILE}/.pico-sdk/openocd/0.12.0+dev/openocd.exe", - } - }, - { - "label": "Risc-V Reset (RP2350)", - "type": "process", - "command": "${userHome}/.pico-sdk/openocd/0.12.0+dev/openocd.exe", - "args": [ - "-s", - "${userHome}/.pico-sdk/openocd/0.12.0+dev/scripts", - "-c", - "set USE_CORE { rv0 rv1 cm0 cm1 }", - "-f", - "interface/cmsis-dap.cfg", - "-f", - "target/rp2350.cfg", - "-c", - "adapter speed 5000; init;", - "-c", - "write_memory 0x40120158 8 { 0x3 }; echo [format \"Info : ARCHSEL 0x%02x\" [read_memory 0x40120158 8 1]];", - "-c", - "reset halt; targets rp2350.rv0; echo [format \"Info : ARCHSEL_STATUS 0x%02x\" [read_memory 0x4012015C 8 1]]; exit" - ], - "problemMatcher": [], - "windows": { - "command": "${env:USERPROFILE}/.pico-sdk/openocd/0.12.0+dev/openocd.exe", + "group": { + "kind": "build", + "isDefault": true } } - ] -} + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index c32035c..dd71dda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,19 +1,3 @@ -# == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == -if(WIN32) - set(USERHOME $ENV{USERPROFILE}) -else() - set(USERHOME $ENV{HOME}) -endif() -set(sdkVersion 2.2.0) -set(toolchainVersion 14_2_Rel1) -set(picotoolVersion 2.2.0) -set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) -if (EXISTS ${picoVscode}) - include(${picoVscode}) -endif() -# ==================================================================================== -set(PICO_BOARD pico CACHE STRING "Board type") - cmake_minimum_required(VERSION 3.13) include(pico_sdk_import.cmake) diff --git a/communication.c b/communication.c index 73e4579..ca8af9f 100644 --- a/communication.c +++ b/communication.c @@ -2,6 +2,7 @@ #include #include "communication.h" #include "messagerie.h" +#include "tusb.h" #define TAMPON_TAILLE 1020 @@ -43,14 +44,28 @@ void augmente_index(unsigned int *index, unsigned int offset){ void communication_reception_message(){ int input_char; int chaîne_octets_reçus[TAMPON_TAILLE]; - absolute_time_t current_time_us, start_time_us; unsigned int index_chaine_recue; unsigned int index_tampon; struct message_t message; // Si un caractère est reçu, ajout du caractère au tampon tournant - start_time_us = get_absolute_time(); - input_char = stdio_getchar_timeout_us(0); + /// TODO: Tester le code suivant à la place de while get_char(); + + char nb_recu=0; + if(tud_cdc_available()){ + char tampon_usb[128]; + nb_recu = tud_cdc_read(tampon_usb, 128); + // copie dans le tampon tournant + for(int i=0; i= TAMPON_TAILLE){ + com_reception_buffer.index_tampon_ecriture = 0; + } + com_reception_buffer.tampon[com_reception_buffer.index_tampon_ecriture] = input_char; + } + } + /* while(input_char != PICO_ERROR_TIMEOUT){ com_reception_buffer.index_tampon_ecriture++; if(com_reception_buffer.index_tampon_ecriture >= TAMPON_TAILLE){ @@ -61,8 +76,7 @@ void communication_reception_message(){ // Caractère suivant ? input_char = stdio_getchar_timeout_us(0); } - current_time_us = get_absolute_time(); - printf(">temps:%lld\n", current_time_us - start_time_us); + */ // Copie du tampon tournant dans une chaine // Parce que c'est plus simple à traiter diff --git a/main.c b/main.c index ce938a5..4adf714 100644 --- a/main.c +++ b/main.c @@ -68,6 +68,8 @@ void main(void) message_binaire[9]= 0; + printf(">Device 1 - demarrage\n"); + for(int i=0; i<10000; i++){ @@ -80,6 +82,7 @@ void main(void) } int nb_ech = 10; int taille_morceau = 60; + int nb_message=0; stdio_init_all(); sleep_ms(5000); gpio_init(PICO_DEFAULT_LED_PIN); @@ -98,16 +101,15 @@ void main(void) envoie_structure(&message_requete_detection, sizeof(message_requete_detection) ); temps_message_detection = get_absolute_time(); current_time_us = get_absolute_time(); - printf(">temps_r:%lld\n", current_time_us - start_time_us); + //printf(">temps_emission:%lld\n", current_time_us - start_time_us); } start_time_us = get_absolute_time(); communication_reception_message(); - current_time_us = get_absolute_time(); - printf(">temps:%lld\n", current_time_us - start_time_us); if(messagerie_message_disponible()){ while(messagerie_message_disponible()){ message = messagerie_get_message(); + nb_message++; if(message.type == 'r'){ if(message.id_carte == 'D'){ temps_message_detection = get_absolute_time(); @@ -123,6 +125,10 @@ void main(void) } } + current_time_us = get_absolute_time(); + //printf(">temps_reception:%lld\n", current_time_us - start_time_us); + printf(">nb_message:%u\n",nb_message); + } diff --git a/messagerie.h b/messagerie.h index 158898e..5f0cd59 100644 --- a/messagerie.h +++ b/messagerie.h @@ -1,6 +1,6 @@ #include "pico/stdlib.h" -#define MESSAGE_TIMEOUT_US 10000 +#define MESSAGE_TIMEOUT_US 2000 struct message_t{ uint8_t type; // 'd' pour demande, 'r' pour une réception de données, 'w' pour écrire des données, '>' pour des logs diff --git a/pico_sdk_import.cmake b/pico_sdk_import.cmake index d493cc2..28efe9e 100644 --- a/pico_sdk_import.cmake +++ b/pico_sdk_import.cmake @@ -3,28 +3,6 @@ # This can be dropped into an external project to help locate this SDK # It should be include()ed prior to project() -# Copyright 2020 (c) 2020 Raspberry Pi (Trading) Ltd. -# -# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the -# following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following -# disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") @@ -40,20 +18,9 @@ if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_P message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") endif () -if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_TAG} AND (NOT PICO_SDK_FETCH_FROM_GIT_TAG)) - set(PICO_SDK_FETCH_FROM_GIT_TAG $ENV{PICO_SDK_FETCH_FROM_GIT_TAG}) - message("Using PICO_SDK_FETCH_FROM_GIT_TAG from environment ('${PICO_SDK_FETCH_FROM_GIT_TAG}')") -endif () - -if (PICO_SDK_FETCH_FROM_GIT AND NOT PICO_SDK_FETCH_FROM_GIT_TAG) - set(PICO_SDK_FETCH_FROM_GIT_TAG "master") - message("Using master as default value for PICO_SDK_FETCH_FROM_GIT_TAG") -endif() - set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") 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") set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") -set(PICO_SDK_FETCH_FROM_GIT_TAG "${PICO_SDK_FETCH_FROM_GIT_TAG}" CACHE FILEPATH "release tag for SDK") if (NOT PICO_SDK_PATH) if (PICO_SDK_FETCH_FROM_GIT) @@ -65,37 +32,11 @@ if (NOT PICO_SDK_PATH) FetchContent_Declare( pico_sdk GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk - GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG} + GIT_TAG master ) - if (NOT pico_sdk) message("Downloading Raspberry Pi Pico SDK") - # GIT_SUBMODULES_RECURSE was added in 3.17 - if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") - FetchContent_Populate( - pico_sdk - QUIET - GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk - GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG} - GIT_SUBMODULES_RECURSE FALSE - - SOURCE_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-src - BINARY_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-build - SUBBUILD_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-subbuild - ) - else () - FetchContent_Populate( - pico_sdk - QUIET - GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk - GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG} - - SOURCE_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-src - BINARY_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-build - SUBBUILD_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-subbuild - ) - endif () - + FetchContent_Populate(pico_sdk) set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) endif () set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})