# Using SD card with portenta

**URL:** <https://forum.arduino.cc/t/using-sd-card-with-portenta/1242137>\
**Category:** Portenta H7\
**Created:** [March 31, 2024, 12:47pm UTC](https://forum.arduino.cc/t/using-sd-card-with-portenta/1242137 "2024-03-31T12:47:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mercala\_eng](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@mercala\_eng](https://forum.arduino.cc/u/mercala_eng)\
**Post date:** [March 31, 2024, 12:47pm UTC](https://forum.arduino.cc/t/using-sd-card-with-portenta/1242137/1 "2024-03-31T12:47:57Z")

</div>

Please, is there any one here that used portenta h7?  
I need to read all the values in text file but I have no idea!! any HELP please?

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [March 31, 2024, 2:52pm UTC](https://forum.arduino.cc/t/using-sd-card-with-portenta/1242137/2 "2024-03-31T14:52:56Z")

</div>

Search the forum for related topics

Here is one

> [@Portenta H7: Write to SD Card](https://forum.arduino.cc/t/portenta-h7-write-to-sd-card/702079):
>
> Hi, I would like to write to an Micro SD Card. I'm using the Pins 55, 57, 59, 61,63, 65 on the high density connector J1 (see appendix). The example code TestSDCARD.ino is working well and I can list some directories on the SD Card. Now I trying to use the FATFileSystem with fopen, fprintf and fclose, but I can't write to the SD Card. The red LED on the Portenta board starts flashing. The Serial output is: Test 1 Which concludes that there is a error in line fprintf(fs,"test \r\n"); #inclu…

---

<div class="post-metadata">

**Author:** ![mercala\_eng](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@mercala\_eng](https://forum.arduino.cc/u/mercala_eng)\
**Post date:** [March 31, 2024, 3:46pm UTC](https://forum.arduino.cc/t/using-sd-card-with-portenta/1242137/3 "2024-03-31T15:46:52Z")

</div>

Thank you, now I can read and write from sdcard.  
But now I am trying to run my code but I got on this error, Why? I have not any sleep function in my code!!

```arduino
In file included from c:\users\lab\appdata\local\arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\sys\reent.h:13:0,
                 from c:\users\lab\appdata\local\arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\math.h:5,
                 from c:\users\lab\appdata\local\arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\c++\7.2.1\cmath:45,
                 from c:\users\lab\appdata\local\arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\c++\7.2.1\math.h:36,
                 from C:\Users\lab\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\4.1.1\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal_def.h:33,
                 from C:\Users\lab\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\4.1.1\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal_rcc.h:29,
                 from C:\Users\lab\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\4.1.1\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/stm32h7xx_hal_conf.h:398,
                 from C:\Users\lab\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\4.1.1\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/STM32H7xx_HAL_Driver/stm32h7xx_hal.h:30,
                 from C:\Users\lab\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\4.1.1\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/CMSIS/stm32h7xx.h:223,
                 from C:\Users\lab\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\4.1.1\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/cmsis.h:22,
                 from C:\Users\lab\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\4.1.1\cores\arduino/mbed/targets/TARGET_STM/PinNamesTypes.h:33,
                 from C:\Users\lab\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\4.1.1\variants\PORTENTA_H7_M7/pinmode_arduino.h:24,
                 from C:\Users\lab\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\4.1.1\cores\arduino/Arduino.h:26,
                 from sketch\portenta.ino.cpp:1:
c:\users\lab\appdata\local\arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\sys\unistd.h:209:10: error: conflicting declaration of C function 'unsigned int sleep(unsigned int)'
 unsigned _EXFUN(sleep, (unsigned int __seconds ));
          ^
In file included from C:\Users\lab\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\4.1.1\cores\arduino/mbed/drivers/include/drivers/HighResClock.h:22:0,
                 from C:\Users\lab\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\4.1.1\cores\arduino/mbed/mbed.h:82,
                 from C:\Users\lab\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\4.1.1\cores\arduino/mbed.h:8,
                 from C:\Users\lab\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\4.1.1\libraries\Portenta_SDCARD\src/SDMMCBlockDevice.h:21,
                 from C:\Users\lab\Desktop\portenta\portenta.ino:12:
C:\Users\lab\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\4.1.1\cores\arduino/mbed/platform/include/platform/mbed_power_mgmt.h:195:20: note: previous declaration 'void sleep()'
 static inline void sleep(void)
                    ^ ~~~~
exit status 1
Error compiling for board Arduino Portenta H7.

```

---

<div class="post-metadata">

**Author:** ![KurtE](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kurte/32/1246572_2.png) [@KurtE](https://forum.arduino.cc/u/KurtE)\
**Post date:** [March 31, 2024, 3:52pm UTC](https://forum.arduino.cc/t/using-sd-card-with-portenta/1242137/4 "2024-03-31T15:52:55Z")

</div>

Sorry I have not done much with the SD (or anything else with the Portenta),  
I did do some experimenting awhile ago as I mentioned in the thread:

> [@Performance of SD and USB Drives on Portenta H7 (and GIGA)](https://forum.arduino.cc/t/performance-of-sd-and-usb-drives-on-portenta-h7-and-giga/1198411):
>
> As I mentioned in the thread: Recently I have been playing with the Arduino GIGA boards and was curious about how the Pro boards that are built with the STM32H747 compare, so I purchased a portenta H7 as well as the Hat Carrier and started to experiment with them. I am also very curious to see if it is easier to debug system level things like the USB Host drivers on these boards versus the GIGA. So one of the first things I did was to start adding support for the Portenta H7 to some of the …

Not sure if it will help or not.

Good luck

---

<div class="post-metadata">

**Author:** ![mercala\_eng](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@mercala\_eng](https://forum.arduino.cc/u/mercala_eng)\
**Post date:** [March 31, 2024, 3:57pm UTC](https://forum.arduino.cc/t/using-sd-card-with-portenta/1242137/5 "2024-03-31T15:57:25Z")

</div>

> [@mercala\_eng](#):
>
> ```arduino
> note: previous declaration 'void sleep()'
> static inline void sleep(void)
> ^ ~~~~
> 
> ```

Thank you. Do you have any idea why I got this error? I have not any sleep function in my code(note: previous declaration 'void sleep()'  
static inline void sleep(void)  
^ ~~~~ )

---

<div class="post-metadata">

**Author:** ![KurtE](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kurte/32/1246572_2.png) [@KurtE](https://forum.arduino.cc/u/KurtE)\
**Post date:** [March 31, 2024, 5:20pm UTC](https://forum.arduino.cc/t/using-sd-card-with-portenta/1242137/6 "2024-03-31T17:20:22Z")

</div>

Sorry not sure: Again I don't use Portenta for much... Bought it, as was curious of the differences between it and the GIGA...

It is two different sets of include files, which both have declares for the sleep function.

The main one was included through the Arduino.h file, the other one was through the  
Portenta library Portenta\_SDCARD which included: SDMMCBlockDevice.h

Maybe problem with that library?

Note: I believe I was running my own library/example code that was displaying pictures off of an SD card (or USB drive), onto an ILI9341 display. Code is up at:  
[ILI9341\_GIGA\_n/examples/tft\_picture\_view\_sd at main · KurtE/ILI9341\_GIGA\_n (github.com)](https://github.com/KurtE/ILI9341_GIGA_n/tree/main/examples/tft_picture_view_sd)

I have not run it in awhile, but did just successfully build the example:

The Example code included:

```arduino
#ifdef ARDUINO_PORTENTA_H7_M7
#include "SDMMCBlockDevice.h"
#include "FATFileSystem.h"
#endif

```

The link shows:

```arduino
C:\Users\kurte\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\4.1.1\bootloaders\PORTENTA_H7\portentah7_bootloader_mbed_hs_v2.elf syntax error: no colon char on the first line character at line 1
Multiple libraries were found for "SdFat.h"
  Used: C:\Users\kurte\Documents\Arduino\libraries\SdFat_real
  Not used: C:\Users\kurte\Documents\Arduino\libraries\SdFat_-_Adafruit_Fork
Using library Arduino_USBHostMbed5 at version 0.3.1 in folder: D:\github\Arduino_USBHostMbed5 
Using library SPI in folder: C:\Users\kurte\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\4.1.1\libraries\SPI (legacy)
Using library Portenta_SDCARD at version 1.0 in folder: C:\Users\kurte\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\4.1.1\libraries\Portenta_SDCARD 
Using library SdFat at version 2.2.2 in folder: C:\Users\kurte\Documents\Arduino\libraries\SdFat_real 
Using library elapsedMillis at version 1.0.6 in folder: C:\Users\kurte\Documents\Arduino\libraries\elapsedMillis 
Using library GIGA_digitalWriteFast in folder: D:\github\UNOR4-stuff\libraries\GIGA_digitalWriteFast (legacy)
Using library JPEGDEC at version 1.4.2 in folder: C:\Users\kurte\Documents\Arduino\libraries\JPEGDEC 
Using library PNGdec at version 1.0.1 in folder: C:\Users\kurte\Documents\Arduino\libraries\PNGdec 
Using library ILI9341_GIGA_n at version 1.1.1 in folder: D:\github\ILI9341_GIGA_n 
Using library LibPrintf at version 1.2.13 in folder: C:\Users\kurte\Documents\Arduino\libraries\LibPrintf 

```

My code is sort of convoluted, as I wrote wrapper class, such the other code could work with files returned by things like SDFat (for SPI connected SD cards)... Which run faster!

---

<div class="post-metadata">

**Author:** ![Hm\_pro](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hm_pro/32/1099726_2.png) [@Hm\_pro](https://forum.arduino.cc/u/Hm_pro)\
**Post date:** [April 3, 2024, 5:05pm UTC](https://forum.arduino.cc/t/using-sd-card-with-portenta/1242137/7 "2024-04-03T17:05:23Z")

</div>

Hi @mercala_eng ,

You can check the example sketches available in Arduino IDE \> Examples:

- PortentaSDCARD \> TESTSDCARD: [ArduinoCore-mbed/libraries/Portenta\_SDCARD/examples/TestSDCARD/TestSDCARD.ino at main · arduino/ArduinoCore-mbed · GitHub](https://github.com/arduino/ArduinoCore-mbed/blob/main/libraries/Portenta_SDCARD/examples/TestSDCARD/TestSDCARD.ino)
- Arduino\_POSIXStorage \> SD\_Card\_Example: [Arduino\_POSIXStorage/examples/SD\_Card\_Example/SD\_Card\_Example.ino at main · arduino-libraries/Arduino\_POSIXStorage · GitHub](https://github.com/arduino-libraries/Arduino_POSIXStorage/blob/main/examples/SD_Card_Example/SD_Card_Example.ino)

Best,

---

<div class="post-metadata">

**Author:** ![mercala\_eng](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@mercala\_eng](https://forum.arduino.cc/u/mercala_eng)\
**Post date:** [April 3, 2024, 5:53pm UTC](https://forum.arduino.cc/t/using-sd-card-with-portenta/1242137/8 "2024-04-03T17:53:31Z")

</div>

Thanks @Hm_pro. I have another question please, I working on code that deal with image make some processing on it when I run my code on teensy 4.1(memory= 1M) the max size of image that I can upload is uint8\_t image[200][200]. The memory of portenta h7 is (2M) so why I can not use image size like [300][300] or [250][250] for the same code?

---

<div class="post-metadata">

**Author:** ![KurtE](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kurte/32/1246572_2.png) [@KurtE](https://forum.arduino.cc/u/KurtE)\
**Post date:** [April 3, 2024, 9:21pm UTC](https://forum.arduino.cc/t/using-sd-card-with-portenta/1242137/9 "2024-04-03T21:21:57Z")

</div>

> [@mercala\_eng](#):
>
> Thanks @Hm_pro. I have another question please, I working on code that deal with image make some processing on it when I run my code on teensy 4.1(memory= 1M) the max size of image that I can upload is uint8\_t image[200][200].

As I have mentioned earlier, I have done very little with the Portenta, a bit more with the GIGA. But have done lots with Teensy 4.x. I don't understand what you are saying here:  
Note: lots more details about the memory on Teensy 4.x can be found at:  
[Teensy® 4.1 (pjrc.com)](https://www.pjrc.com/store/teensy41.html#memory)

Note sure what you mean by upload. Are you wanting your code to contain an image (like a bitmap), that you might use, for example display on a screen? With the Teensy 4.1 you have a flash size of: 8Mb Which can easily store a lot bigger image.  
For example if you look at the example sketch: uncannyEyes\_async\_st7789... for the ST7735\_t3 library that is installed with the Teensy installs, you will see several large images:  
Look at the subdirectory of the example: graphics at the file default\_large.h

The first image defined in this file starts off with:

```arduino
#define SCLERA_WIDTH 375
#define SCLERA_HEIGHT 375

const uint16_t sclera[SCLERA_HEIGHT][SCLERA_WIDTH] PROGMEM = {
  0x6901, 0x6901, 0x6901, 0x6901, 0x6901, 0x6901, 0x6901, 0x6901,
  0x6901, 0x6901, 0x6901, 0x6901, 0x6901, 0x6901, 0x6901, 0x6901,
  0x6901, 0x6901, 0x6901, 0x6901, 0x6901, 0x6901, 0x6901, 0x6901,
  0x6901, 0x6901, 0x6901, 0x6901, 0x6901, 0x6901, 0x6901, 0x6901,
  0x6901, 0x6901, 0x6901, 0x6901, 0x6901, 0x6901, 0x6901, 0x6901,

```

There is a couple of things here that are important: const and PROGMEM. With these defined, the image is stored in flash (Actually everything is stored in flash), but the image is not copied down to RAM (DTCM area). Side effect is the access is slightly slower, but the hardware  
cache helps with this.

Now if instead, you are asking about manipulating an image in memory and then save it away to SD card. I am currently playing with code for the Teensy (in this case the MicroMod) that can read in from a Camera a VGA image (640x480) and save it away to SDCard as a BMP file.

As for using the SD on the Portenta. My playing with it, found it REAL slow. Maybe slightly faster than use SPI... But in my earlier test I found:

> [@Performance of SD and USB Drives on Portenta H7 (and GIGA)](https://forum.arduino.cc/t/performance-of-sd-and-usb-drives-on-portenta-h7-and-giga/1198411/1):
>
> So Loading the barn picture: On Teensy Micromod SDIO: 1.8 seconds, On GIGA and and Portenta: the USB and SD SPI takes about 30 seconds, the SDIO about 19 seconds.

If I remember correctly Bill (@fat16lib) sped up the SDFat library when you connect using SPI. At least at the time I was playing with it, I did not feel like he was going to put in support for the Portenta's SDIO. More details up at:

> [@SdFat tests on GIGA R1](https://forum.arduino.cc/t/sdfat-tests-on-giga-r1/1198629/5):
>
> It is not worth using a SDIO driver with such a small gain. A good DMA SPI driver would be about four times faster than the current SPI driver. A SDIO driver does not help much if does it does transfers like the Teensy DMA driver. Only huge transfers go fast with modern cards. I was able to do that on Teensy with the FIFO driver. The Teensy FIFO driver starts a transfer and keeps the SD in block transfer mode as long as possible. Modern SD cards have huge flash pages and pipe-lined bufferi…

Not sure if that helps with your question or not?
