TWR-K65F180 with MQX: why cannot I use UART0 and UART3? The system crashes

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

TWR-K65F180 with MQX: why cannot I use UART0 and UART3? The system crashes

Jump to solution
2,438 Views
mmoncigoli
Contributor III

Dear community, please I need to ask an explanation for a weird issue I'm having using the "lwip_udpecho_demo" example (under c:\Freescale\KSDK_1.3.0\examples\twrk65f180m\demo_apps\lwip\lwip_udpecho_demo\udpecho_rtos). But, in my opinion, the issue is not due to the SPECIFIC demo example I am using. I guess it's use to MQX RTOS.

Unfortunately my deadline will be this incoming Monday. If I don't fix this issue I cannot deliver my project... :-(

 

ENVIRONMENT I AM USING

- KSDK 1.3.0

- TWR-K65F180 with TWR-SER2

- MQX RTOS

- PEMicro

- Either openSDA or Jlink for debugging

- PC console: either DB9 on TWR-SER2 or openSDA

- GNU-GCC Compiler

 

DESCRIPTION OF THE ISSUE

"lwip_udpecho_demo" code example uses UART2 to display debug strings on the PC-console. I need to make this TWR board communicate with another TWR-K65F180 with TWR-SER2 over UART. So I tried to use, in vain, either UART0 or UART3 (from, respectively, J7 pins 1 and 3 of TWR-SER2 and R40 (PT17) and R39 (PT16) of TWR-K65F180 board. The issue I'm having is that, when my code tries to transmit over UART0 (or UART3) using "UART_DRV_SendDataBlocking(0, bufferData, byteCountBuff, 1000u)", it always crashes inside this function (more precisely, when this function calls "retVal = UART_DRV_StartSendData(instance, txBuff, txSize)").

 

MY ANALYSIS OF THE ISSUE

I also tried to transmit data over UART0 and UART3 (same boards configuration) with the example "uart_blocking" present in the driver examples of the KSDK 1.3.0 folder. In this case I had not problem in term of that, everything worked perfectly! So, since this "uart_blocking" example is not using any RTOS, my guess is that MQX, for some reasons, keeps busy both UART0 and UART3 making my code crashing.  But, in the code, I didn't find the point when MQX opens these two ports.

 

Can this be the right explanation? But, more important, how can I use these two UARTs (0 and 3) using MQX RTOS in my code?

 

 

Thanks so much to all people who are going to help me

Labels (1)
1 Solution
1,645 Views
isaacavila
NXP Employee
NXP Employee

Hello Marco,

About your first question, I can say, yes, you can, and I've made some modifications on lwip_udpecho_demo_mqx_twrk65f180m example to validate it. I attach this main.c file for your reference but I will explain all that I've done in order to get this UART driver to work.

First of all, I included the "fsl_uart_driver.h" file.

#include "fsl_uart_driver.h"

Then, I defined UART 3's handler as it is explained on this document:How To: Using Interrupt Handlers in MQX with KSDK (You can also check this useful post Interrupt handling with KSDK and Kinetis Design Studio)

extern void UART_DRV_IRQHandler(uint32_t instance);

void MQX_UART3_RX_TX_IRQHandler () {

    UART_DRV_IRQHandler(3);

}

After this, on Main task, I configured the UART module (pins, baud rate, etc) and all necessary variables:

const uint8_t buffStart[]   = "\r\n++++++++++++++++ UART Send/Receive Blocking Example +++++++++++++++++\r\n";

    // Inform to start blocking example

    uint32_t byteCountBuff = sizeof(buffStart);

    // Initialize variable uartState of type uart_state_t

    uart_state_t uartState;

    // Fill in uart config data

    uart_user_config_t uartConfig = {

        .bitCountPerChar = kUart8BitsPerChar,

        .parityMode      = kUartParityDisabled,

        .stopBitCount    = kUartOneStopBit,

        .baudRate        = 115200

    };

    /* UART3 pins on PTE4 and PTE5 */

    /* Affects PORTE_PCR4 register */

    PORT_HAL_SetMuxMode(PORTE,4u,kPortMuxAlt3);

    /* Affects PORTE_PCR5 register */

    PORT_HAL_SetMuxMode(PORTE,5u,kPortM

uxAlt3);

UART 3's handler is installed through OSA layer:

OSA_InstallIntHandler(UART3_RX_TX_IRQn, MQX_UART3_RX_TX_IRQHandler);

Finally, I initialize the module and send a basic message:

if (kStatus_UART_Success != UART_DRV_Init(UART3_IDX, &uartState, &uartConfig)) {

        printf("Error on UART initialization\r\n");

    } else {

        UART_DRV_SendDataBlocking(UART3_IDX, buffStart, byteCountBuff,1000);

    }

After this, demo is unaltered and you can see that both UART instances (UART2 as I/O console and UART3) print messages on terminals:

Both Terminals.jpg

This way, you can see that UART can be used as it is used on baremetal examples.

About second point, the way to do it is through NIO (I know about the lack of documentation on this abstraction) but you can base on NIO driver that is used to install default console on MQX system. I can try to explain it deeper if you desire so.

For now, I hope this can help you!

Best Regards,

Isaac

----------------------------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

----------------------------------------------------------------------------------------------------------------------------------------

View solution in original post

15 Replies
1,645 Views
mmoncigoli
Contributor III

Hi Isaac,

Sorry for this late reply, but I haven't checked this post for lots of days. The document attached to your last post is really useful. Right now I have UART driver implemented following what you explained in your post of Feb 3, 2016 12:55 PM, but I will implement it following the NIO document of your previous reply.

Thanks so much

0 Kudos
1,645 Views
isaacavila
NXP Employee
NXP Employee

Hello,

Are you trying to use another UART instance as debug console or you need to have 2 UART (one as debug console and other to communicate different messages to other board)?

Best Regards,

Isaac Avila

1,645 Views
mmoncigoli
Contributor III

Hello Isaac,

Thanks so much for this explanation, now I'm understanding a bit more. I am using 2 UARTs, one as debug console and the other to communicate different messages to another board. The debug console is the one already implemented in the "lwip_udpecho_demo" example (UART2). In order to communicate with other 2 boards, I need to use UART0 and UART3 (the ones I could not make work).

So, at this point, please, I'd like to ask you:

-> how to install NIO serial driver

-> in term of NIO function description, where can I find the proper documentation? I searched in "Freescale MQX™ RTOS Reference Manual" and "Freescale MQX™ RTOS User's Guide", but I didn't find anything.

Thanks again for your precious help

0 Kudos
1,645 Views
mmoncigoli
Contributor III

Actually Isaac, in terms of my question about how to install NIO serial driver, running "lwip_udpecho_demo" example, I think it's already installed in my system, isn't it?

Thanks

0 Kudos
1,645 Views
isaacavila
NXP Employee
NXP Employee

Hello mmoncigoli,

Yes, this NIO driver is already installed when MQX initializes, if you seek on init_bsp.c file (located at BSP_Files folder) you will notice the const NIO_SERIAL_INIT_DATA_STRUCT nio_serial_default_init strcuture that contains setup for default console port (like UART instance, baud rate, etc) and it is installed in _bsp_init function.

This NIO driver is used for debug console, so you can use functions like in POSIX standard (fopen, fclose, ioctl, fwrite, fread) and it is only installed for DEFAULT IO SUBSYSTEM.

If you want to use another UART instance, you can use KSDK drivers as they are (UART_DRV_Init, UART_DRV_SendDataBlocking), however, if you would like to use POSIX standard for this UART instance, you should create a wrapper by installing a new NIO driver like it was installed for DEFAULT_IO_SUBSYSTEM.

I hope this can help you!

Best Regards,

Isaac Avila

----------------------------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

----------------------------------------------------------------------------------------------------------------------------------------

0 Kudos
1,645 Views
mmoncigoli
Contributor III

MQX RTOS on  KSDK_1.3.0

Hello Isaac,

I am looking at NIO documentation for MQX RTOS on  KSDK_1.3.0 and found nothing  :smileyconfused: :smileycry:

At this point, since it's very important for me to close this UART implementation issue in my project as soon as possible, I need to ask you these following two questions please:

1) You wrote: "If you want to use another UART instance, you can use KSDK drivers as they are (UART_DRV_Init, UART_DRV_SendDataBlocking)...". As by my initial question, using these UART_DRV_xxx functions in a project with MQX (and the environment described in my first post), UART_DRV_SendDataBlocking(..) function crashes. It doesn't work. So my question is, is it really possible to use UART_DRV_xxx functions in my project?

