I forgot to hit reply, so following response is outdated, but may help in the future:
If you add clib.c to your project, you can use the stdio functions fopen, fread, fclose, etc with the FILE structure. You may find that easier. I believe that these functions should auto-mount the SD Card as well.
I looked at the source of fat32_init() and fat32_mount(), and I couldn’t find any reason for these to make fat32_open() fail.
I put them back (with some tricky debug see below), and … it works now. And I confirm that your original code was failing.
@BlairLeduc I found what the problem is. In drivers/fat32.c, the function fat32_mount() doesn’t update the internal flag “mount_status”. Everywhere Blair calls fat32_mount(), he updates that flag by calling “mount_status = fat32_mount() “
The problem is that Ariel cannot do that. When he calls fat32_mount(), the internal state of “mount_status” stays un-mounted. When I call fat32_is_ready() for debugging, that fixes the status and it works.
So, IMO, the function fat32_mount() in fat32.c should be renamed everywhere fat32_mount_internal(), and a new function fat32_mount() (the one for users) should be :
I always self-assess with looking at something I wrote six months ago and if I think it looks good, watch out, I have stopped learning!
Looking through the code I should have made fast32_mount() static and not in the public fat32 API. One should just use the fat32 API and the SD card will be mounted automatically or use fat32_is_ready() and if that returns false, use fat32_get_status() to see what is wrong.
However, you are absolutely correct! In the current implementation, that is a bug!
In the same pull request, I added a commit that changes the audio_pwm_is_not_silence range from 100 -> 2000 to 20 -> 20000, which is the full audible range.
I noticed there’s another pull request for an SD card mount fix. I’m curious to know your stance on pull requests (do you accept any, are you planning to accept any, etc).
Thanks again for your contribution to the community. This project is really the back-bone of most PicoCalc projects.