From 70aa56497fa82e35fb025ffedbcefd36f98f3f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Fri, 31 Mar 2017 13:25:42 +0200 Subject: [PATCH] fixed #1 --- Makefile | 7 +- {FATFS => fatfs}/diskio.c | 5 +- {FATFS => fatfs}/ff.c | 4 +- {FATFS => fatfs}/option/ccsbcs.c | 2 +- {FATFS => fatfs}/option/syscall.c | 2 +- .../shimatta_sdio-driver.c | 2 +- .../shimatta_sdio-driver.h | 133 ++++++++++++++++++ .../shimatta_sdio-driver.h~ | 0 {mathlib => include/cmsis}/arm_math.h | 0 {cmsis => include/cmsis}/core_cm4.h | 6 +- {cmsis => include/cmsis}/core_cm4_simd.h | 0 {cmsis => include/cmsis}/core_cmFunc.h | 0 {cmsis => include/cmsis}/core_cmInstr.h | 0 {FATFS => include/fatfs}/diskio.h | 0 {FATFS => include/fatfs}/ff.h | 0 {FATFS => include/fatfs}/ffconf.h | 0 {FATFS => include/fatfs}/integer.h | 0 .../startup}/system_stm32f4xx.h | 0 {cmsis_boot => include}/stm32f407xx.h | 4 +- {cmsis_boot => include}/stm32f4xx.h | 0 {UART => include/uart}/uart.h | 0 main.c | 6 +- {cmsis_boot => startup}/system_stm32f4xx.c | 2 +- syscalls.c => syscalls/syscalls.c | 4 +- {UART => uart}/uart.c | 2 +- 25 files changed, 154 insertions(+), 25 deletions(-) rename {FATFS => fatfs}/diskio.c (93%) rename {FATFS => fatfs}/ff.c (96%) rename {FATFS => fatfs}/option/ccsbcs.c (98%) rename {FATFS => fatfs}/option/syscall.c (96%) rename {FATFS => fatfs}/shimatta_sdio_driver/shimatta_sdio-driver.c (99%) create mode 100644 fatfs/shimatta_sdio_driver/shimatta_sdio-driver.h rename FATFS/shimatta_sdio_driver/shimatta_sdio-driver.h => fatfs/shimatta_sdio_driver/shimatta_sdio-driver.h~ (100%) rename {mathlib => include/cmsis}/arm_math.h (100%) rename {cmsis => include/cmsis}/core_cm4.h (98%) rename {cmsis => include/cmsis}/core_cm4_simd.h (100%) rename {cmsis => include/cmsis}/core_cmFunc.h (100%) rename {cmsis => include/cmsis}/core_cmInstr.h (100%) rename {FATFS => include/fatfs}/diskio.h (100%) rename {FATFS => include/fatfs}/ff.h (100%) rename {FATFS => include/fatfs}/ffconf.h (100%) rename {FATFS => include/fatfs}/integer.h (100%) rename {cmsis_boot => include/startup}/system_stm32f4xx.h (100%) rename {cmsis_boot => include}/stm32f407xx.h (98%) rename {cmsis_boot => include}/stm32f4xx.h (100%) rename {UART => include/uart}/uart.h (100%) rename {cmsis_boot => startup}/system_stm32f4xx.c (97%) rename syscalls.c => syscalls/syscalls.c (91%) rename {UART => uart}/uart.c (97%) diff --git a/Makefile b/Makefile index cc447e0..885e79a 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,9 @@ #Compiler: arm-none-eabi ##################################################################################### #Add Files and Folders below######################################################### -CFILES = main.c syscalls.c UART/uart.c cmsis_boot/system_stm32f4xx.c +CFILES = main.c syscalls/syscalls.c uart/uart.c startup/system_stm32f4xx.c ASFILES = boot/startup_stm32f4xx.S -INCLUDEPATH = -Iboot -Imathlib -Icmsis -Icmsis_boot -IUART +INCLUDEPATH = -Iinclude target = stm32f4sdio @@ -19,8 +19,7 @@ mapfile = dafuqishappening #TODO -CFILES += FATFS/option/syscall.c FATFS/option/ccsbcs.c FATFS/diskio.c FATFS/ff.c FATFS/shimatta_sdio_driver/shimatta_sdio-driver.c -INCLUDEPATH += -IFATFS -IFATFS/shimatta_sdio_driver +CFILES += fatfs/option/syscall.c fatfs/option/ccsbcs.c fatfs/diskio.c fatfs/ff.c fatfs/shimatta_sdio_driver/shimatta_sdio-driver.c ################################################################################### CC=arm-none-eabi-gcc diff --git a/FATFS/diskio.c b/fatfs/diskio.c similarity index 93% rename from FATFS/diskio.c rename to fatfs/diskio.c index cc07e37..b6d190f 100644 --- a/FATFS/diskio.c +++ b/fatfs/diskio.c @@ -8,9 +8,8 @@ /*-----------------------------------------------------------------------*/ //Only ONE device with ONE partition!!! -#include "diskio.h" /* FatFs lower layer API */ -#include - +#include /* FatFs lower layer API */ +#include "shimatta_sdio_driver/shimatta_sdio-driver.h" /* Definitions of physical drive number for each drive */ #define SDCARD 0 /* Example: Map ATA harddisk to physical drive 0 */ diff --git a/FATFS/ff.c b/fatfs/ff.c similarity index 96% rename from FATFS/ff.c rename to fatfs/ff.c index 47b3989..8535aff 100644 --- a/FATFS/ff.c +++ b/fatfs/ff.c @@ -16,8 +16,8 @@ /----------------------------------------------------------------------------*/ -#include "ff.h" /* Declarations of FatFs API */ -#include "diskio.h" /* Declarations of disk I/O functions */ +#include /* Declarations of FatFs API */ +#include /* Declarations of disk I/O functions */ //For get_fattime: //#include diff --git a/FATFS/option/ccsbcs.c b/fatfs/option/ccsbcs.c similarity index 98% rename from FATFS/option/ccsbcs.c rename to fatfs/option/ccsbcs.c index b16db30..76d891b 100644 --- a/FATFS/option/ccsbcs.c +++ b/fatfs/option/ccsbcs.c @@ -25,7 +25,7 @@ / 1258 Vietnam (OEM, Windows) */ -#include "../ff.h" +#include #if _CODE_PAGE == 437 diff --git a/FATFS/option/syscall.c b/fatfs/option/syscall.c similarity index 96% rename from FATFS/option/syscall.c rename to fatfs/option/syscall.c index 921f57e..69dea6f 100644 --- a/FATFS/option/syscall.c +++ b/fatfs/option/syscall.c @@ -4,7 +4,7 @@ /*------------------------------------------------------------------------*/ -#include "../ff.h" +#include #if _FS_REENTRANT diff --git a/FATFS/shimatta_sdio_driver/shimatta_sdio-driver.c b/fatfs/shimatta_sdio_driver/shimatta_sdio-driver.c similarity index 99% rename from FATFS/shimatta_sdio_driver/shimatta_sdio-driver.c rename to fatfs/shimatta_sdio_driver/shimatta_sdio-driver.c index 9b147e0..df7e4c7 100644 --- a/FATFS/shimatta_sdio_driver/shimatta_sdio-driver.c +++ b/fatfs/shimatta_sdio_driver/shimatta_sdio-driver.c @@ -5,7 +5,7 @@ * Mario Hüttel */ -#include +#include "shimatta_sdio-driver.h" #define SETAF(PORT,PIN,AF) PORT->AFR[(PIN < 8 ? 0 : 1)] |= AF << ((PIN < 8 ? PIN : (PIN - 8)) * 4) diff --git a/fatfs/shimatta_sdio_driver/shimatta_sdio-driver.h b/fatfs/shimatta_sdio_driver/shimatta_sdio-driver.h new file mode 100644 index 0000000..660ccc9 --- /dev/null +++ b/fatfs/shimatta_sdio_driver/shimatta_sdio-driver.h @@ -0,0 +1,133 @@ +/* + * shimatta_sdio-driver.h + * + * Created on: Apr 26, 2015 + * Mario Hüttel + */ + +#ifndef FATFS_SHIMATTA_SDIO_DRIVER_SHIMATTA_SDIO_DRIVER_H_ +#define FATFS_SHIMATTA_SDIO_DRIVER_SHIMATTA_SDIO_DRIVER_H_ + +#include +#include + + +DSTATUS SDIO_status(); +DSTATUS SDIO_initialize(); +DRESULT SDIO_disk_read(BYTE *buff, DWORD sector, UINT count); +DRESULT SDIO_disk_write(const BYTE *buff, DWORD sector, UINT count); +DRESULT SDIO_disk_ioctl(BYTE cmd, void* buff); +DWORD get_fattime(); + + +//Defines for Card Status in struct _CardStatus +#define CURRENT_STATE_IDLE 0 +#define CURRENT_STATE_READY 1 +#define CURRENT_STATE_IDENT 2 +#define CURRENT_STATE_STBY 3 +#define CURRENT_STATE_TRAN 4 +#define CURRENT_STATE_DATA 5 +#define CURRENT_STATE_RCV 6 +#define CURRENT_STATE_PRG 7 +#define CURRENT_STATE_DIS 8 + + + +typedef struct _CardStatus { + uint32_t reserved : 3; + uint32_t AKE_SEQ_ERROR : 1; + uint32_t reserved_2 : 1; + uint32_t APP_CMD : 1; + uint32_t reserved_3 : 2; + uint32_t READY_FOR_DATA : 1; + uint32_t CURRENT_STATE : 4; + uint32_t ERASE_RESET : 1; + uint32_t CARD_ECC_DIABLED : 1; + uint32_t WP_ERASE_SKIP : 1; + uint32_t CSD_OVERWRITE : 1; + uint32_t reserved17 : 1; + uint32_t reserved18 : 1; + uint32_t ERROR : 1; + uint32_t CC_ERROR : 1; + uint32_t CARD_ECC_FAILED : 1; + uint32_t ILLEGAL_COMMAND : 1; + uint32_t COM_CRC_ERROR : 1; + uint32_t LOCK_UNLOCK_FAILED : 1; + uint32_t CARD_IS_LOCKED : 1; + uint32_t WP_VIOLATION : 1; + uint32_t ERASE_PARAM : 1; + uint32_t ERASE_SEQ_ERROR : 1; + uint32_t BLOCK_LEN_ERROR : 1; + uint32_t ADDRESS_ERROR : 1; + uint32_t OUT_OF_RANGE : 1; +}CardStatus_t; + + + +typedef enum {CARD_NONE = 0, MMC, SD_V1, SD_V2_SC, SD_V2_HC} card_type_t; + // MMC not supported +typedef struct _SDInfo { + uint16_t rca; + card_type_t type; +}SDInfo_t; + +typedef union _StatusConv { + CardStatus_t statusstruct; + uint32_t value; +}StatusConv_t; + +//General Definitions +//Blocksize: 512 = 2^9 => 9 +#define BLOCKSIZE 9 //9 +//Hardware Flow: Prevents over- and underruns. +#define HW_FLOW 0 //0 +//1 bit: 0 +//4 bit: 1 +#define BUSWIDTH 1 //1 +//Initial Transfer CLK (ca. 400kHz) +#define INITCLK 120 //120 +//Working CLK (Maximum) +#define WORKCLK 0 //0 +//Data Timeout in CLK Cycles +#define DTIMEOUT 150 //150 +//DMA Stream used for TX and RX DMA2 Stream 3 or 6 possible +#define DMASTREAM DMA2_Stream3 + + + +//Port Definitions + +#define PORTCLKMASK (RCC_AHB1ENR_GPIODEN | RCC_AHB1ENR_GPIOCEN) + +#define ALTFUNC 12 + +#define CLKPORT GPIOC +#define D0PORT GPIOC +#define D1PORT GPIOC +#define D2PORT GPIOC +#define D3PORT GPIOC +#define CMDPORT GPIOD + +#define CLKPIN 12 +#define D0PIN 8 +#define D1PIN 9 +#define D2PIN 10 +#define D3PIN 11 +#define CMDPIN 2 + +// Write Protection +#define SDIO_ENABLE_WRITEPROT 0 +#define WRITEPROT_PORT GPIOD // Add this port to port clock mask! +#define WRITEPROT_PIN 0 +#define WRITEPROT_PULLUP 0 +#define WRITEPROT_ACTIVE_LEVEL 0 + +// Card inserted pin +#define SDIO_ENABLE_INS 0 +#define INS_PORT GPIOD // Add this port to port clock mask! +#define INS_PIN 0 +#define INS_PULLUP 0 +#define INS_ACTIVE_LEVEL 0 + + +#endif /* FATFS_SHIMATTA_SDIO_DRIVER_SHIMATTA_SDIO_DRIVER_H_ */ diff --git a/FATFS/shimatta_sdio_driver/shimatta_sdio-driver.h b/fatfs/shimatta_sdio_driver/shimatta_sdio-driver.h~ similarity index 100% rename from FATFS/shimatta_sdio_driver/shimatta_sdio-driver.h rename to fatfs/shimatta_sdio_driver/shimatta_sdio-driver.h~ diff --git a/mathlib/arm_math.h b/include/cmsis/arm_math.h similarity index 100% rename from mathlib/arm_math.h rename to include/cmsis/arm_math.h diff --git a/cmsis/core_cm4.h b/include/cmsis/core_cm4.h similarity index 98% rename from cmsis/core_cm4.h rename to include/cmsis/core_cm4.h index 024302e..5f3b7d6 100644 --- a/cmsis/core_cm4.h +++ b/include/cmsis/core_cm4.h @@ -151,9 +151,9 @@ #endif #include /* standard types definitions */ -#include /* Core Instruction Access */ -#include /* Core Function Access */ -#include /* Compiler specific SIMD Intrinsics */ +#include "core_cmInstr.h" /* Core Instruction Access */ +#include "core_cmFunc.h" /* Core Function Access */ +#include "core_cm4_simd.h" /* Compiler specific SIMD Intrinsics */ #endif /* __CORE_CM4_H_GENERIC */ diff --git a/cmsis/core_cm4_simd.h b/include/cmsis/core_cm4_simd.h similarity index 100% rename from cmsis/core_cm4_simd.h rename to include/cmsis/core_cm4_simd.h diff --git a/cmsis/core_cmFunc.h b/include/cmsis/core_cmFunc.h similarity index 100% rename from cmsis/core_cmFunc.h rename to include/cmsis/core_cmFunc.h diff --git a/cmsis/core_cmInstr.h b/include/cmsis/core_cmInstr.h similarity index 100% rename from cmsis/core_cmInstr.h rename to include/cmsis/core_cmInstr.h diff --git a/FATFS/diskio.h b/include/fatfs/diskio.h similarity index 100% rename from FATFS/diskio.h rename to include/fatfs/diskio.h diff --git a/FATFS/ff.h b/include/fatfs/ff.h similarity index 100% rename from FATFS/ff.h rename to include/fatfs/ff.h diff --git a/FATFS/ffconf.h b/include/fatfs/ffconf.h similarity index 100% rename from FATFS/ffconf.h rename to include/fatfs/ffconf.h diff --git a/FATFS/integer.h b/include/fatfs/integer.h similarity index 100% rename from FATFS/integer.h rename to include/fatfs/integer.h diff --git a/cmsis_boot/system_stm32f4xx.h b/include/startup/system_stm32f4xx.h similarity index 100% rename from cmsis_boot/system_stm32f4xx.h rename to include/startup/system_stm32f4xx.h diff --git a/cmsis_boot/stm32f407xx.h b/include/stm32f407xx.h similarity index 98% rename from cmsis_boot/stm32f407xx.h rename to include/stm32f407xx.h index 6b7ba0c..2cb8194 100644 --- a/cmsis_boot/stm32f407xx.h +++ b/include/stm32f407xx.h @@ -181,8 +181,8 @@ typedef enum * @} */ -#include "core_cm4.h" /* Cortex-M4 processor and core peripherals */ -#include "system_stm32f4xx.h" +#include /* Cortex-M4 processor and core peripherals */ +#include #include /** @addtogroup Peripheral_registers_structures diff --git a/cmsis_boot/stm32f4xx.h b/include/stm32f4xx.h similarity index 100% rename from cmsis_boot/stm32f4xx.h rename to include/stm32f4xx.h diff --git a/UART/uart.h b/include/uart/uart.h similarity index 100% rename from UART/uart.h rename to include/uart/uart.h diff --git a/main.c b/main.c index 91b6d14..2cd6d17 100644 --- a/main.c +++ b/main.c @@ -5,10 +5,8 @@ * Author: mari */ #include -#include -#include - -#include +#include +#include #define OUTPUT(pin) (0b01 << (pin * 2)) diff --git a/cmsis_boot/system_stm32f4xx.c b/startup/system_stm32f4xx.c similarity index 97% rename from cmsis_boot/system_stm32f4xx.c rename to startup/system_stm32f4xx.c index 5ec21da..aa8e122 100644 --- a/cmsis_boot/system_stm32f4xx.c +++ b/startup/system_stm32f4xx.c @@ -114,7 +114,7 @@ * @{ */ -#include "stm32f4xx.h" +#include /** * @} diff --git a/syscalls.c b/syscalls/syscalls.c similarity index 91% rename from syscalls.c rename to syscalls/syscalls.c index cd6ce68..f3b3f9a 100644 --- a/syscalls.c +++ b/syscalls/syscalls.c @@ -2,10 +2,10 @@ * syscalls.c * * Created on: Dec 14, 2014 - * Author: shino-chan + * Author: Mario Huettel */ -#include "uart.h" +#include char* _sbrk(int incr) { extern char heap_low; // Defined by the linker diff --git a/UART/uart.c b/uart/uart.c similarity index 97% rename from UART/uart.c rename to uart/uart.c index 6b7b404..ce13ea3 100644 --- a/UART/uart.c +++ b/uart/uart.c @@ -8,7 +8,7 @@ //PA2 => TX //PA3 => RX //Alternate Function 7 -#include "uart.h" +#include #include void initUART() {