Implementation of an SD card driver for STM32 via a SPI. Tested on stm32f103c8t6. 'SD Specifications Part 1 Physical Layer Simplified Specification Version 9.00' was used as documentation.
Implemented functions:
- Complete initialization process (including all types of SD cards);
- Request basic information about the SD card (size, transfer speed, etc.);
- Single and multiple reading;
- Single and multiple write;
- Erasing sectors of SD card;
- Other low-level work functions.
- Copy this repository;
- Go to the SDCardDriver folder;
- Run the build using
make .
; - flash your microcontroller (I used openosd).
Or you can simply copy the external folder into your project...
The driver files are located here. It is also necessary to implement the CRC, which located here.
The main.с file presents the use of basic functions of working with an SD card. The global variable sd_card_status displays the result of card initialization (version, size, presence of errors)
Note: in this file you need to change the pin in the following lines, which in your case is responsible for the CS:
#define SELECT_SD() \
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET)
#define DISELECT_SD() \
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET)
Used during development:
- stm32f103c8t6;
- ST-LINK v2;
- Micro SD card adapter;
- SD card 16 gb;
- Logic analyzer - Kingst LA1010.