Works succesfully!
This commit is contained in:
@ -17,9 +17,9 @@
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
#include "usb_device.h"
|
||||
#include "usbd_cdc_if.h"
|
||||
#include "main.h"
|
||||
#include "usb_device.h"
|
||||
#include "usbd_cdc_if.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
@ -60,16 +60,17 @@ static void MX_ADC1_Init(void);
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
/* 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;
|
||||
/* 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];
|
||||
char ADC_msg[] = "Received ADC value: ??????????\r\n";
|
||||
char ADC_msg[] = "curr_step ?????? ??????????\r\n";
|
||||
#define ADC_msg_len 32
|
||||
#define ADC_msg_val_pos 20
|
||||
#define ADC_msg_step_pos 12
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
@ -118,13 +119,16 @@ int main(void)
|
||||
ADC_proc.sum = 0;
|
||||
ADC_proc.avg = 0;
|
||||
|
||||
uint32_t curr_points_N_max = 100;
|
||||
uint32_t curr_points_N =0;
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
HAL_GPIO_TogglePin(LED_RED_GPIO_Port, LED_RED_Pin);
|
||||
//HAL_GPIO_TogglePin(LED_RED_GPIO_Port, LED_RED_Pin);
|
||||
//HAL_Delay(100);
|
||||
|
||||
if (ADC_proc_shadow.status == 2) {
|
||||
@ -144,7 +148,24 @@ int main(void)
|
||||
ADC_msg[ADC_msg_val_pos + 7] = (ADC_proc_shadow.avg / 100) % 10 + '0';
|
||||
ADC_msg[ADC_msg_val_pos + 8] = (ADC_proc_shadow.avg / 10) % 10 + '0';
|
||||
ADC_msg[ADC_msg_val_pos + 9] = (ADC_proc_shadow.avg / 1) % 10 + '0';
|
||||
|
||||
ADC_msg[ADC_msg_step_pos + 0] = (Sweep_state.curr_step_N / 100000) % 10 + '0';
|
||||
ADC_msg[ADC_msg_step_pos + 1] = (Sweep_state.curr_step_N / 10000) % 10 + '0';
|
||||
ADC_msg[ADC_msg_step_pos + 2] = (Sweep_state.curr_step_N / 1000) % 10 + '0';
|
||||
ADC_msg[ADC_msg_step_pos + 3] = (Sweep_state.curr_step_N / 100) % 10 + '0';
|
||||
ADC_msg[ADC_msg_step_pos + 4] = (Sweep_state.curr_step_N / 10) % 10 + '0';
|
||||
ADC_msg[ADC_msg_step_pos + 5] = (Sweep_state.curr_step_N / 1) % 10 + '0';
|
||||
|
||||
|
||||
CDC_Transmit_FS((uint8_t *)ADC_msg, ADC_msg_len);
|
||||
//HAL_GPIO_TogglePin(LED_RED_GPIO_Port, LED_RED_Pin);
|
||||
|
||||
if (Sweep_state.curr_step_N > 1000){
|
||||
Sweep_state.curr_step_N = 0;
|
||||
HAL_GPIO_TogglePin(LED_RED_GPIO_Port, LED_RED_Pin);
|
||||
HAL_DelayUS(10);
|
||||
CDC_Transmit_FS((uint8_t *)"Sweep_start\n\r", 14);
|
||||
}
|
||||
|
||||
}
|
||||
//CDC_Transmit_FS((uint8_t *)"Hello from STM32!\r\n", 19);
|
||||
|
||||
@ -57,9 +57,9 @@
|
||||
/* External variables --------------------------------------------------------*/
|
||||
extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
|
||||
extern DMA_HandleTypeDef hdma_adc1;
|
||||
/* USER CODE BEGIN EV */
|
||||
/* Externs are provided via main.h; no extra declarations needed here */
|
||||
/* 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 */
|
||||
@ -205,12 +205,13 @@ 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{
|
||||
Sweep_state.curr_step_started_flag =2; // second half DMA buffer
|
||||
}
|
||||
Sweep_state.curr_step_N++;
|
||||
/* USER CODE END EXTI0_IRQn 0 */
|
||||
HAL_GPIO_EXTI_IRQHandler(CURR_STEP_START_TRG_Pin);
|
||||
/* USER CODE BEGIN EXTI0_IRQn 1 */
|
||||
@ -267,6 +268,7 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
|
||||
HAL_GPIO_WritePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin, GPIO_PIN_SET);
|
||||
|
||||
if (Sweep_state.curr_step_started_flag == 2) {
|
||||
Sweep_state.curr_step_started_flag = 0; // reset flag after processing second half
|
||||
for (uint32_t i = ADC_BUFF_SIZE/2; i < Sweep_state.curr_step_start_DMA_N; i++) {
|
||||
ADC_proc.sum += ADC1_buff_circular[i];
|
||||
}
|
||||
@ -297,6 +299,8 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
|
||||
}
|
||||
ADC_proc.N += ADC_BUFF_SIZE - ADC_BUFF_SIZE/2;
|
||||
}
|
||||
|
||||
//if (0){
|
||||
if (ADC_proc.N >= ADC_BUFF_SIZE*100){
|
||||
ADC_proc_shadow.sum = ADC_proc.sum;
|
||||
ADC_proc_shadow.avg = ADC_proc.avg;
|
||||
@ -319,6 +323,7 @@ void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc)
|
||||
|
||||
HAL_GPIO_TogglePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin);
|
||||
if (Sweep_state.curr_step_started_flag == 1) {
|
||||
Sweep_state.curr_step_started_flag = 0;
|
||||
for (uint32_t i = 0; i < Sweep_state.curr_step_start_DMA_N; i++) {
|
||||
ADC_proc.sum += ADC1_buff_circular[i];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user