FreeRTOS LPUART driver problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FreeRTOS LPUART driver problem

232 Views
Oliver_R
Contributor I

Hi,

I'm using a RT1176 based board with (currently the older) mcux-sdk, but the problem looks identical in the mcuxsdk (really confusing names!):

The Freertos-LPUART driver (fsl_lpuart_freertos.c) does not call HAL_UartInit (fsl_adapter_lpuart.c) in the LPUART_RTOS_Init function. Instead it calls just LPUART_Init, which is not enough!

The problem is that the field s_UartState (line 719 in fsl_fsl_adapter_lpuart.c) is not written in LPUART_Init which then leads to an assertion if a receive interrupt from the UART occurs:

ASSERT ERROR " NULL != uartHandle ": file "D:\usr\TQM\mcuxsdk\core\components\uart\fsl_adapter_lpuart.c" Line "433" function name "HAL_UartInterruptHandle"

So I wonder, how this driver could ever worked, because the array s_UartState is read for the handle in the interrupt driver (and then it is NULL).

So, did I anything wrong or has this driver a problem? Maybe I have to rewrite the code to use a lower API driver for the LPUARTS?

Thanks and bye,
Oliver

 

Labels (1)
0 Kudos
Reply
3 Replies

200 Views
Pablo_Ramos
NXP Employee
NXP Employee

Hi @Oliver_R,

Could you help me with the following question?

Are you using VS Code or MCUXpresso?

If you test with mcuxsdk , does the problem persist?

In VS Code, there is an example project: evkbmimxrt1170_freertos_lpuart_cm7. Could you help me test whether it works with your hardware?

Best Regards,
Pablo

0 Kudos
Reply

169 Views
Oliver_R
Contributor I

Hello,

I'm using the VSCode plugin with the latest mcux-sdk. We're using a TQMa117xL based board and unfortunately the BSP is not yet ready for mcuxsdk.

This means I can't test it right now with mcuxsdk but in the future we will change to it.

The mentioned example is new, as I can't find it in mcux-sdk? I will check it out.

The assertion happens right after the Init function:

lpuart_rtos_config_t mSerConfig;
lpuart_rtos_handle_t mRtosHandle;
_lpuart_handle       mUartHandle;
mRtosHandle = {};
mUartHandle = {};
mSerConfig             = {};
mSerConfig.srcclk = CLOCK_GetRootClockFreq(kCLOCK_Root_Lpuart9);
mSerConfig.base   = LPUART9;
mSerConfig.baudrate    = aBaudrate;
mSerConfig.parity      = kLPUART_ParityDisabled;
mSerConfig.stopbits    = kLPUART_OneStopBit;
mSerConfig.buffer      = mReadBuf;
mSerConfig.buffer_size = sizeof(mReadBuf);
mSerConfig.enableRxRTS = true;
mSerConfig.enableTxCTS = true;
int status = LPUART_RTOS_Init(&mRtosHandle, &mUartHandle, &mSerConfig);

The code is in a C++ class but I will compare the init code with the example.

 

Bye,

Oliver

0 Kudos
Reply

119 Views
Oliver_R
Contributor I

Hi,

in the meantime I discovered, that this is not related only to the FreeRTOS-Uart driver, but also to the underlying lpuart driver.

Unfortunately, I found nothing in the SDK documentation or in the forums to the HAL_Uart-driver

For what reason is the HAL_Uartxxx-API (fsl_adapter_lpuart.c)? Why and when should I use it? There are only two sources in the whole SDK which are using HAL_UartInit at all: fsl_component_serial_port_uart.c and fsl_debug_console.c in the debug_console_lite folder.

The problem I have with this API is that when fsl_adapter_lpuart.c is compiled WITHOUT the define "HAL_UART_TRANSFER_MODE=1" then all lpuart interrupts are defined in this source and then I HAVE to use HAL_UartInit in order to avoid the assertion in the receive IRQ. And as the IRQs are already defined, I have no change to register my own IRQ anymore.

But all UART examples do not set HAL_UART_TRANSFER_MODE=1 and some examples are defining their own IRQs, so I wonder how this could work. I define DEBUG_CONSOLE_TRANSFER_NON_BLOCKING and I'm not using the "utility_debug_console_lite" component.

BTW: What is the difference between "utility_debug_console" and "utility_debug_console_lite"? The SDK documentation is the same for both components?

All of this driver code is very very hard to understand as there is so much preprocessor magic and so few documentation for it.

So I have the impression, that the source "fsl_adapter_lpuart.c" should not be compiled in at all as it defines the lpuart IRQs in an unwanted way which lead to assertions when using other lpuarts than the debug console lpuart.

