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

@ -1,709 +0,0 @@
/*
* File_Handling_RTOS.c
*
* Created on: 14-May-2020
* Author: Controllerstech
*/
#include <File_Handling.h>
#include "stm32f7xx_hal.h"
#define UART USART1
/* =============================>>>>>>>> NO CHANGES AFTER THIS LINE =====================================>>>>>>> */
FATFS fs; // file system
FIL fil; // File
FILINFO fno;
extern FRESULT fresult; // result
extern unsigned long sizeoffile;
UINT br, bw; // File read/write count
/**** capacity related *****/
FATFS *pfs;
DWORD fre_clust;
uint32_t total, free_space;
void Send_Uart (char *string)
{
//HAL_UART_Transmit(UART, (uint8_t *)string, strlen (string), HAL_MAX_DELAY);
}
int Mount_SD (const TCHAR* path)
{
fresult = f_mount(&fs, path, 1);
if (fresult != FR_OK) return 1;
else return 0;
}
int Unmount_SD (const TCHAR* path)
{
fresult = f_mount(NULL, path, 1);
if (fresult == FR_OK) return 0;//Send_Uart ("SD CARD UNMOUNTED successfully...\n\n\n");
return 1;//else Send_Uart("ERROR!!! in UNMOUNTING SD CARD\n\n\n");
}
/* Start node to be scanned (***also used as work area***) */
FRESULT Scan_SD (char* pat)
{
DIR dir;
UINT i;
char *path = malloc(20*sizeof (char));
sprintf (path, "%s",pat);
fresult = f_opendir(&dir, path); /* Open the directory */
if (fresult == FR_OK)
{
for (;;)
{
fresult = f_readdir(&dir, &fno); /* Read a directory item */
if (fresult != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */
if (fno.fattrib & AM_DIR) /* It is a directory */
{
if (!(strcmp ("SYSTEM~1", fno.fname))) continue;
char *buf = malloc(30*sizeof(char));
sprintf (buf, "Dir: %s\r\n", fno.fname);
Send_Uart(buf);
free(buf);
i = strlen(path);
sprintf(&path[i], "/%s", fno.fname);
fresult = Scan_SD(path); /* Enter the directory */
if (fresult != FR_OK) break;
path[i] = 0;
}
else
{ /* It is a file. */
char *buf = malloc(30*sizeof(char));
sprintf(buf,"File: %s/%s\n", path, fno.fname);
Send_Uart(buf);
free(buf);
}
}
f_closedir(&dir);
}
free(path);
return fresult;
}
/* Only supports removing files from home directory */
FRESULT Format_SD (void)
{
DIR dir;
char *path = malloc(20*sizeof (char));
sprintf (path, "%s","/");
fresult = f_opendir(&dir, path); /* Open the directory */
if (fresult == FR_OK)
{
for (;;)
{
fresult = f_readdir(&dir, &fno); /* Read a directory item */
if (fresult != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */
if (fno.fattrib & AM_DIR) /* It is a directory */
{
if (!(strcmp ("SYSTEM~1", fno.fname))) continue;
fresult = f_unlink(fno.fname);
if (fresult == FR_DENIED) continue;
}
else
{ /* It is a file. */
fresult = f_unlink(fno.fname);
}
}
f_closedir(&dir);
}
free(path);
return fresult;
}
FRESULT Write_File (char *name, char *data)
{
/**** check whether the file exists or not ****/
fresult = f_stat (name, &fno);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! *%s* does not exists\n\n", name);
//Send_Uart (buf);
free(buf);
return fresult;
}
else
{
/* Create a file with read write access and open it */
fresult = f_open(&fil, name, FA_OPEN_EXISTING | FA_WRITE);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! No. %d in opening file *%s*\n\n", fresult, name);
//Send_Uart(buf);
free(buf);
return fresult;
}
else
{
fresult = f_write(&fil, data, strlen(data), &bw);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! No. %d while writing to the FILE *%s*\n\n", fresult, name);
//Send_Uart(buf);
free(buf);
}
/* Close file */
fresult = f_close(&fil);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! No. %d in closing file *%s* after writing it\n\n", fresult, name);
//Send_Uart(buf);
free(buf);
}
else
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "File *%s* is WRITTEN and CLOSED successfully\n", name);
//Send_Uart(buf);
free(buf);
}
}
return fresult;
}
}
FRESULT Write_File_byte (char *name, uint8_t *data, unsigned int bytesize)
{
/**** check whether the file exists or not ****/
fresult = f_stat (name, &fno);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! *%s* does not exists\n\n", name);
//Send_Uart (buf);
free(buf);
return fresult;
}
else
{
/* Create a file with read write access and open it */
fresult = f_open(&fil, name, FA_OPEN_EXISTING | FA_WRITE);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! No. %d in opening file *%s*\n\n", fresult, name);
//Send_Uart(buf);
free(buf);
return fresult;
}
else
{
fresult = f_write(&fil, data, bytesize, &bw);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! No. %d while writing to the FILE *%s*\n\n", fresult, name);
//Send_Uart(buf);
free(buf);
}
/* Close file */
fresult = f_close(&fil);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! No. %d in closing file *%s* after writing it\n\n", fresult, name);
//Send_Uart(buf);
free(buf);
}
else
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "File *%s* is WRITTEN and CLOSED successfully\n", name);
//Send_Uart(buf);
free(buf);
}
}
return fresult;
}
}
FRESULT Read_File (char *name)
{
/**** check whether the file exists or not ****/
fresult = f_stat (name, &fno);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
sprintf (buf, "ERRROR!!! *%s* does not exists\n\n", name);
Send_Uart (buf);
free(buf);
return fresult;
}
else
{
/* Open file to read */
fresult = f_open(&fil, name, FA_READ);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
sprintf (buf, "ERROR!!! No. %d in opening file *%s*\n\n", fresult, name);
Send_Uart(buf);
free(buf);
return fresult;
}
/* Read data from the file
* see the function details for the arguments */
char *buffer = malloc(sizeof(f_size(&fil)));
fresult = f_read (&fil, buffer, f_size(&fil), &br);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
free(buffer);
sprintf (buf, "ERROR!!! No. %d in reading file *%s*\n\n", fresult, name);
Send_Uart(buffer);
free(buf);
}
else
{
Send_Uart(buffer);
free(buffer);
/* Close file */
fresult = f_close(&fil);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
sprintf (buf, "ERROR!!! No. %d in closing file *%s*\n\n", fresult, name);
Send_Uart(buf);
free(buf);
}
else
{
char *buf = malloc(100*sizeof(char));
sprintf (buf, "File *%s* CLOSED successfully\n", name);
Send_Uart(buf);
free(buf);
}
}
return fresult;
}
}
FRESULT Seek_Read_File (char *name, uint8_t *data, unsigned int bytesize, unsigned long goto_label)
{
/**** check whether the file exists or not ****/
fresult = f_stat (name, &fno);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
sprintf (buf, "ERRROR!!! *%s* does not exists\n\n", name);
//Send_Uart (buf);
free(buf);
return fresult;
}
else
{
/* Open file to read */
fresult = f_open(&fil, name, FA_READ);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
sprintf (buf, "ERROR!!! No. %d in opening file *%s*\n\n", fresult, name);
//Send_Uart(buf);
free(buf);
return fresult;
}
/* Read data from the file
* see the function details for the arguments */
//char *buffer = malloc(sizeof(f_size(&fil)));
fresult = f_lseek (&fil, goto_label); /* Move file pointer of the file object */
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//free(buffer);
sprintf (buf, "ERROR!!! Can't seek the file: *%s*\n\n", name);
//Send_Uart(buffer);
free(buf);
return fresult;
}
fresult = f_read (&fil, data, bytesize, &br);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//free(buffer);
sprintf (buf, "ERROR!!! No. %d in reading file *%s*\n\n", fresult, name);
//Send_Uart(buffer);
free(buf);
}
else
{
//Send_Uart(buffer);
//free(buffer);
if (goto_label==0)//Set size of file in first 4 bytes
{
sizeoffile = f_size(&fil);
data[0] = (uint8_t) (sizeoffile&0xff);
data[1] = (uint8_t) ((sizeoffile>>8)&0xff);
data[2] = (uint8_t) ((sizeoffile>>16)&0xff);
data[3] = (uint8_t) ((sizeoffile>>24)&0xff);
}
/* Close file */
fresult = f_close(&fil);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
sprintf (buf, "ERROR!!! No. %d in closing file *%s*\n\n", fresult, name);
//Send_Uart(buf);
free(buf);
}
else
{
char *buf = malloc(100*sizeof(char));
sprintf (buf, "File *%s* CLOSED successfully\n", name);
//Send_Uart(buf);
free(buf);
}
}
return fresult;
}
}
FRESULT Create_File (char *name)
{
fresult = f_stat (name, &fno);
if (fresult == FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! *%s* already exists!!!!\n use Update_File \n\n",name);
//Send_Uart(buf);
free(buf);
return fresult;
}
else
{
fresult = f_open(&fil, name, FA_CREATE_ALWAYS|FA_READ|FA_WRITE);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! No. %d in creating file *%s*\n\n", fresult, name);
//Send_Uart(buf);
free(buf);
return fresult;
}
else
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "*%s* created successfully\n Now use Write_File to write data\n",name);
//Send_Uart(buf);
free(buf);
}
fresult = f_close(&fil);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR No. %d in closing file *%s*\n\n", fresult, name);
//Send_Uart(buf);
free(buf);
}
else
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "File *%s* CLOSED successfully\n", name);
//Send_Uart(buf);
free(buf);
}
}
return fresult;
}
FRESULT Update_File (char *name, char *data)
{
/**** check whether the file exists or not ****/
fresult = f_stat (name, &fno);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! *%s* does not exists\n\n", name);
//Send_Uart (buf);
free(buf);
return fresult;
}
else
{
/* Create a file with read write access and open it */
fresult = f_open(&fil, name, FA_OPEN_APPEND | FA_WRITE);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! No. %d in opening file *%s*\n\n", fresult, name);
//Send_Uart(buf);
free(buf);
return fresult;
}
/* Writing text */
fresult = f_write(&fil, data, strlen (data), &bw);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! No. %d in writing file *%s*\n\n", fresult, name);
//Send_Uart(buf);
free(buf);
}
else
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "*%s* UPDATED successfully\n", name);
//Send_Uart(buf);
free(buf);
}
/* Close file */
fresult = f_close(&fil);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! No. %d in closing file *%s*\n\n", fresult, name);
//Send_Uart(buf);
free(buf);
}
else
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "File *%s* CLOSED successfully\n", name);
//Send_Uart(buf);
free(buf);
}
}
return fresult;
}
FRESULT Remove_File (char *name)
{
/**** check whether the file exists or not ****/
fresult = f_stat (name, &fno);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
sprintf (buf, "ERROR!!! *%s* does not exists\n\n", name);
Send_Uart (buf);
free(buf);
return fresult;
}
else
{
fresult = f_unlink (name);
if (fresult == FR_OK)
{
char *buf = malloc(100*sizeof(char));
sprintf (buf, "*%s* has been removed successfully\n", name);
Send_Uart (buf);
free(buf);
}
else
{
char *buf = malloc(100*sizeof(char));
sprintf (buf, "ERROR No. %d in removing *%s*\n\n",fresult, name);
Send_Uart (buf);
free(buf);
}
}
return fresult;
}
FRESULT Create_Dir (char *name)
{
fresult = f_mkdir(name);
if (fresult == FR_OK)
{
char *buf = malloc(100*sizeof(char));
sprintf (buf, "*%s* has been created successfully\n", name);
Send_Uart (buf);
free(buf);
}
else
{
char *buf = malloc(100*sizeof(char));
sprintf (buf, "ERROR No. %d in creating directory *%s*\n\n", fresult,name);
Send_Uart(buf);
free(buf);
}
return fresult;
}
void Check_SD_Space (void)
{
/* Check free space */
f_getfree("", &fre_clust, &pfs);
total = (uint32_t)((pfs->n_fatent - 2) * pfs->csize * 0.5);
char *buf = malloc(30*sizeof(char));
sprintf (buf, "SD CARD Total Size: \t%lu\n",total);
Send_Uart(buf);
free(buf);
free_space = (uint32_t)(fre_clust * pfs->csize * 0.5);
buf = malloc(30*sizeof(char));
sprintf (buf, "SD CARD Free Space: \t%lu\n",free_space);
Send_Uart(buf);
free(buf);
}
FRESULT Update_File_float (char *name, float *data, unsigned int bytesize)
{
/**** check whether the file exists or not ****/
fresult = f_stat (name, &fno);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! *%s* does not exists\n\n", name);
//Send_Uart (buf);
free(buf);
return fresult;
}
else
{
/* Create a file with read write access and open it */
fresult = f_open(&fil, name, FA_OPEN_APPEND | FA_WRITE);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! No. %d in opening file *%s*\n\n", fresult, name);
//Send_Uart(buf);
free(buf);
return fresult;
}
/* Writing text */
fresult = f_write(&fil, data, bytesize, &bw);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! No. %d in writing file *%s*\n\n", fresult, name);
//Send_Uart(buf);
free(buf);
}
else
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "*%s* UPDATED successfully\n", name);
//Send_Uart(buf);
free(buf);
}
/* Close file */
fresult = f_close(&fil);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! No. %d in closing file *%s*\n\n", fresult, name);
//Send_Uart(buf);
free(buf);
}
else
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "File *%s* CLOSED successfully\n", name);
//Send_Uart(buf);
free(buf);
}
}
return fresult;
}
FRESULT Update_File_byte (char *name, uint8_t *data, unsigned int bytesize)
{
/**** check whether the file exists or not ****/
fresult = f_stat (name, &fno);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! *%s* does not exists\n\n", name);
//Send_Uart (buf);
free(buf);
return fresult;
}
else
{
/* Create a file with read write access and open it */
fresult = f_open(&fil, name, FA_OPEN_APPEND | FA_WRITE);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! No. %d in opening file *%s*\n\n", fresult, name);
//Send_Uart(buf);
free(buf);
return fresult;
}
/* Writing text */
fresult = f_write(&fil, data, bytesize, &bw);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! No. %d in writing file *%s*\n\n", fresult, name);
//Send_Uart(buf);
free(buf);
}
else
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "*%s* UPDATED successfully\n", name);
//Send_Uart(buf);
free(buf);
}
/* Close file */
fresult = f_close(&fil);
if (fresult != FR_OK)
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "ERROR!!! No. %d in closing file *%s*\n\n", fresult, name);
//Send_Uart(buf);
free(buf);
}
else
{
char *buf = malloc(100*sizeof(char));
//sprintf (buf, "File *%s* CLOSED successfully\n", name);
//Send_Uart(buf);
free(buf);
}
}
return fresult;
}

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 */

