compiles and works. But needs more testing

This commit is contained in:
2025-12-18 22:17:13 +03:00
parent 01dae2bccd
commit 7ff25c2893
50 changed files with 6884 additions and 6891 deletions

View File

@ -76,26 +76,28 @@ void Error_Handler(void);
#define ADC_BUFF_SIZE 100
#endif
/* Structure describing simple accumulation state for ADC processing */
struct ADC_proc_typedef {
uint8_t status; /* 0 - stopped, 1 - collecting, 2 - filled */
uint32_t sum;
uint32_t avg;
uint32_t N;
};
uint32_t curr_step_start_N = 0;
struct Sweep_state_typedef {
uint32_t curr_step_N;
uint8_t curr_step_started_flag; //0 -- not started or waiting for; 1 -- first 1/2 DMA buff; 2 -- second 1/2 DMA buff
uint32_t curr_step_start_DMA_N;
};
/* Externs provided by main.c */
extern struct ADC_proc adc_process;
extern uint16_t ADC1_buff_circular[ADC_BUFF_SIZE];
/* Structure describing simple accumulation state for ADC processing */
struct ADC_proc_typedef {
uint8_t status; /* 0 - stopped, 1 - collecting, 2 - filled */
uint32_t sum;
uint32_t avg;
uint32_t N;
};
/* Sweep state shared between ISR and main */
struct Sweep_state_typedef {
uint32_t curr_step_N;
uint8_t curr_step_started_flag; //0 -- not started or waiting for; 1 -- first 1/2 DMA buff; 2 -- second 1/2 DMA buff
uint32_t curr_step_start_DMA_N;
};
/* Externs provided by main.c */
extern volatile struct ADC_proc_typedef ADC_proc;
extern volatile struct ADC_proc_typedef ADC_proc_shadow;
extern volatile struct Sweep_state_typedef Sweep_state;
extern volatile uint32_t curr_step_start_N;
extern uint16_t ADC1_buff_circular[ADC_BUFF_SIZE];
/* USER CODE END Private defines */

View File

@ -17,8 +17,9 @@
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "usb_device.h"
#include "main.h"
#include "usb_device.h"
#include "usbd_cdc_if.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
@ -59,9 +60,10 @@ static void MX_ADC1_Init(void);
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* ADC_proc_shadow definition is provided here; structure is declared in main.h */
struct ADC_proc_typedef ADC_proc, ADC_proc_shadow;
struct Sweep_state_typedef Sweep_state;
/* ADC_proc/ADC_proc_shadow/Sweep_state definitions */
volatile struct ADC_proc_typedef ADC_proc, ADC_proc_shadow;
volatile struct Sweep_state_typedef Sweep_state;
volatile uint32_t curr_step_start_N = 0;
/* ADC1 circular DMA buffer definition */
uint16_t ADC1_buff_circular[ADC_BUFF_SIZE];

View File

@ -57,10 +57,9 @@
/* External variables --------------------------------------------------------*/
extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
extern DMA_HandleTypeDef hdma_adc1;
/* USER CODE BEGIN EV */
extern struct ADC_proc_typedef ADC_proc, ADC_proc_shadow;
extern struct Sweep_state_typedef Sweep_state;
/* USER CODE END EV */
/* USER CODE BEGIN EV */
/* Externs are provided via main.h; no extra declarations needed here */
/* USER CODE END EV */
/******************************************************************************/
/* Cortex-M4 Processor Interruption and Exception Handlers */
@ -206,7 +205,7 @@ void SysTick_Handler(void)
void EXTI0_IRQHandler(void)
{
/* USER CODE BEGIN EXTI0_IRQn 0 */
Sweep_state.curr_step_start_DMA_N = ADC_BUFF_SIZE - hdma_adc1.Instance->NDTR;
Sweep_state.curr_step_start_DMA_N = ADC_BUFF_SIZE - hdma_adc1.Instance->NDTR;
if (Sweep_state.curr_step_start_DMA_N < ADC_BUFF_SIZE/2) {
Sweep_state.curr_step_started_flag =1; // first half DMA buffer
} else{