Skip to main content

Using the EEPROM on LM4F232H5QD using StellarisWare driverlib

NOTE: TI renamed Stellaris LM4F232H5QD to Tiva C Series TM4C123GH6PGE - Both these part numbers refer to the same chip. StellarisWare is now superseded by/renamed to TivaWare 2.0. The LM4F232 USB+CAN Evaluation Kit is now rebranded as Tiva™ C Series TM4C123G USB+CAN Development Kit. This blog post refers to the old StellarisWare (SW-LM3S-9107(Stellarisware).exe) and old CodeComposer Studio (CCS5.2.1.00018_win32) and the old part numbers for the microcontroller chip and the evaluation kit.

If you have an LM4F232H5QD Evaluation Board, here is how to use LM4F232H5QD's on chip EEPROM:
  1. Install the development tools - to know how refer steps 1 to 5 of my previous post. Make sure to use the latest version of StellarisWare - the one for LM3S as well as LM4F. On the date of this post, the latest version was SW-LM3S-9453.exe
  2. Make sure that the file "driverlib-cm4f.lib" exists at "C:\StellarisWare\driverlib\ccs-cm4f\Debug". If it doesn't, here is how to build it:
    1. Start Code Composer, click on File>Import>Existing CCS Eclipse Projects.
    2. Browse to C:\StellarisWare\driverlib and import the "ccs-cm4f" project.
    3. Once that is done, right click on the project and click build and driverlib-cm4f.lib will be generated at C:\StellarisWare\driverlib\ccs-cm4f\Debug
  3. Select File>New>CCS Project to create a new project with the following settings:
    1. Project name: eeprom_test
    2. Family: ARM
    3. Variant: Cortex M | Stellaris LM4F232H5QD 
    4. Connection: Stellaris In-Circuit Debug Interface
    5. Template: Empty Project (with main.c)
  4. Replace the content of main.c with the following lines of code:
  5.  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    #include "stdio.h"
    #include "stdlib.h"
    #include "file.h"
    
    #include "inttypes.h"
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/fpu.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/rom.h"
    #include "utils/uartstdio.h"
    #include "driverlib/eeprom.h"
    
    #define EEPROM_TEST_ADDRESS 0x0000
    
    struct eeprom_test_t {
     uint8_t a;
     uint8_t b;
     uint16_t c;
     uint8_t d[12];
    } eeprom_write = { 5, 7, 11223, "Hello World" }, eeprom_read = { 0, 0, 0, { 0 } };
    
    int main(void) {
    
     unsigned long esize, eblock;
    
     // Enable lazy stacking for interrupt handlers.  This allows floating-point
     // instructions to be used within interrupt handlers, but at the expense of
     // extra stack usage.
     ROM_FPULazyStackingEnable();
    
     // Set the clocking to run directly from the crystal.
     ROM_SysCtlClockSet(
       SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ
         | SYSCTL_OSC_MAIN);
    
     //We will be using the UART0 of LM4F232H5QD as console for printing the output
     //When LM4F232H5QD Evaluation Kit is connected to the PC, it enumerates as a virtual serial port
     //Use a terminal program like https://sites.google.com/site/braypp/terminal to open the port at 115200 8-N-1
     ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
     ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
     ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
     ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
     UARTStdioInit(0);
     UARTprintf("EEPROM Test Program for LM4F232H5QD\n");
    
     ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0);
     EEPROMInit();
    
     esize = EEPROMSizeGet();
     UARTprintf("on-chip EEPROM Size is %d bytes\n", esize);
    
     eblock = EEPROMBlockCountGet();
     UARTprintf("on-chip EEPROM number of blocks: %d\n", eblock);
    
     UARTprintf("Writing structure to EEPROM at address %u: {%u,%u,%u,%s}\n",
       EEPROM_TEST_ADDRESS, eeprom_write.a, eeprom_write.b, eeprom_write.c, eeprom_write.d);
     EEPROMProgram((unsigned long *)&eeprom_write, EEPROM_TEST_ADDRESS, sizeof(eeprom_write));
    
     EEPROMRead((unsigned long *)&eeprom_read, EEPROM_TEST_ADDRESS, sizeof(eeprom_read));
     UARTprintf("Read structure from EEPROM at address %u: {%u,%u,%u,%s}\n",
       EEPROM_TEST_ADDRESS, eeprom_read.a, eeprom_read.b, eeprom_read.c, eeprom_read.d);
    
     while (1) {
     }
    }
    
  6. Now we need to perform some project settings. Right click on the "eeprom_test" project and select "Project Properties" and perform the following configurations:
    1. Build>ARM Compiler>Include Options. Add the following two paths to the "#include search path":
           "C:\StellarisWare"
           "C:\StellarisWare\boards\ek-lm4f232"
    2. Build>ARM Linker>File Search Paths Options. Add the following two paths to the "Include Library File" (in this order):
           "libc.a"
           "C:\StellarisWare\driverlib\ccs-cm4f\Debug\driverlib-cm4f.lib"
    3. Build>ARM Compiler>Advanced Options>Predefined symbols. Add the following 3 lines to Pre-define NAME (in this order):
           ccs="ccs"
           PART_LM4F232H5QD
           TARGET_IS_BLIZZARD_RA1
    4. ARM Compiler>Advanced Options>Language Options: Enable Support for GCC Extensions.
    5. ARM Compiler>Advanced Options>Assembler Options: Use unified assembly language must be checked.
    6. ARM Compiler>Advanced Options>Runtime Model Options: Place each function in separate subsection must be "on".
    7. ARM Linker>Basic Options: C System Stack size must be set to 512 bytes.
  7. Add the UART printf utility module:
    1. Right click the project "eeprom_test" (in Project Explorer view) and select New>Folder and create a folder named "drivers"
    2. Right click on this newly created "drivers" folder and select "Import"
    3. Select "General>File System"
    4. Browse to C:\StellarisWare\utils
    5. Check only the box next to uartstdio.c
    6. Click Advanced and tick "Create links in workspace"
    7. Click Finish
  8. Build the project (Ctrl+B)
  9. Enter debug mode (press F11)
  10. Start a serial terminal software (like Bray's Terminal) and open COM port enumerated as the Stellaris Virtual Serial Port with the settings 115200 8-N-1. You can look up the COM port number using Device Manager as shown below. The output of our EEPROM test program will be displayed on the terminal software.
    Using Device Manager to look up the COM port number
  11. Switch to Code Composer and press F8 to Run the program on LM4F232H5QD. 
  12. Observe the output on Bray's Terminal.
Output of EEPROM test program as observed on the Serial Terminal software
You can refer to Chapter 6 of C:\StellarisWare\docs\SW-DRL-UG-9453.pdf  for reference of all the EEPROM API

Comments