Porting the Gainspan application from MQX 3.7 to MQX 4.0

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

Porting the Gainspan application from MQX 3.7 to MQX 4.0

2,362 Views
ThomNet
Contributor III

Hi,

did anybody ever tried with success (!!) to port the Gainspan WiFi application, which works great with the MQX 3.7 release to MQX 4.0? Is it anyway possible because of the different file structure of the two MQX- releases?

I mailed to Gainspan, but they could not promise, to release a MQX 4.0 patch.

Thanks in advance for all kind of hints or information!

Regards

Thomas

Tags (5)
13 Replies

1,137 Views
Martin_
NXP Employee
NXP Employee

Unfortunately I don't have Gainspan, but I did similar port for Atheros Wi-fi card, so I can give some hints:

In general:

1)backup default MQX 3.7 installation to some different folder

2)install Gainspan patch for MQX 3.7

3)use your favourite compare tool to compare what files the Gainspan patch adds to the MQX and what changes in the source codes it has introduced in the BSP;

keep this list open and try to repeat the changes into MQX 4.0.

There are two differences to be considered - new MQX 4.0 spi driver and gpio driver.

Legacy gpio driver is not enabled by default in user_config.h in MQX 4.0, but it can still be enabled. Wi-fi chips usually use couple of GPIO signals for some functions.

With spi, I would recommend to move on to the new MQX 4.0 spi driver. You need to find the low level functions that Gainspan stack calls when it wishes to send/receive data to/from the wi-fi chip. Change this to make the Gainspan stack calls to the default MQX 4.0 spi driver. Note that MQX 4.0 spi driver keeps chip select signal asserted until fflush(), thus, when wi-fi chip needs chip select negaion, call fflush().

Then you need to port also the demo application(s). Changes applied for AR4100 for your reference on the link below:

https://community.freescale.com/message/318565#318565

0 Kudos

1,137 Views
ThomNet
Contributor III

Hi Martin,


thanks for your answer.


Since I'm having the AR4100 board in my lab, I checked the 3.7 patch on MQX 4.0 with your httpserv applikation and all the changes which you described. I'm using the K60N512- board.


The application hangs in the for routine when the ipcfg_init_device function is called up for the second time for the AR4100 device, i.e it is not returning from that function.


SInce your described application is working, is there anything you can recomment, what and where to check? Do I need to have special jumper settings on either the 4100 board or on my cpu board?


Regards


Thomas

0 Kudos

1,137 Views
Martin_
NXP Employee
NXP Employee

Thomas,

try to decrease the SPI bus speed to 10 Mbits. I'm afraid sometimes 20 Mbits from CPU board via multiple PCI connectors to TWR is too much for signal integrity. That was also somehow connected with the position of TWR-SER in the TWR-ELEV .... with 20 MHz I have the TWR-WIFI-AR4100 in the top position of TWR-ELEV and the TWR-K60N512 just one position below.

there is a low level function Hcd_Init()

c:\Freescale\Freescale_MQX_4_0\mqx\source\io\enet\atheros_wifi\common_src\hcd\spi_hcd.c

about line 996 it tries to read a status register from the wi-fi chip over SPI, for the 1st time after startup. check SPI bus signals on the oscillocope, if everything seems correct. I expect this assert is the place where it goes:

/* NOTE: if this assert fails it suggests that SPI communication with the WIFI device

         * is not functioning. Perhaps the 2 chips are not connected. */

        A_ASSERT(pDCxt->hcd.MaxWriteBufferSpace == EXPECTED_MAX_WRITE_BUFFER_SPACE);

please let me know if you make it work or not.

1,137 Views
ThomNet
Contributor III

Hi Martin,

thanks for your quick answer.

I just checked my application again. I had an SD card inserted into the SD card holder. After unplugging it, it went through the hole init- process ending with the shell, even with 20 MBit. I can see the SSID on my mobile devices!! That's the good news.

The bad news is: I'm not reaching any of the two webservers, neither through the connected LAN nor through WiFi.

I send a ping from my desktop: no reply. It tells me: network not reachable.

Any idea on that?

Regards

Thomas

0 Kudos

1,137 Views
Martin_
NXP Employee
NXP Employee

hmm, are you trying to connect from the same local network ? for example, when web server runs on 192.168.0.200 try to configure your PC to 192.168.0.3 for example ....

1,137 Views
ThomNet
Contributor III

Hi Martin,

I checked my AR 4100 applicatin. It's working just great on the wired LAN as well as on WiFi in adhoc mode. Sorry for the confusion.

I would like to use it with my SD card now. Do you have an idea, how to combine the AR4100 init process and the use of the card?

Regards

Thomas

0 Kudos

1,137 Views
Martin_
NXP Employee
NXP Employee

Perfect !

for SD card, I think you need to check first if there is a conflict in hardware resources (signals) between SD card interface and wi-fi chip interface. AR4100 uses SPI2 signals and 2 GPIOs. Is there one of these signals connected to the SD card too ?

0 Kudos

1,137 Views
ThomNet
Contributor III

Hi Martin,

