Выпилен DMA и FreeRTOS

This commit is contained in:
2022-01-30 22:47:38 +03:00
parent c92b94dc52
commit 5fc1ea7550
42 changed files with 89 additions and 30630 deletions

View File

@@ -18,9 +18,8 @@
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "cmsis_os.h"
#include "gyro_mes.h"
#include "stdio.h"
#include "gyro_mes.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
@@ -50,13 +49,10 @@
/* Private variables ---------------------------------------------------------*/
SPI_HandleTypeDef hspi1;
DMA_HandleTypeDef hdma_spi1_rx;
DMA_HandleTypeDef hdma_spi1_tx;
UART_HandleTypeDef huart1;
DMA_HandleTypeDef hdma_usart1_tx;
osThreadId calcsUartTaskHandle;
/* USER CODE BEGIN PV */
/* USER CODE END PV */
@@ -67,8 +63,6 @@ static void MX_GPIO_Init(void);
static void MX_SPI1_Init(void);
static void MX_DMA_Init(void);
static void MX_USART1_UART_Init(void);
void StartCalcsUartTask(void const * argument);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
@@ -78,8 +72,6 @@ void StartCalcsUartTask(void const * argument);
uint8_t data_out[6] = {0};
uint8_t flag_receive = 0;
uint8_t flag_cs = 0;
xSemaphoreHandle mutex;
xSemaphoreHandle semaphoreBin;
/* USER CODE END 0 */
/**
@@ -118,36 +110,6 @@ int main(void)
HAL_Delay(100);
/* USER CODE END 2 */
/* USER CODE BEGIN RTOS_MUTEX */
/* add mutexes, ... */
/* USER CODE END RTOS_MUTEX */
/* USER CODE BEGIN RTOS_SEMAPHORES */
/* add semaphores, ... */
/* USER CODE END RTOS_SEMAPHORES */
/* USER CODE BEGIN RTOS_TIMERS */
/* start timers, add new ones, ... */
/* USER CODE END RTOS_TIMERS */
/* USER CODE BEGIN RTOS_QUEUES */
/* add queues, ... */
/* USER CODE END RTOS_QUEUES */
/* Create the thread(s) */
/* definition and creation of defaultTask */
osThreadDef(calcsUartTask, StartCalcsUartTask, osPriorityNormal, 0, 128);
calcsUartTaskHandle = osThreadCreate(osThread(calcsUartTask), NULL);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
mutex = xSemaphoreCreateMutex();
vSemaphoreCreateBinary(semaphoreBin);
/* Start scheduler */
//osKernelStart();
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
int8_t res = comand_mes(data_in, sizeof(data_in) / sizeof(data_in[0]));
@@ -156,7 +118,7 @@ int main(void)
{
flag_cs = 1;
CS1_ON();
int res = HAL_SPI_TransmitReceive_DMA(&hspi1, (uint8_t*) (data_in), (uint8_t *) (data_out), sizeof(data_in) / sizeof(data_in[0]));
int res = HAL_SPI_TransmitReceive_IT(&hspi1, (uint8_t*) (data_in), (uint8_t *) (data_out), sizeof(data_in) / sizeof(data_in[0]));
while(!flag_receive && res == 0) {
HAL_Delay(1);
}
@@ -164,7 +126,7 @@ int main(void)
flag_receive = 0;
flag_cs = 2;
CS2_ON();
res = HAL_SPI_TransmitReceive_DMA(&hspi1, (uint8_t*) (data_in), (uint8_t *) (data_out), sizeof(data_in) / sizeof(data_in[0]));
res = HAL_SPI_TransmitReceive_IT(&hspi1, (uint8_t*) (data_in), (uint8_t *) (data_out), sizeof(data_in) / sizeof(data_in[0]));
while(!flag_receive && res == 0) {
HAL_Delay(1);
}
@@ -172,7 +134,7 @@ int main(void)
flag_receive = 0;
flag_cs = 3;
CS3_ON();
res = HAL_SPI_TransmitReceive_DMA(&hspi1, (uint8_t*) (data_in), (uint8_t *) (data_out), sizeof(data_in) / sizeof(data_in[0]));
res = HAL_SPI_TransmitReceive_IT(&hspi1, (uint8_t*) (data_in), (uint8_t *) (data_out), sizeof(data_in) / sizeof(data_in[0]));
while(!flag_receive && res == 0) {
HAL_Delay(1);
}
@@ -311,14 +273,8 @@ static void MX_DMA_Init(void)
__HAL_RCC_DMA1_CLK_ENABLE();
/* DMA interrupt init */
/* DMA1_Channel2_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Channel2_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel2_IRQn);
/* DMA1_Channel3_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Channel3_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel3_IRQn);
/* DMA1_Channel4_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Channel4_IRQn, 5, 0);
HAL_NVIC_SetPriority(DMA1_Channel4_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel4_IRQn);
}
@@ -344,7 +300,7 @@ static void MX_GPIO_Init(void)
/*Configure GPIO pins : CS1_Pin CS2_Pin CS3_Pin */
GPIO_InitStruct.Pin = CS1_Pin|CS2_Pin|CS3_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
@@ -361,50 +317,21 @@ static void MX_GPIO_Init(void)
/* USER CODE BEGIN 4 */
void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
{
struct sData data;
if(hspi == &hspi1)
{
//HAL_SPI_Receive_DMA(&hspi1, data_out, sizeof(data_out));
flag_receive = 1;
static portBASE_TYPE xHigherPriorityTaskWoken;
xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(semaphoreBin, &xHigherPriorityTaskWoken);
int8_t res = status_mes(data_out, sizeof(data_out) / sizeof(data_out), &data);
if(res == 0)
{
char str[40];
sprintf (str, "Gyro%u! Temp = %i; Rate = %i.", flag_cs, data.temp, data.rate);
HAL_UART_Transmit_DMA(&huart1, (uint8_t*)str, sizeof(str));
}
}
}
/* USER CODE END 4 */
/* USER CODE BEGIN Header_StartDefaultTask */
/**
* @brief Function implementing the defaultTask thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartDefaultTask */
void StartCalcsUartTask(void const * argument)
{
/* USER CODE BEGIN 5 */
/* Infinite loop */
struct sData data;
for(;;)
{
//xSemaphoreTake(semaphoreBin, portMAX_DELAY);
if(xSemaphoreTake(mutex, portMAX_DELAY) == pdTRUE) {
int8_t res = status_mes(data_out, sizeof(data_out) / sizeof(data_out), &data);
if(res == 0)
{
char str[40];
sprintf (str, "Gyro%u! Temp = %i; Rate = %i.", flag_cs, data.temp, data.rate);
HAL_UART_Transmit_DMA(&huart1, (uint8_t*)str, sizeof(str));
}
}
xSemaphoreGive(mutex);
osDelay(1);
}
/* USER CODE END 5 */
}
/**
* @brief This function is executed in case of error occurrence.
* @retval None