Otazky ohladom STM32

Všetko čo sa týka mikropočítačov + Sekcia Arduino

Moderátori: psichac, Moderátori

Používateľov profilový obrázok
Tribec Zacks
Pokročilý člen
Pokročilý člen
Príspevky: 709
Dátum registrácie: 26 Jún 2010, 00:00
Bydlisko: Levice / Cork IRL
Vek: 41
Kontaktovať používateľa:

Re: Otazky ohladom STM32

Príspevok od používateľa Tribec Zacks » 21 Nov 2022, 14:57

cube ma integrovany srial wire viewer, v podstate integrovane pouzivanie ITM debug hw co je na mcu. pozri stm cube ide dokumentaciu a vsetko okolo SWV, to co hladas najdes pod swv statistical profiling.
0
Kreativita a motivacia je to, co prinasa originalne napady a myslienky, disciplina je to, co ich dokaze zrealizovat.

Používateľov profilový obrázok
Tribec Zacks
Pokročilý člen
Pokročilý člen
Príspevky: 709
Dátum registrácie: 26 Jún 2010, 00:00
Bydlisko: Levice / Cork IRL
Vek: 41
Kontaktovať používateľa:

Re: Otazky ohladom STM32

Príspevok od používateľa Tribec Zacks » 21 Nov 2022, 15:02

niki31 napísal:
21 Nov 2022, 14:45
Na internete píšu že sa môže použiť na meranie času, časovač systick. Ja síce nepoužívam žiaden RTOS ale používam HAL knižnice. No a nieje mi jasné či neovplyvním HAL alebo ST-Link keď budem zasahovať do registrov systicku. Niekde som čítal že ST-Link priamo využíva systick ale či na svojom čipe alebo na čipe ktorý programujem, to som sa nedozvedel.
hal pouziva systick na meranie timeoutu, citanim nic nepokazis, mozes na zaciatku funkcie lognut cas, na konci tiez a iba odratat, ale naco ked mozes vyuzit hw profile countre a hw na tych cortexoch na to urceny.
0
Kreativita a motivacia je to, co prinasa originalne napady a myslienky, disciplina je to, co ich dokaze zrealizovat.

Používateľov profilový obrázok
niki31
Stály člen
Stály člen
Príspevky: 172
Dátum registrácie: 05 Feb 2010, 00:00
Bydlisko: Žilinský kraj
Vek: 49

Re: Otazky ohladom STM32

Príspevok od používateľa niki31 » 21 Nov 2022, 15:33

Skúsim to s tým systickom, nemôžem použiť nič čo je zviazané s pinmi. Všetky piny využívam vrátane SWD pinu. ST-Link je pripojený iba dvoma vodičmi. Čo sú "hw profile countre" zatiaľ neviem, s STM32 som začal len
nedávno. Mám stiahnutú len základnú dokumentáciu a je to cez 10 000 strán, tak ešte potrvá než sa cez to prehryziem.
0
Niki31

Používateľov profilový obrázok
Tribec Zacks
Pokročilý člen
Pokročilý člen
Príspevky: 709
Dátum registrácie: 26 Jún 2010, 00:00
Bydlisko: Levice / Cork IRL
Vek: 41
Kontaktovať používateľa:

Re: Otazky ohladom STM32

Príspevok od používateľa Tribec Zacks » 21 Nov 2022, 16:28

tak mozno ti pomozu live expressions (zapni pod debugger konfiguraciou ak niesu)
na zaciatku funkcie logni cas zo systicku, tak isto na konci, prerataj na ms/us podla potreby a uloz do nejakej globalnej premennej, tu si potom pridaj do tych live expr. je to v realnom case, len update rate je trochu limitovany.
image.png
0
Kreativita a motivacia je to, co prinasa originalne napady a myslienky, disciplina je to, co ich dokaze zrealizovat.

Používateľov profilový obrázok
Tribec Zacks
Pokročilý člen
Pokročilý člen
Príspevky: 709
Dátum registrácie: 26 Jún 2010, 00:00
Bydlisko: Levice / Cork IRL
Vek: 41
Kontaktovať používateľa:

Re: Otazky ohladom STM32

Príspevok od používateľa Tribec Zacks » 21 Nov 2022, 16:47

btw ak pouzivas ten maly usb mini klon stmlink v2, tak swo tam vies dorobit (velmi uzitocna vec :rolleyes:):
https://lujji.github.io/blog/stlink-clone-trace/
0
Kreativita a motivacia je to, co prinasa originalne napady a myslienky, disciplina je to, co ich dokaze zrealizovat.

