Skip to content

Commit

Permalink
add: SD card via SPI manipulation prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
luftaquila committed Jul 25, 2024
1 parent de103f6 commit 8b171d0
Show file tree
Hide file tree
Showing 9 changed files with 625 additions and 27 deletions.
5 changes: 3 additions & 2 deletions device/firmware/Core/Inc/energymeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include <stdint.h>
#include <string.h>

#include "usbd_cdc_if.h"

/******************************************************************************
* debug serial configuration
*/
Expand All @@ -28,6 +26,9 @@ extern char debug_buffer[];
/******************************************************************************
* peripheral configuration
*/
#define UART_CONS huart1
#define SPI_SD hspi1
#define SPI_RF hspi2


/******************************************************************************
Expand Down
7 changes: 5 additions & 2 deletions device/firmware/Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ extern "C" {

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

#include "types.h"
#include "energymeter.h"
/* USER CODE END Includes */

/* Exported types ------------------------------------------------------------*/
Expand Down Expand Up @@ -83,9 +84,11 @@ void Error_Handler(void);
#define SD_MISO_GPIO_Port GPIOB
#define SD_MOSI_Pin GPIO_PIN_5
#define SD_MOSI_GPIO_Port GPIOB
#define SD_CS_Pin GPIO_PIN_6
#define SD_CS_GPIO_Port GPIOB

/* USER CODE BEGIN Private defines */

#define SD_SPI_HANDLE SPI_SD
/* USER CODE END Private defines */

#ifdef __cplusplus
Expand Down
3 changes: 0 additions & 3 deletions device/firmware/Core/Src/energymeter.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#include "main.h"
#include "rtc.h"
#include "stm32f1xx_hal.h"
#include "types.h"
#include "energymeter.h"

char debug_buffer[MAX_LEN_DEBUG_STR];

Expand Down
10 changes: 10 additions & 0 deletions device/firmware/Core/Src/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ void MX_GPIO_Init(void)
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(SD_CS_GPIO_Port, SD_CS_Pin, GPIO_PIN_RESET);

/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = LED_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
Expand All @@ -66,6 +69,13 @@ void MX_GPIO_Init(void)
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
HAL_GPIO_Init(USB_SENSE_GPIO_Port, &GPIO_InitStruct);

/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = SD_CS_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(SD_CS_GPIO_Port, &GPIO_InitStruct);

}

/* USER CODE BEGIN 2 */
Expand Down
14 changes: 6 additions & 8 deletions device/firmware/FATFS/Target/user_diskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
/* Includes ------------------------------------------------------------------*/
#include <string.h>
#include "ff_gen_drv.h"
#include "user_diskio_spi.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
Expand Down Expand Up @@ -81,8 +82,7 @@ DSTATUS USER_initialize (
)
{
/* USER CODE BEGIN INIT */
Stat = STA_NOINIT;
return Stat;
return USER_SPI_initialize(pdrv);
/* USER CODE END INIT */
}

Expand All @@ -96,8 +96,7 @@ DSTATUS USER_status (
)
{
/* USER CODE BEGIN STATUS */
Stat = STA_NOINIT;
return Stat;
return USER_SPI_status(pdrv);
/* USER CODE END STATUS */
}

Expand All @@ -117,7 +116,7 @@ DRESULT USER_read (
)
{
/* USER CODE BEGIN READ */
return RES_OK;
return USER_SPI_read(pdrv, buff, sector, count);
/* USER CODE END READ */
}

Expand All @@ -139,7 +138,7 @@ DRESULT USER_write (
{
/* USER CODE BEGIN WRITE */
/* USER CODE HERE */
return RES_OK;
return USER_SPI_write(pdrv, buff, sector, count);
/* USER CODE END WRITE */
}
#endif /* _USE_WRITE == 1 */
Expand All @@ -159,8 +158,7 @@ DRESULT USER_ioctl (
)
{
/* USER CODE BEGIN IOCTL */
DRESULT res = RES_ERROR;
return res;
return USER_SPI_ioctl(pdrv, cmd, buff);
/* USER CODE END IOCTL */
}
#endif /* _USE_IOCTL == 1 */
Expand Down
Loading

0 comments on commit 8b171d0

Please sign in to comment.