Bye,
Oliver

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2292566%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EFreeRTOS%20LPUART%20driver%20problem%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2292566%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI'm%20using%20a%20RT1176%20based%20board%20with%20(currently%20the%20older)%20mcux-sdk%2C%20but%20the%20problem%20looks%20identical%20in%20the%20mcuxsdk%20(really%20confusing%20names!)%3A%3C%2FP%3E%3CP%3EThe%20Freertos-LPUART%20driver%20(fsl_lpuart_freertos.c)%20does%20not%20call%20HAL_UartInit%20(fsl_adapter_lpuart.c)%20in%20the%20LPUART_RTOS_Init%20function.%20Instead%20it%20calls%20just%20LPUART_Init%2C%20which%20is%20not%20enough!%3C%2FP%3E%3CP%3EThe%20problem%20is%20that%20the%20field%20s_UartState%20(line%20719%20in%20fsl_fsl_adapter_lpuart.c)%20is%20not%20written%20in%20LPUART_Init%20which%20then%20leads%20to%20an%20assertion%20if%20a%20receive%20interrupt%20from%20the%20UART%20occurs%3A%3C%2FP%3E%3CP%3EASSERT%20ERROR%20%22%20NULL%20!%3D%20uartHandle%20%22%3A%20file%20%22D%3A%5Cusr%5CTQM%5Cmcuxsdk%5Ccore%5Ccomponents%5Cuart%5Cfsl_adapter_lpuart.c%22%20Line%20%22433%22%20function%20name%20%22HAL_UartInterruptHandle%22%3C%2FP%3E%3CP%3ESo%20I%20wonder%2C%20how%20this%20driver%20could%20ever%20worked%2C%20because%20the%20array%20s_UartState%20is%20read%20for%20the%20handle%20in%20the%20interrupt%20driver%20(and%20then%20it%20is%20NULL).%3C%2FP%3E%3CP%3ESo%2C%20did%20I%20anything%20wrong%20or%20has%20this%20driver%20a%20problem%3F%20Maybe%20I%20have%20to%20rewrite%20the%20code%20to%20use%20a%20lower%20API%20driver%20for%20the%20LPUARTS%3F%3C%2FP%3E%3CP%3EThanks%20and%20bye%2C%3CBR%20%2F%3EOliver%3C%2FP%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2292566%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3Ei.MXRT%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2293028%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20FreeRTOS%20LPUART%20driver%20problem%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2293028%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3EI'm%20using%20the%20VSCode%20plugin%20with%20the%20latest%20mcux-sdk.%20We're%20using%20a%20TQMa117xL%20based%20board%20and%20unfortunately%20the%20BSP%20is%20not%20yet%20ready%20for%20mcuxsdk.%3C%2FP%3E%3CP%3EThis%20means%20I%20can't%20test%20it%20right%20now%20with%20mcuxsdk%20but%20in%20the%20future%20we%20will%20change%20to%20it.%3C%2FP%3E%3CP%3EThe%20mentioned%20example%20is%20new%2C%20as%20I%20can't%20find%20it%20in%20mcux-sdk%3F%20I%20will%20check%20it%20out.%3C%2FP%3E%3CP%3EThe%20assertion%20happens%20right%20after%20the%20Init%20function%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-cpp%22%3E%3CCODE%3Elpuart_rtos_config_t%20mSerConfig%3B%0Alpuart_rtos_handle_t%20mRtosHandle%3B%0A_lpuart_handle%20%20%20%20%20%20%20mUartHandle%3B%0AmRtosHandle%20%3D%20%7B%7D%3B%0AmUartHandle%20%3D%20%7B%7D%3B%0AmSerConfig%20%20%20%20%20%20%20%20%20%20%20%20%20%3D%20%7B%7D%3B%0AmSerConfig.srcclk%20%3D%20CLOCK_GetRootClockFreq(kCLOCK_Root_Lpuart9)%3B%0AmSerConfig.base%20%20%20%3D%20LPUART9%3B%0AmSerConfig.baudrate%20%20%20%20%3D%20aBaudrate%3B%0AmSerConfig.parity%20%20%20%20%20%20%3D%20kLPUART_ParityDisabled%3B%0AmSerConfig.stopbits%20%20%20%20%3D%20kLPUART_OneStopBit%3B%0AmSerConfig.buffer%20%20%20%20%20%20%3D%20mReadBuf%3B%0AmSerConfig.buffer_size%20%3D%20sizeof(mReadBuf)%3B%0AmSerConfig.enableRxRTS%20%3D%20true%3B%0AmSerConfig.enableTxCTS%20%3D%20true%3B%0Aint%20status%20%3D%20LPUART_RTOS_Init(%26amp%3BmRtosHandle%2C%20%26amp%3BmUartHandle%2C%20%26amp%3BmSerConfig)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EThe%20code%20is%20in%20a%20C%2B%2B%20class%20but%20I%20will%20compare%20the%20init%20code%20with%20the%20example.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EBye%2C%3C%2FP%3E%3CP%3EOliver%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2292771%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20FreeRTOS%20LPUART%20driver%20problem%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2292771%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F212331%22%20target%3D%22_blank%22%3E%40Oliver_R%3C%2FA%3E%2C%3C%2FP%3E%0A%3CP%3ECould%20you%20help%20me%20with%20the%20following%20question%3F%3C%2FP%3E%0A%3CP%3EAre%20you%20using%20VS%20Code%20or%20MCUXpresso%3F%3C%2FP%3E%0A%3CP%3EIf%20you%20test%20with%20mcuxsdk%20%2C%20does%20the%20problem%20persist%3F%3C%2FP%3E%0A%3CP%3EIn%20VS%20Code%2C%20there%20is%20an%20example%20project%3A%20evkbmimxrt1170_freertos_lpuart_cm7.%20Could%20you%20help%20me%20test%20whether%20it%20works%20with%20your%20hardware%3F%3C%2FP%3E%0A%3CP%3EBest%20Regards%2C%3CBR%20%2F%3EPablo%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2294017%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20FreeRTOS%20LPUART%20driver%20problem%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2294017%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3Ein%20the%20meantime%20I%20discovered%2C%20that%20this%20is%20not%20related%20only%20to%20the%20FreeRTOS-Uart%20driver%2C%20but%20also%20to%20the%20underlying%20lpuart%20driver.%3C%2FP%3E%3CP%3EUnfortunately%2C%20I%20found%20nothing%20in%20the%20SDK%20documentation%20or%20in%20the%20forums%20to%20the%20HAL_Uart-driver%3C%2FP%3E%3CP%3EFor%20what%20reason%20is%20the%20HAL_Uartxxx-API%20(fsl_adapter_lpuart.c)%3F%20Why%20and%20when%20should%20I%20use%20it%3F%20There%20are%20only%20two%20sources%20in%20the%20whole%20SDK%20which%20are%20using%20HAL_UartInit%20at%20all%3A%20fsl_component_serial_port_uart.c%20and%20fsl_debug_console.c%20in%20the%20debug_console_lite%20folder.%3C%2FP%3E%3CP%3EThe%20problem%20I%20have%20with%20this%20API%20is%20that%20when%20fsl_adapter_lpuart.c%20is%20compiled%20WITHOUT%20the%20define%20%22HAL_UART_TRANSFER_MODE%3D1%22%20then%20all%20lpuart%20interrupts%20are%20defined%20in%20this%20source%20and%20then%20I%20HAVE%20to%20use%20HAL_UartInit%20in%20order%20to%20avoid%20the%20assertion%20in%20the%20receive%20IRQ.%20And%20as%20the%20IRQs%20are%20already%20defined%2C%20I%20have%20no%20change%20to%20register%20my%20own%20IRQ%20anymore.%3C%2FP%3E%3CP%3EBut%20all%20UART%20examples%20do%20not%20set%20HAL_UART_TRANSFER_MODE%3D1%20and%20some%20examples%20are%20defining%20their%20own%20IRQs%2C%20so%20I%20wonder%20how%20this%20could%20work.%20I%20define%20DEBUG_CONSOLE_TRANSFER_NON_BLOCKING%20and%20I'm%20not%20using%20the%20%22utility_debug_console_lite%22%20component.%3C%2FP%3E%3CP%3EBTW%3A%20What%20is%20the%20difference%20between%20%22utility_debug_console%22%20and%20%22utility_debug_console_lite%22%3F%20The%20SDK%20documentation%20is%20the%20same%20for%20both%20components%3F%3C%2FP%3E%3CP%3EAll%20of%20this%20driver%20code%20is%20very%20very%20hard%20to%20understand%20as%20there%20is%20so%20much%20preprocessor%20magic%20and%20so%20few%20documentation%20for%20it.%3C%2FP%3E%3CP%3ESo%20I%20have%20the%20impression%2C%20that%20the%20source%20%22fsl_adapter_lpuart.c%22%20should%20not%20be%20compiled%20in%20at%20all%20as%20it%20defines%20the%20lpuart%20IRQs%20in%20an%20unwanted%20way%20which%20lead%20to%20assertions%20when%20using%20other%20lpuarts%20than%20the%20debug%20console%20lpuart.%3C%2FP%3E%3CP%3EBye%2C%3CBR%20%2F%3EOliver%3C%2FP%3E%3C%2FLINGO-BODY%3E