AnsweredAssumed Answered

Mailbox Message disappears

Question asked by ferrario.fabio.001 on Jun 5, 2017
Latest reply on Sep 28, 2017 by gesieniec.lukasz

I am trying to implement a Modbus sever on the STM32f746 Nucleo.

 

- LWIP is running

- Cache is enabled

- MPU is protecting 2 areas as non cacheable, one for the ethernet descriptors, the other one for my variables

- Socket Server is running on port 80

 

I added the Freemodbus1.5 library files to the project and started a standard Modbus Task.

 

void vMBServerTask( void *arg )
{
    eMBErrorCode    xStatus; 
    portTickType    xTicks;
    pppSetAuth( PPPAUTHTYPE_NONE, NULL, NULL );   // TO DO clean code and remove this
  
    for(;;)
    {
                if(eMBTCPInit( MB_TCP_PORT_USE_DEFAULT ) != MB_ENOERR )
                {
                     printf("can't initalize modbus stack!\r\n" );
                }
                else if( eMBEnable(  ) != MB_ENOERR )
                {
                     printf("can't enable modbus stack!\r\n" );
                }
                else
                {
                    eMBEventType eEvent=EV_READY;
                    xMBPortEventPost(eEvent);   //Just a saty test
                    do
                    {                
                          /* Application code here. */
                          xStatus = eMBPoll();

                          /* Update input registers with the current system  tick. */
                          xTicks = xTaskGetTickCount(  );

                          /* Note: little endian stuff */
                          usRegInputBuf[0] = ( USHORT ) ( xTicks );
                          usRegInputBuf[1] = ( USHORT ) ( xTicks >> 16UL );
                    }
                    while( ( xStatus == MB_ENOERR )/* && ( ePPPThrCtlCur == CONNECTED ) */);
                    ( void )eMBDisable(  );
                    ( void )eMBClose(  );
                }
            }
}

 

Code compliles fine but in portvent.c where I needed to update the call

  xMailBox = sys_mbox_new(  );    //this call is outdated

  with

    if (sys_mbox_new( &xMailBox, 8)!=ERR_OK)
    {
        printf ("Failed to init Mailbox");
        return (FALSE);
    }
    else
    {
        printf ("Mailbox Init OK");
        return (TRUE);
    }

 

Modbus connection works fine.

The issue arises when sending a MODBUS request
1- The stack works fine, connection is accepted and the callback

 

prvxMBTCPPortReceive(...)

 

is called when I request data from my pc.

 

This funciton  in turn calls

sys_mbox_post( xMailBox, &eMailBoxEvent );

that shows no problems and returns osOK.

 

Now the task polls the Mailbox

uiTimeSpent = sys_arch_mbox_fetch( xMailBox, &peMailBoxEvent, MB_POLL_CYCLETIME );

returns a timeout, so no messages. The posted message apparently disappeared making my efforts nonsense.

 

I am working with TRUE Studio.

 

Hope somebody can help me..

 

Fabio

Outcomes