Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed SDFileSystem_NUCLEO_32
main.cpp
- Committer:
- hakusan270
- Date:
- 2020-12-18
- Revision:
- 0:0f6db11f0aad
File content as of revision 0:0f6db11f0aad:
#include "mbed.h"
#include "SDFileSystem.h"
DigitalIn btn(D2);
RawSerial pc(PA_2, PA_3);
//SDFileSystem sd(D11, D12, D13, D10, "sd", NC, SDFileSystem::SWITCH_NONE, 20000000); // mosi, miso, sclk, name, card detect, sw type, freq
//SDFileSystem sd(PB_15, PB_14, PB_13, D4, "sd", NC, SDFileSystem::SWITCH_NONE, 20000000); // mosi, miso, sclk, CS,name, card detect, sw type, freq
SDFileSystem sd(D11,D12,D13,A0, "sd", NC, SDFileSystem::SWITCH_NONE,10000000); // mosi, miso, sclk, CS,name, card detect, sw type, freq
// trim '\n'
void ntrim(char *str)
{
int i;
for (i = 0; str[i] != 0; ++i);
if (i > 0 && str[i - 1] == '\n')
str[i - 1] = 0;
}
int main()
{
pc.printf("Hello\r\n");
// SD filesystem
// SDFileSystem *sd = new SDFileSystem(D11, D12, D13, D10, "sd", NC, SDFileSystem::SWITCH_NONE, 20000000); // mosi, miso, sclk, name, card detect, sw type, freq
while (1)
{
// if (btn) continue;
// file open
FILE *fp = fopen("/sd/test.txt", "r");
if (fp == NULL)
{
printf("open error!!\r\n");
goto neww;
//while(1);
}
// read text file
char buf[1024];
while (fgets(buf, sizeof(buf), fp) != NULL)
{
ntrim(buf);
printf("%s\r\n", buf);
}
// file close
fclose(fp);
neww:
fp = fopen("/sd/test.txt", "a");
fprintf(fp,"test write\n");
fclose(fp);
while(1);
wait(1);
}
}