{"action":"created","issue":{"url":"https://api.github.com/repos/espressif/arduino-esp32/issues/591","repository_url":"https://api.github.com/repos/espressif/arduino-esp32","labels_url":"https://api.github.com/repos/espressif/arduino-esp32/issues/591/labels{/name}","comments_url":"https://api.github.com/repos/espressif/arduino-esp32/issues/591/comments","events_url":"https://api.github.com/repos/espressif/arduino-esp32/issues/591/events","html_url":"https://github.com/espressif/arduino-esp32/issues/591","id":252434112,"number":591,"title":"SD Card Corruption using extern \"C\"","user":{"login":"wildnut","id":16809863,"avatar_url":"https://avatars1.githubusercontent.com/u/16809863?v=4","gravatar_id":"","url":"https://api.github.com/users/wildnut","html_url":"https://github.com/wildnut","followers_url":"https://api.github.com/users/wildnut/followers","following_url":"https://api.github.com/users/wildnut/following{/other_user}","gists_url":"https://api.github.com/users/wildnut/gists{/gist_id}","starred_url":"https://api.github.com/users/wildnut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wildnut/subscriptions","organizations_url":"https://api.github.com/users/wildnut/orgs","repos_url":"https://api.github.com/users/wildnut/repos","events_url":"https://api.github.com/users/wildnut/events{/privacy}","received_events_url":"https://api.github.com/users/wildnut/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-08-23T22:23:05Z","updated_at":"2017-08-24T00:39:32Z","closed_at":null,"body":"\r\n### Hardware:\r\nBoard:\t\t\t\t\t\t\tAnalogLamb ESP32\r\nCore Installation/update date:\t\t\tLatest\r\nIDE name:\t\t\t\t\t\t\tEclipse\r\n\r\n\r\n\r\n### Description:\r\nHi,\r\n\r\nFirst of all, thanks for the great library!  :)  It certainly makes many tasks much easier.  \r\n\r\nSo here's the problem I'm having and perhaps I am doing something wrong.  In Platform IO, the SD card library works great.  I can read/write with no problems using the great steps provided in the example and SD image.   No problems with PlatformIO using the arduino framework even after rebooting, taking the card out, etc.   All is well!\r\n\r\nHowever, I have started recently using Eclipse and the \"make\" command.  I copied the exact same code that's in the SD example, changed void setup() to extern \"C\" void app_main() and then I upload the new code (I don't change the setting in make menuconfig to use Arduino, I leave it alone) using the make command from the command line.  Everything uploads fine and the program runs.  Here's a portion:   \r\n\r\nWriting file: /hello.txt\r\nFile written\r\nAppending to file: /hello.txt\r\nMessage appended\r\nReading file: /hello.txt\r\nRead from file: Hello World!\r\nDeleting file: /foo.txt\r\nFile deleted\r\nRenaming file /hello.txt to /foo.txt\r\nFile renamed\r\nReading file: /foo.txt\r\nRead from file: Hello World!\r\n0 bytes read for 0 ms\r\n\r\nIt stops with the last line above.  \r\n\r\nThe \"foo.txt\" file was a carry-over from the PlatformIO test which gets deleted per the example sketch.   So, I then reboot the ESP32 and the card will no longer mount.  I then try the card in Windows and it can no longer be read nor can it be formatted.  I've tried using some of them in Android and a camera and the cards appear to be no longer usable.   This is my 4th SD card that this has happened to . . . I've used 3 micro SD cards and one large one from different manufacturers and they all seem to get corrupted to the point that they can't be used at all.\r\n\r\nAm I doing something wrong with my code?  As mentioned, I am only adding the extern \"C\" section and then re-uploading.   Has anyone else tried this process as outline above . . . using extern \"C\" rather than the Arduino menuconfig changes?\r\n\r\nThanks for your help!  Once again, great library . . . but I've hit a bump in the road.  :)   \r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/espressif/arduino-esp32/issues/comments/324500117","html_url":"https://github.com/espressif/arduino-esp32/issues/591#issuecomment-324500117","issue_url":"https://api.github.com/repos/espressif/arduino-esp32/issues/591","id":324500117,"user":{"login":"wildnut","id":16809863,"avatar_url":"https://avatars1.githubusercontent.com/u/16809863?v=4","gravatar_id":"","url":"https://api.github.com/users/wildnut","html_url":"https://github.com/wildnut","followers_url":"https://api.github.com/users/wildnut/followers","following_url":"https://api.github.com/users/wildnut/following{/other_user}","gists_url":"https://api.github.com/users/wildnut/gists{/gist_id}","starred_url":"https://api.github.com/users/wildnut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wildnut/subscriptions","organizations_url":"https://api.github.com/users/wildnut/orgs","repos_url":"https://api.github.com/users/wildnut/repos","events_url":"https://api.github.com/users/wildnut/events{/privacy}","received_events_url":"https://api.github.com/users/wildnut/received_events","type":"User","site_admin":false},"created_at":"2017-08-24T00:39:32Z","updated_at":"2017-08-24T00:39:32Z","body":"Well, at least so far, the issue has been fixed.  I first tried changing the make menuconfig to use Arduino and then using setup() and loop() - which worked fine without SD card corruption.  I then removed those settings and changed the menuconfig to use app_main instead of Arduino.   I then re-looked over my code and realized that I had left out \"initArduino();\" in the app_main which, at least for the time being, seems to be the resolution unless it happens again.  :)    I also forgot to mention in the previous message that I did include \"#include \"Arduino.h\"\" at the top.  So, from what I can tell thus far with a very limited amount of testing . . . \"initArduino()\" is the solution to preventing card corruption.  Time will tell though, but hopefully it's that simple.   So, it was a mistake on my part.  Surprise!  Surprise!!  \r\n\r\nThanks again for all your hard work in creating such an amazing library.  "}}
{"actor":{"display_login":"wildnut"}}