IMXRT LPUART non-blocking transfer API makes error handling difficult

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

IMXRT LPUART non-blocking transfer API makes error handling difficult

333 Views
nxp16
Contributor III

Hi,

I've been looking at the "transfer" API for LPUART, for interrupt-based non-blocking transfers.  It seems to do a decent job of wrapping all the "happy case" handling of LPUART interrupts, etc, and providing a good high level API for just receiving data when it's ready (i.e. handling IDLE, RX ready, TX complete, etc).  However, it makes handling UART errors very difficult. 

There is no error handling inside the LPUART_TransferHandleIRQ function, and just after that function in fsl_lpuart.c is a bogus empty LPUART_TransferHandleErrorIRQ containing a comment "To be implemented by the user".  This looks completely half-baked.

The only way to actually handle UART errors seems to be to override the default LPUARTx_IRQHandler functions so that instead of calling LPUARTx_RX_DriverIRQHandler (or TX), you'd have to call your own function that handles errors and passes on "happy case" interrupts to the original LPUARTx_RX/TX_DriverIRQHandler so it can call into LPUART_TransferHandleErrorIRQ.

In addition you'd have to enable those error interrupts yourself outside the transfer API by calling LPUART_EnableInterrupts, and in your error handling also call LPUART_DisableInterrupts and deal with clearing them, etc.

This seems like a lot of extra hassle to handle errors.  Why is this not baked into the transfer API itself?

-m

0 Kudos
Reply
5 Replies

292 Views
Habib_MS
NXP Employee
NXP Employee

Hello @nxp16,

Thank you for the detailed feedback. I understand that the SDK could be a little ambiguous since these are intended to provide a common use cases for each peripheral functionality. We are constantly working to improve our APIs thanks also of recommendations like this. Thank you for the recommendations, and we hope that LPUART's error handling will be implemented in future releases.
On the other hand, could you please let me know which specific error conditions you are interested in handling and which device you are using? With that information, I can suggest documentation related to those error conditions that may help with your implementation.

BR
Habib

0 Kudos
Reply

276 Views
nxp16
Contributor III

All possible errors.  This applies to pretty much all peripherals (SPI, I2C, etc) that have a transfer API but no error handling.  LPUART on IMXRT1172 specifically has framing, parity, and noise errors that aren't handled.  Unfortunately right now all these peripherals require some hacking to handle errors when using the transfer API.  I had to override the actual default IRQ handlers to check for errors before calling the SDK handler.

Thanks,

-m

0 Kudos
Reply

263 Views
Habib_MS
NXP Employee
NXP Employee

Hello @nxp16,

I understand that this may require additional development time, sorry for that, we continuing working to improve our SDKs. As a reference, you may review the following structure of the SDK (version 26.6) function called "LPUART_TransferHandleIRQ" and implement a similar recovery flow as your application requires.

Habib_MS_1-1784062752001.png

BR
Habib

0 Kudos
Reply

254 Views
nxp16
Contributor III

Yes, I've already implemented something similar.  Thanks for sending that.

0 Kudos
Reply

226 Views
Habib_MS
NXP Employee
NXP Employee

Hello @nxp16,

