/** ******************************************************************************* * @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) { }