big refactoring and features added

This commit is contained in:
Ayzen
2026-04-24 16:51:15 +03:00
parent eafc328caa
commit ea1fbb071d
184 changed files with 35336 additions and 75480 deletions

View File

@ -28,45 +28,70 @@
/* USER CODE END 0 */
#else
/* USER CODE BEGIN FirstSection */
/* can be used to modify / undefine following code or add new definitions */
/* USER CODE END FirstSection */
/* Includes ------------------------------------------------------------------*/
#include "bsp_driver_sd.h"
/* USER CODE BEGIN FirstSection */
/* can be used to modify / undefine following code or add new definitions */
/* USER CODE END FirstSection */
/* Includes ------------------------------------------------------------------*/
#include "bsp_driver_sd.h"
/* Extern variables ---------------------------------------------------------*/
extern SD_HandleTypeDef hsd1;
/* USER CODE BEGIN BeforeInitSection */
/* can be used to modify / undefine following code or add code */
/* USER CODE END BeforeInitSection */
/* USER CODE BEGIN BeforeInitSection */
/* can be used to modify / undefine following code or add code */
static volatile uint8_t g_last_bsp_sd_init_status = MSD_ERROR_SD_NOT_PRESENT;
static volatile uint8_t g_last_bsp_sd_detect_status = SD_NOT_PRESENT;
static volatile uint8_t g_last_bsp_sd_hal_init_status = HAL_ERROR;
static volatile uint8_t g_last_bsp_sd_wide_bus_status = HAL_ERROR;
static volatile uint32_t g_last_bsp_sd_hal_error = 0u;
void BSP_SD_GetDebugInfo(bsp_sd_debug_info_t *out_info)
{
if (out_info == NULL)
{
return;
}
out_info->last_init_status = g_last_bsp_sd_init_status;
out_info->last_detect_status = g_last_bsp_sd_detect_status;
out_info->last_hal_init_status = g_last_bsp_sd_hal_init_status;
out_info->last_wide_bus_status = g_last_bsp_sd_wide_bus_status;
out_info->last_hal_error = g_last_bsp_sd_hal_error;
}
/* USER CODE END BeforeInitSection */
/**
* @brief Initializes the SD card device.
* @retval SD status
*/
__weak uint8_t BSP_SD_Init(void)
{
uint8_t sd_state = MSD_OK;
/* Check if the SD card is plugged in the slot */
if (BSP_SD_IsDetected() != SD_PRESENT)
{
return MSD_ERROR_SD_NOT_PRESENT;
}
/* HAL SD initialization */
sd_state = HAL_SD_Init(&hsd1);
/* Configure SD Bus width (4 bits mode selected) */
if (sd_state == MSD_OK)
{
/* Enable wide operation */
if (HAL_SD_ConfigWideBusOperation(&hsd1, SDMMC_BUS_WIDE_4B) != HAL_OK)
{
sd_state = MSD_ERROR;
}
}
return sd_state;
}
__weak uint8_t BSP_SD_Init(void)
{
uint8_t sd_state = MSD_OK;
g_last_bsp_sd_detect_status = BSP_SD_IsDetected();
g_last_bsp_sd_hal_init_status = HAL_ERROR;
g_last_bsp_sd_wide_bus_status = HAL_ERROR;
g_last_bsp_sd_hal_error = 0u;
/* Check if the SD card is plugged in the slot */
if (g_last_bsp_sd_detect_status != SD_PRESENT)
{
g_last_bsp_sd_init_status = MSD_ERROR_SD_NOT_PRESENT;
return MSD_ERROR_SD_NOT_PRESENT;
}
hsd1.Init.BusWide = SDMMC_BUS_WIDE_1B;
hsd1.Init.ClockDiv = 118u;
/* HAL SD initialization */
sd_state = HAL_SD_Init(&hsd1);
g_last_bsp_sd_hal_init_status = sd_state;
g_last_bsp_sd_hal_error = hsd1.ErrorCode;
/* Configure SD Bus width (4 bits mode selected) */
if (sd_state == MSD_OK)
{
g_last_bsp_sd_wide_bus_status = HAL_OK;
}
g_last_bsp_sd_init_status = sd_state;
return sd_state;
}
/* USER CODE BEGIN AfterInitSection */
/* can be used to modify previous code / undefine following code / add code */
/* USER CODE END AfterInitSection */