added stop mode feature

This commit is contained in:
unknown 2025-04-21 13:11:12 +05:30
parent 441cc1c516
commit 96727ac84d
33 changed files with 413470 additions and 47 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -59,6 +59,9 @@ void Error_Handler(void);
/* Private defines -----------------------------------------------------------*/
#define USER_LED_Pin GPIO_PIN_10
#define USER_LED_GPIO_Port GPIOF
#define USER_BUTTON1_Pin GPIO_PIN_0
#define USER_BUTTON1_GPIO_Port GPIOC
#define USER_BUTTON1_EXTI_IRQn EXTI0_IRQn
#define USER_BUTTON_Pin GPIO_PIN_10
#define USER_BUTTON_GPIO_Port GPIOA
#define LED_RED_Pin GPIO_PIN_15

View File

@ -52,6 +52,7 @@ void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void DebugMon_Handler(void);
void EXTI0_IRQHandler(void);
void TIM2_IRQHandler(void);
void UART4_IRQHandler(void);
void TIM7_IRQHandler(void);

View File

@ -553,6 +553,12 @@ static void MX_GPIO_Init(void)
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : USER_BUTTON1_Pin */
GPIO_InitStruct.Pin = USER_BUTTON1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(USER_BUTTON1_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : USER_BUTTON_Pin */
GPIO_InitStruct.Pin = USER_BUTTON_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
@ -566,6 +572,10 @@ static void MX_GPIO_Init(void)
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LED_RED_GPIO_Port, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI0_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}
@ -598,7 +608,7 @@ void StartDefaultTask(void const * argument)
LOG(LOG_INFO, "looping Current Minute: %d", cur_time.Minutes);
LOG(LOG_INFO, "looping Current seconds: %d", cur_time.Seconds);
osDelay(5000);
osDelay(2000);
}
/* USER CODE END 5 */
}

View File

@ -163,6 +163,20 @@ void DebugMon_Handler(void)
/* please refer to the startup file (startup_stm32f4xx.s). */
/******************************************************************************/
/**
* @brief This function handles EXTI line0 interrupt.
*/
void EXTI0_IRQHandler(void)
{
/* USER CODE BEGIN EXTI0_IRQn 0 */
/* USER CODE END EXTI0_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(USER_BUTTON1_Pin);
/* USER CODE BEGIN EXTI0_IRQn 1 */
/* USER CODE END EXTI0_IRQn 1 */
}
/**
* @brief This function handles TIM2 global interrupt.
*/

View File

@ -0,0 +1,54 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file fatfs.c
* @brief Code for fatfs applications
******************************************************************************
* @attention
*
* Copyright (c) 2025 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 */
#include "fatfs.h"
uint8_t retUSER; /* Return value for USER */
char USERPath[4]; /* USER logical drive path */
FATFS USERFatFS; /* File system object for USER logical drive */
FIL USERFile; /* File object for USER */
/* USER CODE BEGIN Variables */
/* USER CODE END Variables */
void MX_FATFS_Init(void)
{
/*## FatFS: Link the USER driver ###########################*/
retUSER = FATFS_LinkDriver(&USER_Driver, USERPath);
/* USER CODE BEGIN Init */
/* additional user code for init */
/* USER CODE END Init */
}
/**
* @brief Gets Time from RTC
* @param None
* @retval Time in DWORD
*/
DWORD get_fattime(void)
{
/* USER CODE BEGIN get_fattime */
return 0;
/* USER CODE END get_fattime */
}
/* USER CODE BEGIN Application */
/* USER CODE END Application */

View File