2877
Src/main.c

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -51,9 +51,11 @@
/* #define DISABLE_SD_INIT */
/* USER CODE END disableSDInit */
/* Private variables ---------------------------------------------------------*/
/* Disk status */
static volatile DSTATUS Stat = STA_NOINIT;
/* Private variables ---------------------------------------------------------*/
/* Disk status */
static volatile DSTATUS Stat = STA_NOINIT;
static volatile DSTATUS g_last_initialize_status = STA_NOINIT;
static volatile DSTATUS g_last_status_result = STA_NOINIT;
/* Private function prototypes -----------------------------------------------*/
static DSTATUS SD_CheckStatus(BYTE lun);
@ -81,9 +83,18 @@ const Diskio_drvTypeDef SD_Driver =
#endif /* _USE_IOCTL == 1 */
};
/* USER CODE BEGIN beforeFunctionSection */
/* can be used to modify / undefine following code or add new code */
/* USER CODE END beforeFunctionSection */
/* USER CODE BEGIN beforeFunctionSection */
/* can be used to modify / undefine following code or add new code */
DSTATUS sd_diskio_debug_get_last_initialize_status(void)
{
return g_last_initialize_status;
}
DSTATUS sd_diskio_debug_get_last_status_result(void)
{
return g_last_status_result;
}
/* USER CODE END beforeFunctionSection */
/* Private functions ---------------------------------------------------------*/
@ -104,9 +115,9 @@ static DSTATUS SD_CheckStatus(BYTE lun)
* @param lun : not used
* @retval DSTATUS: Operation status
*/
DSTATUS SD_initialize(BYTE lun)
{
Stat = STA_NOINIT;
DSTATUS SD_initialize(BYTE lun)
{
Stat = STA_NOINIT;
#if !defined(DISABLE_SD_INIT)
@ -115,22 +126,25 @@ Stat = STA_NOINIT;
Stat = SD_CheckStatus(lun);
}
#else
Stat = SD_CheckStatus(lun);
#endif
return Stat;
}
#else
Stat = SD_CheckStatus(lun);
#endif
g_last_initialize_status = Stat;
return Stat;
}
/**
* @brief Gets Disk Status
* @param lun : not used
* @retval DSTATUS: Operation status
*/
DSTATUS SD_status(BYTE lun)
{
return SD_CheckStatus(lun);
}
DSTATUS SD_status(BYTE lun)
{
g_last_status_result = SD_CheckStatus(lun);
return g_last_status_result;
}
/* USER CODE BEGIN beforeReadSection */
/* can be used to modify previous code / undefine following code / add new code */

