I am trying to do a basic project with KL25Z freedom PE and KSDK.
I have setup the lpsci component for uart0 and it seems to be running OK. But, I also setup the "install interrupt" option in PE, but the interrupt is not firing when sending or receiving data. Is there something else missing that I need to do?
KSDK 1.2
KDS 3
Solved! Go to Solution.
Hello M J:
None of your changes should be required. The receive interrupt is not enabled until you call a receive API (UART_DRV_ReceiveData or UART_DRV_ReceiveDataBlocking). In your project you are not calling any of both. Those functions require a pointer-to-buffer parameter in which you want to store the received data.
Regards!
Jorge Gonzalez
It appears that the NVIC is not setup by PE. I am now trying to enable the NVIC manually as follows. An interrupt is apprarenly auto triggered and there is an unhanlded event where the code jumper to DefaultISR. Can someone tell me what I am doing wrong with the follow setup?
//uart0 is setup by pe before this point, still need to setup the NVIC....
LPSCI_HAL_DisableReceiver(UART0_IDX);
LPSCI_HAL_DisableTransmitter(UART0_IDX);
//enable interrupts
//NVIC_EnableIRQ(UART0_IRQn); //setup nvic
INT_SYS_EnableIRQ(UART0_IRQn);
//void * INT_SYS_InstallHandler(IRQn_Type irqNumber, void (*handler)(void));
INT_SYS_InstallHandler(UART0_IRQn, uart0_irq); //void uart0_irq(void) function declared locally
UART0_C2 |= UART0_C2_RIE_MASK; //enalbe the rx ie bit
LPSCI_HAL_EnableReceiver(UART0_IDX);
LPSCI_HAL_EnableTransmitter(UART0_IDX);
Hello M J:
The interrupt is enabled in NVIC in the function LPSCI_DRV_Init(), which is called automatically if Auto Initialization is selected from the component.
Actually I think your issue is an oversight of PE developers because Rx/Tx callbacks are enabled in the component by default, but that can cause issues if the callback is not implemented as explained in this thread: Configuring MKL25 LPSCI with fsl_lpsci Processor Expert bean
In that link you can find an example provided by colleague Li Kan.
Just in case I also recreated the example project from [C:\Freescale\KSDK_1.2.0\examples\frdmkl25z\driver_examples\lpsci\lpsci_non_blocking], but in a project with Processor Expert. You can find it attached.
I hope this helps. Let me know if you have further issues.
Regards!,
Jorge Gonzalez
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Jorge,
I have done some more experimenting and had hoped that the release of SDK 1.3 would have fixed this problem, but the problem persists with SDK 1.3.
The problem seems to be different from the link you mentioned where it was the way that the RX callback was being handled that was the problem.
1) The first issue is that the Receive interrupt enable is not setup after the SDK has initialized the uart0 peripheral. I have ensured the the RX callback is selected and the Install interrupt is selected in PE. I have to manually enable the RIE bit in main for the interrupt to occur.
added to main enable the the recieve interrupt enable:
UART0_C2 |= UART_C2_RIE_MASK;
2) The check for RX data is not working if((UART0_BRD_C2_RIE(base)) && (UART0_BRD_S1_RDRF(base))). I have to replace it with UART0_S1 && UART_S1_RDRF_MASK in order for it to work.
((UART0_BRD_C2_RIE(base)) && (UART0_BRD_S1_RDRF(base))) replaced with UART0_S1 && UART_S1_RDRF_MASK
3) The code crashes when the LPSCI_DRV_IRQHandler is entered in the fsl_lpsci_driver.c sdk getChar function is called. I have found the cause for the hard fault to be when the LPSCI_HAL_Getchar(base, lpsciState->rxBuff); is called. I have to directly read the uart0_d register and it works fine.
LPSCI_HAL_Getchar(base, lpsciState->rxBuff); replaced with the following:
lpsciState->rxBuff = UART0_D
I am not sure why I would need to make so many changes in order to get the SDK code to work? Attached is my project with fixes.
Hello M J:
None of your changes should be required. The receive interrupt is not enabled until you call a receive API (UART_DRV_ReceiveData or UART_DRV_ReceiveDataBlocking). In your project you are not calling any of both. Those functions require a pointer-to-buffer parameter in which you want to store the received data.
Regards!
Jorge Gonzalez
Thank you Jorge!
Hi Jorge,
I have tried to build your project, but I get a weird issue where the project says "Nothing to build for project KL25_UART_PE", even after running a "clean" and regenerating the PE code. Oh well.
I have looked at the given example you linked here Configuring MKL25 LPSCI with fsl_lpsci Processor Expert bean
The project attached in the link does work with the lpsci does work with echoing data to the screen using the rx interrupt callback. However when I comment out the main loop section of code there is seems to be hard fault and the "default isr" is called killing the program.
// when this main loop code is commented out the program crashes!
if(kStatus_LPSCI_Success == LPSCI_DRV_ReceiveData(FSL_LPSCICOM1, &rx_data, 1u))
{
// Wait until we receive a user character
while (kStatus_LPSCI_RxBusy == LPSCI_DRV_GetReceiveStatus(FSL_LPSCICOM1, NULL)) {}
// Echo received character
tx_data = rx_data;
LPSCI_DRV_SendData(FSL_LPSCICOM1, &tx_data, 1u);
while (kStatus_LPSCI_TxBusy == LPSCI_DRV_GetTransmitStatus(FSL_LPSCICOM1, NULL)) {}
}
Any idea why the program would crash with the section commented out?? I did some experimentation, but could not figure out why. It does seem to be a KSDK driver issue somehow.
I have re-attached the project here for reference.
Hello M J:
Exactly what part are you commenting out? I took your project and commented that code. It worked from my side with no hardfaults, but obviously the project does nothing, just sitting in the for loop.
About your question above, INT_SYS_EnableIRQGlobal enables the peripheral interrupts at the NVIC level in general, like a master switch, but INT_SYS_EnableIRQ is also required to enable each individual interrupt you may need.
Regards!
Jorge Gonzalez
Thank you Jorge. It has been a challenge understanding the framework of SDK and how the basic implementations of things like the interrupts are setup within the SDK.
I have found you AN on using interrupts in the KSDK and KDS, which has been very valuable in understanding the important elements. I hope you continue to create docs like this in the future! Thank you.
Though it is still unclear to me what the difference is between the INT_SYS_EnableIRQ and INT_SYS_EnableIRQGlobal? Can you explain why and when you use one vs the other?