100 lines
1.8 KiB
C
100 lines
1.8 KiB
C
/*
|
|
* main.c
|
|
*
|
|
* Created on: Apr 25, 2015
|
|
* Author: mari
|
|
*/
|
|
#include <stm32f4xx.h>
|
|
#include <cmsis/arm_math.h>
|
|
#include <fatfs/ff.h>
|
|
#include <fatfs/diskio.h>
|
|
#include <uart/uart.h>
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
|
|
#define OUTPUT(pin) (0x01 << (pin * 2))
|
|
|
|
FATFS SDfs;
|
|
FIL file;
|
|
DIR root;
|
|
volatile int w;
|
|
volatile uint32_t sdio_wait;
|
|
|
|
int initreq = 0xFF;
|
|
|
|
int main() {
|
|
char buff[1024];
|
|
char *name;
|
|
FILINFO fno;
|
|
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
|
|
__DSB();
|
|
GPIOA->MODER |= OUTPUT(6) | OUTPUT(7);
|
|
GPIOA->ODR |= (1<<7);
|
|
SysTick_Config(8*1680000);
|
|
// f_mount(&SDfs, "0:/", 1);
|
|
w = 0;
|
|
initUART();
|
|
setvbuf(stdout, NULL, _IONBF, 0);
|
|
//while(w<10);
|
|
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);
|
|
if (initreq == FR_OK) {
|
|
f_gets(buff, sizeof(buff), &file);
|
|
printf("%s:\r\n%s\r\n",name, buff);
|
|
f_close(&file);
|
|
}
|
|
|
|
}
|
|
}
|
|
//fflush(stdout);
|
|
|
|
while(1);
|
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
|
|
}
|