Používateľov profilový obrázok
niki31
Stály člen
Stály člen
Príspevky: 172
Dátum registrácie: 05 Feb 2010, 00:00
Bydlisko: Žilinský kraj
Vek: 49

Re: Otazky ohladom STM32

Príspevok od používateľa niki31 » 04 Apr 2023, 10:39

Nevie niekto prečo vždy pri generovaní kódu po úprave v dizajnéri návrhu, začne IDE sťahovať súbor "stm32cube_fw_h7_v1100zip" ? Ten súbor má vyše 1GB a je to pekne zdĺhavé, otravné a plytvá to časom a dátami. Ako to vypnúť alebo obísť?
0
Niki31

Dumitru
Stály člen
Stály člen
Príspevky: 377
Dátum registrácie: 06 Nov 2011, 22:19
Vek: 32

Re: Otazky ohladom STM32

Príspevok od používateľa Dumitru » 19 Sep 2023, 19:52

Ahojte potreboval by som pomoc ohľadom ADC , mam chip STM32G071RBT6 podľa datasheetu sľubujú 2.5MSPS,
image.png
Mam nastavene 3 vstupne kanály ktoré samplujem za sebou

Kód: Vybrať všetko

Scan conversion mode
, Clock pre MCU je 64Mhz ktoré pre adc podelím na 2 teda 32Mhz ak dobre počítam tak pre 1kanal je

Kód: Vybrať všetko

tconv = 12.5+1.5 = 14
cycle ja mam 3 takže 32Mhz/42=762KSPS, ďalej používam DMA a ak som správne pochopil ak mam nastavene

Kód: Vybrať všetko

End of Conversion Selection = End of sequence of conversion 
tak raz za 1/762kHz sekúnd mi z DMA prekopíruje dáta do mnou definovaného bufferu na moje prekvapenie ale procesor nestíha nič iné len merať a kopírovať tie data :confused:
image.png
V maine v nekonečnom cykle inkrementujem Counter++; v debugu ale sa mení len hodnota ADC prevodníku

A to iste mam aj pre 64Mhz/4, 64Mhz/6, 64Mhz/8, 64Mhz/10, až pri 64Mhz/12 sa procesor dostane do mainu a je schopný aspoň inkrementovať premennú Counter 64Mhz/12/42 je 128KSPS čož oproty slubenim 2.5MSPS je celkom malo potreboval by som aspoň 200KSPS.
Ako nato ?
V prílohe prikladám nastavenia procesoru
ADC_PARAMETER_SETTING.JPG
DMA_SETTINGS.JPG
CLOCK.JPG
0

Atlan
Zaslúžilý člen
Zaslúžilý člen
Príspevky: 1148
Dátum registrácie: 01 Feb 2008, 00:00
Bydlisko: Kosice okolie

Re: Otazky ohladom STM32

Príspevok od používateľa Atlan » 20 Sep 2023, 06:21

A program je kde?
0

Dumitru
Stály člen
Stály člen
Príspevky: 377
Dátum registrácie: 06 Nov 2011, 22:19
Vek: 32

Re: Otazky ohladom STM32

Príspevok od používateľa Dumitru » 20 Sep 2023, 08:03

A program je kde?

Kód: Vybrať všetko

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @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"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

#define ADC_BUFF_SIZE 3

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc1;
DMA_HandleTypeDef hdma_adc1;

/* USER CODE BEGIN PV */

volatile uint16_t ADC_buff[ADC_BUFF_SIZE] = {0};
volatile uint16_t Counter = 0;

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_ADC1_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_ADC1_Init();
  /* USER CODE BEGIN 2 */

  HAL_ADC_Start_DMA(&hadc1,(uint32_t *)&ADC_buff,ADC_BUFF_SIZE);

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    Counter++;
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Configure the main internal regulator output voltage
  */
  HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;
  RCC_OscInitStruct.PLL.PLLN = 8;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
  RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief ADC1 Initialization Function
  * @param None
  * @retval None
  */
