2017-06-05 04:59 AM
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 callbackprvxMBTCPPortReceive(...)
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
2017-06-05 02:03 PM
A partial rewrite of the library, completely removing the MailBox, fixed the problem.
Kinda brute force. Modbus requests are processed rightaway once the TCP Stack and
This solution has a smaller memeory footprint and runs ok @1ms.
Maximum latency has been measured over a couple of hours.
If somebody is intereted mail me.
2017-09-28 07:14 AM
Hi,
I am also trying to implement Modbus server. I have a problem with sys_mbox_post( xMailBox, &eMailBoxEvent ); because it never ends when data is received. I am interested your solution. Can you share it?