2020-04-04 02:10 PM
Hey guys,
I am pretty new to stm32 (-> beginner) and I am trying to create a .txt file on my sd card. My pc is connected by usb to the Nucleo-L476RG board, which is connected to an onboard sd card.
These are the connected pins:
/**SDMMC1 GPIO Configuration
PC8 ------> SDMMC1_D0
PC9 ------> SDMMC1_D1
PC10 ------> SDMMC1_D2
PC11 ------> SDMMC1_D3
PC12 ------> SDMMC1_CK
PD2 ------> SDMMC1_CMD
*/
I already checked the PC12 pin and saw a good working sd clk.
I have uploaded my project, which is created by CubeMX.
I appreciate any kind of help.
Thank you in advance,
Greetings
#include "main.h"
#include "fatfs.h"
ADC_HandleTypeDef hadc1;
ADC_HandleTypeDef hadc2;
DMA_HandleTypeDef hdma_adc1;
DMA_HandleTypeDef hdma_adc2;
SD_HandleTypeDef hsd1;
SPI_HandleTypeDef hspi2;
FATFS fs; /* Filesystem object */
FIL fil; /* File object */
FRESULT res; /* API result code */
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC1_Init();
MX_ADC2_Init();
MX_SDMMC1_SD_Init();
MX_SPI2_Init();
MX_FATFS_Init();
/* USER CODE BEGIN 2 */
HAL_Delay(500);
/*PA12 = SD Detecteion Pin*/
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_12,GPIO_PIN_RESET);
f_mount(&fs,SDPath,1);
f_open(&fil,"text.txt",FA_CREATE_ALWAYS);
f_close(&fil);
2020-04-07 12:50 PM
Hey,
I am using System Workbench for STM32 - Eclipse and I am using AC6.
Yes I am somehow trying to get the SD_Init working.
Greetings,
Trung
2021-02-15 06:32 PM
@Community member-Xuan Hi!
have you fixed this problem?
I have encountered the same problem, and I tried https://github.com/eziya/STM32_SPI_SDCARD
still couldn't get it work.
2021-02-15 07:07 PM
The thread relates to a 4-bit SDIO/SDMMC implementation, not an SPI one.
The SPI implementation can be achieved via the AdaFruit Shield code.
STM32Cube_FW_H7_V1.5.0\Drivers\BSP\Adafruit_Shield\stm32_adafruit_sd.c (see L4 equivalent)
ST generally provides workable / portable code examples, negating the need to provide a specific tutorial or re-explanation.
The best end-to-end examples tend to be for the EVAL series boards.