stm32f4-sdio/main.c

100 lines
1.8 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>
#include <stdint.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;
volatile uint32_t sdio_wait;
int initreq = 0xFF;
2015-12-08 21:31:41 +01:00
2015-04-26 17:54:51 +02:00
int main() {
char buff[1024];
2017-04-06 17:03:53 +02:00
char *name;
FILINFO fno;
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
2015-04-26 17:54:51 +02:00
__DSB();
GPIOA->MODER |= OUTPUT(6) | OUTPUT(7);
GPIOA->ODR |= (1<<7);
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, name, FA_READ);
2017-04-06 17:03:53 +02:00
if (initreq == FR_OK) {
f_gets(buff, sizeof(buff), &file);
printf("%s:\r\n%s\r\n",name, buff);
2017-04-06 17:03:53 +02:00
f_close(&file);
}
}
}
//fflush(stdout);
2017-04-06 17:03:53 +02:00
while(1);
2015-04-26 17:54:51 +02:00
}
2015-12-08 21:31:41 +01:00
void HardFault_Handler(uint32_t *stack) {
// unsigned int stacked_r0;
// unsigned int stacked_r1;
// unsigned int stacked_r2;
// unsigned int stacked_r3;
// unsigned int stacked_r12;
// unsigned int stacked_lr;
// unsigned int stacked_pc;
// unsigned int stacked_psr;
//
// stacked_r0 = stack[0];
// stacked_r1 = stack[1];
// stacked_r2 = stack[2];
// stacked_r3 = stack[3];
//
// stacked_r12 = stack[4];
// stacked_lr = stack[5];
// stacked_pc = stack[6];
// stacked_psr = stack[7];
GPIOA->MODER |= OUTPUT(6) | OUTPUT(7);
GPIOA->ODR |= (1<<6) | (1<<7);
while(1);
}
2015-04-26 17:54:51 +02:00
void SysTick_Handler()
{
GPIOA->ODR ^= (1<<6)|(1<<7);
w++;
sdio_wait++;
}
void SDIO_wait_ms(unsigned int i) {
sdio_wait = 0;
while(sdio_wait<i);
2015-04-26 17:54:51 +02:00
}