Closed thibeaux closed 3 years ago
Don't think I did this step correct in user_diskio_spi.c:
//Make sure you set #define SD_SPI_HANDLE as some hspix in main.h
//Make sure you set #define SD_CS_GPIO_Port as some GPIO port in main.h
//Make sure you set #define SD_CS_Pin as some GPIO pin in main.h
extern SPI_HandleTypeDef SD_SPI_HANDLE;
In user_diskio_spi.c my code begins with this:
#include "stm32f4xx_hal.h"" /* Provide the low-level HAL functions */
#include "user_diskio_spi.h"
//If you want to use a different SPI port change hspi1 here and elsewhere in this file
extern SPI_HandleTypeDef hspi1;
//(Note that the _256 is used as a mask to clear the prescalar bits as it provides binary 111 in the correct position)
#define FCLK_SLOW() { MODIFY_REG(hspi1.Instance->CR1, SPI_BAUDRATEPRESCALER_256, SPI_BAUDRATEPRESCALER_128); } /* Set SCLK = slow, approx 280 KBits/s*/
#define FCLK_FAST() { MODIFY_REG(hspi1.Instance->CR1, SPI_BAUDRATEPRESCALER_256, SPI_BAUDRATEPRESCALER_8); } /* Set SCLK = fast, approx 4.5 MBits/s */
#define CS_HIGH() {HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, GPIO_PIN_SET);}
#define CS_LOW() {HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, GPIO_PIN_RESET);}
and my main.h looks like this:
/* Private defines -----------------------------------------------------------*/
#define B1_Pin GPIO_PIN_13
#define B1_GPIO_Port GPIOC
#define USART_TX_Pin GPIO_PIN_2
#define USART_TX_GPIO_Port GPIOA
#define USART_RX_Pin GPIO_PIN_3
#define USART_RX_GPIO_Port GPIOA
#define TMS_Pin GPIO_PIN_13
#define TMS_GPIO_Port GPIOA
#define TCK_Pin GPIO_PIN_14
#define TCK_GPIO_Port GPIOA
#define SWO_Pin GPIO_PIN_3
#define SWO_GPIO_Port GPIOB
#define SPI1_CS_Pin GPIO_PIN_6
#define SPI1_CS_GPIO_Port GPIOB
/* USER CODE BEGIN Private defines */
#define SD_SPI_HANDLE hspi1 // added to main.h
/* USER CODE END Private defines */
FIXED I forgot to ensure that I formatted this file to a FAT32 format and I did not preload the test.txt file on to the SD card.
Here is proof of success:
I'm getting an error 128. I am following this tutorial https://01001000.xyz/2020-08-09-Tutorial-STM32CubeIDE-SD-card/ and was able to solve the issue with the f_open error 3 by fixing the user_diskio.c code by adding in the SPI returns using the user_diskio_spi.h. Now, that I am getting the size available on my SD card to print to putty using my UART. I'm getting a new error. f_open error (128).
I'm using SANSIDK ULTRA micro SD Card 32GB, which sandisk says they have SPI functionality here https://www.alliedelec.com/m/d/04db416b291011446889dbd6129e2644.pdf , see section 1.7 SPI Mode.
SPI1 SETTINGS AND SET UP
I manually changed these values to match my naming scheme `#define CS_HIGH() {HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, GPIO_PIN_SET);}
define CS_LOW() {HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, GPIO_PIN_RESET);}`