2) Since NIO documentation for MQX RTOS is, practically, non existent, can I implement UARTs communication using different MQX driver code which currently has description documentation available? Can I use, in my environment described above, "Formatted I/O Library", for example? One problem I've just found about that, is that "fio.h" file is not present in all my installed Freescale code ("KSDK_1.3.0", "KDS_3.0.0" and "CW MCU v10.6").

If you can help me about this topic, it would be really great.

Thanks so much for your time

Marco

0 Kudos
1,646 Views
isaacavila
NXP Employee
NXP Employee

Hello Marco,

About your first question, I can say, yes, you can, and I've made some modifications on lwip_udpecho_demo_mqx_twrk65f180m example to validate it. I attach this main.c file for your reference but I will explain all that I've done in order to get this UART driver to work.

First of all, I included the "fsl_uart_driver.h" file.

#include "fsl_uart_driver.h"

Then, I defined UART 3's handler as it is explained on this document:How To: Using Interrupt Handlers in MQX with KSDK (You can also check this useful post Interrupt handling with KSDK and Kinetis Design Studio)

extern void UART_DRV_IRQHandler(uint32_t instance);

void MQX_UART3_RX_TX_IRQHandler () {

    UART_DRV_IRQHandler(3);

}

After this, on Main task, I configured the UART module (pins, baud rate, etc) and all necessary variables:

