1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
 *******************************************************************************
 * @file     app.c
 * @create   2023-08-01    
 * @author   Panchip BLE GROUP
 * @note
 * Copyright (c) 2022 Shanghai Panchip Microelectronics Co.,Ltd.
 *
 *******************************************************************************
 */
#include "app.h"
#include "app_log.h"
#define UART_RECV_BUF_SIZE      128
#define UART_SEND_BUF_SIZE      128
#define UART_TEST_SIZE          8
 
uint8_t revDataBuf[UART_RECV_BUF_SIZE];
uint8_t sendDataBuf[UART_SEND_BUF_SIZE];
uint8_t rx_changdu;
extern uint8_t shengji_flag;
extern uint8_t only_one;
void app_uart_rx_dma_callback(UART_Cb_Flag_Opt flag, uint8_t *pOutPtr, uint16_t size)
{
//    printf("UART Rx with DMA Done, recv data size = %d.\n", size);
 
    // Copy data from UART Rx buffer to Tx buffer
//    memcpy(sendDataBuf, pOutPtr, size);
    memcpy(revDataBuf, pOutPtr, size);
    if(revDataBuf[0]==0x55&&revDataBuf[1]==0xAA&&revDataBuf[2]==0x75
    &&revDataBuf[3]==0x70&&revDataBuf[4]==0x64&&revDataBuf[5]==0x61
    &&revDataBuf[6]==0x74&&revDataBuf[7]==0x65)
    {
//        HAL_UART_SendData_DMA(&UART0_OBJ, revDataBuf, UART_TEST_SIZE);
        shengji_flag=1;
        only_one=1;
    }
    else
    {
        
    }
//    HAL_Status sts = HAL_UART_SendData_DMA(&UART0_OBJ, sendDataBuf, UART_TEST_SIZE);
//    if (sts != HAL_OK)
//    {
//        printf("Error: HAL Uart Send Data with DMA Fail, error code = %d!\n", sts);
//    }
        memset(revDataBuf, 0, 128);
        HAL_Status sts = HAL_UART_ReceiveData_DMA(&UART0_OBJ, revDataBuf, UART_TEST_SIZE);
        if (sts != HAL_OK)
        {
    //        printf("Error: HAL Uart Receive Data with DMA Fail, error code = %d!\n", sts);
        }
    
}
 
void app_uart_tx_dma_callback(UART_Cb_Flag_Opt flag, uint8_t *pOutPtr, uint16_t size)
{
//    printf("UART Tx with DMA Done, sent data size = %d.\n", size);
 
//    // Start UART Rx with DMA
//    HAL_Status sts = HAL_UART_ReceiveData_DMA(&UART0_OBJ, revDataBuf, UART_TEST_SIZE);
//    if (sts != HAL_OK)
//    {
////        printf("Error: HAL Uart Receive Data with DMA Fail, error code = %d!\n", sts);
//    }
}
 
static void uart0_init(void)
{
    SYS_SET_MFP(P1, 6, UART0_TX);
    SYS_SET_MFP(P1, 7, UART0_RX);
    GPIO_EnableDigitalPath(P1, BIT7);
 
    UART0_OBJ.initObj.baudRate = 921600;
    UART0_OBJ.initObj.format = HAL_UART_FMT_8_N_1;
    if (HAL_UART_Init(&UART0_OBJ) != HAL_OK) {
        printf("Error: HAL Uart Init Fail!\n");
    }
 
    HAL_DMA_Init();
 
    if (HAL_UART_Init_DMA(&UART0_OBJ, HAL_UART_DMA_TX, app_uart_tx_dma_callback) != HAL_OK) {
        printf("Error: HAL Uart Tx DMA Init Fail!\n");
    }
    if (HAL_UART_Init_DMA(&UART0_OBJ, HAL_UART_DMA_RX, app_uart_rx_dma_callback) != HAL_OK) {
        printf("Error: HAL Uart Rx DMA Init Fail!\n");
    }
}
 
 
/**
 *******************************************************************************
 * @brief user initialization entry
 *******************************************************************************
 */
void setup(void)
{
    APP_LOG_INFO("app started\n");
    // Init peripheral module
    uart0_init();
 
    // Start UART Rx with DMA
    HAL_Status sts = HAL_UART_ReceiveData_DMA(&UART0_OBJ, revDataBuf, UART_TEST_SIZE);
    if (sts != HAL_OK)
    {
        printf("Error: HAL Uart Receive Data with DMA Fail, error code = %d!\n", sts);
    }
    /* ble stack initialization. */
    app_ble_init();
 
    /**
     * TODO: user add application initialization code in here.
     */
}
 
/**
 *******************************************************************************
 * @brief this is main thread entry if CONFIG_OS_EN=1;
 *        this is main loop entry if CONFIG_OS_EN=0
 *******************************************************************************
 */
void loop(void)
{
 
}