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>
|
2017-04-03 18:56:02 +02:00
|
|
|
#include <fatfs/diskio.h>
|
2017-04-06 17:03:53 +02:00
|
|
|
#include <uart/uart.h>
|
|
|
|
#include <stdio.h>
|
2017-04-15 19:50:17 +02:00
|
|
|
#include <stdint.h>
|
2018-11-07 17:18:24 +01:00
|
|
|
|
2015-04-26 17:54:51 +02:00
|
|
|
#define OUTPUT(pin) (0b01 << (pin * 2))
|
|
|
|
|
|
|
|
FATFS SDfs;
|
2015-04-30 11:59:37 +02:00
|
|
|
FIL file;
|
2017-04-06 17:03:53 +02:00
|
|
|
DIR root;
|
2017-04-03 01:35:20 +02:00
|
|
|
volatile int w;
|
2017-04-15 19:50:17 +02:00
|
|
|
volatile uint32_t sdio_wait;
|
2017-04-03 01:35:20 +02:00
|
|
|
|
2017-04-03 18:56:02 +02:00
|
|
|
int initreq = 0xFF;
|
2015-12-08 21:31:41 +01:00
|
|
|
|
2015-04-26 17:54:51 +02:00
|
|
|
int main() {
|
2017-04-15 19:50:17 +02:00
|
|
|
char buff[1024];
|
2017-04-06 17:03:53 +02:00
|
|
|
char *name;
|
|
|
|
FILINFO fno;
|
2017-04-15 19:50:17 +02:00
|
|
|
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
|
2015-04-26 17:54:51 +02:00
|
|
|
__DSB();
|
2017-04-15 19:50:17 +02:00
|
|
|
GPIOA->MODER |= OUTPUT(6) | OUTPUT(7);
|
|
|
|
GPIOA->ODR |= (1<<7);
|
2015-04-26 17:54:51 +02:00
|
|
|
SysTick_Config(8*1680000);
|
2017-04-03 01:35:20 +02:00
|
|
|
// f_mount(&SDfs, "0:/", 1);
|
2017-04-03 18:56:02 +02:00
|
|
|
w = 0;
|
2017-04-06 17:03:53 +02:00
|
|
|
initUART();
|
|
|
|
setvbuf(stdout, NULL, _IONBF, 0);
|
2017-04-15 19:50:17 +02:00
|
|
|
//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;
|
2017-04-15 19:50:17 +02:00
|
|
|
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);
|
2017-04-15 19:50:17 +02:00
|
|
|
printf("%s:\r\n%s\r\n",name, buff);
|
2017-04-06 17:03:53 +02:00
|
|
|
f_close(&file);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2017-04-15 19:50:17 +02:00
|
|
|
//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
|
|
|
|
2017-04-15 19:50:17 +02: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()
|
|
|
|
{
|
2017-04-15 19:50:17 +02:00
|
|
|
GPIOA->ODR ^= (1<<6)|(1<<7);
|
2017-04-03 01:35:20 +02:00
|
|
|
w++;
|
2017-04-15 19:50:17 +02:00
|
|
|
sdio_wait++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDIO_wait_ms(unsigned int i) {
|
|
|
|
sdio_wait = 0;
|
|
|
|
while(sdio_wait<i);
|
|
|
|
|
2015-04-26 17:54:51 +02:00
|
|
|
}
|