Changeset 22 for trunk/fw_g473rct/Core


Ignore:
Timestamp:
Aug 29, 2025, 6:15:42 PM (33 hours ago)
Author:
f.jahn
Message:

DMA Rx funktioniert, aber BETA und nur feste Baudrate

Location:
trunk/fw_g473rct/Core
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/fw_g473rct/Core/Inc/main.h

    r20 r22  
    7070#define ADC2_IN3_UBAT__Pin GPIO_PIN_6
    7171#define ADC2_IN3_UBAT__GPIO_Port GPIOA
    72 #define ADC2_IN4_UBAT__Pin GPIO_PIN_7
    73 #define ADC2_IN4_UBAT__GPIO_Port GPIOA
    7472#define ADC3_IN12_MOSFET_TEMP_Pin GPIO_PIN_0
    7573#define ADC3_IN12_MOSFET_TEMP_GPIO_Port GPIOB
  • trunk/fw_g473rct/Core/Inc/stm32g4xx_it.h

    r20 r22  
    6161void DMA1_Channel4_IRQHandler(void);
    6262void DMA1_Channel5_IRQHandler(void);
     63void DMA1_Channel6_IRQHandler(void);
     64void USART1_IRQHandler(void);
     65void USART2_IRQHandler(void);
    6366/* USER CODE BEGIN EFP */
    6467
  • trunk/fw_g473rct/Core/Src/adc.c

    r20 r22  
    5959  hadc1.Init.GainCompensation = 0;
    6060  hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
    61   hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;
     61  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
    6262  hadc1.Init.LowPowerAutoWait = DISABLE;
    6363  hadc1.Init.ContinuousConvMode = ENABLE;
     
    6868  hadc1.Init.DMAContinuousRequests = ENABLE;
    6969  hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
    70   hadc1.Init.OversamplingMode = DISABLE;
     70  hadc1.Init.OversamplingMode = ENABLE;
     71  hadc1.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_256;
     72  hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_4;
     73  hadc1.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;
     74  hadc1.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE;
    7175  if (HAL_ADC_Init(&hadc1) != HAL_OK)
    7276  {
     
    8892  sConfig.Channel = ADC_CHANNEL_1;
    8993  sConfig.Rank = ADC_REGULAR_RANK_1;
    90   sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
     94  sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5;
    9195  sConfig.SingleDiff = ADC_DIFFERENTIAL_ENDED;
    9296  sConfig.OffsetNumber = ADC_OFFSET_NONE;
     
    123127  hadc2.Init.GainCompensation = 0;
    124128  hadc2.Init.ScanConvMode = ADC_SCAN_DISABLE;
    125   hadc2.Init.EOCSelection = ADC_EOC_SEQ_CONV;
     129  hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
    126130  hadc2.Init.LowPowerAutoWait = DISABLE;
    127131  hadc2.Init.ContinuousConvMode = ENABLE;
     
    130134  hadc2.Init.DMAContinuousRequests = ENABLE;
    131135  hadc2.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
    132   hadc2.Init.OversamplingMode = DISABLE;
     136  hadc2.Init.OversamplingMode = ENABLE;
     137  hadc2.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_256;
     138  hadc2.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_4;
     139  hadc2.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;
     140  hadc2.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE;
    133141  if (HAL_ADC_Init(&hadc2) != HAL_OK)
    134142  {
     
    140148  sConfig.Channel = ADC_CHANNEL_3;
    141149  sConfig.Rank = ADC_REGULAR_RANK_1;
    142   sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
    143   sConfig.SingleDiff = ADC_DIFFERENTIAL_ENDED;
     150  sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5;
     151  sConfig.SingleDiff = ADC_SINGLE_ENDED;
    144152  sConfig.OffsetNumber = ADC_OFFSET_NONE;
    145153  sConfig.Offset = 0;
     
    396404    hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
    397405    hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
    398     hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
     406    hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
    399407    hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
    400408    hdma_adc1.Init.Mode = DMA_CIRCULAR;
     
    435443    /**ADC2 GPIO Configuration
    436444    PA6     ------> ADC2_IN3
    437     PA7     ------> ADC2_IN4
    438     */
    439     GPIO_InitStruct.Pin = ADC2_IN3_UBAT__Pin|ADC2_IN4_UBAT__Pin;
     445    */
     446    GPIO_InitStruct.Pin = ADC2_IN3_UBAT__Pin;
    440447    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
    441448    GPIO_InitStruct.Pull = GPIO_NOPULL;
    442     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
     449    HAL_GPIO_Init(ADC2_IN3_UBAT__GPIO_Port, &GPIO_InitStruct);
    443450
    444451    /* ADC2 DMA Init */
     
    449456    hdma_adc2.Init.PeriphInc = DMA_PINC_DISABLE;
    450457    hdma_adc2.Init.MemInc = DMA_MINC_ENABLE;
    451     hdma_adc2.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
     458    hdma_adc2.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
    452459    hdma_adc2.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
    453460    hdma_adc2.Init.Mode = DMA_CIRCULAR;
     
    665672    /**ADC2 GPIO Configuration
    666673    PA6     ------> ADC2_IN3
    667     PA7     ------> ADC2_IN4
    668     */
    669     HAL_GPIO_DeInit(GPIOA, ADC2_IN3_UBAT__Pin|ADC2_IN4_UBAT__Pin);
     674    */
     675    HAL_GPIO_DeInit(ADC2_IN3_UBAT__GPIO_Port, ADC2_IN3_UBAT__Pin);
    670676
    671677    /* ADC2 DMA DeInit */
  • trunk/fw_g473rct/Core/Src/dma.c

    r20 r22  
    6060  HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 0, 0);
    6161  HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn);
     62  /* DMA1_Channel6_IRQn interrupt configuration */
     63  HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 0, 0);
     64  HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn);
    6265
    6366}
  • trunk/fw_g473rct/Core/Src/stm32g4xx_hal_msp.c

    r20 r22  
    7373  /* System interrupt init*/
    7474
     75  /** Configure the internal voltage reference buffer high impedance mode
     76  */
     77  HAL_SYSCFG_VREFBUF_HighImpedanceConfig(SYSCFG_VREFBUF_HIGH_IMPEDANCE_ENABLE);
     78
     79  /** Disable the Internal Voltage Reference buffer
     80  */
     81  HAL_SYSCFG_DisableVREFBUF();
     82
    7583  /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral
    7684  */
  • trunk/fw_g473rct/Core/Src/stm32g4xx_it.c

    r20 r22  
    2323/* Private includes ----------------------------------------------------------*/
    2424/* USER CODE BEGIN Includes */
     25#include "modbus.h"
    2526/* USER CODE END Includes */
    2627
     
    6162extern DMA_HandleTypeDef hdma_adc4;
    6263extern DMA_HandleTypeDef hdma_adc5;
     64extern DMA_HandleTypeDef hdma_usart2_rx;
     65extern UART_HandleTypeDef huart1;
     66extern UART_HandleTypeDef huart2;
    6367/* USER CODE BEGIN EV */
    6468
     
    273277}
    274278
     279/**
     280  * @brief This function handles DMA1 channel6 global interrupt.
     281  */
     282void DMA1_Channel6_IRQHandler(void)
     283{
     284  /* USER CODE BEGIN DMA1_Channel6_IRQn 0 */
     285
     286  /* USER CODE END DMA1_Channel6_IRQn 0 */
     287  HAL_DMA_IRQHandler(&hdma_usart2_rx);
     288  /* USER CODE BEGIN DMA1_Channel6_IRQn 1 */
     289
     290  /* USER CODE END DMA1_Channel6_IRQn 1 */
     291}
     292
     293/**
     294  * @brief This function handles USART1 global interrupt / USART1 wake-up interrupt through EXTI line 25.
     295  */
     296void USART1_IRQHandler(void)
     297{
     298  /* USER CODE BEGIN USART1_IRQn 0 */
     299
     300  /* USER CODE END USART1_IRQn 0 */
     301  HAL_UART_IRQHandler(&huart1);
     302  /* USER CODE BEGIN USART1_IRQn 1 */
     303
     304  /* USER CODE END USART1_IRQn 1 */
     305}
     306
     307/**
     308  * @brief This function handles USART2 global interrupt / USART2 wake-up interrupt through EXTI line 26.
     309  */
     310void USART2_IRQHandler(void)
     311{
     312  /* USER CODE BEGIN USART2_IRQn 0 */
     313
     314  /* USER CODE END USART2_IRQn 0 */
     315  HAL_UART_IRQHandler(&huart2);
     316  /* USER CODE BEGIN USART2_IRQn 1 */
     317//MODBUS_UART_IRQHandler(&huart2);
     318  /* USER CODE END USART2_IRQn 1 */
     319}
     320
    275321/* USER CODE BEGIN 1 */
    276322
  • trunk/fw_g473rct/Core/Src/usart.c

    r20 r22  
    2727UART_HandleTypeDef huart1;
    2828UART_HandleTypeDef huart2;
     29DMA_HandleTypeDef hdma_usart2_rx;
    2930
    3031/* USART1 init function */
     
    8687  huart2.Instance = USART2;
    8788  huart2.Init.BaudRate = 115200;
    88   huart2.Init.WordLength = UART_WORDLENGTH_8B;
     89  huart2.Init.WordLength = UART_WORDLENGTH_9B;
    8990  huart2.Init.StopBits = UART_STOPBITS_1;
    90   huart2.Init.Parity = UART_PARITY_NONE;
     91  huart2.Init.Parity = UART_PARITY_EVEN;
    9192  huart2.Init.Mode = UART_MODE_TX_RX;
    9293  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
     
    9495  huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
    9596  huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
    96   huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
     97  huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_SWAP_INIT;
     98  huart2.AdvancedInit.Swap = UART_ADVFEATURE_SWAP_ENABLE;
    9799  if (HAL_UART_Init(&huart2) != HAL_OK)
    98100  {
     
    152154    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
    153155
     156    /* USART1 interrupt Init */
     157    HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
     158    HAL_NVIC_EnableIRQ(USART1_IRQn);
    154159  /* USER CODE BEGIN USART1_MspInit 1 */
    155160
     
    186191    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
    187192
     193    /* USART2 DMA Init */
     194    /* USART2_RX Init */
     195    hdma_usart2_rx.Instance = DMA1_Channel6;
     196    hdma_usart2_rx.Init.Request = DMA_REQUEST_USART2_RX;
     197    hdma_usart2_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
     198    hdma_usart2_rx.Init.PeriphInc = DMA_PINC_DISABLE;
     199    hdma_usart2_rx.Init.MemInc = DMA_MINC_ENABLE;
     200    hdma_usart2_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
     201    hdma_usart2_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
     202    hdma_usart2_rx.Init.Mode = DMA_NORMAL;
     203    hdma_usart2_rx.Init.Priority = DMA_PRIORITY_LOW;
     204    if (HAL_DMA_Init(&hdma_usart2_rx) != HAL_OK)
     205    {
     206      Error_Handler();
     207    }
     208
     209    __HAL_LINKDMA(uartHandle,hdmarx,hdma_usart2_rx);
     210
     211    /* USART2 interrupt Init */
     212    HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
     213    HAL_NVIC_EnableIRQ(USART2_IRQn);
    188214  /* USER CODE BEGIN USART2_MspInit 1 */
    189215
     
    209235    HAL_GPIO_DeInit(GPIOC, GPIO_PIN_4|GPIO_PIN_5);
    210236
     237    /* USART1 interrupt Deinit */
     238    HAL_NVIC_DisableIRQ(USART1_IRQn);
    211239  /* USER CODE BEGIN USART1_MspDeInit 1 */
    212240
     
    227255    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
    228256
     257    /* USART2 DMA DeInit */
     258    HAL_DMA_DeInit(uartHandle->hdmarx);
     259
     260    /* USART2 interrupt Deinit */
     261    HAL_NVIC_DisableIRQ(USART2_IRQn);
    229262  /* USER CODE BEGIN USART2_MspDeInit 1 */
    230263
Note: See TracChangeset for help on using the changeset viewer.