Hi,
I'm trying to use a Coral Micro Dev board, which features an RT1176 MCU, to facilitate UART communication via UART2 to a custom board. Basically, I want to send a single byte via UART to the board, receive a large chunk of data (about 64K) in return, process that, repeat. This works (in principle), if I use the LPUART_WriteBlocking and LPUART_ReadBlocking functions from the LPUART driver (fsl_lpuart.c). However, probably due to the very high datarate, I occasionally received RxHardwareOverrun error, so I tried implementing the same functionality using the EDMA unit instead.
Unfortunately, this didn't work at all. While I can send data via UART2 using LPUART_SendEDMA, the board subsequently resets itself, presumably when trying to call the corresponding ISR upon TxIdle. With a JTAG debugger connected, the board does not reboot, but the PC ends up stuck at address 0x00223104.
Here's a short example of my code:
#include <cstdio>
#include <inttypes.h>
#include <FreeRTOS.h>
#include <task.h>
#include "fsl_lpuart.h"
#include "fsl_lpuart_edma.h"
#include "fsl_dmamux.h"
#include "libs/base/led.h"
#include "MIMXRT1176_cm7.h"
void LPUART_UserCallback(LPUART_Type *base, lpuart_edma_handle_t *handle, status_t status, void *userData);
edma_handle_t tx_edma_handle;
edma_handle_t rx_edma_handle;
lpuart_edma_handle_t lpuart_edma_handle;
lpuart_transfer_t sendXfer;
AT_NONCACHEABLE_SECTION(uint8_t rx_edma_buffer[8192]);
AT_NONCACHEABLE_SECTION(uint8_t tx_edma_buffer[8]);
void LPUART_UserCallback(LPUART_Type *base, lpuart_edma_handle_t *handle, status_t status, void *userData) {
// nothing yet
}
extern "C" [[noreturn]] void app_main(void *param) {
(void)param;
vTaskDelay(pdMS_TO_TICKS(5000));
clock_root_config_t root_cfg = {0};
lpuart_config_t lpuart_config;
edma_config_t edma_config;
root_cfg.mux = kCLOCK_LPUART2_ClockRoot_MuxOscRc400M;
root_cfg.div = 5;
CLOCK_SetRootClock(kCLOCK_Root_Lpuart2, &root_cfg);
LPUART_GetDefaultConfig(&lpuart_config);
lpuart_config.baudRate_Bps = 6000000;
lpuart_config.enableTx = true;
lpuart_config.enableRx = true;
lpuart_config.parityMode = kLPUART_ParityDisabled;
lpuart_config.stopBitCount = kLPUART_OneStopBit;
lpuart_config.dataBitsCount = kLPUART_EightDataBits;
LPUART_Init(LPUART2, &lpuart_config, CLOCK_GetRootClockFreq(kCLOCK_Root_Lpuart2));
DMAMUX_Init(DMAMUX0);
DMAMUX_SetSource(DMAMUX0, 0U, kDmaRequestMuxLPUART2Tx);
DMAMUX_SetSource(DMAMUX0, 1U, kDmaRequestMuxLPUART2Rx);
DMAMUX_EnableChannel(DMAMUX0, 0U);
DMAMUX_EnableChannel(DMAMUX0, 1U);
EDMA_GetDefaultConfig(&edma_config);
EDMA_Init(DMA0, &edma_config);
EDMA_CreateHandle(&tx_edma_handle, DMA0, 0U);
EDMA_CreateHandle(&rx_edma_handle, DMA0, 1U);
LPUART_TransferCreateHandleEDMA(LPUART2, &lpuart_edma_handle, LPUART_UserCallback, NULL, &tx_edma_handle, &rx_edma_handle);
sendXfer.data = &tx_edma_buffer[0];
sendXfer.dataSize = 1;
LPUART_SendEDMA(LPUART2, &lpuart_edma_handle, &sendXfer);
while (true);
}
And here's the CMakeLists.txt I'm using to build my project:
cmake_minimum_required(VERSION 3.13)
# Toolchain must be set before project() call.
if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/coralmicro/cmake/toolchain-arm-none-eabi-gcc.cmake)
endif()
project(coralmicro-app CXX C ASM)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
include_directories(coralmicro)
add_subdirectory(coralmicro)
add_executable_m7(coralmicro-app
main_cm7.cc
${CMAKE_CURRENT_SOURCE_DIR}/coralmicro/third_party/nxp/rt1176-sdk/devices/MIMXRT1176/drivers/fsl_lpuart_edma.c
)
target_include_directories(coralmicro-app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/coralmicro
${CMAKE_CURRENT_SOURCE_DIR}/coralmicro/third_party/CMSIS/CMSIS/Core/Include
${CMAKE_CURRENT_SOURCE_DIR}/coralmicro/third_party/nxp/rt1176-sdk/devices/MIMXRT1176/drivers
)
target_link_libraries(coralmicro-app PRIVATE -Wl,--start-group)
target_link_libraries(coralmicro-app PRIVATE libs_base-m7_freertos)
target_link_libraries(coralmicro-app PRIVATE libs_nxp_rt1176-sdk_freertos)
target_link_libraries(coralmicro-app PRIVATE m)
target_link_libraries(coralmicro-app PRIVATE c)
target_link_libraries(coralmicro-app PRIVATE gcc)
target_link_libraries(coralmicro-app PRIVATE nosys)
target_link_libraries(coralmicro-app PRIVATE -Wl,--end-group)
What am I missing here? Is there some additional configuration to be done to make this work?
Any help is greatly appreciated...
Thanks!
Solved! Go to Solution.
Once sent the date you can add the function LPUART_ReceiveEDMA() to start receiving.
Make sure that DMA channels and interruption are enabled.
Best regards,
Omar
Once sent the date you can add the function LPUART_ReceiveEDMA() to start receiving.
Make sure that DMA channels and interruption are enabled.
Best regards,
Omar