Skip to content

Commit 42812dd

Browse files
author
eurkaaaa
committed
fly+uwb
1 parent 6fa4610 commit 42812dd

14 files changed

Lines changed: 2877 additions & 32 deletions

File tree

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"files.associations": {
3+
"gpio.h": "c",
4+
"usart.h": "c",
5+
"stm32l4xx_ll_gpio.h": "c",
6+
"uart_receive.h": "c",
7+
"uart_hal.h": "c"
8+
}
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* uart_hal.h
3+
*
4+
* Created on: May 19, 2024
5+
* Author: mfxjx
6+
*/
7+
8+
#ifndef ATHENA_DECK_HAL_INC_UART_HAL_H_
9+
#define ATHENA_DECK_HAL_INC_UART_HAL_H_
10+
#include <stdint.h>
11+
12+
13+
void UART_DMA_Transmit(uint8_t *data, uint32_t length);
14+
15+
#endif /* ATHENA_DECK_HAL_INC_UART_HAL_H_ */
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* uart_hal.c
3+
*
4+
* Created on: May 19, 2024
5+
* Author: mfxjx
6+
*/
7+
8+
#include "uart_hal.h"
9+
#include "stm32l4xx.h"
10+
#include "stm32l4xx_ll_usart.h"
11+
#include "stm32l4xx_ll_dma.h"
12+
#include <stdio.h>
13+
14+
void UART_DMA_Transmit(uint8_t *data, uint32_t length) {
15+
16+
LL_DMA_ConfigAddresses(DMA1, LL_DMA_CHANNEL_2,
17+
(uint32_t)data, // data为需要发送的数据数组的地址
18+
LL_USART_DMA_GetRegAddr(USART3, LL_USART_DMA_REG_DATA_TRANSMIT),
19+
LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
20+
21+
LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_2, length);
22+
23+
LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_2);
24+
25+
LL_USART_EnableDMAReq_TX(USART3);
26+
27+
osDelay(5);
28+
29+
LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_2);
30+
31+
}
32+
33+
void UART_DMA_Receive(uint8_t *data, uint32_t length){
34+
35+
LL_DMA_ConfigAddresses(DMA1, LL_DMA_CHANNEL_3,
36+
LL_USART_DMA_GetRegAddr(USART3, LL_USART_DMA_REG_DATA_RECEIVE),
37+
(uint32_t)data,
38+
LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
39+
40+
LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_3, length);
41+
42+
LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_3);
43+
44+
LL_USART_EnableDMAReq_TX(USART3);
45+
46+
osDelay(10);
47+
48+
LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_3);
49+
50+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* uart_receive.h
3+
*
4+
* Created on: Jun 15, 2024
5+
* Author: mfxjx
6+
*/
7+
8+
#ifndef SYSDRIVER_INC_UART_RECEIVE_H_
9+
#define SYSDRIVER_INC_UART_RECEIVE_H_
10+
11+
#include "FreeRTOS.h"
12+
#include "task.h"
13+
#include "queue.h"
14+
#include "semphr.h"
15+
16+
extern QueueHandle_t UartRxQueue;
17+
extern SemaphoreHandle_t UartRxReady;
18+
19+
void CreateUartRxQueue(void);
20+
void UartRxCallback(void);
21+
22+
23+
#endif /* SYSDRIVER_INC_UART_RECEIVE_H_ */
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* uart_receive.c
3+
*
4+
* Created on: Jun 15, 2024
5+
* Author: mfxjx
6+
*/
7+
8+
#include <stdio.h>
9+
#include <stdint.h>
10+
#include <string.h>
11+
#include <stdbool.h>
12+
#include "uart_hal.h"
13+
#include "uart_receive.h"
14+
15+
16+
#define QUEUE_LENGTH 1024
17+
#define ITEM_SIZE sizeof(uint8_t)
18+
19+
QueueHandle_t UartRxQueue = NULL;
20+
21+
void CreateUartRxQueue(void) {
22+
UartRxQueue = xQueueCreate(QUEUE_LENGTH, ITEM_SIZE);
23+
if (UartRxQueue == NULL) {
24+
while(1);
25+
}
26+
}
27+
28+
void UartRxCallback(void){
29+
xSemaphoreGiveFromISR(UartRxReady, NULL);
30+
}
31+
32+