View File

@ -20,9 +20,10 @@
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f7xx_it.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "app_core.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
@ -39,34 +40,23 @@
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
extern uint32_t TO6, TO7, TO6_uart, TO10, TO10_counter;
extern uint16_t UART_rec_incr, UART_header, COMMAND[CL_16];
extern uint8_t uart_buf, flg_tmt, CPU_state, State_Data[2], UART_transmission_request, u_tx_flg, TIM10_coflag;
extern task_t task;
extern task_state;
extern LD_Blinker_StateTypeDef LD_blinker;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
void UART_RxCpltCallback(void);
void DMA2_Stream7_TransferComplete(void);
/* USER CODE END PFP */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/* External variables --------------------------------------------------------*/
extern ADC_HandleTypeDef hadc1;
extern ADC_HandleTypeDef hadc3;
extern TIM_HandleTypeDef htim8;
extern TIM_HandleTypeDef htim10;
extern TIM_HandleTypeDef htim11;
/* USER CODE BEGIN EV */
/* External variables --------------------------------------------------------*/
extern ADC_HandleTypeDef hadc1;
extern ADC_HandleTypeDef hadc3;
/* USER CODE BEGIN EV */
/* USER CODE END EV */
@ -226,35 +216,25 @@ void ADC_IRQHandler(void)
/**
* @brief This function handles TIM1 update interrupt and TIM10 global interrupt.
*/
void TIM1_UP_TIM10_IRQHandler(void)
{
/* USER CODE BEGIN TIM1_UP_TIM10_IRQn 0 */
//HAL_GPIO_WritePin(GPIOG, GPIO_PIN_9, GPIO_PIN_SET); // set the current step laser current trigger
//HAL_GPIO_WritePin(GPIOG, GPIO_PIN_9, GPIO_PIN_RESET);
TO10++;
if (TO10 == TO10_counter)
TIM10_coflag = 1;
/* USER CODE END TIM1_UP_TIM10_IRQn 0 */
HAL_TIM_IRQHandler(&htim10);
/* USER CODE BEGIN TIM1_UP_TIM10_IRQn 1 */
/* USER CODE END TIM1_UP_TIM10_IRQn 1 */
void TIM1_UP_TIM10_IRQHandler(void)
{
/* USER CODE BEGIN TIM1_UP_TIM10_IRQn 0 */
/* USER CODE END TIM1_UP_TIM10_IRQn 0 */
/* USER CODE BEGIN TIM1_UP_TIM10_IRQn 1 */
/* USER CODE END TIM1_UP_TIM10_IRQn 1 */
}
/**
* @brief This function handles TIM1 trigger and commutation interrupts and TIM11 global interrupt.
*/
void TIM1_TRG_COM_TIM11_IRQHandler(void)
{
/* USER CODE BEGIN TIM1_TRG_COM_TIM11_IRQn 0 */
TIM11 -> CR1 |= 1 << 3; //sets timer to one-pulse mode. So it will turn off at the next UpdateEvent (Mach-Zander)
TIM4 -> CR1 |= 1 << 3; //sets timer to one-pulse mode. So it will turn off at the next UpdateEvent (ADC clock)
TIM11 -> DIER &= ~(1); //disable interrupt
/* USER CODE END TIM1_TRG_COM_TIM11_IRQn 0 */
HAL_TIM_IRQHandler(&htim11);
/* USER CODE BEGIN TIM1_TRG_COM_TIM11_IRQn 1 */
/* USER CODE END TIM1_TRG_COM_TIM11_IRQn 1 */
void TIM1_TRG_COM_TIM11_IRQHandler(void)
{
/* USER CODE BEGIN TIM1_TRG_COM_TIM11_IRQn 0 */
/* USER CODE END TIM1_TRG_COM_TIM11_IRQn 0 */
/* USER CODE BEGIN TIM1_TRG_COM_TIM11_IRQn 1 */
/* USER CODE END TIM1_TRG_COM_TIM11_IRQn 1 */
}
/**
@ -273,50 +253,53 @@ void TIM2_IRQHandler(void)
/**
* @brief This function handles USART1 global interrupt.
*/
void USART1_IRQHandler(void)
{
/* USER CODE BEGIN USART1_IRQn 0 */
volatile uint8_t temp;
if(LL_USART_IsActiveFlag_RXNE(USART1) && LL_USART_IsEnabledIT_RXNE(USART1))
{
UART_RxCpltCallback();
}
else
{
if(LL_USART_IsActiveFlag_ORE(USART1))
{
//temp = USART1->RDR;
temp+= LL_USART_ReceiveData8(USART1);
}
else if(LL_USART_IsActiveFlag_FE(USART1))
{
//(void) USART1->RDR;
temp+= LL_USART_ReceiveData8(USART1);
}
else if(LL_USART_IsActiveFlag_NE(USART1))
{
//(void) USART1->RDR;
temp+= LL_USART_ReceiveData8(USART1);
}
else if(LL_USART_IsActiveFlag_PE(USART1))
{
//(void) USART1->RDR;
temp+= LL_USART_ReceiveData8(USART1);
}
else
{
if(LL_USART_IsActiveFlag_TC(USART6) && LL_USART_IsEnabledIT_TC(USART6))
{
LL_USART_ClearFlag_TC(USART1);
//test_counter += 1;
//if(UART_transmission_busy == 1){
LL_USART_DisableIT_TC(USART1);
//UART_transmission_busy = 0;
}
}
}
/* USER CODE END USART1_IRQn 0 */
void USART1_IRQHandler(void)
{
/* USER CODE BEGIN USART1_IRQn 0 */
uint8_t discarded_byte = 0u;
uint8_t uart_error_detected = 0u;
if (LL_USART_IsActiveFlag_PE(USART1))
{
LL_USART_ClearFlag_PE(USART1);
uart_error_detected = 1u;
}
if (LL_USART_IsActiveFlag_FE(USART1))
{
LL_USART_ClearFlag_FE(USART1);
uart_error_detected = 1u;
}
if (LL_USART_IsActiveFlag_NE(USART1))
{
LL_USART_ClearFlag_NE(USART1);
uart_error_detected = 1u;
}
if (LL_USART_IsActiveFlag_ORE(USART1))
{
LL_USART_ClearFlag_ORE(USART1);
uart_error_detected = 1u;
}
if (uart_error_detected != 0u)
{
if (LL_USART_IsActiveFlag_RXNE(USART1))
{
discarded_byte = LL_USART_ReceiveData8(USART1);
(void)discarded_byte;
}
app_on_uart_error();
}
else if (LL_USART_IsActiveFlag_RXNE(USART1) && LL_USART_IsEnabledIT_RXNE(USART1))
{
app_on_uart_byte(LL_USART_ReceiveData8(USART1));
}
else if (LL_USART_IsActiveFlag_TC(USART1) && LL_USART_IsEnabledIT_TC(USART1))
{
LL_USART_ClearFlag_TC(USART1);
LL_USART_DisableIT_TC(USART1);
}
/* USER CODE END USART1_IRQn 0 */
/* USER CODE BEGIN USART1_IRQn 1 */
/* USER CODE END USART1_IRQn 1 */
@ -325,37 +308,13 @@ void USART1_IRQHandler(void)
/**
* @brief This function handles TIM8 update interrupt and TIM13 global interrupt.
*/
void TIM8_UP_TIM13_IRQHandler(void)
{
/* USER CODE BEGIN TIM8_UP_TIM13_IRQn 0 */
// HAL_GPIO_TogglePin(LD_blinker.signal_port, LD_blinker.signal_pin);
//HAL_GPIO_TogglePin(OUT_11_GPIO_Port, OUT_11_Pin);
//*
switch (LD_blinker.state) {
case 0: //no LD update required
break;
case 1: //LD ON, need update
//Set_LTEC(LD_blinker.task_type , LD_blinker.param);
//LD_blinker.state = 0;
break;
case 2: //set LD ON, blinking
//Set_LTEC(TT_CHANGE_CURR_2, task.current_param);
Set_LTEC(2 , LD_blinker.param);
HAL_GPIO_WritePin(LD_blinker.signal_port, LD_blinker.signal_pin, GPIO_PIN_SET);
LD_blinker.state = 3;
break;
case 3: //set LD OFF, blinking
Set_LTEC(2 , 0);
HAL_GPIO_WritePin(LD_blinker.signal_port, LD_blinker.signal_pin, GPIO_PIN_RESET);
LD_blinker.state = 2;
break;
}
//*/
/* USER CODE END TIM8_UP_TIM13_IRQn 0 */
HAL_TIM_IRQHandler(&htim8);
/* USER CODE BEGIN TIM8_UP_TIM13_IRQn 1 */
/* USER CODE END TIM8_UP_TIM13_IRQn 1 */
void TIM8_UP_TIM13_IRQHandler(void)
{
/* USER CODE BEGIN TIM8_UP_TIM13_IRQn 0 */
/* USER CODE END TIM8_UP_TIM13_IRQn 0 */
/* USER CODE BEGIN TIM8_UP_TIM13_IRQn 1 */
/* USER CODE END TIM8_UP_TIM13_IRQn 1 */
}
/**
@ -374,54 +333,49 @@ void TIM5_IRQHandler(void)
/**
* @brief This function handles TIM6 global interrupt, DAC1 and DAC2 underrun error interrupts.
*/
void TIM6_DAC_IRQHandler(void)
{
/* USER CODE BEGIN TIM6_DAC_IRQn 0 */
void TIM6_DAC_IRQHandler(void)
{
/* USER CODE BEGIN TIM6_DAC_IRQn 0 */
/* USER CODE END TIM6_DAC_IRQn 0 */
/* USER CODE BEGIN TIM6_DAC_IRQn 1 */
if(LL_TIM_IsActiveFlag_UPDATE(TIM6))
{
LL_TIM_ClearFlag_UPDATE(TIM6);
TO6++;//increment tick
//10 ms or 100 Hz
HAL_GPIO_TogglePin(TEST_01_GPIO_Port, TEST_01_Pin);
//HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);
}
/* USER CODE END TIM6_DAC_IRQn 1 */
/* USER CODE BEGIN TIM6_DAC_IRQn 1 */
if(LL_TIM_IsActiveFlag_UPDATE(TIM6))
{
LL_TIM_ClearFlag_UPDATE(TIM6);
app_on_tim6_tick();
}
/* USER CODE END TIM6_DAC_IRQn 1 */
}
/**
* @brief This function handles TIM7 global interrupt.
*/
void TIM7_IRQHandler(void)
{
void TIM7_IRQHandler(void)
{
/* USER CODE BEGIN TIM7_IRQn 0 */
/* USER CODE END TIM7_IRQn 0 */
/* USER CODE BEGIN TIM7_IRQn 1 */
if(LL_TIM_IsActiveFlag_UPDATE(TIM7))
{
LL_TIM_ClearFlag_UPDATE(TIM7);
TO7++;
//1 ms or 1000 Hz
//HAL_GPIO_TogglePin(TEST_01_GPIO_Port, TEST_01_Pin);
}
/* USER CODE END TIM7_IRQn 1 */
/* USER CODE BEGIN TIM7_IRQn 1 */
if(LL_TIM_IsActiveFlag_UPDATE(TIM7))
{
LL_TIM_ClearFlag_UPDATE(TIM7);
app_on_tim7_tick();
}
/* USER CODE END TIM7_IRQn 1 */
}
/**
* @brief This function handles DMA2 stream7 global interrupt.
*/
void DMA2_Stream7_IRQHandler(void)
{
/* USER CODE BEGIN DMA2_Stream7_IRQn 0 */
if(LL_DMA_IsActiveFlag_TC7(DMA2) == 1)
{
DMA2_Stream7_TransferComplete();
u_tx_flg = 0;//indicate that transfer compete
}
else if(LL_DMA_IsActiveFlag_TE7(DMA2) == 1)
void DMA2_Stream7_IRQHandler(void)
{
/* USER CODE BEGIN DMA2_Stream7_IRQn 0 */
if(LL_DMA_IsActiveFlag_TC7(DMA2) == 1)
{
LL_DMA_ClearFlag_TC7(DMA2);
app_on_dma_tx_complete();
}
else if(LL_DMA_IsActiveFlag_TE7(DMA2) == 1)
{
LL_DMA_ClearFlag_TE7(DMA2);
}
@ -431,212 +385,6 @@ void DMA2_Stream7_IRQHandler(void)
/* USER CODE END DMA2_Stream7_IRQn 1 */
}
/* USER CODE BEGIN 1 */
void UART_RxCpltCallback(void)
{
uart_buf = LL_USART_ReceiveData8(USART1);
switch (UART_rec_incr)
{
case 0:
TO6_uart = TO6;//Save the time of start rec. command
flg_tmt = 1;//Set the timeout flag
UART_header = uart_buf;
UART_rec_incr++;
break;
case 1:
UART_header += ((uint16_t)uart_buf<<8);
switch (UART_header)
{
case 0x1111: //received long packet
UART_rec_incr = 2;//timeout flag is still setting!
break;
case 0x2222: //Back to default
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
CPU_state = DEFAULT_ENABLE;
break;
case 0x3333: //Transmith saved DATA
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
CPU_state = TRANS_S_ENABLE;
break;
case 0x4444: //Received packet
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
CPU_state = TRANS_ENABLE;
break;
case 0x5555: //Erase saved DATA
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
CPU_state = REMOVE_FILE;
break;
case 0x6666: //Request state
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
CPU_state = STATE;
break;
case 0x7777:
UART_rec_incr = 2;//timeout flag is still setting!
break;
case AD9102_CMD_HEADER: // AD9102 command
UART_rec_incr = 2;//timeout flag is still setting!
break;
case AD9833_CMD_HEADER: // AD9833 command
UART_rec_incr = 2;//timeout flag is still setting!
break;
case DS1809_CMD_HEADER: // DS1809 UC/DC pulse command
UART_rec_incr = 2;//timeout flag is still setting!
break;
case STM32_DAC_CMD_HEADER: // STM32 internal DAC command
UART_rec_incr = 2;//timeout flag is still setting!
break;
case AD9102_WAVE_CTRL_HEADER: // AD9102 custom waveform control command
UART_rec_incr = 2;//timeout flag is still setting!
break;
case AD9102_WAVE_DATA_HEADER: // AD9102 custom waveform data packet
UART_rec_incr = 2;//timeout flag is still setting!
break;
default: //error decoding header
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
//UART_transmission_request = MESS_01;
//CPU_state = HALT;
State_Data[0] |= UART_ERR;
CPU_state = DEFAULT_ENABLE;//Parking system and send error state!
break;
}
break;
case (AD9102_CMD_8 - 1):
if (UART_header == AD9102_CMD_HEADER)
{
if ((UART_rec_incr & 0x0001) > 0)
COMMAND[(UART_rec_incr >> 1) - 1] += ((uint16_t)(uart_buf)) << 8;
else
COMMAND[(UART_rec_incr >> 1) - 1] = (uint16_t)(uart_buf);
CPU_state = AD9102_CMD;
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
}
else if (UART_header == AD9833_CMD_HEADER)
{
if ((UART_rec_incr & 0x0001) > 0)
COMMAND[(UART_rec_incr >> 1) - 1] += ((uint16_t)(uart_buf)) << 8;
else
COMMAND[(UART_rec_incr >> 1) - 1] = (uint16_t)(uart_buf);
CPU_state = AD9833_CMD;
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
}
else if (UART_header == DS1809_CMD_HEADER)
{
if ((UART_rec_incr & 0x0001) > 0)
COMMAND[(UART_rec_incr >> 1) - 1] += ((uint16_t)(uart_buf)) << 8;
else
COMMAND[(UART_rec_incr >> 1) - 1] = (uint16_t)(uart_buf);
CPU_state = DS1809_CMD;
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
}
else if (UART_header == STM32_DAC_CMD_HEADER)
{
if ((UART_rec_incr & 0x0001) > 0)
COMMAND[(UART_rec_incr >> 1) - 1] += ((uint16_t)(uart_buf)) << 8;
else
COMMAND[(UART_rec_incr >> 1) - 1] = (uint16_t)(uart_buf);
CPU_state = STM32_DAC_CMD;
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
}
else if (UART_header == AD9102_WAVE_CTRL_HEADER)
{
if ((UART_rec_incr & 0x0001) > 0)
COMMAND[(UART_rec_incr >> 1) - 1] += ((uint16_t)(uart_buf)) << 8;
else
COMMAND[(UART_rec_incr >> 1) - 1] = (uint16_t)(uart_buf);
CPU_state = AD9102_WAVE_CTRL_CMD;
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
}
else
{
if ((UART_rec_incr&0x0001)>0)
COMMAND[(UART_rec_incr>>1)-1] += ((uint16_t)(uart_buf))<<8;
else
COMMAND[(UART_rec_incr>>1)-1] = (uint16_t)(uart_buf);
UART_rec_incr++;
UART_transmission_request = NO_MESS;
}
break;
case (CL_8 - 1):
if (UART_header == 0x1111)
{
if ((UART_rec_incr & 0x0001) > 0)
COMMAND[(UART_rec_incr >> 1) - 1] += ((uint16_t)(uart_buf)) << 8;
else
COMMAND[(UART_rec_incr >> 1) - 1] = (uint16_t)(uart_buf);
CPU_state = DECODE_ENABLE;
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
}
else if (UART_header == AD9102_WAVE_DATA_HEADER)
{
if ((UART_rec_incr & 0x0001) > 0)
COMMAND[(UART_rec_incr >> 1) - 1] += ((uint16_t)(uart_buf)) << 8;
else
COMMAND[(UART_rec_incr >> 1) - 1] = (uint16_t)(uart_buf);
CPU_state = AD9102_WAVE_DATA_CMD;
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
}
else
{
if ((UART_rec_incr&0x0001)>0)
COMMAND[(UART_rec_incr>>1)-1] += ((uint16_t)(uart_buf))<<8;
else
COMMAND[(UART_rec_incr>>1)-1] = (uint16_t)(uart_buf);
UART_rec_incr++;
UART_transmission_request = NO_MESS;
}
break;
case (TSK_8 - 1):
if (UART_header == 0x7777)
{
if ((UART_rec_incr&0x0001)>0)
COMMAND[(UART_rec_incr>>1)-1] += ((uint16_t)(uart_buf))<<8;
else
COMMAND[(UART_rec_incr>>1)-1] = (uint16_t)(uart_buf);
CPU_state = DECODE_TASK;
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
}
else
{
if ((UART_rec_incr&0x0001)>0)
COMMAND[(UART_rec_incr>>1)-1] += ((uint16_t)(uart_buf))<<8;
else
COMMAND[(UART_rec_incr>>1)-1] = (uint16_t)(uart_buf);
UART_rec_incr++;
UART_transmission_request = NO_MESS;
}
break;
default:
if ((UART_rec_incr&0x0001)>0)
COMMAND[(UART_rec_incr>>1)-1] += ((uint16_t)(uart_buf))<<8;
else
COMMAND[(UART_rec_incr>>1)-1] = (uint16_t)(uart_buf);
UART_rec_incr++;
UART_transmission_request = NO_MESS;
break;
}
// HAL_UART_Receive_IT(&huart1, &uart_buf, 1);
}
//-----------------------------------------------
void DMA2_Stream7_TransferComplete(void)
{
LL_DMA_ClearFlag_TC7(DMA2);
}
//-----------------------------------------------
/* USER CODE END 1 */
/* USER CODE BEGIN 1 */
/* IRQ forwarding lives in app_core.c. */
/* USER CODE END 1 */

View File

@ -1,530 +0,0 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32f7xx_it.c
* @brief Interrupt Service Routines.
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f7xx_it.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
extern uint32_t TO6, TO7, TO6_uart, TO10, TO10_counter;
extern uint16_t UART_rec_incr, UART_header, COMMAND[CL_16];
extern uint8_t uart_buf, flg_tmt, CPU_state, State_Data[2], UART_transmission_request, u_tx_flg, TIM10_coflag;
extern task_t task;
extern task_state;
extern LD_Blinker_StateTypeDef LD_blinker;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
void UART_RxCpltCallback(void);
void DMA2_Stream7_TransferComplete(void);
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/* External variables --------------------------------------------------------*/
extern ADC_HandleTypeDef hadc1;
extern ADC_HandleTypeDef hadc3;
extern TIM_HandleTypeDef htim8;
extern TIM_HandleTypeDef htim10;
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/******************************************************************************/
/* Cortex-M7 Processor Interruption and Exception Handlers */
/******************************************************************************/
/**
* @brief This function handles Non maskable interrupt.
*/
void NMI_Handler(void)
{
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
/* USER CODE END NonMaskableInt_IRQn 0 */
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
while (1)
{
}
/* USER CODE END NonMaskableInt_IRQn 1 */
}
/**
* @brief This function handles Hard fault interrupt.
*/
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
/* USER CODE END HardFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
/* USER CODE END W1_HardFault_IRQn 0 */
}
}
/**
* @brief This function handles Memory management fault.
*/
void MemManage_Handler(void)
{
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
/* USER CODE END MemoryManagement_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
/* USER CODE END W1_MemoryManagement_IRQn 0 */
}
}
/**
* @brief This function handles Pre-fetch fault, memory access fault.
*/
void BusFault_Handler(void)
{
/* USER CODE BEGIN BusFault_IRQn 0 */
/* USER CODE END BusFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_BusFault_IRQn 0 */
/* USER CODE END W1_BusFault_IRQn 0 */
}
}
/**
* @brief This function handles Undefined instruction or illegal state.
*/
void UsageFault_Handler(void)
{
/* USER CODE BEGIN UsageFault_IRQn 0 */
/* USER CODE END UsageFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_UsageFault_IRQn 0 */
/* USER CODE END W1_UsageFault_IRQn 0 */
}
}
/**
* @brief This function handles System service call via SWI instruction.
*/
void SVC_Handler(void)
{
/* USER CODE BEGIN SVCall_IRQn 0 */
/* USER CODE END SVCall_IRQn 0 */
/* USER CODE BEGIN SVCall_IRQn 1 */
/* USER CODE END SVCall_IRQn 1 */
}
/**
* @brief This function handles Debug monitor.
*/
void DebugMon_Handler(void)
{
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
/* USER CODE END DebugMonitor_IRQn 0 */
/* USER CODE BEGIN DebugMonitor_IRQn 1 */
/* USER CODE END DebugMonitor_IRQn 1 */
}
/**
* @brief This function handles Pendable request for system service.
*/
void PendSV_Handler(void)
{
/* USER CODE BEGIN PendSV_IRQn 0 */
/* USER CODE END PendSV_IRQn 0 */
/* USER CODE BEGIN PendSV_IRQn 1 */
/* USER CODE END PendSV_IRQn 1 */
}
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn 0 */
/* USER CODE END SysTick_IRQn 0 */
HAL_IncTick();
/* USER CODE BEGIN SysTick_IRQn 1 */
/* USER CODE END SysTick_IRQn 1 */
}
/******************************************************************************/
/* STM32F7xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32f7xx.s). */
/******************************************************************************/
/**
* @brief This function handles ADC1, ADC2 and ADC3 global interrupts.
*/
void ADC_IRQHandler(void)
{
/* USER CODE BEGIN ADC_IRQn 0 */
/* USER CODE END ADC_IRQn 0 */
HAL_ADC_IRQHandler(&hadc1);
HAL_ADC_IRQHandler(&hadc3);
/* USER CODE BEGIN ADC_IRQn 1 */
/* USER CODE END ADC_IRQn 1 */
}
/**
* @brief This function handles TIM1 update interrupt and TIM10 global interrupt.
*/
void TIM1_UP_TIM10_IRQHandler(void)
{
/* USER CODE BEGIN TIM1_UP_TIM10_IRQn 0 */
TO10++;
if (TO10 == TO10_counter)
TIM10_coflag = 1;
/* USER CODE END TIM1_UP_TIM10_IRQn 0 */
HAL_TIM_IRQHandler(&htim10);
/* USER CODE BEGIN TIM1_UP_TIM10_IRQn 1 */
/* USER CODE END TIM1_UP_TIM10_IRQn 1 */
}
/**
* @brief This function handles TIM2 global interrupt.
*/
void TIM2_IRQHandler(void)
{
/* USER CODE BEGIN TIM2_IRQn 0 */
/* USER CODE END TIM2_IRQn 0 */
/* USER CODE BEGIN TIM2_IRQn 1 */
/* USER CODE END TIM2_IRQn 1 */
}
/**
* @brief This function handles USART1 global interrupt.
*/
void USART1_IRQHandler(void)
{
/* USER CODE BEGIN USART1_IRQn 0 */
volatile uint8_t temp;
if(LL_USART_IsActiveFlag_RXNE(USART1) && LL_USART_IsEnabledIT_RXNE(USART1))
{
UART_RxCpltCallback();
}
else
{
if(LL_USART_IsActiveFlag_ORE(USART1))
{
//temp = USART1->RDR;
temp+= LL_USART_ReceiveData8(USART1);
}
else if(LL_USART_IsActiveFlag_FE(USART1))
{
//(void) USART1->RDR;
temp+= LL_USART_ReceiveData8(USART1);
}
else if(LL_USART_IsActiveFlag_NE(USART1))
{
//(void) USART1->RDR;
temp+= LL_USART_ReceiveData8(USART1);
}
else if(LL_USART_IsActiveFlag_PE(USART1))
{
//(void) USART1->RDR;
temp+= LL_USART_ReceiveData8(USART1);
}
else
{
if(LL_USART_IsActiveFlag_TC(USART6) && LL_USART_IsEnabledIT_TC(USART6))
{
LL_USART_ClearFlag_TC(USART1);
//test_counter += 1;
//if(UART_transmission_busy == 1){
LL_USART_DisableIT_TC(USART1);
//UART_transmission_busy = 0;
}
}
}
/* USER CODE END USART1_IRQn 0 */
/* USER CODE BEGIN USART1_IRQn 1 */
/* USER CODE END USART1_IRQn 1 */
}
/**
* @brief This function handles TIM8 update interrupt and TIM13 global interrupt.
*/
void TIM8_UP_TIM13_IRQHandler(void)
{
/* USER CODE BEGIN TIM8_UP_TIM13_IRQn 0 */
switch (LD_blinker.state) {
case 0: //no LD update required
break;
case 1: //LD ON, need update
Set_LTEC(LD_blinker.task_type , LD_blinker.param);
LD_blinker.state = 0;
break;
case 2: //set LD ON, blinking
Set_LTEC(LD_blinker.task_type , LD_blinker.param);
HAL_GPIO_WritePin(LD_blinker.signal_port, LD_blinker.signal_pin, GPIO_PIN_SET);
LD_blinker.state = 3;
break;
case 3: //set LD OFF, blinking
Set_LTEC(LD_blinker.task_type , 0.0);
HAL_GPIO_WritePin(LD_blinker.signal_port, LD_blinker.signal_pin, GPIO_PIN_RESET);
LD_blinker.state = 2;
break;
}
/* USER CODE END TIM8_UP_TIM13_IRQn 0 */
HAL_TIM_IRQHandler(&htim8);
/* USER CODE BEGIN TIM8_UP_TIM13_IRQn 1 */
/* USER CODE END TIM8_UP_TIM13_IRQn 1 */
}
/**
* @brief This function handles TIM5 global interrupt.
*/
void TIM5_IRQHandler(void)
{
/* USER CODE BEGIN TIM5_IRQn 0 */
/* USER CODE END TIM5_IRQn 0 */
/* USER CODE BEGIN TIM5_IRQn 1 */
/* USER CODE END TIM5_IRQn 1 */
}
/**
* @brief This function handles TIM6 global interrupt, DAC1 and DAC2 underrun error interrupts.
*/
void TIM6_DAC_IRQHandler(void)
{
/* USER CODE BEGIN TIM6_DAC_IRQn 0 */
/* USER CODE END TIM6_DAC_IRQn 0 */
/* USER CODE BEGIN TIM6_DAC_IRQn 1 */
if(LL_TIM_IsActiveFlag_UPDATE(TIM6))
{
LL_TIM_ClearFlag_UPDATE(TIM6);
TO6++;//increment tick
//10 ms or 100 Hz
HAL_GPIO_TogglePin(TEST_01_GPIO_Port, TEST_01_Pin);
//HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);
}
/* USER CODE END TIM6_DAC_IRQn 1 */
}
/**
* @brief This function handles TIM7 global interrupt.
*/
void TIM7_IRQHandler(void)
{
/* USER CODE BEGIN TIM7_IRQn 0 */
/* USER CODE END TIM7_IRQn 0 */
/* USER CODE BEGIN TIM7_IRQn 1 */
if(LL_TIM_IsActiveFlag_UPDATE(TIM7))
{
LL_TIM_ClearFlag_UPDATE(TIM7);
TO7++;
//1 ms or 1000 Hz
//HAL_GPIO_TogglePin(TEST_01_GPIO_Port, TEST_01_Pin);
}
/* USER CODE END TIM7_IRQn 1 */
}
/**
* @brief This function handles DMA2 stream7 global interrupt.
*/
void DMA2_Stream7_IRQHandler(void)
{
/* USER CODE BEGIN DMA2_Stream7_IRQn 0 */
if(LL_DMA_IsActiveFlag_TC7(DMA2) == 1)
{
DMA2_Stream7_TransferComplete();
u_tx_flg = 0;//indicate that transfer compete
}
else if(LL_DMA_IsActiveFlag_TE7(DMA2) == 1)
{
LL_DMA_ClearFlag_TE7(DMA2);
}
/* USER CODE END DMA2_Stream7_IRQn 0 */
/* USER CODE BEGIN DMA2_Stream7_IRQn 1 */
/* USER CODE END DMA2_Stream7_IRQn 1 */
}
/* USER CODE BEGIN 1 */
void UART_RxCpltCallback(void)
{
uart_buf = LL_USART_ReceiveData8(USART1);
switch (UART_rec_incr)
{
case 0:
TO6_uart = TO6;//Save the time of start rec. command
flg_tmt = 1;//Set the timeout flag
UART_header = uart_buf;
UART_rec_incr++;
break;
case 1:
UART_header += ((uint16_t)uart_buf<<8);
switch (UART_header)
{
case 0x1111: //received long packet
UART_rec_incr = 2;//timeout flag is still setting!
break;
case 0x2222: //Back to default
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
CPU_state = DEFAULT_ENABLE;
break;
case 0x3333: //Transmith saved DATA
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
CPU_state = TRANS_S_ENABLE;
break;
case 0x4444: //Received packet
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
CPU_state = TRANS_ENABLE;
break;
case 0x5555: //Erase saved DATA
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
CPU_state = REMOVE_FILE;
break;
case 0x6666: //Request state
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
CPU_state = STATE;
break;
case 0x7777:
UART_rec_incr = 2;//timeout flag is still setting!
break;
default: //error decoding header
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
//UART_transmission_request = MESS_01;
//CPU_state = HALT;
State_Data[0] |= UART_ERR;
CPU_state = DEFAULT_ENABLE;//Parking system and send error state!
break;
}
break;
case (CL_8 - 1):
if (UART_header == 0x1111)
{
if ((UART_rec_incr & 0x0001) > 0)
COMMAND[(UART_rec_incr >> 1) - 1] += ((uint16_t)(uart_buf)) << 8;
else
COMMAND[(UART_rec_incr >> 1) - 1] = (uint16_t)(uart_buf);
CPU_state = DECODE_ENABLE;
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
}
else
{
if ((UART_rec_incr&0x0001)>0)
COMMAND[(UART_rec_incr>>1)-1] += ((uint16_t)(uart_buf))<<8;
else
COMMAND[(UART_rec_incr>>1)-1] = (uint16_t)(uart_buf);
UART_rec_incr++;
UART_transmission_request = NO_MESS;
}
break;
case (TSK_8 - 1):
if (UART_header == 0x7777)
{
if ((UART_rec_incr&0x0001)>0)
COMMAND[(UART_rec_incr>>1)-1] += ((uint16_t)(uart_buf))<<8;
else
COMMAND[(UART_rec_incr>>1)-1] = (uint16_t)(uart_buf);
CPU_state = DECODE_TASK;
UART_rec_incr = 0;
flg_tmt = 0;//Reset the timeout flag
}
else
{
if ((UART_rec_incr&0x0001)>0)
COMMAND[(UART_rec_incr>>1)-1] += ((uint16_t)(uart_buf))<<8;
else
COMMAND[(UART_rec_incr>>1)-1] = (uint16_t)(uart_buf);
UART_rec_incr++;
UART_transmission_request = NO_MESS;
}
break;
default:
if ((UART_rec_incr&0x0001)>0)
COMMAND[(UART_rec_incr>>1)-1] += ((uint16_t)(uart_buf))<<8;
else
COMMAND[(UART_rec_incr>>1)-1] = (uint16_t)(uart_buf);
UART_rec_incr++;
UART_transmission_request = NO_MESS;
break;
}
// HAL_UART_Receive_IT(&huart1, &uart_buf, 1);
}
//-----------------------------------------------
void DMA2_Stream7_TransferComplete(void)
{
LL_DMA_ClearFlag_TC7(DMA2);
}
//-----------------------------------------------
/* USER CODE END 1 */