static void MX_ADC1_Init(void)
{

  /* USER CODE BEGIN ADC1_Init 0 */

  /* USER CODE END ADC1_Init 0 */

  ADC_ChannelConfTypeDef sConfig = {0};

  /* USER CODE BEGIN ADC1_Init 1 */

  /* USER CODE END ADC1_Init 1 */

  /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
  */
  hadc1.Instance = ADC1;
  hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV2;
  hadc1.Init.Resolution = ADC_RESOLUTION_12B;
  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  hadc1.Init.LowPowerAutoWait = DISABLE;
  hadc1.Init.LowPowerAutoPowerOff = DISABLE;
  hadc1.Init.ContinuousConvMode = ENABLE;
  hadc1.Init.NbrOfConversion = 3;
  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc1.Init.DMAContinuousRequests = ENABLE;
  hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_1CYCLE_5;
  hadc1.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_1CYCLE_5;
  hadc1.Init.OversamplingMode = DISABLE;
  hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
  if (HAL_ADC_Init(&hadc1) != HAL_OK)
  {
    Error_Handler();
  }

  /** Configure Regular Channel
  */
  sConfig.Channel = ADC_CHANNEL_8;
  sConfig.Rank = ADC_REGULAR_RANK_1;
  sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }

  /** Configure Regular Channel
  */
  sConfig.Channel = ADC_CHANNEL_9;
  sConfig.Rank = ADC_REGULAR_RANK_2;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }

  /** Configure Regular Channel
  */
  sConfig.Channel = ADC_CHANNEL_10;
  sConfig.Rank = ADC_REGULAR_RANK_3;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN ADC1_Init 2 */

  /* USER CODE END ADC1_Init 2 */

}

/**
  * Enable DMA controller clock
  */
static void MX_DMA_Init(void)
{

  /* DMA controller clock enable */
  __HAL_RCC_DMA1_CLK_ENABLE();

  /* DMA interrupt init */
  /* DMA1_Channel1_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);

}

/**
  * @brief GPIO Initialization Function
  * @param None
  * @retval None
  */
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(LED4_GPIO_Port, LED4_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin : LED4_Pin */
  GPIO_InitStruct.Pin = LED4_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  HAL_GPIO_Init(LED4_GPIO_Port, &GPIO_InitStruct);

/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
0

Používateľov profilový obrázok
Tribec Zacks
Pokročilý člen
Pokročilý člen
Príspevky: 709
Dátum registrácie: 26 Jún 2010, 00:00
Bydlisko: Levice / Cork IRL
Vek: 41
Kontaktovať používateľa:

Re: Otazky ohladom STM32

Príspevok od používateľa Tribec Zacks » 20 Sep 2023, 10:14

Dumitru, len z velmi rychleho pozretia:

ADC mas v continuous mode, (velmi nepouzivam HAL) ale pls over ci to neznamena ze akonahle skonci konverziu tak robi hned dalsiu, ak sa toto potvrdi tak to trigeruje dma (po tej 14 cyklovej konverzii), to hned prenese data a skoci do prerusenia. adc konverzia 14cyklov, prerusenie tiez (bez fpu) a tak je mcu nonstop v preruseni.

kazdopadne nastav timer na zaciatok cca 1khz ktoreho event (capture/compare) trigeruje ADC v single mode, (timer negeneruje prerusenie, len spusta ADC), nasledne ADC triggeruje DMA prenos (tiez bez prerusenia). jedine prerusenie v tomto pripade je DMA transfer complete. potom zvys frekvenciu timeru.
0
Kreativita a motivacia je to, co prinasa originalne napady a myslienky, disciplina je to, co ich dokaze zrealizovat.

Dumitru
Stály člen
Stály člen
Príspevky: 377
Dátum registrácie: 06 Nov 2011, 22:19
Vek: 32

Re: Otazky ohladom STM32

Príspevok od používateľa Dumitru » 20 Sep 2023, 22:19

Dumitru, len z velmi rychleho pozretia:

ADC mas v continuous mode, (velmi nepouzivam HAL) ale pls over ci to neznamena ze akonahle skonci konverziu tak robi hned dalsiu, ak sa toto potvrdi tak to trigeruje dma (po tej 14 cyklovej konverzii), to hned prenese data a skoci do prerusenia. adc konverzia 14cyklov, prerusenie tiez (bez fpu) a tak je mcu nonstop v preruseni.

kazdopadne nastav timer na zaciatok cca 1khz ktoreho event (capture/compare) trigeruje ADC v single mode, (timer negeneruje prerusenie, len spusta ADC), nasledne ADC triggeruje DMA prenos (tiez bez prerusenia). jedine prerusenie v tomto pripade je DMA transfer complete. potom zvys frekvenciu timeru.
Ďakujem za reakciu spravil som tak ako ste hovorili a to tak že výstup s timeru som si vyviedol von a tak tiež spínam výstup keď ADC vyvolá prerušenie a malo by to platiť aj pre DMA, v prerušení znova spustím meranie s použitím DMA.

Kód: Vybrať všetko

void HAL_ADC_ConvCpltCallback (ADC_HandleTypeDef* hadc1)
{
	HAL_GPIO_TogglePin(LED4_GPIO_Port, LED4_Pin);
   HAL_ADC_Start_DMA(hadc1, (uint32_t *)&ADC_buff, ADC_BUFF_SIZE);
}
prikladám foto merania červený je signál z timeru a žltý by mal byť signál vtedy keď adc dokonči meranie a nahrá dáta do DMA.
TIM_40Khz.JPG
TIM_60Khz.JPG
TIM_80Khz.JPG
TIM_100Khz.JPG
TIM_150Khz.JPG
TIM_200Khz.JPG
TIM_250Khz.JPG
TIM_1Mhz.JPG
viac ako 15us sa mi nepodarilo dosiahnuť a už pri 1Mhz procesor sa nevie dostať do mainu a inkrementovať tam premennú.

Každopádne neviem pre 3kanaly dosiahnuť ani 100KSPS :confused:

Kód: Vybrať všetko

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @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"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

#define ADC_BUFF_SIZE 3

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc1;
DMA_HandleTypeDef hdma_adc1;

TIM_HandleTypeDef htim2;

UART_HandleTypeDef huart1;

/* USER CODE BEGIN PV */

volatile uint16_t ADC_buff[ADC_BUFF_SIZE] = {0};
volatile uint16_t Counter = 0;

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_ADC1_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_TIM2_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_ADC1_Init();
  MX_USART1_UART_Init();
  MX_TIM2_Init();
  /* USER CODE BEGIN 2 */
 HAL_TIM_Base_Start(&htim2);
  HAL_TIM_OC_Start_IT(&htim2, TIM_CHANNEL_1);
  HAL_ADC_Start_DMA(&hadc1, (uint32_t *)&ADC_buff, ADC_BUFF_SIZE);

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)

  {

	  //HAL_GPIO_TogglePin(LED4_GPIO_Port, LED4_Pin);
	  Counter++;
	  //HAL_Delay(500);
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Configure the main internal regulator output voltage
  */
  HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;
  RCC_OscInitStruct.PLL.PLLN = 8;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
  RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief ADC1 Initialization Function
  * @param None
  * @retval None
  */
static void MX_ADC1_Init(void)
{

  /* USER CODE BEGIN ADC1_Init 0 */

  /* USER CODE END ADC1_Init 0 */

  ADC_ChannelConfTypeDef sConfig = {0};

  /* USER CODE BEGIN ADC1_Init 1 */

  /* USER CODE END ADC1_Init 1 */

  /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
  */
  hadc1.Instance = ADC1;
  hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
  hadc1.Init.Resolution = ADC_RESOLUTION_12B;
  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  hadc1.Init.LowPowerAutoWait = DISABLE;
  hadc1.Init.LowPowerAutoPowerOff = DISABLE;
  hadc1.Init.ContinuousConvMode = DISABLE;
  hadc1.Init.NbrOfConversion = 3;
  hadc1.Init.DiscontinuousConvMode = DISABLE;
  hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T2_TRGO;
  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING;
  hadc1.Init.DMAContinuousRequests = DISABLE;
  hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_1CYCLE_5;
  hadc1.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_1CYCLE_5;
  hadc1.Init.OversamplingMode = DISABLE;
  hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
  if (HAL_ADC_Init(&hadc1) != HAL_OK)
  {
    Error_Handler();
  }

  /** Configure Regular Channel
  */
  sConfig.Channel = ADC_CHANNEL_8;
  sConfig.Rank = ADC_REGULAR_RANK_1;
  sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }

  /** Configure Regular Channel
  */
  sConfig.Channel = ADC_CHANNEL_9;
  sConfig.Rank = ADC_REGULAR_RANK_2;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }

  /** Configure Regular Channel
  */
  sConfig.Channel = ADC_CHANNEL_10;
  sConfig.Rank = ADC_REGULAR_RANK_3;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN ADC1_Init 2 */

  /* USER CODE END ADC1_Init 2 */

}

/**
  * @brief TIM2 Initialization Function
  * @param None
  * @retval None
  */
static void MX_TIM2_Init(void)
{

  /* USER CODE BEGIN TIM2_Init 0 */

  /* USER CODE END TIM2_Init 0 */

  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  TIM_MasterConfigTypeDef sMasterConfig = {0};
  TIM_OC_InitTypeDef sConfigOC = {0};

  /* USER CODE BEGIN TIM2_Init 1 */

  /* USER CODE END TIM2_Init 1 */
  htim2.Instance = TIM2;
  htim2.Init.Prescaler = 0;
  htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim2.Init.Period = 32-1;
  htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
  {
    Error_Handler();
  }
  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_TIM_OC_Init(&htim2) != HAL_OK)
  {
    Error_Handler();
  }
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
  {
    Error_Handler();
  }
  sConfigOC.OCMode = TIM_OCMODE_TOGGLE;
  sConfigOC.Pulse = 0;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  if (HAL_TIM_OC_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN TIM2_Init 2 */

  /* USER CODE END TIM2_Init 2 */
  HAL_TIM_MspPostInit(&htim2);

}

/**
  * @brief USART1 Initialization Function
  * @param None
  * @retval None
  */
static void MX_USART1_UART_Init(void)
{

  /* USER CODE BEGIN USART1_Init 0 */

  /* USER CODE END USART1_Init 0 */

  /* USER CODE BEGIN USART1_Init 1 */

  /* USER CODE END USART1_Init 1 */
  huart1.Instance = USART1;
  huart1.Init.BaudRate = 115200;
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
  huart1.Init.StopBits = UART_STOPBITS_1;
  huart1.Init.Parity = UART_PARITY_NONE;
  huart1.Init.Mode = UART_MODE_TX_RX;
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
  huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  if (HAL_UART_Init(&huart1) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN USART1_Init 2 */

  /* USER CODE END USART1_Init 2 */

}

/**
  * Enable DMA controller clock
  */
static void MX_DMA_Init(void)
{

  /* DMA controller clock enable */
  __HAL_RCC_DMA1_CLK_ENABLE();

  /* DMA interrupt init */
  /* DMA1_Channel1_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);

}

/**
  * @brief GPIO Initialization Function
  * @param None
  * @retval None
  */
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(LED4_GPIO_Port, LED4_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin : LED4_Pin */
  GPIO_InitStruct.Pin = LED4_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  HAL_GPIO_Init(LED4_GPIO_Port, &GPIO_InitStruct);

/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}

/* USER CODE BEGIN 4 */

void HAL_ADC_ConvCpltCallback (ADC_HandleTypeDef* hadc1)
{
   //HAL_GPIO_TogglePin(LED4_GPIO_Port, LED4_Pin);
	HAL_GPIO_TogglePin(LED4_GPIO_Port, LED4_Pin);
   HAL_ADC_Start_DMA(hadc1, (uint32_t *)&ADC_buff, ADC_BUFF_SIZE);
}

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
0

Používateľov profilový obrázok
Tribec Zacks
Pokročilý člen
Pokročilý člen
Príspevky: 709
Dátum registrácie: 26 Jún 2010, 00:00
Bydlisko: Levice / Cork IRL
Vek: 41
Kontaktovať používateľa:

Re: Otazky ohladom STM32

Príspevok od používateľa Tribec Zacks » 20 Sep 2023, 22:48

fuuu neni dobre, postol si ze tam mas povoleny callback z prerusenia adc kde znovu spustas dma, toho sa musis zbavit, ani timer, ani adc nesmu generovat prerusenia, len sa kaskadovo v hardwari spustat, timer->adc->dma, cez HAL ti velmi neporadim, ale robil som podobne samplovanie joysticku x/y a ide to tak nakonfigurovat na hardwari velmi pekne. btw pokial to nepotrebujes na nejaky casovo kriticky signal processing a nieco preratavat po kazdom sampli, tak ani nemusis generovat ziadne prerusenia, ani dma, len citat z pamate hotove data. tak isto pozri ci to vies dma streamovat do TCM bloku pamati (zalezi od micra a dma) tam ma cpu priamy pristup a nesharuje pristup na ahb s dma.
0
Kreativita a motivacia je to, co prinasa originalne napady a myslienky, disciplina je to, co ich dokaze zrealizovat.

Napísať odpoveď
  • Podobné témy
    Odpovedí
    Zobrazení
    Posledný príspevok