const uint8_t buffStart[]   = "\r\n++++++++++++++++ UART Send/Receive Blocking Example +++++++++++++++++\r\n";

    // Inform to start blocking example

    uint32_t byteCountBuff = sizeof(buffStart);

    // Initialize variable uartState of type uart_state_t

    uart_state_t uartState;

    // Fill in uart config data

    uart_user_config_t uartConfig = {

        .bitCountPerChar = kUart8BitsPerChar,

        .parityMode      = kUartParityDisabled,

        .stopBitCount    = kUartOneStopBit,

        .baudRate        = 115200

    };

    /* UART3 pins on PTE4 and PTE5 */

    /* Affects PORTE_PCR4 register */

    PORT_HAL_SetMuxMode(PORTE,4u,kPortMuxAlt3);

    /* Affects PORTE_PCR5 register */

    PORT_HAL_SetMuxMode(PORTE,5u,kPortM

uxAlt3);

UART 3's handler is installed through OSA layer:

OSA_InstallIntHandler(UART3_RX_TX_IRQn, MQX_UART3_RX_TX_IRQHandler);

Finally, I initialize the module and send a basic message:

if (kStatus_UART_Success != UART_DRV_Init(UART3_IDX, &uartState, &uartConfig)) {

        printf("Error on UART initialization\r\n");

    } else {

        UART_DRV_SendDataBlocking(UART3_IDX, buffStart, byteCountBuff,1000);

    }

After this, demo is unaltered and you can see that both UART instances (UART2 as I/O console and UART3) print messages on terminals:

Both Terminals.jpg

This way, you can see that UART can be used as it is used on baremetal examples.

About second point, the way to do it is through NIO (I know about the lack of documentation on this abstraction) but you can base on NIO driver that is used to install default console on MQX system. I can try to explain it deeper if you desire so.

For now, I hope this can help you!

Best Regards,

Isaac

----------------------------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

----------------------------------------------------------------------------------------------------------------------------------------

1,645 Views
mmoncigoli
Contributor III

Hello Isaac,

Many many thanks for the explanation you gave me about point 1 of my email. Now it works perfectly! I also tried, in the same lwip echo example, to use both UART3 and UART0 following your example and it worked without any problem.

When I initially tried using UART_DRV_SendDataBlocking(..) it crashed because, looking at your good code example, I didn't create and initialized the interrupt handler for the UART3 I tried to use (with UART_DRV_IRQHandler(3) and OSA_InstallIntHandler(..)).

That being said, I would like to understand how to implement peripheral code library (point 2 of my email of Feb 3rd). For this reason, following your previous reply, I would like to ask you:

a) In what KSDK_1.3.0 example with MQX I can find a NIO UART code implementation?

b) Can I implement UARTs communication using different MQX driver code (compared to NIO) which currently has description documentation available? Can I use, in my environment described above, "Formatted I/O Library", for example? (This is actually the question of point 2 of my post of Feb 3rd).

Thanks so much for your precious help

0 Kudos
1,645 Views
isaacavila
NXP Employee
NXP Employee

Hello,

That's good to know that you could use UART instances and KSDK's drivers in your MQX project.

Unfortunatelly, there is no example for NIO UART implementation, there are only folders that contain source and header files that show you how it should be implemented (nio_mem, nio_serial, nio_tty). They are located at: <KSDK_1_3_PATH>\rtos\mqx\mqx\source\nio\drivers, but there are not examples projects.

We hope to create a basic NIO document that could show you how to setup up your driver and how it works, but it is still planned and hope to be finished soon.

Sorry for this inconvenience!

Best Regards,

Isaac Avila

----------------------------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

----------------------------------------------------------------------------------------------------------------------------------------

0 Kudos
1,645 Views
mmoncigoli
Contributor III

Thanks a lot Isaac for your reply! Unfortunately I guessed I would have received that answer.

How about point b) of my previous post? Can I use "Formatted I/O Library" to implement serial communication on my system?

Thanks so much

0 Kudos
1,645 Views
isaacavila
NXP Employee
NXP Employee

Hello,

I am not 100% sure but I think the only way to do it, is to install a NIO driver like it was installed for default console, as i previously said, it is installed in init_bsp.c file.

I will make an update until a further analysis would be made.

I hope this can help,

Best Regards,

Isaac

0 Kudos
1,645 Views
mmoncigoli
Contributor III

Thanks a lot Isaac!

0 Kudos
1,645 Views
isaacavila
NXP Employee
NXP Employee

Hello,

Here is a basic guide that explains the way to create you own NIO driver in MQX for KSDK. Installing NIO driver in MQX for KSDK

I hope you can find it helpful!

Regards

Isaac

1,645 Views
isaacavila
NXP Employee
NXP Employee

Hello,

For formatted I/O functions, the MQX_STDLIB library is given (<KSDK_1_3_PATH>\rtos\mqx\mqx_stdlib), and basically, NIO drivers use these function in order to access to read, write functions.

I almost finish the document to guide you through NIO installation. i will let you know as soon as it is available.

Best Regards,

Isaac Avila

1,645 Views
mmoncigoli
Contributor III

Thanks a lot Isaac, I will check it and, if it works, I'll set this discussion as "Answered"

0 Kudos