Code utilisé pour tester la vitesse de la liaison USB CDC avec un Raspberry Pi Pico en USB Host

This commit is contained in:
Samuel 2025-08-26 23:16:20 +02:00
parent 27951754ed
commit 1798c1ca4e
6 changed files with 84 additions and 4 deletions

12
.vscode/tasks.json vendored
View File

@ -7,7 +7,17 @@
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
"isDefault": false
}
},
{
"type": "shell",
"command": "cd build; cmake ../ -DLOG=1; make Flash",
"label": "Flash with LOG=1",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": false
}
},
{

View File

@ -22,6 +22,7 @@ target_sources(host_cdc_msc_hid PUBLIC
cdc_app.c
diskio_USB.c
diskio_SDIO.c
log_usb.c
lib/FatFs/source/ff.c
lib/FatFs/source/ffsystem.c
lib/FatFs/source/diskio.c
@ -75,3 +76,5 @@ add_custom_target(Flash
DEPENDS host_cdc_msc_hid
COMMAND sudo picotool load -f ${PROJECT_BINARY_DIR}/host_cdc_msc_hid.uf2
)
add_definitions(-DPICO_STDIO_ENABLE_CRLF_SUPPORT=0)

View File

@ -26,6 +26,10 @@
#include "tusb.h"
#include "bsp/board_api.h"
#include "log_usb.h"
#include <stdio.h>
volatile bool in_transfert_cb = 0;
size_t get_console_inputs(uint8_t* buf, size_t bufsize) {
size_t count = 0;
@ -65,14 +69,38 @@ void cdc_app_task(void) {
// Invoked when received new data
void tuh_cdc_rx_cb(uint8_t idx) {
if(in_transfert_cb){
printf("already processing data\n");
return;
}
absolute_time_t current_time_us, start_time_us;
start_time_us = get_absolute_time();
in_transfert_cb = 1;
uint8_t buf[64 + 1]; // +1 for extra null character
char chaine[1024];
uint32_t const bufsize = sizeof(buf) - 1;
// forward cdc interfaces -> console
uint32_t count = tuh_cdc_read(idx, buf, bufsize);
buf[count] = 0;
printf("%s", (char*) buf);
log_analyse_input_string(buf, count);
log_get(chaine);
current_time_us = get_absolute_time();
if(strlen(chaine)> 0){
printf("%s", chaine);
printf(">temp_rec:%d\n", current_time_us);
chaine[0] = '\0';
}
in_transfert_cb = 0;
}
// Invoked when a device with CDC interface is mounted

37
log_usb.c Normal file
View File

@ -0,0 +1,37 @@
#include <string.h>
char tampon[1020];
char log_dispo[1020]={'\0'};
unsigned int index_tampon=0;
void log_analyse_input_string(const char * input_data, unsigned int str_len){
// On charge les données dans le tampon
// Si on a un message complet, on charge dans log dispo (s'il y a la place)
static int copy = 0;
for(int i=0; i< str_len; i++){
if(input_data[i] == '>'){
copy = 1;
}
if(copy == 1){
tampon[index_tampon] = input_data[i];
index_tampon++;
if(input_data[i] == '\n'){
copy = 0;
tampon[index_tampon] = '\0';
strcat(log_dispo, tampon);
index_tampon=0;
}
}
}
}
// On renvoi la chaine et on remet log_dispo à 0;
void log_get(char * chaine){
strcpy(chaine, log_dispo);
log_dispo[0] = '\0';
}

2
log_usb.h Normal file
View File

@ -0,0 +1,2 @@
void log_analyse_input_string(char * input_data, unsigned int str_len);
void log_get(char * chaine);

4
main.c
View File

@ -161,8 +161,8 @@ int main(void) {
led_blinking_task();
cdc_app_task();
hid_app_task();
log_to_sd(big_big_buffer);
log_to_usb(big_big_buffer); // à commenter pour obtenir un test juste sur la carte SD.(ou simplement ne pas brancher de clé USB)
//log_to_sd(big_big_buffer);
//log_to_usb(big_big_buffer); // à commenter pour obtenir un test juste sur la carte SD.(ou simplement ne pas brancher de clé USB)
}
}