@ -0,0 +1,47 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file fatfs.h
* @brief Header for fatfs applications
******************************************************************************
* @attention
*
* Copyright (c) 2025 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 */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __fatfs_H
#define __fatfs_H
#ifdef __cplusplus
extern "C" {
#endif
#include "ff.h"
#include "ff_gen_drv.h"
#include "user_diskio.h" /* defines USER_Driver as external */
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern uint8_t retUSER; /* Return value for USER */
extern char USERPath[4]; /* USER logical drive path */
extern FATFS USERFatFS; /* File system object for USER logical drive */
extern FIL USERFile; /* File object for USER */
void MX_FATFS_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /*__fatfs_H */

View File

@ -0,0 +1,167 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file user_diskio.c
* @brief This file includes a diskio driver skeleton to be completed by the user.
******************************************************************************
* @attention
*
* Copyright (c) 2025 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 */
#ifdef USE_OBSOLETE_USER_CODE_SECTION_0
/*
* Warning: the user section 0 is no more in use (starting from CubeMx version 4.16.0)
* To be suppressed in the future.
* Kept to ensure backward compatibility with previous CubeMx versions when
* migrating projects.
* User code previously added there should be copied in the new user sections before
* the section contents can be deleted.
*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
#endif
/* USER CODE BEGIN DECL */
/* Includes ------------------------------------------------------------------*/
#include <string.h>
#include "ff_gen_drv.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Disk status */
static volatile DSTATUS Stat = STA_NOINIT;
/* USER CODE END DECL */
/* Private function prototypes -----------------------------------------------*/
DSTATUS USER_initialize (BYTE pdrv);
DSTATUS USER_status (BYTE pdrv);
DRESULT USER_read (BYTE pdrv, BYTE *buff, DWORD sector, UINT count);
#if _USE_WRITE == 1
DRESULT USER_write (BYTE pdrv, const BYTE *buff, DWORD sector, UINT count);
#endif /* _USE_WRITE == 1 */
#if _USE_IOCTL == 1
DRESULT USER_ioctl (BYTE pdrv, BYTE cmd, void *buff);
#endif /* _USE_IOCTL == 1 */
Diskio_drvTypeDef USER_Driver =
{
USER_initialize,
USER_status,
USER_read,
#if _USE_WRITE
USER_write,
#endif /* _USE_WRITE == 1 */
#if _USE_IOCTL == 1
USER_ioctl,
#endif /* _USE_IOCTL == 1 */
};
/* Private functions ---------------------------------------------------------*/
/**
* @brief Initializes a Drive
* @param pdrv: Physical drive number (0..)
* @retval DSTATUS: Operation status
*/
DSTATUS USER_initialize (
BYTE pdrv /* Physical drive nmuber to identify the drive */
)
{
/* USER CODE BEGIN INIT */
Stat = STA_NOINIT;
return Stat;
/* USER CODE END INIT */
}
/**
* @brief Gets Disk Status
* @param pdrv: Physical drive number (0..)
* @retval DSTATUS: Operation status
*/
DSTATUS USER_status (
BYTE pdrv /* Physical drive number to identify the drive */
)
{
/* USER CODE BEGIN STATUS */
Stat = STA_NOINIT;
return Stat;
/* USER CODE END STATUS */
}
/**
* @brief Reads Sector(s)
* @param pdrv: Physical drive number (0..)
* @param *buff: Data buffer to store read data
* @param sector: Sector address (LBA)
* @param count: Number of sectors to read (1..128)
* @retval DRESULT: Operation result
*/
DRESULT USER_read (
BYTE pdrv, /* Physical drive nmuber to identify the drive */
BYTE *buff, /* Data buffer to store read data */
DWORD sector, /* Sector address in LBA */
UINT count /* Number of sectors to read */
)
{
/* USER CODE BEGIN READ */
return RES_OK;
/* USER CODE END READ */
}
/**
* @brief Writes Sector(s)
* @param pdrv: Physical drive number (0..)
* @param *buff: Data to be written
* @param sector: Sector address (LBA)
* @param count: Number of sectors to write (1..128)
* @retval DRESULT: Operation result
*/
#if _USE_WRITE == 1
DRESULT USER_write (
BYTE pdrv, /* Physical drive nmuber to identify the drive */
const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector address in LBA */
UINT count /* Number of sectors to write */
)
{
/* USER CODE BEGIN WRITE */
/* USER CODE HERE */
return RES_OK;
/* USER CODE END WRITE */
}
#endif /* _USE_WRITE == 1 */
/**
* @brief I/O control operation
* @param pdrv: Physical drive number (0..)
* @param cmd: Control code
* @param *buff: Buffer to send/receive control data
* @retval DRESULT: Operation result
*/
#if _USE_IOCTL == 1
DRESULT USER_ioctl (
BYTE pdrv, /* Physical drive nmuber (0..) */
BYTE cmd, /* Control code */
void *buff /* Buffer to send/receive control data */
)
{
/* USER CODE BEGIN IOCTL */
DRESULT res = RES_ERROR;
return res;
/* USER CODE END IOCTL */
}
#endif /* _USE_IOCTL == 1 */

View File

@ -0,0 +1,43 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file user_diskio.h
* @brief This file contains the common defines and functions prototypes for
* the user_diskio driver.
******************************************************************************
* @attention
*
* Copyright (c) 2025 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 */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USER_DISKIO_H
#define __USER_DISKIO_H
#ifdef __cplusplus
extern "C" {
#endif
/* USER CODE BEGIN 0 */
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
extern Diskio_drvTypeDef USER_Driver;
/* USER CODE END 0 */
#ifdef __cplusplus
}
#endif
#endif /* __USER_DISKIO_H */

View File

@ -63,43 +63,44 @@ Mcu.Name=STM32F413Z(G-H)Tx
Mcu.Package=LQFP144
Mcu.Pin0=PE2
Mcu.Pin1=PC14-OSC32_IN
Mcu.Pin10=PB14
Mcu.Pin11=PB15
Mcu.Pin12=PG6
Mcu.Pin13=PC7
Mcu.Pin14=PC9
Mcu.Pin15=PA10
Mcu.Pin16=PA11
Mcu.Pin17=PA12
Mcu.Pin18=PA13
Mcu.Pin19=PA14
Mcu.Pin10=PC2
Mcu.Pin11=PB14
Mcu.Pin12=PB15
Mcu.Pin13=PG6
Mcu.Pin14=PC7
Mcu.Pin15=PC9
Mcu.Pin16=PA10
Mcu.Pin17=PA11
Mcu.Pin18=PA12
Mcu.Pin19=PA13
Mcu.Pin2=PC15-OSC32_OUT
Mcu.Pin20=PC10
Mcu.Pin21=PD0
Mcu.Pin22=PD1
Mcu.Pin23=PD2
Mcu.Pin24=PD3
Mcu.Pin25=PD6
Mcu.Pin26=PG15
Mcu.Pin27=PB5
Mcu.Pin28=PB6
Mcu.Pin29=PB8
Mcu.Pin20=PA14
Mcu.Pin21=PC10
Mcu.Pin22=PD0
Mcu.Pin23=PD1
Mcu.Pin24=PD2
Mcu.Pin25=PD3
Mcu.Pin26=PD6
Mcu.Pin27=PG15
Mcu.Pin28=PB5
Mcu.Pin29=PB6
Mcu.Pin3=PF6
Mcu.Pin30=PB9
Mcu.Pin31=VP_FATFS_VS_Generic
Mcu.Pin32=VP_FREERTOS_VS_CMSIS_V1
Mcu.Pin33=VP_RTC_VS_RTC_Activate
Mcu.Pin34=VP_RTC_VS_RTC_Calendar
Mcu.Pin35=VP_SYS_VS_tim2
Mcu.Pin36=VP_TIM7_VS_ClockSourceINT
Mcu.Pin37=VP_USB_DEVICE_VS_USB_DEVICE_MSC_FS
Mcu.Pin30=PB8
Mcu.Pin31=PB9
Mcu.Pin32=VP_FATFS_VS_Generic
Mcu.Pin33=VP_FREERTOS_VS_CMSIS_V1
Mcu.Pin34=VP_RTC_VS_RTC_Activate
Mcu.Pin35=VP_RTC_VS_RTC_Calendar
Mcu.Pin36=VP_SYS_VS_tim2
Mcu.Pin37=VP_TIM7_VS_ClockSourceINT
Mcu.Pin38=VP_USB_DEVICE_VS_USB_DEVICE_MSC_FS
Mcu.Pin4=PF8
Mcu.Pin5=PF9
Mcu.Pin6=PF10
Mcu.Pin7=PH0 - OSC_IN
Mcu.Pin8=PH1 - OSC_OUT
Mcu.Pin9=PC2
Mcu.PinsNb=38
Mcu.Pin9=PC0
Mcu.PinsNb=39
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32F413ZHTx
@ -108,6 +109,7 @@ MxDb.Version=DB.6.0.130
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
NVIC.DMA2_Stream6_IRQn=true\:13\:0\:true\:false\:true\:true\:false\:true\:true
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
NVIC.EXTI0_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true
NVIC.ForceEnableDMAVector=true
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
@ -164,6 +166,10 @@ PB9.GPIOParameters=GPIO_PuPd
PB9.GPIO_PuPd=GPIO_PULLUP
PB9.Mode=mmc_8_bits_Wide_bus
PB9.Signal=SDIO_D5
PC0.GPIOParameters=GPIO_Label
PC0.GPIO_Label=USER_BUTTON1
PC0.Locked=true
PC0.Signal=GPXTI0
PC10.GPIOParameters=GPIO_PuPd
PC10.GPIO_PuPd=GPIO_PULLUP
PC10.Locked=true
@ -329,6 +335,8 @@ RTC.WeekDay=RTC_WEEKDAY_SUNDAY
RTC.Year=24
SDIO.HardwareFlowControl=SDIO_HARDWARE_FLOW_CONTROL_ENABLE
SDIO.IPParameters=HardwareFlowControl
SH.GPXTI0.0=GPIO_EXTI0
SH.GPXTI0.ConfNb=1
SH.S_CKOUTDFSDM1.0=DFSDM1_CKOUT,CKOUT
SH.S_CKOUTDFSDM1.1=DFSDM1_CKOUT,PDM_SPI_input_from_ch1_and_internal_clock
SH.S_CKOUTDFSDM1.ConfNb=2

View File

@ -88,6 +88,9 @@ uint8_t record_started=0;
uint8_t record_stoped=0;
uint8_t flag = 0;
uint32_t pressStart;
char FileName[100];
uint8_t pre_sec = 0;
typedef struct
@ -100,7 +103,7 @@ typedef struct
Recording_Breakout_TimeTypeDef Brkot_time;
extern void SystemClock_Config(void);
/*****************************************************************************/
/* */
/* F U N C T I O N P R O T O T Y P E S */
@ -117,6 +120,8 @@ void App_AudioRecCallbackFnc(App_AudioRec_State_t state);
void get_audio_file_name(char *file_name, uint8_t rec_break_hr, uint8_t rec_break_min);
void Recording_breakout();
void App_Check_for_stopMode();
/*****************************************************************************/
/* */
/* F U N C T I O N S */
@ -225,6 +230,7 @@ void App_OSTask(void const * argument)
for(;;)
{
App_Task(5);
App_Check_for_stopMode();
osDelay(10);
}
}
@ -380,20 +386,6 @@ time_t getUnixTimeStamp()
void Recording_breakout(){
// HAL_RTC_GetTime(RTC_HDL, &cur_time, RTC_FORMAT_BIN);
// if(cur_time.Seconds != pre_sec){
//
//// LOG(LOG_INFO, "looping Current Minute: %d", cur_time.Minutes);
//// LOG(LOG_INFO, "looping Current seconds: %d", cur_time.Seconds);
//
// pre_sec = cur_time.Seconds;
// }
// LOG(LOG_INFO, "looping Current Minute: %d", cur_time.Minutes);
// LOG(LOG_INFO, "looping Current seconds: %d", cur_time.Seconds);
if(cur_time.Hours == Brkot_time.Brkot_Hours && cur_time.Minutes == Brkot_time.Brkot_Minutes)
{
if (App_AudioRec_Stop() != 0) {
@ -416,6 +408,50 @@ void Recording_breakout(){
}
}
void App_Check_for_stopMode()
{
if (flag == 0){
pressStart = HAL_GetTick();
}
if(HAL_GPIO_ReadPin(USER_BUTTON1_GPIO_Port, USER_BUTTON1_Pin) == GPIO_PIN_SET){
flag = 1;
if (HAL_GetTick() - pressStart >= 2000){
LOG(LOG_INFO, "ENTERED stop MODE......");
RUN_LED_OFF();
HAL_Delay(10);
HAL_SuspendTick();
// Enter Stop Mode with regulator ON, wake on EXTI (WFI instruction)
HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
// MCU is now in Stop Mode — resumes here after wake-up
// Reconfigure system clock (must be done after wake from Stop)
SystemClock_Config();
HAL_ResumeTick();
LOG(LOG_INFO, "WAKE UP FORM STOP MODE.....");
flag = 0;
}
}
else{
flag = 0;
}
}
/*****************************************************************************/
/* See header file of description */
/*****************************************************************************/
@ -553,6 +589,14 @@ void App_Timer_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
}
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if (GPIO_Pin == USER_BUTTON1_Pin)
{
// Wake-up happened — no need to do anything unless needed
}
}
/*****************************************************************************/
/* */
/* E N D O F F I L E */

