Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made it possible to print to any HardwareSerial object pointer #148

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dzalf
Copy link

@dzalf dzalf commented Mar 5, 2024

The library currently prints information from the SD Card like filenames, and file sizes to the Serial port (connected to USB in most cases) by default.

By assigning a pointer to a HardwareSerial object it is possible to print such information to any port selected by the user.

This becomes relevant when working with chips that have multiple UART ports: e.g. when debugging code on a separate serial port.

@CLAassistant
Copy link

CLAassistant commented Mar 5, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

github-actions bot commented Mar 5, 2024

Memory usage change @ e5a92b2

Board flash % RAM for global variables %
arduino:avr:mega 🔺 0 - +164 0.0 - +0.06 0 - 0 0.0 - 0.0
arduino:avr:nano 🔺 0 - +164 0.0 - +0.53 0 - 0 0.0 - 0.0
arduino:mbed_nano:nano33ble 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nano:nanorp2040connect 🔺 0 - +6 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7:target_core=cm4 N/A N/A N/A N/A
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A
arduino:megaavr:nona4809 🔺 0 - +164 0.0 - +0.33 0 - 0 0.0 - 0.0
arduino:sam:arduino_due_x_dbg 🔺 0 - +8 0.0 - 0.0 N/A N/A
arduino:samd:mkrzero 🔺 0 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
Click for full report table
Board examples/CardInfo
flash
% examples/CardInfo
RAM for global variables
% examples/Datalogger
flash
% examples/Datalogger
RAM for global variables
% examples/DumpFile
flash
% examples/DumpFile
RAM for global variables
% examples/Files
flash
% examples/Files
RAM for global variables
% examples/NonBlockingWrite
flash
% examples/NonBlockingWrite
RAM for global variables
% examples/ReadWrite
flash
% examples/ReadWrite
RAM for global variables
% examples/listfiles
flash
% examples/listfiles
RAM for global variables
%
arduino:avr:mega 164 0.06 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:avr:nano 164 0.53 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:mbed_nano:nano33ble 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:mbed_nano:nanorp2040connect 6 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:mbed_portenta:envie_m7:target_core=cm4 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
arduino:megaavr:nona4809 164 0.33 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:sam:arduino_due_x_dbg 8 0.0 N/A N/A 0 0.0 N/A N/A 0 0.0 N/A N/A 0 0.0 N/A N/A 0 0.0 N/A N/A 0 0.0 N/A N/A 0 0.0 N/A N/A
arduino:samd:mkrzero 4 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
Click for full report CSV
Board,examples/CardInfo<br>flash,%,examples/CardInfo<br>RAM for global variables,%,examples/Datalogger<br>flash,%,examples/Datalogger<br>RAM for global variables,%,examples/DumpFile<br>flash,%,examples/DumpFile<br>RAM for global variables,%,examples/Files<br>flash,%,examples/Files<br>RAM for global variables,%,examples/NonBlockingWrite<br>flash,%,examples/NonBlockingWrite<br>RAM for global variables,%,examples/ReadWrite<br>flash,%,examples/ReadWrite<br>RAM for global variables,%,examples/listfiles<br>flash,%,examples/listfiles<br>RAM for global variables,%
arduino:avr:mega,164,0.06,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:avr:nano,164,0.53,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:mbed_nano:nano33ble,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:mbed_nano:nanorp2040connect,6,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:mbed_portenta:envie_m7:target_core=cm4,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A
arduino:mbed_portenta:envie_m7,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A
arduino:megaavr:nona4809,164,0.33,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:sam:arduino_due_x_dbg,8,0.0,N/A,N/A,0,0.0,N/A,N/A,0,0.0,N/A,N/A,0,0.0,N/A,N/A,0,0.0,N/A,N/A,0,0.0,N/A,N/A,0,0.0,N/A,N/A
arduino:samd:mkrzero,4,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0

@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Mar 5, 2024
@dzalf
Copy link
Author

dzalf commented Mar 6, 2024

Dear @per1234

Do you have any idea why the tests failed on the Leonardo board?

Cheers

@per1234
Copy link
Contributor

per1234 commented Mar 6, 2024

@dzalf have you looked at the logs:

