stm32f4-sdio/main.c

68 lines
1.1 KiB
C
Raw Normal View History

2015-04-26 17:54:51 +02:00
/*
* main.c
*
* Created on: Apr 25, 2015
* Author: mari
*/
#include <stm32f4xx.h>
2017-03-31 13:25:42 +02:00
#include <cmsis/arm_math.h>
#include <fatfs/ff.h>
#include <fatfs/diskio.h>
2017-04-06 17:03:53 +02:00
#include <uart/uart.h>
#include <stdio.h>
2015-04-26 17:54:51 +02:00
#define OUTPUT(pin) (0b01 << (pin * 2))
FATFS SDfs;
FIL file;
2017-04-06 17:03:53 +02:00
DIR root;
volatile int w;
DSTATUS SDIO_initialize();
int initreq = 0xFF;
2015-12-08 21:31:41 +01:00
2015-04-26 17:54:51 +02:00
int main() {
2017-04-06 17:03:53 +02:00
char buff[100];
char *name;
FILINFO fno;
2015-04-26 17:54:51 +02:00
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
__DSB();
GPIOD->MODER |= OUTPUT(12) | OUTPUT(13);
2015-04-26 17:54:51 +02:00
SysTick_Config(8*1680000);
// f_mount(&SDfs, "0:/", 1);
w = 0;
2017-04-06 17:03:53 +02:00
initUART();
setvbuf(stdout, NULL, _IONBF, 0);
while(w<10);
2017-04-06 17:03:53 +02:00
initreq = f_mount(&SDfs, "0:/", 1);
while(initreq);
initreq = f_opendir(&root, "/");
if (initreq == FR_OK) {
if (!f_readdir(&root, &fno))
{
name = fno.fname;
initreq = f_open(&file, _T("test.txt"), FA_READ);
if (initreq == FR_OK) {
f_gets(buff, sizeof(buff), &file);
printf("test.txt:\r\n%s\r\n", buff);
f_close(&file);
}
}
}
fflush(stdout);
while(1);
2015-04-26 17:54:51 +02:00
}
2015-12-08 21:31:41 +01:00
2015-04-26 17:54:51 +02:00
void SysTick_Handler()
{
GPIOD->ODR ^= (1<<12);
w++;
2015-04-26 17:54:51 +02:00
}