View File

@ -101,6 +101,8 @@ int32_t pdm_dma_buf[AUDIO_PDM_DMA_BUF_SIZE];
static App_AudioRec_State_t rec_state = AUDIO_REC_STATE_INIT ;
//_app_rec_break_state_t rec_break_state = IDLE;
static App_AudioRecCb_t usr_callback_fnc;
/*****************************************************************************/

View File

@ -48,6 +48,7 @@
/* */
/*****************************************************************************/
typedef enum _app_audio_rec_state_t_
{
AUDIO_REC_STATE_INIT = 0,
@ -56,12 +57,22 @@ typedef enum _app_audio_rec_state_t_
AUDIO_REC_STATE_STOPPED
}App_AudioRec_State_t;
//App_rec_break_state_t rec_break_state = IDLE;
typedef void (*App_AudioRecCb_t) (App_AudioRec_State_t state);
/*****************************************************************************/
/* */
/* F U N C T I O N P R O T O T Y P E S */
/* */
/*****************************************************************************/
enum _app_rec_break_state_t
{
IDLE = 0,
RECORDING,
STOPED
};
uint8_t App_AudioRec_Init(App_AudioRecCb_t app_cb);
uint8_t App_AudioRec_Start(char* out_file);

View File

@ -31,7 +31,7 @@
MAJOR_VERSION "." MINOR_VERSION "." BUG_FIX_VERSION "." BUILD_VERSION
*/
#define APP_SW_VER_STR "00.00.00.0888"
#define APP_SW_VER_STR "00.00.00.0918"
/*****************************************************************************/
/* E N D O F F I L E */