10 years, 4 months ago.

cc3000_hostdriver_mbedsocket combined with SDFileSystem not working

Hi mbed-friends,

If I only use SDFileSystem or cc3000_hostdriver_mbedsocket in a project, they work, so the configurations seems right for each. But if I use them together in the same project it doesn't work. It does not matter if they share the same SPI bus or use different SPI busses.

I use a Adafruit Wifi Shield (cc3000) which also has an SD card slot on it used on SPI1. The platform is an Seeed Arch Max, which also has an SD card slot on SPI2. I tested cc3000_hostdriver_mbedsocket in together with either SD card slot (SPI1 or SPI2).

Has anybody been successful to let both libraries work in one project? Any help is much appreciated. I will also try to print more information to debug it.

/* mbed Microcontroller Library
 * Copyright (c) 2006-2013 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "mbed.h"
#include "SDFileSystem.h"
#include "cc3000.h"
#include "main.h"
#include "NTPClient.h"

#define CC3000_IRQ   D3
#define CC3000_EN    D5
#define CC3000_CS    D10
#define CC3000_MOSI  D11
#define CC3000_MISO  D12
#define CC3000_SCLK  D13

#define SD_CS           D4 
#define SD_MOSI         D11
#define SD_MISO         D12
#define SD_SCK          D13

#define SSID         "Prakjaroen"
#define PHRASE       "A4B5C6D7E8F9"
#define SECURITY     WPA2

#define IP           "192.168.2.165"
#define MASK         "255.255.255.0"
#define GW           "192.168.2.1"
#define DHCP         0
#define STATIC_IP    1
#define IP_INIT      DHCP

//SDFileSystem sd(SD_MOSI, SD_MISO, SD_SCK, SD_CS, "sd"); // the pinout on the mbed

using namespace mbed_cc3000;

// cc3000 wifi(irq, en, cs, SPI(mosi, miso, sclk), SSID, PHRASE, WPA2, false);
// +5V  VCC     5V               +5V
// GND  GND     GND              GND
// D8   INT     Interrupt        PA_9
// D9   EN      WiFi Enable      PC_7
// D10  CS      SPI Chip Select  PB_6
// D11  MOSI    SPI MOSI         PA_7
// D12  MISO    SPI MISO         PA_6
// D13  SCK     SPI Clock        PA_5



/* cc3000 module declaration specific for user's board. Check also init() */
#if (MY_BOARD == WIGO)
cc3000 wifi(PTA16, PTA13, PTD0, SPI(PTD2, PTD3, PTC5), SSID, PHRASE, SECURITY, false);
Serial pc(USBTX, USBRX);
#elif (MY_BOARD == WIFI_DIPCORTEX)
cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37), SSID, PHRASE, SECURITY, false);
Serial pc(UART_TX, UART_RX);
#elif (MY_BOARD == MBED_BOARD_EXAMPLE)
cc3000 wifi(CC3000_IRQ, CC3000_EN, CC3000_CS, SPI(CC3000_MOSI, CC3000_MISO, CC3000_SCLK), SSID, PHRASE, SECURITY, false); //SparkFun Board on Arduino pin definitions
//Serial pc(USBTX, USBRX);
//    Serial pc(P4_28, P4_29);

//SDFileSystem sd(SD_MOSI, SD_MISO, SD_SCK, SD_CS, "sd"); // the pinout on the mbed

    #if defined TARGET_NUCLEO_F411RE
    Serial pc(USBTX, USBRX);
    #elif defined(TARGET_ARCH_PRO)
    Serial pc(P4_28, P4_29);
    #elif defined(TARGET_ARCH_MAX)
    Serial pc(USBTX, USBRX);
    Serial bt(D6, D7);  // tx, rx, Arch Max
    #elif defined(TARGET_LPC4337)
    Serial pc(P2_10, P2_11); // TX, RX
    #else
    Serial pc(USBTX, USBRX);
    #endif


#else

#endif

SDFileSystem sd(SD_MOSI, SD_MISO, SD_SCK, SD_CS, "sd"); // the pinout on the mbed

// array to store RM parameters from EEPROM
unsigned char cRMParamsFromEeprom[128];

// array to store MAC address from EEPROM
unsigned char cMacFromEeprom[6];

/**
 *  \brief NTP client demo
 *  \param  none
 *  \return int
 */
int main() {
    uint8_t firmware_ver[2];
    signed char mac_status = -1;
    unsigned char FW_status = 1;

    init(); /* board dependent init */
    pc.baud(230400);
    bt.baud(9600);

    printf("\r\nCombining cc3000 and SDFileSystem on same or different SPI bus.\r\n");

    printf("Target   : ");
#if defined TARGET_NUCLEO_F411RE
    printf("NUCLEO F411RE\r\n");
#elif defined(TARGET_ARCH_PRO)
    printf("Seeed Arch PRO\r\n");
#elif defined(TARGET_ARCH_MAX)
    printf("Seeed Arch Max\r\n");
#elif defined(TARGET_LPC4337)
    printf("LPC4337\r\n");
#else
    printf("Unknown\r\n");
#endif

    printf("CPU Clock: %3.3f MHz\r\n", ((float)SystemCoreClock/1000000.0));

    printf("MAC      : ");
    char mac_board[6];
    mbed_mac_address(mac_board);
    for(int i=0; i<6;i++) {
        printf("%02X", mac_board[i]);
        if (i < 5) printf(":");
    }
    printf("\r\n");


#if (IP_INIT == STATIC_IP)
    printf("Initialize the interface with a static IP address...\r\n");
    wifi.init(IP, MASK, GW);
#else
    printf("Initialize the interface with DHCP...\r\n");
    wifi.init();
#endif /* STM32F10X_CL */


    // SD Card:
    printf("SD Card test\r\n");
    mkdir("/sd/mydir", 0777);
    printf("Directory /sd/mydir created\r\n");
    
    FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
    if(fp == NULL) {
        printf("Could not open file /sd/mydir/sdtest.txt for write\r\n");
    }
    fprintf(fp, "The quick brown fox jumps over the lazy dog.\r\n");
    fclose(fp); 
    printf("File /sd/mydir/sdtest.txt written!\r\n");


// CC3000:

    printf("CC3000 test\r\n");
    printf("Read from cc3000...\r\n");
        
    // Read Firmware Version and MAC Address
    FW_status = wifi.read_sp_version(firmware_ver);   // read actual Firmware version
    if(FW_status == 0){
        printf("Firmware version: %d.%d\r\n", firmware_ver[0], firmware_ver[1]);
        mac_status = wifi.get_mac_address(cMacFromEeprom);
        if(mac_status == 0){
            printf("MAC address     : ");
            for(int i = 0; i < 6; i++) {
                printf("%02X", cMacFromEeprom[i]);
                if (i < 5) printf(":");
            }
            printf("\r\n");
        }
    } else {
        printf("ERROR: CC3000 not found - check connections !\r\n");
    }

    // WiFi parameters
    printf("WiFi parameters:\r\n");
    printf("SSID            : %s\r\n", SSID);
    printf("Phrase          : %s\r\n", PHRASE);
    printf("Security        : ");
    if (SECURITY == 0) printf("NONE");
    if (SECURITY == 1) printf("WEP");
    if (SECURITY == 2) printf("WPA");
    if (SECURITY == 3) printf("WPA2");
    printf("\r\n");
    
    // Connect to WiFi
    printf("Bring the interface up...\r\n");
    if (wifi.connect(30000) == -1) {
        printf("ERROR: Failed to connect. Please verify connection details and try again.\r\n");
    }
    char *ip     = wifi.getIPAddress();
    char *mask   = wifi.getNetworkMask();
    char *gate   = wifi.getGateway();
    char *mac    = wifi.getMACAddress();
    bool conn    = wifi.is_connected();
    bool dhcp    = wifi.is_dhcp_configured();
    bool enabled = wifi.is_enabled();
    
    printf("IP              : %s\r\n", ip);
    printf("Netmask         : %s\r\n", mask);
    printf("Gateway         : %s\r\n", gate);
    printf("MAC             : %s\r\n", mac);
    printf("Connected       : %d\r\n", conn);
    printf("DHCP            : %d\r\n", dhcp);
    printf("Enabled         : %d\r\n", enabled);

  
    // Read time from server
    NTPClient ntp_client;
    // NTP Server Parameters
    char* domain_name = "0.nl.pool.ntp.org";
    int   port_number = 123;
    time_t ct_time;
    char time_buffer[80];    
    char time_buffer_old[80];    

    printf("Reading time: ");
    if (ntp_client.setTime(domain_name, port_number) == 0) {
        printf("Passed.\r\n");
        ct_time = time(NULL) + 7200; // Summer time - Convert to Europe/Amsterdam Time
        set_time(ct_time);
        strftime(time_buffer, 80, "%a %d-%b-%Y %T", localtime(&ct_time));
        printf("Time            : %s\r\n", time_buffer);
    } else {
        printf("FAILED!\r\n");
    }

    strcpy(time_buffer_old, "Dummy value");
    while(1) {
        ct_time = time(NULL);
        strftime(time_buffer, 80, "%a %d-%b-%Y %T", localtime(&ct_time));
        if (strcmp(time_buffer, time_buffer_old) != 0) {
            strcpy(time_buffer_old, time_buffer);
            printf("%s\r\n", time_buffer);
            bt.printf("%s\r\n", time_buffer);
            strftime(time_buffer, 80, "%T", localtime(&ct_time));
            // 21:00:00
            if ((time_buffer[3] == '0') && (time_buffer[4] == '0') && 
                (time_buffer[6] == '0') && (time_buffer[7] == '0')) {
                // Sync once per hour
                printf("Reading time: ");
                if (ntp_client.setTime(domain_name, port_number) == 0) {
                    printf("Passed.\r\n");
                    ct_time = time(NULL) + 7200; // Summer time - Convert to Europe/Amsterdam Time
                    set_time(ct_time);
                    strftime(time_buffer, 80, "%a %d-%b-%Y %T", localtime(&ct_time));
                } else {
                    printf("FAILED!\r\n");
                }
            }
        }
        wait(0.1);
    }
}


Hangs here:

Target   : Seeed Arch Max
CPU Clock: 168.000 MHz
MAC      : 00:02:F7:F0:00:00
Initialize the interface with DHCP...

I haven't tested this. We know cc3000 is sensitive to timing so there might be a problem there (my initial guess). If you pinpoint the problem, please share.

posted by Martin Kojtal 02 Sep 2015

Thanks Martin. Time is limiting me at the moment, hence I postponed narrowing down the problem, a bit. I would best start trying other platforms.

posted by Jack Berkhout 18 Sep 2015
Be the first to answer this question.