This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Combining fatSD from RTOS & pressure_bmp180 examples for EK-TM4C123GXL

Other Parts Discussed in Thread: EK-TM4C123GXL

I keep trying to record data from the  Sensor Hub Booster Pack into an SD card, for this reason i would really like to combine those examples. 

What i tried is to put the code from the pressure_bmp180.c into de fatSD example from RTOS.

So the thing is that I could call the funcions to use the BPM180 APIs into the fatSD example, i just had to erase the ROM berore every function and it buids and shows no errors, ¡BUT IT DOSENT WORK!.

Then I runed it step by step in the disassembly window and found the line when it brokes. That line is in the initBMP180 API when the code gets there it just show no more lines in the disassembly window.

Any advice is helpful.

My  host is windows 7 

 Using the EK-TM4C123GXL and CCS_6.1.2.00015.

  • Hello Frank,

    Did you add the "sensorlib.lib" file to the SD card project?

    Thanks,
    Sai
  • Hi Sai,

    Yes I did, actually I tried to keep all the propertis from the pressure example.

    I also added driverlib.lib

    Thanks.
  • So the thing is that I could call the funcions to use the BPM180 APIs into the fatSD example, i just had to erase the ROM berore every function and it buids and shows no errors, ¡BUT IT DOSENT WORK!.

    Then I runed it step by step in the disassembly window and found the line when it brokes. That line is in the initBMP180 API when the code gets there it just show no more lines in the disassembly window.

    Rather sounds like a project configuration issue. Perhaps the stack is far too small.

    Maybe within RTOS - which raises the level of complexity "slightly".

  • Hi f. m.

    In Properties/ARM linker/Basic Options the original numbers where:

    1024 for the pressure example
    512 for the fatSD example

    So I changed it to 1024 in the fatSD example.

    ¿You think that is the problem? ¿Do i had to keep it in 512?

    Thanks in regard.
  • 1024 for the pressure example
    512 for the fatSD example

    So I changed it to 1024 in the fatSD example.

    ¿You think that is the problem? ¿Do i had to keep it in 512?

    It's not that simple. Determining the required stack size is "planning for the worst case", and depends (besides the ABI) heavily on the complexity of your project / source code.

    I didn't use the fatSD (most propably Chan's fatFS) on the TM4C, nor your RTOS.

    But I have projects based on fatFS and "larger" newlib implementations (printf()), requiring about 2 .. 4 kByte of stack.

    Don't ask me about TI-RTOS - never tried it. Usually, these RTOS implementation use tasks, which have their own stacks ...

  • ¿So what is you recomendation?

    Because i tried to use Chan´s fatFS but neither is simple, I could not even take away the error messages of unresolved simbols for the basic APIs like fmount or fwrite.

    Your opinion is very valuable. Thanks.
  • Because i tried to use Chan´s fatFS but neither is simple, I could not even take away the error messages of unresolved simbols for the basic APIs like fmount or fwrite.

    I didn't mean to switch over to fatFS, just voiced the assumption that fatSD is probably based on fatFS. (A "plain" fatFS requires you to implement the low-level driver routines ...). If you have a working fatSD example, stick to it.

    As for the stack size, it is still an assumption that this is the cause of your problem. But effects like you described when debugging point to a thrashed stack context. When I find the stack of my project too small, I usually double it's size. If that works, you can still reduce it's size afterwards.

    BTW, my favourite toolchain is notorious for setting a tiny default stack size (128 byte). Remember, the stack is always used in (32-bit) words.

  • I´ve been doubling the size, but the code is still breaking in the same line.
  • I´ve been doubling the size, but the code is still breaking in the same line.

    Have you tried to examine the reason for the fault with a debugger ? Here is a good guide.

    Albeit that might be useless if the stack is still too small, and the cause is "random" stack content.

    Alternatively, try to pin down the assembler instruction that fails (with context, i.e. preceeding instructions). Perhaps an access to non-existing or not enabled periphery.

  • Hello Frank,

    Which RTOS are you using? Note that the libraries in TivaWare are not re-entrant. So while calling the APIs from TivaWare, the application should make sure that proper safeguards are taken. TI-RTOS provides a middle layer for the peripheral driver library of TivaWare that allows certain drivers to be re-entrant. But other libraries like USB, Graphics and Sensor Library should still be safe guarded by the application.

    Is there a requirement to use RTOS or the fatSD example? If all you want to do is to store the sensor data to an SD card, then the example "sd_card" in the folder "./examples/boards/dk-tm4c123g" of TivaWare can be used. It does not use an RTOS.

    Thanks,
    Sai
  • But you know which things di i have to change to make it work in the EK-TM4C123G ?????
  • And no, there is no need to use RTOS, the reason that make me use it, is because its the first code that allows me to write on the SD whit the EK-TM4C123G and CCSv6.
    Mi version of RTOS is: tirtos_tivac_2_16_00_08
    I am going to try whit the example of Tiva ware.
  • Hello Frank,

    It is very hard with the information available to figure out why the MCU faults, especially as an RTOS is being used.

    If you think you don't need to use RTOS for this project then I would recommend using the non-RTOS version of the SD card example, from TivaWare, and add the "pressure_bmp180" example to it.

    If you want to use the RTOS, then the possible culprits to my mind are:
    * SysTick Interrupt. I hope your application does not use this peripheral, as most likely the RTOS would be using the SysTick as a heart beat.
    * One of the other two Interrupts (I2C3 and WTIMER5) might be messing up the context-switch. I2C has an RTOS safe version of the driver. Are you using it? Timer does not have this, so you have to be careful while using it. TI-RTOS has other resources that can be used instead of the Hardware timers.
    * How is the code for "pressure_bmp180" added to the fatSD application? Is it added as a seperate task? If yes, then is the stack allocated to this specific task (not the system level stack) sufficient? You could use the "ROV" utility of TI-RTOS to get some debug information on the Stack usage of each task.

    There could be other issues too, but these would be the first concerns I would address.

    If this is the first time you are using TI-RTOS or RTOS in general, I would recommend that you add an application like "blinky" to the existing TI-RTOS project as a separate task and make it work. Then you could break down the "pressure_bmp180" functionality into smaller parts and add them to the RTOS project and test if the project works at each stage.

    Thanks,
    Sai
  • I was giving the sd card example a try and it seems to work, i just modify the pins of the SPI on the mmc-dk-tm4c123g for the ones of the SPI0 at the EK.

    The point is that the program shows no errors, but it is not creating the files as it should.

    ¿Do you know what am i doing wrong??
  • Hello Frank,

    SSI0 cannot be accessed through the BoosterPack. How are you connecting the SD card to the EK-TM4C123GXL? Are you uisng a BoosterPack? If so, which one?

    In the file "mmc-dk-tm4c123g.c" you will have to update the SSI peripheral and the GPIO Port and GPIO pin for each function of the SSI, like SDC_SSI_CLK, SDC_SSI_TX etc.

    Thanks,
    Sai
  • I´m using an sparkfun socket and conecting it whit jumpers, for me is really important to use the SSI0.

    I´ve been working on it. and it seems to be communicating whit the card, but when i call fmount it returns FR_INVALID_DRIVE, i have read elm chan page a lot of times ang get no ansewers. ¿Can you help me at this point please?
  • Hello Frank,

    Why is it important to use SSI0? Why can't you use some other SSI instance, like SSI2, whose GPIOs are available on the Boosterpack and conform to the BoosterPack standard? This way you could use a Boosterpack in the future if required.

    Can you show the connections (that you are using) between the TM4C device and the SD card socket?

    The error "FR_INVALID_DRIVE" most likely is generated if the parameter "vol" is invalid. Please check the example "sd_card" in the folder "./examples/boards/dk-tm4c123g/sd_card" to see how fatFS APIs should be called.

    Thanks,
    Sai
  • Its important to use SSI0 because its going to be plugged to another system that already connects the socket to that port.
    I couldnt put a picture, but my connections are
    PA2--------CLK
    PA3--------FSS or CS
    PA4--------RX or MISO
    PA5--------TX or MOSI

    And the obvious connections to Vdd and GND

    ¿Do you know how to declare the parameter vol?
    I tried to check what you suggested me, but i didnt found something that explains the way to call the APIs (only the elm chan page)
    Thanks.
  • For now im testing this code just to verify the APIs are working as they should.

    // Includes ------------------------------------------------------------------------------------------
    #include <stdint.h>
    #include <stdbool.h>
    #include <string.h>

    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"

    #include "driverlib/fpu.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom.h"
    #include "driverlib/rom_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/systick.h"
    #include "driverlib/uart.h"

    #include "utils/uartstdio.h"

    #include "ff.h"
    #include "diskio.h"


    // Defines -------------------------------------------------------------------------------------------
    #define LED_RED GPIO_PIN_1
    #define LED_BLUE GPIO_PIN_2
    #define LED_GREEN GPIO_PIN_3




    // Variables -----------------------------------------------------------------------------------------
    FATFS sdVolume; // FatFs work area needed for each volume
    FIL logfile; // File object needed for each open file
    uint16_t fp; // Used for sizeof




    // Functions -----------------------------------------------------------------------------------------
    void ConfigureUART(void){

    // Enable the peripherals used by UART
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    // Set GPIO A0 and A1 as UART pins.
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    // Configure UART clock using UART utils
    UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    UARTStdioConfig(0, 115200, 16000000);
    }


    void FloatToPrint(float floatValue, uint32_t splitValue[2]){
    int32_t i32IntegerPart;
    int32_t i32FractionPart;

    i32IntegerPart = (int32_t) floatValue;
    i32FractionPart = (int32_t) (floatValue * 1000.0f);
    i32FractionPart = i32FractionPart - (i32IntegerPart * 1000);
    if(i32FractionPart < 0)
    {
    i32FractionPart *= -1;
    }

    splitValue[0] = i32IntegerPart;
    splitValue[1] = i32FractionPart;
    }

    void fatalError(char errMessage[]){
    UARTprintf(errMessage);
    ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, LED_RED);
    while(1);
    }



    // Main ----------------------------------------------------------------------------------------------
    int main(void){

    // Enable lazy stacking
    ROM_FPULazyStackingEnable();

    // Set the system clock to run at 40Mhz off PLL with external crystal as reference.
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);

    // Initialize the UART and write status.
    ConfigureUART();
    UARTprintf("SD Example\n");

    // Enable LEDs
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_RED|LED_BLUE|LED_GREEN);
    ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, 0);

    // Start SD Card Stuff - Borrowed from examples

    // Initialize result variable
    UINT bw;

    // Mount the SD Card
    switch(f_mount(&sdVolume, "", 0)){
    case FR_OK:
    UARTprintf("SD Card mounted successfully\n");
    break;
    case FR_INVALID_DRIVE:
    fatalError("ERROR: Invalid drive number\n");
    break;
    case FR_DISK_ERR:
    fatalError("ERROR: DiskIO error - Check hardware!\n");
    break;
    case FR_NOT_READY:
    fatalError("ERROR: Medium removal or disk_initialize\n");
    break;
    case FR_NO_FILESYSTEM:
    fatalError("ERROR: No valid FAT volume on drive\n");
    break;
    default:
    fatalError("ERROR: Something went wrong\n");
    break;
    }

    if(f_open(&logfile, "newfile.txt", FA_WRITE | FA_OPEN_ALWAYS) == FR_OK) { // Open file - If nonexistent, create
    //f_lseek(&logfile, logfile.fsize); // Move forward by filesize; logfile.fsize+1 is not needed in this application
    f_write(&logfile, "Parachutes\n", 11, &bw); // Append word
    UARTprintf("File size is \n"); // Print size
    f_close(&logfile); // Close the file
    if (bw == 11) {
    ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, LED_GREEN); // Lights green LED if data written well
    }
    }

    // Wait Forever
    while(1);

    }
  • Frank Gonzalez said:

    ¿Do you know how to declare the parameter vol?
    I tried to check what you suggested me, but i didnt found something that explains the way to call the APIs (only the elm chan page)

    I got the following code from the example "sd_card" in the folder "./examples/boards/dk-tm4c123g/sd_card" of TivaWare. This is the example I asked you to refer in my earlier post.

        //
        // Mount the file system, using logical disk 0.
        //
        iFResult = f_mount(0, &g_sFatFs);
        if(iFResult != FR_OK)
        {
            UARTprintf("f_mount error: %s\n", StringFromFResult(iFResult));
            return(1);
        }

    The variable g_sFatFs is declared as below, in the same example:

    static FATFS g_sFatFs;

    Also in the future, please use the Syntaxhighlighter. It can be accessed by clicking on "Use rich formatting" link, when the reply button is clicked, and then clicking on the icon Insert code using Syntaxhighlighter. It's very hard to read code when it is in plain text.

    Thanks,

    Sai