I have the F120 card up and running with the same magic behaviour: only with power on reset it works well. Do you have any idea, why this happens? Is it a question of timing or resetting the AR4100 hardware?

Also, what I'm planning to do next is, to combine the WiFi application with a DHCP server.

It was working already with my gainspan app.

Now I added the same code to the actual AR4100 app with the result, that the DHCP server is working but the webservers are not working anymore. Here is the code:

Old code, which you know:

for (i = 0; i < n_devices; i++)
{
    params[i] = httpd_default_params(NULL);
    params[i]->af = HTTP_INET_AF;  //IPv4+IPv6, set connection family from config.h

#if RTCSCFG_ENABLE_IP6  

    params[i]->if_scope_id = HTTP_SCOPE_ID;// set interface number here. 0 is any .

#endif

    if (params[i])
    {
        sprintf(indexes[i], "\\index.html", i);
        params[i]->root_dir = (HTTPD_ROOT_DIR_STRUCT*)root_dir;
        params[i]->index_page = indexes[i];
        /*
        ** If there is only one interface listen on any IP address
        ** so address can change in runtime (DHCP etc.)
        */
        if ((i == 0) && (n_devices == 1))
        {
            params[i]->address = INADDR_ANY;
        }
        else
        {
            params[i]->address = ip_addr[i];
        }

#if PSP_MQX_CPU_IS_MCF5223X

        params[i]->max_ses = 1;

#else

        params[i]->max_ses = _RTCS_socket_part_max - 1;

#endif

        server[i] = httpd_init(params[i]);
    }
    HTTPD_SET_PARAM_CGI_TBL(server[i], (HTTPD_CGI_LINK_STRUCT*)cgi_lnk_tbl);

#if HTTPD_SEPARATE_TASK || !HTTPDCFG_POLL_MODE

    printf("Starting http server No.%d on IP %d.%d.%d.%d ...", i, (ip_addr[i]>>24) & 0xFF, (ip_addr[i]>>16) & 0xFF, (ip_addr[i]>>8) & 0xFF, ip_addr[i] & 0xFF);
    error = httpd_server_run(server[i]);
    if (error)
    {
        printf("[FAIL]\n");
    }
    else
    {
        printf("[OK]\n");
    }

#endif

}

  

Here comes the code, I added:


/********************* Starten des DHCP- Servers, 12.5.2013 *******************/

  

   _task_create(0,DHCP_SERVER_TASK,0);

   printf("Der DHCP- Server wurde gestarted ...\n");


finish. The server task you will find behind the while loop


/************************* SD-Card- Task starten ******************************/

   

_task_create(0,TBDS_SDCARD_TASK,0);
printf("SD-Card-Task wurde kreiert!\n");

   

/************************** Hier wird die Shell gestartet *********************/

   

   

   /* Set up Trival File System to server webpages */      

   if ((error = _io_tfs_install("tfs:", tfs_data)) != 0)

   {

  printf("\nTFS install returned: %08x\n", error);

   }

  

/******************************************************************************/

  

   SEC_Initialize();

   _task_create(0, TBDS_IO_TASK, 0); // start io task

   

/*********************** Hier wird die Shell gestartet ************************/

   

#if HTTPD_SEPARATE_TASK || !HTTPDCFG_POLL_MODE
_task_create(0, SHELL_TASK, 0);
_task_block();

#else

printf("Servers polling started.\n")
while (1)
{
    for (i = 0; i < n_devices; i++)
    {
        httpd_server_poll(server[i], 1);
    }
    /* user stuff come here - only non blocking calls */
}

#endif

}

  

/* Security task */

void tbds_io_task(uint_32 temp) {

   while (1) {

  Input_Poll();         // Hier werden die beiden Taster SW1 und SW2 abgefragt, Prototyp in tbds_security_private.h
  cpu_happy_light();    // Aufruf der Steuerfunktion zum Erzeugen einer CPU- Happy_Light
  _time_delay(50);     // Zeitschleife

   }

}

Here comes the DHCP server task:

void dhcpserver_task(uint_32 initial_data)