https://github.com/arduino-libraries/SD/actions/runs/8148913387/job/22272654075?pr=148#step:3:170

  /home/runner/Arduino/libraries/SD/src/utility/SdFat.h:281:73: error: could not convert '& Serial' from 'Serial_*' to 'HardwareSerial*'
     void ls(uint8_t flags = 0, uint8_t indent = 0, HardwareSerial *port = &Serial);
                                                                           ^~~~~~~
  /home/runner/Arduino/libraries/SD/src/utility/SdFat.h:287:84: error: could not convert '& Serial' from 'Serial_*' to 'HardwareSerial*'
     static void printDirName(const dir_t &dir, uint8_t width, HardwareSerial *port = &Serial);
                                                                                      ^~~~~~~
  /home/runner/Arduino/libraries/SD/src/utility/SdFat.h:288:69: error: could not convert '& Serial' from 'Serial_*' to 'HardwareSerial*'
     static void printFatDate(uint16_t fatDate, HardwareSerial *port = &Serial);
                                                                       ^~~~~~~
  /home/runner/Arduino/libraries/SD/src/utility/SdFat.h:289:69: error: could not convert '& Serial' from 'Serial_*' to 'HardwareSerial*'
     static void printFatTime(uint16_t fatTime, HardwareSerial *port = &Serial);
                                                                       ^~~~~~~
  /home/runner/Arduino/libraries/SD/src/utility/SdFat.h:290:64: error: could not convert '& Serial' from 'Serial_*' to 'HardwareSerial*'
     static void printTwoDigits(uint8_t v, HardwareSerial *port = &Serial);
                                                                  ^~~~~~~
  /home/runner/work/SD/SD/examples/CardInfo/CardInfo.ino: In function 'void setup()':
  /home/runner/work/SD/SD/examples/CardInfo/CardInfo.ino:113:35: error: cannot convert 'Serial_*' to 'HardwareSerial*' for argument '3' to 'void SdFile::ls(uint8_t, uint8_t, HardwareSerial*)'

You can reproduce it locally by installing the version of the library from this PR, selecting Tools > Board > Arduino AVR Boards > Arduino Leonardo from the Arduino IDE menus, and then compiling a sketch sketch that uses the SD library.

Note this:

https://github.com/arduino/ArduinoCore-avr/blob/1.8.6/cores/arduino/USBAPI.h#L154

extern Serial_ Serial;

@dzalf
Copy link
Author

dzalf commented Mar 7, 2024

Dear @per1234

Apologies, I had not seen those.

It makes sense to me now. I wasn't aware of the extern Serial object declaration on the Leonardo API.

Any workaround ideas to integrate this enhancement?

Copy link

Memory usage change @ 03b49f0

Board flash % RAM for global variables %
arduino:avr:mega 🔺 0 - +164 0.0 - +0.06 0 - 0 0.0 - 0.0
arduino:avr:nano 🔺 0 - +164 0.0 - +0.53 0 - 0 0.0 - 0.0
arduino:mbed_nano:nano33ble 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nano:nanorp2040connect 🔺 0 - +2 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A
arduino:mbed_portenta:envie_m7:target_core=cm4 N/A N/A N/A N/A
arduino:megaavr:nona4809 🔺 0 - +164 0.0 - +0.33 0 - 0 0.0 - 0.0
arduino:sam:arduino_due_x_dbg 🔺 0 - +8 0.0 - 0.0 N/A N/A
arduino:samd:mkrzero 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
Click for full report table
Board examples/CardInfo
flash
% examples/CardInfo
RAM for global variables
% examples/Datalogger
flash
% examples/Datalogger
RAM for global variables
% examples/DumpFile
flash
% examples/DumpFile
RAM for global variables
% examples/Files
flash
% examples/Files
RAM for global variables
% examples/NonBlockingWrite
flash
% examples/NonBlockingWrite
RAM for global variables
% examples/ReadWrite
flash
% examples/ReadWrite
RAM for global variables
% examples/listfiles
flash
% examples/listfiles
RAM for global variables
%
arduino:avr:mega 164 0.06 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:avr:nano 164 0.53 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:mbed_nano:nano33ble 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:mbed_nano:nanorp2040connect 2 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
arduino:mbed_portenta:envie_m7:target_core=cm4 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
arduino:megaavr:nona4809 164 0.33 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:sam:arduino_due_x_dbg 8 0.0 N/A N/A 0 0.0 N/A N/A 0 0.0 N/A N/A 0 0.0 N/A N/A 0 0.0 N/A N/A 0 0.0 N/A N/A 0 0.0 N/A N/A
arduino:samd:mkrzero 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
Click for full report CSV
Board,examples/CardInfo<br>flash,%,examples/CardInfo<br>RAM for global variables,%,examples/Datalogger<br>flash,%,examples/Datalogger<br>RAM for global variables,%,examples/DumpFile<br>flash,%,examples/DumpFile<br>RAM for global variables,%,examples/Files<br>flash,%,examples/Files<br>RAM for global variables,%,examples/NonBlockingWrite<br>flash,%,examples/NonBlockingWrite<br>RAM for global variables,%,examples/ReadWrite<br>flash,%,examples/ReadWrite<br>RAM for global variables,%,examples/listfiles<br>flash,%,examples/listfiles<br>RAM for global variables,%
arduino:avr:mega,164,0.06,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:avr:nano,164,0.53,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:mbed_nano:nano33ble,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:mbed_nano:nanorp2040connect,2,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:mbed_portenta:envie_m7,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A
arduino:mbed_portenta:envie_m7:target_core=cm4,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A
arduino:megaavr:nona4809,164,0.33,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:sam:arduino_due_x_dbg,8,0.0,N/A,N/A,0,0.0,N/A,N/A,0,0.0,N/A,N/A,0,0.0,N/A,N/A,0,0.0,N/A,N/A,0,0.0,N/A,N/A,0,0.0,N/A,N/A
arduino:samd:mkrzero,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants