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

DMA Rx funktioniert, aber BETA und nur feste Baudrate

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.