{

    DHCPSRV_DATA_STRUCT dhcpsrv_data;

    uchar dhcpsrv_options[200];

    _ip_address routers[1];

    uchar_ptr optptr;

    uint_32 error;

    uint_32 optlen;

    error = DHCPSRV_init("DHCP server", 7, 2000); //"DHCP Server", 7, 2000

    if(error != RTCS_OK)

    {

        printf("\nDHCP server initialize returned : %08x\n",error);

        printf("\nFailed to initialize the DHCP server\n");

        _task_destroy(MQX_NULL_TASK_ID);

    }

    printf("\nDHCP Server running...\n");

    /* Fill in the required parameters: */

    /* 192.168.3.1: */

    dhcpsrv_data.SERVERID = 0xC0A80201; //192.168.02.01

    /* 1 hour leases: */

    dhcpsrv_data.LEASE    = 0xFFFFFFFF; // für immer

    /* 255.255.255.0: */

    dhcpsrv_data.MASK  = 0xFFFFFF00; //255.255.255.0

    /* TFTP server address: */

    dhcpsrv_data.SADDR = 0xC0A80201; //192.168.02.01

    _mem_zero(dhcpsrv_data.SNAME,sizeof(dhcpsrv_data.SNAME));

    _mem_zero(dhcpsrv_data.FILE,sizeof(dhcpsrv_data.FILE));

    /* Fill in the options: */

    optptr = dhcpsrv_options;

    optlen = sizeof(dhcpsrv_options);

    /* Default IP TTL: */

    DHCPSRV_option_int8(&optptr,&optlen,23,64);

    /* MTU: */

    DHCPSRV_option_int16(&optptr,&optlen,26,1500);

    /* Renewal time: */

    DHCPSRV_option_int32(&optptr,&optlen,58,3600);

    /* Rebinding time: */

    DHCPSRV_option_int32(&optptr,&optlen,59,5400);

    /* Domain name: */

    DHCPSRV_option_string(&optptr,&optlen,15,"arc.com");

    /* Broadcast address: */

    DHCPSRV_option_addr(&optptr,&optlen,28,0xC0A802ff);

    /* Router list: */

    routers[0] = 0xC0A80201;

//    routers[1] = 0xC0A80305;

//    routers[2] = 0xC0A80306;

    DHCPSRV_option_addrlist( &optptr, &optlen, 3, routers, 0); // 3,3

    DHCPSRV_ippool_add(0xC0A80281, 7, &dhcpsrv_data, dhcpsrv_options, optptr - dhcpsrv_options);

    _task_block();

}


Do I have to integrate the DHCP server initialisation into the for loop?

Regards

Thomas


0 Kudos

1,137 Views
hongtranduc
Contributor II

Hi Thomas,

You don't need to create a separate task for calling DHCPSRV_init and DHCPSRV_ippool_add, you just simply call DHCPSRV_init() then adding ippool by DHCPSRV_ippool_add after that in main thread.

Actually, the DHCPSRV_init will request rtcs to create a separate task including its mutex, in the DHCPSRV_task() internal task function, it already has a infinite loop inside. Then when you add new ippool the DHCPSRV will wait to acquire the mutex then adding requested pool to DHCP's internal structure.

Regards,

-Hong

0 Kudos

1,137 Views
ThomNet
Contributor III

Hi Hong,

thanks for your response.

I changed my DHCP server task to a function and I'm calling it up in the main task right after RTCS is created. The DHCP server is working really well and fast, but my 2 webservers are still gone, see the code:

error = RTCS_create();
if (error != RTCS_OK)
{
    printf("RTCS failed to initialize, error = 0x%X\n", error);
    _task_block();
}
_IP_forward = FALSE;

   

printf ("RTCS created!\n");

   

/********************* Starten des DHCP- Servers, 13.5.2013 *******************/

     dhcpserver();

//   _task_create(0,DHCP_SERVER_TASK,0);

//   printf("Der DHCP- Server wurde gestarted ...\n");

  

/******************************************************************************/   

 
for (i = 0; (i < n_devices) && (n_devices != 0); i++)
{

   .........................


Any other idea?


Regards


Thomas

0 Kudos

1,137 Views
ThomNet
Contributor III

Hi Martin,

everything works with a small constraint. The decicive information came from the mail from Sebastian Irimia, saying, that jumper J12 has to be on the 1-2 position. Mine was on 2-3. And it has a really cool performance.

Here the constraint:

If I make a power up reset with the little switch on the primary edge card, everything works perfect, whether the SD card is inserted or not. If I do a soft reset with the reset button on the CPU board, it reacts like Sebastian is describing: it comes up after a while with the error message error 4AFF and only the LAN webserver is initialized with OK. If I do a power reset again, everything works fine again.

Strange, isn't it?!

May be this information is helpfull for Sebastian as well. I have planned also to check it witk a F120 card. I will let you know, how that works with my application.

Oh, another question: Why do you create 2 webserver, one for LAN and one for WiFi? Wouldn't it be possible, to run both on the same IP address?

Regards

Thomas

0 Kudos

1,137 Views
ThomNet
Contributor III

Hi Martin,

thanks again.

It seems, that it is going to be hardware time. Yes, signals are connected to each other. I will check, what logic signals I will see on the signal pins with a logic analyser.

I will let you know the result and may be a goog solution to separate them with some extra hardware.

Would it be difficult, to change the driver to SPI1 and to rewire some signals to that interface?

Regards

Thomas

0 Kudos

1,137 Views
ThomNet
Contributor III

Martin,

I'm not in my lab anymore, but you are probably right, my PC is running on 192.168.2.x and the K60 LAN webserver ist programmed to 192.168.1.200. So that will be the reason, why they don't talk to each other.

Could you check something else for me: The 4100 connection can work in "managed" and in "adhoc", as in config.h. Could you check in your application, whether it is working in both modes? I like to work my app in adhoc mode.

I will test everything again this evening, when I will be back.

Also, as my web application is running from my SD card, do you have any idea, how I can combine AR4100 plus SD card later. Is this only a matter on how to start the different tasks?

Regards

Thomas

0 Kudos