Ignore:
Timestamp:
Jan 15, 2025, 4:04:20 PM (16 hours ago)
Author:
Zed
Message:

USART3 TX DMA is working.

Location:
ctrl/firmware/Main/CubeMX/Core/Src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ctrl/firmware/Main/CubeMX/Core/Src/app_threadx.c

    r61 r64  
    8282  /* USER CODE BEGIN App_ThreadX_Init */
    8383
    84   // Allocate the stack for main thread
     84  // Allocate the stack for key thread
    8585  ret = tx_byte_allocate(byte_pool, &keys_thread_pointer, KEYS_THREAD_STACK_SIZE_BYTES, TX_NO_WAIT);
    8686  if (ret != TX_SUCCESS) { printf("Cannot allocate bytes of memory!\n"); return ret; }
    8787
    8888  char* scan_keys_thread_name = "Scan Keys Thread";
    89   ret = tx_thread_create(&scan_keys_thread_ptr, scan_keys_thread_name, scanKeysThread, 0x0001,  keys_thread_pointer, KEYS_THREAD_STACK_SIZE_BYTES, TX_MAX_PRIORITIES-1, TX_MAX_PRIORITIES-1, TX_NO_TIME_SLICE, TX_AUTO_START);
     89  ret = tx_thread_create(&scan_keys_thread_ptr, scan_keys_thread_name, scanKeysThread, 0x0001, keys_thread_pointer, KEYS_THREAD_STACK_SIZE_BYTES, TX_MAX_PRIORITIES-1, TX_MAX_PRIORITIES-1, TX_NO_TIME_SLICE, TX_AUTO_START);
    9090  if (ret != TX_SUCCESS) { printf("Cannot create %s!\n", scan_keys_thread_name); return ret; }
    9191
    9292
    93 
     93  // Allocate the stack for gsm thread
    9494  ret = tx_byte_allocate(byte_pool, &gsm_thread_pointer, GSM_THREAD_STACK_SIZE_BYTES, TX_NO_WAIT);
    9595  if (ret != TX_SUCCESS) { printf("Cannot allocate bytes of memory!\n"); return ret; }
  • ctrl/firmware/Main/CubeMX/Core/Src/dma.c

    r47 r64  
    4747  HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 0, 0);
    4848  HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn);
     49  /* DMA1_Stream1_IRQn interrupt configuration */
     50  HAL_NVIC_SetPriority(DMA1_Stream1_IRQn, 0, 0);
     51  HAL_NVIC_EnableIRQ(DMA1_Stream1_IRQn);
     52  /* DMA1_Stream2_IRQn interrupt configuration */
     53  HAL_NVIC_SetPriority(DMA1_Stream2_IRQn, 0, 0);
     54  HAL_NVIC_EnableIRQ(DMA1_Stream2_IRQn);
    4955
    5056}
  • ctrl/firmware/Main/CubeMX/Core/Src/stm32h7xx_it.c

    r63 r64  
    6262extern DMA_HandleTypeDef hdma_spi4_tx;
    6363extern SPI_HandleTypeDef hspi4;
     64extern DMA_HandleTypeDef hdma_usart3_rx;
     65extern DMA_HandleTypeDef hdma_usart3_tx;
    6466extern UART_HandleTypeDef huart3;
    6567extern TIM_HandleTypeDef htim7;
     
    182184
    183185/**
     186  * @brief This function handles DMA1 stream1 global interrupt.
     187  */
     188void DMA1_Stream1_IRQHandler(void)
     189{
     190  /* USER CODE BEGIN DMA1_Stream1_IRQn 0 */
     191
     192  /* USER CODE END DMA1_Stream1_IRQn 0 */
     193  HAL_DMA_IRQHandler(&hdma_usart3_rx);
     194  /* USER CODE BEGIN DMA1_Stream1_IRQn 1 */
     195
     196  /* USER CODE END DMA1_Stream1_IRQn 1 */
     197}
     198
     199/**
     200  * @brief This function handles DMA1 stream2 global interrupt.
     201  */
     202void DMA1_Stream2_IRQHandler(void)
     203{
     204  /* USER CODE BEGIN DMA1_Stream2_IRQn 0 */
     205
     206  /* USER CODE END DMA1_Stream2_IRQn 0 */
     207  HAL_DMA_IRQHandler(&hdma_usart3_tx);
     208  /* USER CODE BEGIN DMA1_Stream2_IRQn 1 */
     209
     210  /* USER CODE END DMA1_Stream2_IRQn 1 */
     211}
     212
     213/**
    184214  * @brief This function handles USART3 global interrupt.
    185215  */
     
    239269/* USER CODE BEGIN 1 */
    240270
    241 void HAL_UART_RxCpltCallback(UART_HandleTypeDef * huart)
    242 {
    243         if (huart->Instance == USART3) gsmUnitSentData();
    244 }
    245 
    246271//------------------------------------------------------------------------------
    247272
     273void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
     274{
     275        if (huart->Instance == USART3) gsmUnitSentData(Size);
     276}
     277
     278//------------------------------------------------------------------------------
     279
     280/*void HAL_UART_RxCpltCallback(UART_HandleTypeDef * huart)
     281{
     282        //if (huart->Instance == USART3) gsmUnitSentData();
     283}*/
     284
     285//------------------------------------------------------------------------------
     286
    248287/* USER CODE END 1 */
  • ctrl/firmware/Main/CubeMX/Core/Src/usart.c

    r63 r64  
    2626
    2727UART_HandleTypeDef huart3;
     28DMA_HandleTypeDef hdma_usart3_rx;
     29DMA_HandleTypeDef hdma_usart3_tx;
    2830
    2931/* USART3 init function */
     
    119121    HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
    120122
     123    /* USART3 DMA Init */
     124    /* USART3_RX Init */
     125    hdma_usart3_rx.Instance = DMA1_Stream1;
     126    hdma_usart3_rx.Init.Request = DMA_REQUEST_USART3_RX;
     127    hdma_usart3_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
     128    hdma_usart3_rx.Init.PeriphInc = DMA_PINC_DISABLE;
     129    hdma_usart3_rx.Init.MemInc = DMA_MINC_ENABLE;
     130    hdma_usart3_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
     131    hdma_usart3_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
     132    hdma_usart3_rx.Init.Mode = DMA_CIRCULAR;
     133    hdma_usart3_rx.Init.Priority = DMA_PRIORITY_LOW;
     134    hdma_usart3_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
     135    if (HAL_DMA_Init(&hdma_usart3_rx) != HAL_OK)
     136    {
     137      Error_Handler();
     138    }
     139
     140    __HAL_LINKDMA(uartHandle,hdmarx,hdma_usart3_rx);
     141
     142    /* USART3_TX Init */
     143    hdma_usart3_tx.Instance = DMA1_Stream2;
     144    hdma_usart3_tx.Init.Request = DMA_REQUEST_USART3_TX;
     145    hdma_usart3_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
     146    hdma_usart3_tx.Init.PeriphInc = DMA_PINC_DISABLE;
     147    hdma_usart3_tx.Init.MemInc = DMA_MINC_ENABLE;
     148    hdma_usart3_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
     149    hdma_usart3_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
     150    hdma_usart3_tx.Init.Mode = DMA_NORMAL;
     151    hdma_usart3_tx.Init.Priority = DMA_PRIORITY_HIGH;
     152    hdma_usart3_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
     153    if (HAL_DMA_Init(&hdma_usart3_tx) != HAL_OK)
     154    {
     155      Error_Handler();
     156    }
     157
     158    __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart3_tx);
     159
    121160    /* USART3 interrupt Init */
    122161    HAL_NVIC_SetPriority(USART3_IRQn, 0, 0);
     
    147186    HAL_GPIO_DeInit(GPIOD, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_11|GPIO_PIN_12);
    148187
     188    /* USART3 DMA DeInit */
     189    HAL_DMA_DeInit(uartHandle->hdmarx);
     190    HAL_DMA_DeInit(uartHandle->hdmatx);
     191
    149192    /* USART3 interrupt Deinit */
    150193    HAL_NVIC_DisableIRQ(USART3_IRQn);
Note: See TracChangeset for help on using the changeset viewer.