Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

PSoC™ 6 Forum Discussions

StLe_4753786
Level 3
First like received
Level 3

Hi,

Could anyone point me to an example showing PSoC6 with internet connectivity using a GSM modem on an UART port (e.g. SIMCom or Quectel modem)?  I assume it should make use of FreeRTOS and LwIP Point-to-Point (PPP) stack.  Thanks!

Best Regards,

Stan

0 Likes
1 Solution
StLe_4753786
Level 3
First like received
Level 3

Hi Rakshith,

I have found a workable solution in FreeRTOSConfig.h. 

If I want to use:

#define configUSE_TICKLESS_IDLE 2

then I would need to add:

#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 200

The default configEXPECTED_IDLE_TIME_BEFORE_SLEEP is 2, which is too aggressive on my setup.  If I use a value of 100, it would fail intermittently (such as fail to connect to PPP, or fail to download a file using the connection).  Using 200 seems to be stable.

If I have to perform a debug session (e.g. step through code, pause execution etc), then I would have to set:

#define configUSE_TICKLESS_IDLE 0

otherwise, the assertion in tasks.c happens frequently.

Thanks for your help!

Best Regards.

Stan

View solution in original post

11 Replies
Rakshith
Moderator
Moderator 1000 replies posted 750 replies posted 500 replies posted
Moderator

Hi StLe_4753786​,

Unfortunately we do not have an example where a PSoC 6 is interfaced with a GSM module. Can you please let me know which GSM module you are using? If it uses AT commands then you should be able to interface it using UART. Please check these threads and let me know if they help:

In Application Programming with GSM and External EEPROM

UART RX INTERRUPT PROGRAM FOR CY8CKIT 49

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes
StLe_4753786
Level 3
First like received
Level 3

Hi Rakshith,

I'm using SIMCom 7600G modem.  I'm able to exchange AT commands with it when UART is in non-interrupt mode.   This part is quite reliable.

The complexity comes when I compiled LwIP (PPP files) and enabled UART interrupt mode.  This is necessary, because network connectivity is basically asynchronous.  Now I'm seeing that there is a high chance of failure for the modem to enter PPP mode.  The symptoms are UART data corruption or the receiving task was not executed.  (It's supposed to receive packets in a queue, placed by the UART ISR).

That's why I thought of looking for a working example.

Best Regards,

Stan

0 Likes
Rakshith
Moderator
Moderator 1000 replies posted 750 replies posted 500 replies posted
Moderator

Hi Stan,

Can you please let me know if you are using mbed or AnyCloud in your application?

You could enable the debug prints to try and debug the issue by using the following defines in lwipopts.h:

#define PPP_THREAD_NAME "ppp"

#define PPP_THREAD_STACKSIZE 200

#define PPP_THREAD_PRIO 2

#define LWIP_DEBUG 1

#define PPP_DEBUG LWIP_DBG_ON

PPP packets should start and end with 0x7E. Can you please let me know if you are able to observe this? If not, then as you have mentioned it might be due to interrupt priority that is set for UART interrupt. Can you increase the priority in that case and let me know if that works?

Thanks and Regards,

Rakshith

Thanks and Regards,
Rakshith M B
0 Likes
StLe_4753786
Level 3
First like received
Level 3

Hi Rakshith,

I'm using FreeRTOS (WIFI BT Prototyping Kit, MTB). I started from "AnyCloud Secure TCP Client" example.  I have been able to log LwIP and PPP transactions using lwipopts.h. 

When the problem occurs, PPP would complain that the input packets received from the modem are corrupted.  I have used UART ISR priority =5, and the task waiting for the queued packets, has priority =4.  I have tried increasing the task priority but did not help.  By freak chance, I have managed to see success in getting PPP to work, but it's very rare.  It appears that the code is basically ok, but something else it messing up the UART ISR or threading.

Best Regards,

Stan

0 Likes
Rakshith
Moderator
Moderator 1000 replies posted 750 replies posted 500 replies posted
Moderator

Hi Stan,

This seems to be a scheduling and ISR priority issue. Can you please let me know the value of configMAX_SYSCALL_INTERRUPT_PRIORITY that you have set?

Also, are FreeRTOS APIs called from the ISR?

Can you increase the priority of the UART interrupt to be greater than configMAX_SYSCALL_INTERRUPT_PRIORITY and let me know if this helps?

You can find more information regarding the macro in this link - FreeRTOS - The Free RTOS configuration constants and configuration options - FREE Open Source RTOS f...