Core/Inc/main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern "C" {
3939
#include "stm32l4xx_ll_utils.h"
4040
#include "stm32l4xx_ll_pwr.h"
4141
#include "stm32l4xx_ll_spi.h"
42+
#include "stm32l4xx_ll_usart.h"
4243
#include "stm32l4xx_ll_gpio.h"
4344

4445
#if defined(USE_FULL_ASSERT)

Core/Inc/stm32l4xx_it.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ void I2C1_EV_IRQHandler(void);
6464
void I2C1_ER_IRQHandler(void);
6565
void SPI2_IRQHandler(void);
6666
void SPI3_IRQHandler(void);
67+
void USART3_IRQHandler(void);
6768
void DMA2_Channel1_IRQHandler(void);
6869
void DMA2_Channel2_IRQHandler(void);
6970
void DMA2_Channel3_IRQHandler(void);

Core/Inc/usart.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ extern "C" {
3232

3333
/* USER CODE END Includes */
3434

35-
extern UART_HandleTypeDef huart3;
36-
3735
/* USER CODE BEGIN Private defines */
3836

3937
/* USER CODE END Private defines */

Core/Src/freertos.c

Lines changed: 70 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
/* USER CODE BEGIN Includes */
2929
#include "i2c_drv.h"
3030
#include "spi_drv.h"
31+
#include "uart_hal.h"
3132
#include "tca6408a.h"
3233
#include "vl53l5cx_api.h"
3334
#include "test_tof.h"
3435
#include "calibration.h"
3536
#include "w25q64_ll.h"
37+
#include "uart_receive.h"
3638
#include "libdw3000.h"
3739
#include "dw3000.h"
3840
#include "dwTypes.h"
@@ -53,7 +55,12 @@ SemaphoreHandle_t spiDeckRxComplete = NULL;
5355
SemaphoreHandle_t spiDeckMutex = NULL;
5456
SemaphoreHandle_t uwbIrqSemaphore = NULL;
5557
uint8_t uwbdata_tx[260];
56-
58+
static uint8_t Pos[26];
59+
static uint8_t Pos_new[17];
60+
static float para[4];
61+
static float padX = 0.0;
62+
static float padY = 0.0;
63+
static float padZ = 0.0;
5764
//拔尖基地展示
5865
float datas_f[6];
5966

@@ -121,7 +128,7 @@ static void uwbTask(void *argument);
121128
/* USER CODE END FunctionPrototypes */
122129

123130
void StartDefaultTask(void *argument);
124-
131+
void compute();
125132
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
126133

127134
/**
@@ -135,7 +142,7 @@ void MX_FREERTOS_Init(void) {
135142
rxComplete = xSemaphoreCreateBinary();
136143
spiMutex = xSemaphoreCreateMutex();
137144
UartRxReady = xSemaphoreCreateBinary();
138-
145+
CreateUartRxQueue();
139146
if (txComplete == NULL || rxComplete == NULL || spiMutex == NULL)
140147
{
141148
while (1);
@@ -182,42 +189,76 @@ void MX_FREERTOS_Init(void) {
182189
* @param argument: Not used
183190
* @retval None
184191
*/
192+
void para_get()
193+
{
194+
padX = para[0];
195+
padY = para[1];
196+
padZ = para[2];
197+
}
198+
199+
void para_reget()
200+
{
201+
para[0] = padX;
202+
para[1] = padY;
203+
para[2] = padZ;
204+
}
185205

206+
void compute()
207+
{
208+
switch(Pos[24])
209+
{
210+
case 0:
211+
//add more control 1up 0down
212+
if(Pos[25])
213+
{
214+
padZ = 0.3f;
215+
Pos_new[16] = 1;
216+
}
217+
else
218+
{
219+
Pos_new[16] = 0;
220+
}
221+
break;
222+
case 1:
223+
if(Pos[25])
224+
{
225+
Pos_new[16] = 2;
226+
}
227+
else
228+
{
229+
padZ = 0.3f;
230+
Pos_new[16] = 3;
231+
}
232+
break;
233+
}
234+
}
186235
/* USER CODE END Header_StartDefaultTask */
187236
void StartDefaultTask(void *argument)
188237
{
189238
/* USER CODE BEGIN StartDefaultTask */
190239
/* Infinite loop */
191-
// static uint8_t w25qID;
192-
// BSP_W25Qx_Read_ID(&w25qID);
193-
194-
240+
uint8_t index = 0;
195241
while(1)
196242
{
243+
if (xSemaphoreTake(UartRxReady, 0) == pdPASS)
244+
{
245+
while (index < 26 && xQueueReceive(UartRxQueue, &Pos[index], 0) == pdPASS)
246+
{
247+
index++;
248+
}
249+
if(index == 26)
250+
{
251+
memcpy(para, (float *)Pos, 16);
252+
para_get();
253+
compute();
254+
para_reget();
255+
memcpy(Pos_new, (uint8_t *)para, 16);
256+
UART_DMA_Transmit(Pos_new, 17);
257+
index=0;
258+
}
259+
}
197260
vTaskDelay(1);
198261
}
199-
// BSP_W25Qx_Init();
200-
// uint8_t ID[2]={0};
201-
// BSP_W25Qx_Read_ID(ID);
202-
// //BSP_W25Qx_Erase_Chip();
203-
// BSP_W25Qx_Erase_Block(0x123456);
204-
// uint8_t tx_data[128] = {0xef};
205-
// uint8_t rx_data[128] = {0x00};
206-
// BSP_W25Qx_Write(tx_data, 0x123456, 128);
207-
// BSP_W25Qx_Read(rx_data, 0x123456, 4);
208-
// BSP_W25Qx_Erase_Block(0x123456);
209-
// BSP_W25Qx_Read(rx_data, 0x123456, 4);
210-
//
211-
// uint8_t ID[4];
212-
// I2C_expander_initialize();
213-
// initialize_sensors_I2C(&vl53l5dev_f,1);
214-
// vl53l5cx_start_ranging(&vl53l5dev_f);
215-
// while(1){
216-
// LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_9);
217-
// LL_mDelay(100);
218-
// get_sensor_data(&vl53l5dev_f, &vl53l5_res_f);
219-
// }
220-
// }
221262
/* USER CODE END StartDefaultTask */
222263
}
223264

Core/Src/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "dma.h"
2323
#include "i2c.h"
2424
#include "spi.h"
25+
#include "usart.h"
2526
#include "gpio.h"
2627

2728
/* Private includes ----------------------------------------------------------*/
@@ -106,6 +107,7 @@ int main(void)
106107
MX_SPI3_Init();
107108
MX_SPI2_Init();
108109
MX_SPI1_Init();
110+
MX_USART3_UART_Init();
109111

110112
/* USER CODE BEGIN 2 */
111113

0 commit comments

Comments
 (0)