Please let me know if you have any further questions.
BR
Habib

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2394386%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EIMXRT%20LPUART%20non-blocking%20transfer%20API%20makes%20error%20handling%20difficult%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2394386%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI've%20been%20looking%20at%20the%20%22transfer%22%20API%20for%20LPUART%2C%20for%20interrupt-based%20non-blocking%20transfers.%26nbsp%3B%20It%20seems%20to%20do%20a%20decent%20job%20of%20wrapping%20all%20the%20%22happy%20case%22%20handling%20of%20LPUART%20interrupts%2C%20etc%2C%20and%20providing%20a%20good%20high%20level%20API%20for%20just%20receiving%20data%20when%20it's%20ready%20(i.e.%20handling%20IDLE%2C%20RX%20ready%2C%20TX%20complete%2C%20etc).%26nbsp%3B%20However%2C%20it%20makes%20handling%20UART%20errors%20very%20difficult.%26nbsp%3B%3C%2FP%3E%3CP%3EThere%20is%20no%20error%20handling%20inside%20the%20LPUART_TransferHandleIRQ%20function%2C%20and%20just%20after%20that%20function%20in%20fsl_lpuart.c%20is%20a%20bogus%20empty%20LPUART_TransferHandleErrorIRQ%20containing%20a%20comment%20%22To%20be%20implemented%20by%20the%20user%22.%26nbsp%3B%20This%20looks%20completely%20half-baked.%3C%2FP%3E%3CP%3EThe%20only%20way%20to%20actually%20handle%20UART%20errors%20seems%20to%20be%20to%20override%20the%20default%20LPUARTx_IRQHandler%20functions%20so%20that%20instead%20of%20calling%20LPUARTx_RX_DriverIRQHandler%20(or%20TX)%2C%20you'd%20have%20to%20call%20your%20own%20function%20that%20handles%20errors%20and%20passes%20on%20%22happy%20case%22%20interrupts%20to%20the%20original%20LPUARTx_RX%2FTX_DriverIRQHandler%20so%20it%20can%20call%20into%20LPUART_TransferHandleErrorIRQ.%3C%2FP%3E%3CP%3EIn%20addition%20you'd%20have%20to%20enable%20those%20error%20interrupts%20yourself%20outside%20the%20transfer%20API%20by%20calling%20LPUART_EnableInterrupts%2C%20and%20in%20your%20error%20handling%20also%20call%20LPUART_DisableInterrupts%20and%20deal%20with%20clearing%20them%2C%20etc.%3C%2FP%3E%3CP%3EThis%20seems%20like%20a%20lot%20of%20extra%20hassle%20to%20handle%20errors.%26nbsp%3B%20Why%20is%20this%20not%20baked%20into%20the%20transfer%20API%20itself%3F%3C%2FP%3E%3CP%3E-m%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2394550%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20IMXRT%20LPUART%20non-blocking%20transfer%20API%20makes%20error%20handling%20difficult%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2394550%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F70127%22%20target%3D%22_blank%22%3E%40nxp16%3C%2FA%3E%2C%3C%2FP%3E%0A%3CP%3EThank%20you%20for%20the%20detailed%20feedback.%20I%20understand%20that%20the%20SDK%20could%20be%20a%20little%20ambiguous%20since%20these%20are%20intended%20to%20provide%20a%20common%20use%20cases%20for%20each%20peripheral%20functionality.%20We%20are%20constantly%20working%20to%20improve%20our%20APIs%20thanks%20also%20of%20recommendations%20like%20this.%20Thank%20you%20for%20the%20recommendations%2C%20and%20we%20hope%20that%20LPUART's%20error%20handling%20will%20be%20implemented%20in%20future%20releases.%3CBR%20%2F%3EOn%20the%20other%20hand%2C%20could%20you%20please%20let%20me%20know%20which%20specific%20error%20conditions%20you%20are%20interested%20in%20handling%20and%20which%20device%20you%20are%20using%3F%20With%20that%20information%2C%20I%20can%20suggest%20documentation%20related%20to%20those%20error%20conditions%20that%20may%20help%20with%20your%20implementation.%3C%2FP%3E%0A%3CP%3EBR%3CBR%20%2F%3EHabib%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2395100%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20IMXRT%20LPUART%20non-blocking%20transfer%20API%20makes%20error%20handling%20difficult%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2395100%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F70127%22%20target%3D%22_blank%22%3E%40nxp16%3C%2FA%3E%2C%3C%2FP%3E%0A%3CP%3EI%20understand%20that%20this%20may%20require%20additional%20development%20time%2C%20sorry%20for%20that%2C%20we%20continuing%20working%20to%20improve%20our%20SDKs.%20As%20a%20reference%2C%20you%20may%20review%20the%20following%20structure%20of%20the%20SDK%20(version%2026.6)%20function%20called%20%22LPUART_TransferHandleIRQ%22%20and%20implement%20a%20similar%20recovery%20flow%20as%20your%20application%20requires.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Habib_MS_1-1784062752001.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Habib_MS_1-1784062752001.png%22%20style%3D%22width%3A%20810px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Habib_MS_1-1784062752001.png%22%20style%3D%22width%3A%20810px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Habib_MS_1-1784062752001.png%22%20style%3D%22width%3A%20810px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Habib_MS_1-1784062752001.png%22%20style%3D%22width%3A%20810px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F392297i1130A2A44C5E0A70%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Habib_MS_1-1784062752001.png%22%20alt%3D%22Habib_MS_1-1784062752001.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EBR%3CBR%20%2F%3EHabib%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2394935%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20IMXRT%20LPUART%20non-blocking%20transfer%20API%20makes%20error%20handling%20difficult%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2394935%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EAll%20possible%20errors.%26nbsp%3B%20This%20applies%20to%20pretty%20much%20all%20peripherals%20(SPI%2C%20I2C%2C%20etc)%20that%20have%20a%20transfer%20API%20but%20no%20error%20handling.%26nbsp%3B%20LPUART%20on%20IMXRT1172%20specifically%20has%20framing%2C%20parity%2C%20and%20noise%20errors%20that%20aren't%20handled.%26nbsp%3B%20Unfortunately%20right%20now%20all%20these%20peripherals%20require%20some%20hacking%20to%20handle%20errors%20when%20using%20the%20transfer%20API.%26nbsp%3B%20I%20had%20to%20override%20the%20actual%20default%20IRQ%20handlers%20to%20check%20for%20errors%20before%20calling%20the%20SDK%20handler.%3C%2FP%3E%3CP%3EThanks%2C%3C%2FP%3E%3CP%3E-m%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2395601%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20IMXRT%20LPUART%20non-blocking%20transfer%20API%20makes%20error%20handling%20difficult%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2395601%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F70127%22%20target%3D%22_blank%22%3E%40nxp16%3C%2FA%3E%2C%3C%2FP%3E%0A%3CP%3EPlease%20let%20me%20know%20if%20you%20have%20any%20further%20questions.%3CBR%20%2F%3EBR%3CBR%20%2F%3EHabib%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2395452%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20IMXRT%20LPUART%20non-blocking%20transfer%20API%20makes%20error%20handling%20difficult%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2395452%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EYes%2C%20I've%20already%20implemented%20something%20similar.%26nbsp%3B%20Thanks%20for%20sending%20that.%3C%2FP%3E%3C%2FLINGO-BODY%3E