Thanks and Regards,

Rakshith

Thanks and Regards,
Rakshith M B
0 Likes
StLe_4753786
Level 3
First like received
Level 3

Hi Rakshith,

My FreeRTOSConfig.h has these defined:

        #define configPRIO_BITS             __NVIC_PRIO_BITS

        #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY    5

        #define configMAX_SYSCALL_INTERRUPT_PRIORITY    ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )

The value of configMAX_SYSCALL_INTERRUPT_PRIORITY works out to be 160, which is way too high to try exceeding in my UART interrupt priority.  If I try something like 161, there will be an assertion in vPortValidateInterruptPriority()  CM4F/port.c

My UART ISR is calling cy_rtos_put_queue() which is implemented using FreeRTOS APIs.  I have attached my FreeRTOSConfig.h (essentially the same as the one in "AnyCloud Secure TCP Client" example).  Also, some key functions in my modem uart code.  What do you think could be wrong?

Best Regards,

Stan

0 Likes
Rakshith
Moderator
Moderator 1000 replies posted 750 replies posted 500 replies posted
Moderator

Hi Stan,

As __NVIC_PRIO_BITS is 3 in the case of PSoC 6, only the first three bits are considered (bit7 - bit5). So, in your case the first three bits of configMAX_SYSCALL_INTERRUPT_PRIORITY are 101 which is 5 and hence the UART interrupt must have a higher interrupt than that. Can you please set the interrupt priority accordingly and let me know if that helped?

Thanks and Regards,

Rakshith

Thanks and Regards,
Rakshith M B
0 Likes
StLe_4753786
Level 3
First like received
Level 3

Hi Rakshith,

I have tried setting UART interrupt to 6 (it was 5 previously), and it seemed to work a little better.  I have gotten a higher chance of success in PPP connection and in my ability to download a file using the connection.  However, I'm seeing an assertion in the IDLE thread (tasks.c line 2506).  (I have also seen this assertion intermittently prior to making this code change). 

My FreeRTOSConfig.h currently has configUSE_TICKLESS_IDLE set to 2 (the default value).  What do you think could be wrong?

===================== libs/freertos/Source/tasks.c ==============

#if ( configUSE_TICKLESS_IDLE != 0 )

void vTaskStepTick( const TickType_t xTicksToJump )

{

/* Correct the tick count value after a period during which the tick

was suppressed.  Note this does *not* call the tick hook function for

each stepped tick. */

configASSERT( ( xTickCount + xTicksToJump ) <= xNextTaskUnblockTime );         // <-- this line asserts

xTickCount += xTicksToJump;

traceINCREASE_TICK_COUNT( xTicksToJump );

}

#endif /* configUSE_TICKLESS_IDLE */

# Values read from debugger:

    xTicksToJump = 25450

    xTickCount = 6205

    xNextTaskUnblockTime = 6300

Thanks and Best Regards,

Stan

0 Likes
Rakshith
Moderator
Moderator 1000 replies posted 750 replies posted 500 replies posted
Moderator

Hi Stan,

These discussions might be helpful -

FreeRTOS Tickless Tick Correction Issue - Nordic DevZone

A question or two about tickless support. - FreeRTOS

Can you also check with one of the AnyCloud Code examples with tickless IDLE enabled mainly the FreeRTOSConfig.h? You can find the Code Examples here - Cypress Semiconductor Corporation · GitHub

Hope this helps,

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes
StLe_4753786
Level 3
First like received
Level 3

Hi Rakshith,

I have found a workable solution in FreeRTOSConfig.h. 

If I want to use:

#define configUSE_TICKLESS_IDLE 2

then I would need to add:

#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 200

The default configEXPECTED_IDLE_TIME_BEFORE_SLEEP is 2, which is too aggressive on my setup.  If I use a value of 100, it would fail intermittently (such as fail to connect to PPP, or fail to download a file using the connection).  Using 200 seems to be stable.

If I have to perform a debug session (e.g. step through code, pause execution etc), then I would have to set:

#define configUSE_TICKLESS_IDLE 0

otherwise, the assertion in tasks.c happens frequently.

Thanks for your help!

Best Regards.

Stan

Rakshith
Moderator
Moderator 1000 replies posted 750 replies posted 500 replies posted
Moderator

Hi Stan,

Thank you for sharing your results and observation with the community

Best Regards,

Rakshith

Thanks and Regards,
Rakshith M B
0 Likes