From 2f051541cc9c869068f3d0761cb6d44979014d2a Mon Sep 17 00:00:00 2001 From: Samuel Date: Mon, 9 Jun 2025 18:48:02 +0200 Subject: [PATCH] =?UTF-8?q?Inclut=20maintenant=20le=20"disque"=20dans=20le?= =?UTF-8?q?=20chemin=20du=20fichier,=20qui=20permet=20d'=C3=A9crire=20sur?= =?UTF-8?q?=20une=20cl=C3=A9=20m=C3=AAme=20si=20elle=20est=20banch=C3=A9e?= =?UTF-8?q?=20au=20HUB.=20Ou=20d'=C3=A9crire=20sur=20deux=20cl=C3=A9s=20(n?= =?UTF-8?q?on=20test=C3=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .vscode/c_cpp_properties.json | 36 ++++++++++++++++ .vscode/settings.json | 9 ++++ .vscode/tasks.json | 25 +++++++++++ Journal.txt | 23 +--------- lib/source/ffconf.h | 2 +- msc_app.c | 80 +++++++++++++++++++++++++++++------ 7 files changed, 139 insertions(+), 37 deletions(-) create mode 100644 .gitignore create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d163863 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..c4f03aa --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,36 @@ +{ + "env": { + "myDefaultIncludePath": [ + "${workspaceFolder}", + "${workspaceFolder}/build", + "${workspaceFolder}/build/generated/pico_base", + "${env:PICO_SDK_PATH}/src/**/include", + "${env:PICO_SDK_PATH}/lib/**/src", + "${workspaceFolder}/lib/source" + + ], + "myCompilerPath": "/usr/bin/arm-none-eabi-gcc" + }, + "configurations": [ + { + "name": "Linux", + "intelliSenseMode": "linux-gcc-arm", + "includePath": [ + "${myDefaultIncludePath}", + "${workspaceFolder}/build/" + ], + "compilerPath": "/usr/bin/arm-none-eabi-gcc", + "cStandard": "c11", + "cppStandard": "c++17", + "browse": { + "path": [ + "${workspaceFolder}" + ], + "limitSymbolsToIncludedHeaders": true, + "databaseFilename": "" + }, + "configurationProvider": "ms-vscode.cmake-tools" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a173292 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "files.associations": { + "board.h": "c", + "tusb.h": "c", + "inttypes.h": "c", + "stdlib.h": "c", + "cdefs.h": "c" + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..7c45674 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,25 @@ +{ + "tasks": [ + { + "type": "shell", + "command": "cd build; cmake ../ -DLOG=2; make Flash", + "label": "Flash with LOG=2", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "type": "shell", + "command": "cd build; cmake ../ ; make Flash", + "label": "CMake & Make & Flash", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/Journal.txt b/Journal.txt index 005759c..318a24d 100644 --- a/Journal.txt +++ b/Journal.txt @@ -2,33 +2,12 @@ Journal USB Host 6 juin 2025 -On arrive à activer les logs, mais avec 2 manipulations : +On arrive à activer les logs, mais avec 1 manipulations, comme indiqué dans la documentation, mais avec la dernière version. tasks.json ---------- "command": "cd build; cmake ../ -DCMAKE_BUILD_TYPE=Debug -DLOG=2; make Flash", - -diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake -index 1eab95304..278e7e152 100644 ---- a/hw/bsp/rp2040/family.cmake -+++ b/hw/bsp/rp2040/family.cmake -@@ -49,13 +49,13 @@ if (NOT TARGET _rp2040_family_inclusion_marker) - set(TINYUSB_DEBUG_LEVEL 0) - if (CMAKE_BUILD_TYPE STREQUAL "Debug") - message("Compiling TinyUSB with CFG_TUSB_DEBUG=1") -- set(TINYUSB_DEBUG_LEVEL 1) -+ set(TINYUSB_DEBUG_LEVEL 2) - endif() - - target_compile_definitions(tinyusb_common_base INTERFACE - CFG_TUSB_MCU=OPT_MCU_RP2040 - CFG_TUSB_OS=OPT_OS_PICO -- #CFG_TUSB_DEBUG=${TINYUSB_DEBUG_LEVEL} -+ CFG_TUSB_DEBUG=${TINYUSB_DEBUG_LEVEL} - ) - - #------------------------------------ Doc de FsFat diff --git a/lib/source/ffconf.h b/lib/source/ffconf.h index e3d20e6..e108df1 100644 --- a/lib/source/ffconf.h +++ b/lib/source/ffconf.h @@ -166,7 +166,7 @@ / Drive/Volume Configurations /---------------------------------------------------------------------------*/ -#define FF_VOLUMES 1 +#define FF_VOLUMES 10 /* Number of volumes (logical drives) to be used. (1-10) */ diff --git a/msc_app.c b/msc_app.c index 61742e9..b76efb0 100644 --- a/msc_app.c +++ b/msc_app.c @@ -26,8 +26,8 @@ #include "tusb.h" #include "ff.h" #include "diskio.h" - -#include +#include "pico/time.h" +#include "stdlib.h" //--------------------------------------------------------------------+ // MACRO TYPEDEF CONSTANT ENUM DECLARATION @@ -38,10 +38,16 @@ static scsi_inquiry_resp_t inquiry_resp; static FATFS fatfs[CFG_TUH_DEVICE_MAX]; // for simplicity only support 1 LUN per device static volatile bool _disk_busy[CFG_TUH_DEVICE_MAX]; +bool file_accessible = false; +FIL fp; + +void log_to_usb(const char * message); + bool inquiry_complete_cb(uint8_t dev_addr, tuh_msc_complete_data_t const * cb_data) { msc_cbw_t const* cbw = cb_data->cbw; msc_csw_t const* csw = cb_data->csw; + FRESULT error; if (csw->status != 0) { @@ -66,33 +72,78 @@ bool inquiry_complete_cb(uint8_t dev_addr, tuh_msc_complete_data_t const * cb_da uint8_t const drive_num = dev_addr-1; char drive_path[3] = "0:"; drive_path[0] += drive_num; - if ( f_mount(&fatfs[drive_num], "", 1) != FR_OK ) + printf("dev_addr: %d\ndrive_num: %d\n", dev_addr, drive_num); + error = f_mount(&fatfs[drive_num], drive_path, 1); + if ( error != FR_OK ) { - printf("FatFs mount failed\n"); + printf("FatFs mount failed, error: %d\n", error); return true; } - - - FIL fp; + const char buffer[]= "Ceci est le test de Poivron Robotique\n"; - int nb_byte_witten; + char big_buffer[0x1000]; // 4 ko + char big_big_buffer[0x10000]; // 16 ko + int nb_byte_written; + absolute_time_t current_time, start_time; + char filepath[50]; + filepath[0] = drive_path[0]; + filepath[1] = ':'; + filepath[2] = '\0'; + strcat(filepath, "Poivron.txt"); + printf("filepath:%s\n", filepath); - FRESULT error; - error = f_open(&fp, "Poivron.txt", FA_WRITE | FA_OPEN_ALWAYS); + + error = f_open(&fp, filepath, FA_WRITE | FA_OPEN_ALWAYS); if(error){ printf("f_open: error %d\n", error); } - if(f_write(&fp, buffer, strlen(buffer), &nb_byte_witten)){ - printf("f_write: error %d\n", error); - }else{ - printf("Ecris: %d octets\n", nb_byte_witten); + file_accessible = true; + + // Ecrit petit buffer + log_to_usb(buffer); + // Ecrit gros buffer + int size = 0; + big_buffer[0]= '\0'; + while(size + strlen(buffer) < 0x1000){ + strcat(big_buffer, buffer); + size += strlen(buffer); } + log_to_usb(big_buffer); + + // Ecrit très gros buffer + size = 0; + big_big_buffer[0]= '\0'; + while(size + strlen(buffer) < 0x10000){ + strcat(big_buffer, buffer); + size += strlen(buffer); + } + log_to_usb(big_big_buffer); + + + f_close(&fp); printf("Fichier Poivron.txt cree avec succes\n"); return true; } +void log_to_usb(const char * message){ + int nb_byte_written; + absolute_time_t current_time, start_time; + start_time = get_absolute_time(); + FRESULT error; + if(file_accessible){ + error = f_write(&fp, message, strlen(message), &nb_byte_written); + if(error){ + printf("f_write: error %d\n", error); + return; + } + f_sync(&fp); + current_time = get_absolute_time(); + printf("Ecrit: %d octets en %llu us\n", nb_byte_written, current_time - start_time); + } +} + //------------- IMPLEMENTATION -------------// void tuh_msc_mount_cb(uint8_t dev_addr) { @@ -104,6 +155,7 @@ void tuh_msc_mount_cb(uint8_t dev_addr) void tuh_msc_umount_cb(uint8_t dev_addr) { + file_accessible = false; (void) dev_addr; printf("A MassStorage device is unmounted\r\n"); }