PlatformIO Community

SD Card reading with TM4C123 & "rei-vilo/SD" SD Library

Hi,
I am complete beginner in this programming and MCU, so i am not sure if what i am doing is correct or no.
I am trying to use “rei-vilo/SD” SD Library with TI TM4C 132 Board, but file is not Compile, I am doing the following:

The platform.ini is as following:

[env:lptm4c123gh6pm]
platform = titiva
board = lptm4c123gh6pm
framework = arduino
lib_deps = 
	SPI
	rei-vilo/SD@0.0.0-alpha+sha.a8a1454af9
lib_ldf_mode = chain+
build_flags = -Dyield()=delay(0)
platform_packages = 
	framework-energiativa@https://github.com/maxgerhardt/tivac-core.git
	platformio/toolchain-gccarmnoneeabi@~1.80301.0

The code i am trying to run is the following:

#include <Arduino.h>
#include <SPI.h>
#include <C:/Repo/Test/.pio/libdeps/lptm4c123gh6pm/SD/SD.h>

//bool begin(uint8_t chipSelectPin, uint8_t sckRateID = SPI_HALF_SPEED, int8_t SPI_Port = -1, int8_t cardDetectionPin = -1,int8_t level = LOW);

// set up variables using the SD utility library functions:
Sd2Card card;


const int chipSelect = PA_3; //cs PIN

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);

  Serial.print("\nInitializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
  pinMode(12, OUTPUT);     // change this to 53 on a mega


  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(chipSelect, SPI_HALF_SPEED, 0)) { // 2 is the SPI module number here.
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card is inserted?");
    Serial.println("* Is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    return;
  } else {
    Serial.println("Wiring is correct and a card is present.");
  }

  }


void loop(void) {

}

When compiling, it gives the following error:


Processing lptm4c123gh6pm (platform: titiva; board: lptm4c123gh6pm; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/titiva/lptm4c123gh6pm.html                                                                                  PLATFORM: TI TIVA (3.1.0) > TI LaunchPad (Tiva C) w/ tm4c123 (80MHz)
HARDWARE: LPTM4C123GH6PM 80MHz, 32KB RAM, 256KB Flash
DEBUG: Current (ti-icdi) On-board (ti-icdi)
PACKAGES:
 - framework-energiativa @ 1.10004.0+sha.964fac0 (git+https://github.com/maxgerhardt/tivac-core.git) 
 - toolchain-gccarmnoneeabi @ 1.80301.190214 (8.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain+, Compatibility ~ soft
Framework incompatible library C:\Repo\Test\.pio\libdeps\lptm4c123gh6pm\SD
More details about "Library Compatibility Mode": https://docs.platformio.org/page/librarymanager/ldf.html#ldf-compat-mode
Found 11 compatible libraries
Scanning dependencies...     
Dependency Graph
|-- SPI @ 1.0.0 (License: Unknown, Path: C:\Users\Bashar\.platformio\packages\framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20\libraries\SPI)
Building in release mode
arm-none-eabi-g++ -o .pio\build\lptm4c123gh6pm\src\main.cpp.o -c -fno-rtti -fno-exceptions -fno-threadsafe-statics -std=gnu++11 -mthumb -Os -ffunction-sections -fd
ata-sections -Wall -nostdlib -mcpu=cortex-m4 -mabi=aapcs -mfloat-abi=hard -mfpu=fpv4-sp-d16 --param max-inline-insns-single=500 -DF_CPU=80000000L -DPLATFORMIO=60105 -DENERGIA_ARCH_TIVAC -DENERGIA_EK_TM4C123GXL -Dyield()=delay(0) -DARDUINO=10805 -DENERGIA=10004 -Dprintf=iprintf -Iinclude -Isrc -IC:\Users\Bashar\.platformio\packages\framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20\libraries\SPI -IC:\Users\Bashar\.platformio\packages\framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20\system -IC:\Users\Bashar\.platformio\packages\framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20\system\inc -IC:\Users\Bashar\.platformio\packages\framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20\system\driverlib -IC:\Users\Bashar\.platformio\packages\framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20\cores\tivac -IC:\Users\Bashar\.platformio\packages\framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20\variants\EK-TM4C123GXL src\main.cppsrc\main.cpp:3:10: fatal error: SD.h: No such file or directory                                                                                                    
************************************************************
* Looking for SD.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:SD.h"
* Web  > https://registry.platformio.org/search?q=header:SD.h
*
************************************************************

 #include <SD.h>
          ^~~~~~
compilation terminated.
*** [.pio\build\lptm4c123gh6pm\src\main.cpp.o] Error 1
=================================================================== [FAILED] Took 2.58 seconds ===================================================================

 *  The terminal process "C:\Users\Bashar\.platformio\penv\Scripts\platformio.exe 'run', '--environment', 'lptm4c123gh6pm'" terminated with exit code: 1. 

Even after i update the path in the file “c_cpp_properties.json” or also using the UI edit configuration as below, i am still getting the same result as above.

{
    "configurations": [
        {
            "name": "PlatformIO",
            "includePath": [
                "c:/Repo/Test/include",
                "c:/Repo/Test/src",
                "C:/Repo/Test/.pio/libdeps/lptm4c123gh6pm/SD/",
                "C:/Repo/Test/.pio/libdeps/lptm4c123gh6pm/SD/utility/",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/SPI",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/system",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/system/inc",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/system/driverlib",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/cores/tivac",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/variants/EK-TM4C123GXL",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/AIR430BoostEuropeETSI",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/AIR430BoostEuropeETSI/utility",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/AIR430BoostUSAFCC",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/AIR430BoostUSAFCC/utility",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/EEPROM/src",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/EduBPMKII_Screen",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/Ethernet",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/Ethernet/utility",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/Kentec_35_SPI/src",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/LiquidCrystal/src",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/Servo",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/WiFi",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/WiFi/utility",
                "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/Wire/src"
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "path": [
                    "c:/Repo/Test/include",
                    "c:/Repo/Test/src",
                    "C:/Repo/Test/.pio/libdeps/lptm4c123gh6pm/SD/",
                    "C:/Repo/Test/.pio/libdeps/lptm4c123gh6pm/SD/utility/",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/SPI",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/system",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/system/inc",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/system/driverlib",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/cores/tivac",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/variants/EK-TM4C123GXL",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/AIR430BoostEuropeETSI",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/AIR430BoostEuropeETSI/utility",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/AIR430BoostUSAFCC",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/AIR430BoostUSAFCC/utility",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/EEPROM/src",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/EduBPMKII_Screen",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/Ethernet",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/Ethernet/utility",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/Kentec_35_SPI/src",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/LiquidCrystal/src",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/Servo",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/WiFi",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/WiFi/utility",
                    "C:/Users/Bashar/.platformio/packages/framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20/libraries/Wire/src",
                    ""
                ]
            },
            "defines": [
                "F_CPU=80000000L",
                "PLATFORMIO=60105",
                "ENERGIA_ARCH_TIVAC",
                "ENERGIA_EK_TM4C123GXL",
                "yield()=delay(0)",
                "ARDUINO=10805",
                "ENERGIA=10004",
                "printf=iprintf",
                ""
            ],
            "cStandard": "c11",
            "cppStandard": "c++11",
            "compilerPath": "C:/Users/Bashar/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc.exe",
            "compilerArgs": [
                "-mthumb",
                "-mcpu=cortex-m4",
                "-mabi=aapcs",
                "-mfloat-abi=hard",
                "-mfpu=fpv4-sp-d16",
                ""
            ]
        }
    ],
    "version": 4
}

I tried update the path in the include (h) files

  1. #Include <SD.h> in the main.cpp
  2. #include </utility/SdFat.h> in the SD.h file
  3. #include <utility/SdFatUtil.h> in the SD.h file

(To be honest, not sure if this is a a good thing to do based on compiling result)

So they would be looking as following:

#include <C:/Repo/Test/.pio\libdeps/lptm4c123gh6pm/SD/SD.h>
---------------------------------------------------------------------------------------
#include <C:/Repo/Test/.pio/libdeps/lptm4c123gh6pm/SD/utility/SdFat.h>
#include <C:/Repo/Test/.pio/libdeps/lptm4c123gh6pm/SD/utility/SdFatUtil.h>

And the result from compiling was as following:


Processing lptm4c123gh6pm (platform: titiva; board: lptm4c123gh6pm; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/titiva/lptm4c123gh6pm.html                                                                                  PLATFORM: TI TIVA (3.1.0) > TI LaunchPad (Tiva C) w/ tm4c123 (80MHz)
HARDWARE: LPTM4C123GH6PM 80MHz, 32KB RAM, 256KB Flash
DEBUG: Current (ti-icdi) On-board (ti-icdi)
PACKAGES:
 - framework-energiativa @ 1.10004.0+sha.964fac0 (git+https://github.com/maxgerhardt/tivac-core.git) 
 - toolchain-gccarmnoneeabi @ 1.80301.190214 (8.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain+, Compatibility ~ soft
Framework incompatible library C:\Repo\Test\.pio\libdeps\lptm4c123gh6pm\SD
More details about "Library Compatibility Mode": https://docs.platformio.org/page/librarymanager/ldf.html#ldf-compat-mode
Found 11 compatible libraries
Scanning dependencies...     
Dependency Graph
|-- SPI @ 1.0.0 (License: Unknown, Path: C:\Users\Bashar\.platformio\packages\framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20\libraries\SPI)
Building in release mode
arm-none-eabi-g++ -o .pio\build\lptm4c123gh6pm\src\main.cpp.o -c -fno-rtti -fno-exceptions -fno-threadsafe-statics -std=gnu++11 -mthumb -Os -ffunction-sections -fd
ata-sections -Wall -nostdlib -mcpu=cortex-m4 -mabi=aapcs -mfloat-abi=hard -mfpu=fpv4-sp-d16 --param max-inline-insns-single=500 -DF_CPU=80000000L -DPLATFORMIO=60105 -DENERGIA_ARCH_TIVAC -DENERGIA_EK_TM4C123GXL -Dyield()=delay(0) -DARDUINO=10805 -DENERGIA=10004 -Dprintf=iprintf -Iinclude -Isrc -IC:\Users\Bashar\.platformio\packages\framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20\libraries\SPI -IC:\Users\Bashar\.platformio\packages\framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20\system -IC:\Users\Bashar\.platformio\packages\framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20\system\inc -IC:\Users\Bashar\.platformio\packages\framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20\system\driverlib -IC:\Users\Bashar\.platformio\packages\framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20\cores\tivac -IC:\Users\Bashar\.platformio\packages\framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20\variants\EK-TM4C123GXL src\main.cpparm-none-eabi-g++ -o .pio\build\lptm4c123gh6pm\firmware.elf -T lm4fcpp_blizzard.ld -mthumb -Os -nostartfiles -nostdlib -mcpu=cortex-m4 -mabi=aapcs -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wl,--entry=ResetISR -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -fsingle-precision-constant .pio\build\lptm4c123gh6pm\src\main.cpp.o -LC:\Users\Bashar\.platformio\platforms\titiva\ldscripts -L.pio\build\lptm4c123gh6pm -LC:\Users\Bashar\.platformio\packages\framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20\variants\EK-TM4C123GXL -LC:\Users\Bashar\.platformio\packages\framework-energiativa@src-6b41a908e28e87862f6277c517fd5c20\system\driverlib -Wl,--start-group .pio\build\lptm4c123gh6pm\lib311\libSPI.a -lc -lgcc -lm -ldriverlib .pio\build\lptm4c123gh6pm\libFrameworkEnergia.a -Wl,--end-group                                                                                                                      c:/users/bashar/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld.exe: .pio\build\lptm4c123gh6pm\sr
c\main.cpp.o: in function `setup':                                                                                                                                 main.cpp:(.text.setup+0x2c): undefined reference to `Sd2Card::init(unsigned char, unsigned char, signed char, signed char, signed char)'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\lptm4c123gh6pm\firmware.elf] Error 1
=================================================================== [FAILED] Took 3.50 seconds ===================================================================

 *  The terminal process "C:\Users\Bashar\.platformio\penv\Scripts\platformio.exe 'run', '--environment', 'lptm4c123gh6pm'" terminated with exit code: 1. 

After many trails of uninstalling the vs code and Platformio still getting the same result.

Please if anyone knows what is wrong and can help me to resolve it.

Thanks in advance for the support.

You have to add

lib_compat_mode = off

to the platformio.ini, then it will compile.

The compatiblity check sees that the library declares compatibility with the framework

But the platformio.ini says framework = arduino (this was recently renamed), so it sees it as non-compatible and excludes the library from the build system. See docs.

I do not understand though why PlatformIO’s fix against this, aka equalizing energia with arduino, does not work here.

Thanks Max, now its working and board is communicating with SD card.

Another issue i am facing is when i try to use SPI port (0) but working fine for port (2), its not working, i am using this code to initiate it:

 if (!card.init(chipSelect, SPI_HALF_SPEED, 0))

Even when chipSelect is PA3 or 12, still same result, not initiating for port 0. but port 2 is working ok.