S32K344 - LPUART Tx Send Hard Fault

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

S32K344 - LPUART Tx Send Hard Fault

Jump to solution
1,398 Views
DiaDev
Contributor III

Hi,

I'm working on an S32K platform using FreeRTOS. I have two tasks (UartTask1 and UartTask2) that frequently call debug_log() to send messages over UART.

Logging structure:

  • debug_log() formats the message and enqueues it into a FreeRTOS queue.

  • A dedicated uart_log_task() dequeues and sends each message using Lpuart_Uart_Ip_AsyncSend().

  • UART TX completion is confirmed using a callback that sets a uart_tx_done flag.

  • A small vTaskDelay() is added after UART transmission in the log task — no queue overflow is observed.

Issue:
Every time UART starts sending, only a few characters are printed or sometimes garbage, and then the system hits a hard fault.

This happens consistently during UART transmission, not before.

Key finding:
When I isolate UART and test it outside of the logging system (no queue, no multiple tasks), it works fine. So the UART driver itself seems okay.

Question:

  • What could be causing this crash in the multitask logging setup?

  • Is it possible that a shared/static buffer (like tx_data) is getting overwritten or accessed before TX completes?

  • Are there specific precautions for using Lpuart_Uart_Ip_AsyncSend() with FreeRTOS and multiple tasks?

Any help or suggestions would be greatly appreciated.

Thanks in advance!


I have attached snippet code and lpuart config.

Tags (2)
0 Kudos
Reply
1 Solution
1,343 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

try to identify a cause of hard fault. You can refer to: How To Debug A Fault Exception On ARM Cortex-M(V7M) MCU(S32K3XX)
Maybe just increasing stack, heap size can help.

BR, Petr

View solution in original post

0 Kudos
Reply
1 Reply
1,344 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

try to identify a cause of hard fault. You can refer to: How To Debug A Fault Exception On ARM Cortex-M(V7M) MCU(S32K3XX)
Maybe just increasing stack, heap size can help.

BR, Petr

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2131479%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ES32K344%20-%20LPUART%20Tx%20Send%20Hard%20Fault%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2131479%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI'm%20working%20on%20an%20S32K%20platform%20using%20FreeRTOS.%20I%20have%20two%20tasks%20(UartTask1%20and%20UartTask2)%20that%20frequently%20call%20debug_log()%20to%20send%20messages%20over%20UART.%3C%2FP%3E%3CP%3E%3CSTRONG%3ELogging%20structure%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3Edebug_log()%20formats%20the%20message%20and%20enqueues%20it%20into%20a%20FreeRTOS%20queue.%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EA%20dedicated%20uart_log_task()%20dequeues%20and%20sends%20each%20message%20using%20Lpuart_Uart_Ip_AsyncSend().%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EUART%20TX%20completion%20is%20confirmed%20using%20a%20callback%20that%20sets%20a%20uart_tx_done%20flag.%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EA%20small%20vTaskDelay()%20is%20added%20after%20UART%20transmission%20in%20the%20log%20task%20%E2%80%94%20no%20queue%20overflow%20is%20observed.%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%3CSTRONG%3EIssue%3A%3C%2FSTRONG%3E%3CBR%20%2F%3EEvery%20time%20UART%20starts%20sending%2C%20only%20a%20few%20characters%20are%20printed%20or%20sometimes%20garbage%2C%20and%20then%20the%20system%20hits%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Ehard%20fault%3C%2FSTRONG%3E.%3C%2FP%3E%3CP%3EThis%20happens%20consistently%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Eduring%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EUART%20transmission%2C%20not%20before.%3C%2FP%3E%3CP%3E%3CSTRONG%3EKey%20finding%3A%3C%2FSTRONG%3E%3CBR%20%2F%3EWhen%20I%20isolate%20UART%20and%20test%20it%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Eoutside%20of%20the%20logging%20system%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E(no%20queue%2C%20no%20multiple%20tasks)%2C%20it%20works%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Efine%3C%2FSTRONG%3E.%20So%20the%20UART%20driver%20itself%20seems%20okay.%3C%2FP%3E%3CP%3E%3CSTRONG%3EQuestion%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3EWhat%20could%20be%20causing%20this%20crash%20in%20the%20multitask%20logging%20setup%3F%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EIs%20it%20possible%20that%20a%20shared%2Fstatic%20buffer%20(like%20tx_data)%20is%20getting%20overwritten%20or%20accessed%20before%20TX%20completes%3F%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EAre%20there%20specific%20precautions%20for%20using%20Lpuart_Uart_Ip_AsyncSend()%20with%20FreeRTOS%20and%20multiple%20tasks%3F%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3EAny%20help%20or%20suggestions%20would%20be%20greatly%20appreciated.%3C%2FP%3E%3CP%3EThanks%20in%20advance!%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EI%20have%20attached%20snippet%20code%20and%20lpuart%20config.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2134852%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K344%20-%20LPUART%20Tx%20Send%20Hard%20Fault%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2134852%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CP%3Etry%20to%20identify%20a%20cause%20of%20hard%20fault.%20You%20can%26nbsp%3B%3CSPAN%3Erefer%20to%3A%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2FS32K-Knowledge-Base%2FHow-To-Debug-A-Fault-Exception-On-ARM-Cortex-M-V7M-MCU-S32K3XX%2Fta-p%2F1595570%22%20target%3D%22_self%22%3EHow%20To%20Debug%20A%20Fault%20Exception%20On%20ARM%20Cortex-M(V7M)%20MCU(S32K3XX)%3C%2FA%3E%3CBR%20%2F%3EMaybe%20just%20increasing%20stack%2C%20heap%20size%20can%20help.%3C%2FP%3E%0A%3CP%3EBR%2C%20Petr%3C%2FP%3E%3C%2FLINGO-BODY%3E