I am using Espressif ESP32S2 DevKitM-1 in Arduino IDE. I need to use a CPP example that came with ESP-IDF (specifically sdmmc example under esp-idf\examples\storage\sd_card\sdmmc).
it works just fine in VSCode but compilation fails in Arduino IDE. I can see it loading libraries which do contain all the definitions in the headers but still IDE complains "'SDMMC_HOST_DEFAULT' was not declared in this scope"
I need to do this project in Arduino IDE because I already have a working code I need to add to. I also tried to Import Arduino .ino into VSC using Platformio but that struggles with include libraries and even simple delay() functions. in short, after many many hours, ive given up trying to move my project to VSC. So now I am left with trying to bring the .CPP to Arduino IDE.
Welcome to the forums. If you post your code here, you will increase your chances of assistance dramatically. Please take a moment to read the sticky post at the top of the forum about how to do so, along with lots of other good information to maximize the help
I have experimented with about 85% of the ESP32's API. I found most but not all of the ESP32 API's work in the Arduino IDE. The biggest trick is that the configuration structures are defined and used in the Arduino IDE a bit differently than with using the ESPRESSIF IDE thingy.
I did change to SPI and made some progress but still getting errors...different Errors
:\esp\esp-idf\examples\storage\sd_card\sdspi\main\sd_card_example_main\sd_card_example_main.ino: In function 'void app_main()':
sd_card_example_main:85:35: error: invalid conversion from 'int' to 'spi_host_device_t' [-fpermissive]
ret = spi_bus_initialize(host.slot, &bus_cfg, SPI_DMA_CHAN);
~~~~~^~~~
In file included from C:\Users\Val V\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1/tools/sdk/esp32s2/include/driver/include/driver/spi_master.h:12,
from C:\Users\Val V\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1/tools/sdk/esp32s2/include/driver/include/driver/sdspi_host.h:14,
from C:\Users\Val V\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1/tools/sdk/esp32s2/include/fatfs/vfs/esp_vfs_fat.h:20,
from D:\esp\esp-idf\examples\storage\sd_card\sdspi\main\sd_card_example_main\sd_card_example_main.ino:14:
C:\Users\Val V\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1/tools/sdk/esp32s2/include/driver/include/driver/spi_common.h:139:48: note: initializing argument 1 of 'esp_err_t spi_bus_initialize(spi_host_device_t, const spi_bus_config_t*, spi_dma_chan_t)'
esp_err_t spi_bus_initialize(spi_host_device_t host_id, const spi_bus_config_t *bus_config, spi_dma_chan_t dma_chan);
~~~~~~~~~~~~~~~~~~^~~~~~~
sd_card_example_main:27:22: error: invalid conversion from 'int' to 'gpio_num_t' [-fpermissive]
#define PIN_NUM_CS 13
^~
D:\esp\esp-idf\examples\storage\sd_card\sdspi\main\sd_card_example_main\sd_card_example_main.ino:94:27: note: in expansion of macro 'PIN_NUM_CS'
slot_config.gpio_cs = PIN_NUM_CS;
^~~~~~~~~~
sd_card_example_main:95:32: error: invalid conversion from 'int' to 'spi_host_device_t' [-fpermissive]
slot_config.host_id = host.slot;
~~~~~^~~~
sd_card_example_main:169:23: error: invalid conversion from 'int' to 'spi_host_device_t' [-fpermissive]
spi_bus_free(host.slot);
~~~~~^~~~
In file included from C:\Users\Val V\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1/tools/sdk/esp32s2/include/driver/include/driver/spi_master.h:12,
from C:\Users\Val V\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1/tools/sdk/esp32s2/include/driver/include/driver/sdspi_host.h:14,
from C:\Users\Val V\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1/tools/sdk/esp32s2/include/fatfs/vfs/esp_vfs_fat.h:20,
from D:\esp\esp-idf\examples\storage\sd_card\sdspi\main\sd_card_example_main\sd_card_example_main.ino:14:
C:\Users\Val V\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1/tools/sdk/esp32s2/include/driver/include/driver/spi_common.h:152:42: note: initializing argument 1 of 'esp_err_t spi_bus_free(spi_host_device_t)'
esp_err_t spi_bus_free(spi_host_device_t host_id);
~~~~~~~~~~~~~~~~~~^~~~~~~
exit status 1
invalid conversion from 'int' to 'spi_host_device_t' [-fpermissive]
#include <driver/spi_master.h>
#include "sdkconfig.h"
#include "esp_system.h" //This inclusion configures the peripherals in the ESP system.
//
//#define MAGTYPE true
//#define XGTYPE false
//
uint8_t GetLowBits();
int8_t GetHighBits();
int fReadSPIdata16bits( spi_device_handle_t &h, int address );
int fWriteSPIdata8bits( spi_device_handle_t &h, int address, int sendData );
int fInitializeSPI_Devices( spi_device_handle_t &h, int csPin);
// spi_device_handle_t fInitializeSPI_Devices( int csPin);
int fInitializeSPI_Channel( int spiCLK, int spiMOSI, int spiMISO, spi_host_device_t SPI_Host, bool EnableDMA);
Thank you for your reply. I apologize, I dont understand. Since I started using SD SPI example code. I am getting new / different error "error: invalid conversion from 'int' ".
Integers are not implicitly converted to enum values in C++. The example uses C, which doesn't impose type safety. Use the enumerator names from the documentation. Don't use macros to define constants.