You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
4.0 KiB
127 lines
4.0 KiB
#include "main.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
DMA_HandleTypeDef hSAIDMA;
|
|
|
|
/**
|
|
* Initializes the Global MSP.
|
|
*/
|
|
void HAL_MspInit(void) {
|
|
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
|
}
|
|
|
|
/**
|
|
* @brief UART MSP Initialization
|
|
* This function configures the hardware resources used in this example
|
|
* @param huart: UART handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_UART_MspInit(UART_HandleTypeDef* huart) {
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
|
if(huart->Instance == USART3) {
|
|
/** Initializes the peripherals clock
|
|
*/
|
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART3;
|
|
PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_D2PCLK1;
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
|
|
Error_Handler();
|
|
}
|
|
|
|
/* Peripheral clock enable */
|
|
__HAL_RCC_USART3_CLK_ENABLE();
|
|
|
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
/**USART3 GPIO Configuration
|
|
PD9 ------> USART3_RX
|
|
PD8 ------> USART3_TX
|
|
*/
|
|
GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_8;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
|
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
}
|
|
}
|
|
|
|
static uint32_t SAI1_client = 0;
|
|
|
|
void HAL_SAI_MspInit(SAI_HandleTypeDef* hSAI) {
|
|
GPIO_InitTypeDef GPIO_InitStruct;
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
|
/* SAI1 */
|
|
if(hSAI->Instance == SAI1_Block_B) {
|
|
/* Peripheral clock enable */
|
|
|
|
/** Initializes the peripherals clock
|
|
*/
|
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SAI1;
|
|
PeriphClkInitStruct.PLL2.PLL2M = 2;
|
|
PeriphClkInitStruct.PLL2.PLL2N = 19;
|
|
PeriphClkInitStruct.PLL2.PLL2P = 10;
|
|
PeriphClkInitStruct.PLL2.PLL2Q = 2;
|
|
PeriphClkInitStruct.PLL2.PLL2R = 2;
|
|
PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_3;
|
|
PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOWIDE;
|
|
PeriphClkInitStruct.PLL2.PLL2FRACN = 5414;
|
|
PeriphClkInitStruct.Sai1ClockSelection = RCC_SAI1CLKSOURCE_PLL2;
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
|
|
Error_Handler();
|
|
}
|
|
|
|
if (SAI1_client == 0) {
|
|
__HAL_RCC_SAI1_CLK_ENABLE();
|
|
}
|
|
SAI1_client++;
|
|
|
|
/**SAI1_B_Block_B GPIO Configuration
|
|
PF6 ------> SAI1_SD_B
|
|
PF8 ------> SAI1_SCK_B
|
|
PF7 ------> SAI1_MCLK_B
|
|
PF9 ------> SAI1_FS_B
|
|
*/
|
|
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_8|GPIO_PIN_7|GPIO_PIN_9;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
GPIO_InitStruct.Alternate = GPIO_AF6_SAI1;
|
|
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
|
|
|
|
/* Configure DMA used for SAI1 */
|
|
__HAL_RCC_DMA2_CLK_ENABLE();
|
|
|
|
hSAIDMA.Init.Request = DMA_REQUEST_SAI1_B;
|
|
hSAIDMA.Init.Direction = DMA_MEMORY_TO_PERIPH;
|
|
hSAIDMA.Init.PeriphInc = DMA_PINC_DISABLE;
|
|
hSAIDMA.Init.MemInc = DMA_MINC_ENABLE;
|
|
hSAIDMA.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
|
|
hSAIDMA.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
|
|
hSAIDMA.Init.Mode = DMA_CIRCULAR;
|
|
hSAIDMA.Init.Priority = DMA_PRIORITY_HIGH;
|
|
hSAIDMA.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
|
|
hSAIDMA.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
|
|
hSAIDMA.Init.MemBurst = DMA_MBURST_SINGLE;
|
|
hSAIDMA.Init.PeriphBurst = DMA_PBURST_SINGLE;
|
|
|
|
/* Select the DMA instance to be used for the transfer : DMA2_Stream6 */
|
|
hSAIDMA.Instance = DMA2_Stream6;
|
|
|
|
/* Associate the DMA handle */
|
|
__HAL_LINKDMA(hSAI, hdmatx, hSAIDMA);
|
|
|
|
/* Deinitialize the Stream for new transfer */
|
|
HAL_DMA_DeInit(&hSAIDMA);
|
|
|
|
/* Configure the DMA Stream */
|
|
if (HAL_OK != HAL_DMA_Init(&hSAIDMA)) {
|
|
Error_Handler();
|
|
}
|
|
|
|
HAL_NVIC_SetPriority(DMA2_Stream6_IRQn, 0x01, 0);
|
|
HAL_NVIC_EnableIRQ(DMA2_Stream6_IRQn);
|
|
|
|
printf("DMA initialised\r\n");
|
|
}
|
|
}
|
|
|