You are on page 1of 10

LAB 7: USB

Aim: To send data back and forth across a bulk transfer-mode USB connection.
Theory:
Standards:

USB 1.1
Defines Host (master) and Device (slave)
Speeds to 12Mbits/sec
Devices can consume 500mA (100mA for startup)
USB 2.0
Speeds to 480Mbits/sec
OTG addendum
USB 3.0
Speeds to 4.8Gbits/sec
New connector(s)
Separate transmit/receive data lines

TM4C123GH6PM USB
USB 2.0 full speed (12 Mbps) and low speed (1.5 Mbps) operation
On-the-go (OTG), Host and Device functions
Integrated PHY
Transfer types: Control, Interrupt, Bulk and Isochronous
Device Firmware Update (DFU) device in ROM
Procedure
Import the Project

The usb_bulk_example project is one of the TivaWare examples.


When you import the project, note that it will be automatically copied into your workspace,
preserving the original files.
Click Project Import Existing CCS Eclipse Project.
Make the settings shown below and click Finish

Build, Download and Run The Code

Make sure your evaluation boards USB DEBUG port is connected to your PC and that the
usb_dev_bulk project is active.
Build and download your application by clicking the Debug button on the menu bar
Click the Terminate button, and when CCS returns to the CCS Edit perspective, unplug the USB
cable from the LaunchPads DEBUG port.
Move the PWR SELECT switch on the board to the DEVICE position.
Plug your USB cable into the USB DEVICE connector on the side of the LaunchPad board.
The green LED in the emulator section of the LaunchPad should be lit, verifying that the board is
powered.
In a few moments, your computer will detect that a generic bulk device has been plugged into the
USB port.
If necessary, install the driver for this device from:
C:\TI\TivaWare_C_Series-1.1\windows_drivers
Make sure that you installed the StellarisWare Windows-side USB examples from www.ti.com/swusb-win as shown in module one.

Click Start All Programs Texas Instruments Stellaris USB Examples USB Bulk
Example. The window below will appear:

Type something in the window and press Enter. For instance TI as shown below:

The host application will send the two ASCII bytes representing TI over the USB port to the
LaunchPad board.
The code there will change uppercase to lowercase, blink the LED and echo the transmission. Then
the host application will display the returned string.

Digging Deeper

Type EXIT to terminate the USB Bulk Example program on your PC.
Connect your other USB cable from your PC to the DEBUG USB port the on the LaunchPad and
move the PWR SELECT switch on the board to the DEBUG position.
The green LED in the emulator section of the LaunchPad should be lit, verifying that the board is
powered. You should now have both ports connected to your PC.
In Code Composer Studio, if usb_dev_bulk.c is not already open, expand the usb_dev_bulk project
in the Project Explorer pane and double-click on usb_dev_bulk.c to open it for editing.

Watching the Instrumentation:

As shown earlier in module 1, start your terminal program and connect it to the Stellaris Virtual
Serial Port. Arrange the terminal window so that it takes up no more than a quarter of your screen
and position it in the upper left of your screen.
Resize CCS so that it takes up the lower half of your screen. Click the Debug button to build and
download the code and reconnect to your LaunchPad. Run the code by clicking the Resume
button.
Start the USB Bulk Example Windows application as shown in step 5. Place thewindow in the upper
right corner of your screen. This would be much easier with multiple screens, wouldnt it?
Note the status on your terminal display and type something, like TEXAS INSTRUMENTS into
the USB Bulk Example Windows application and press Enter. Note that the terminal program will
display.
Click the Suspend button in CCS to halt the program.

Result: Transmission of data back and forth is achieved using USB bulk transfer and putty software.

LAB8
1. WRITING TO FLASH
Aim: Create code to write to flash
Theory
256KB / 40MHz starting at 0x00000000
Organized in 1KB independently erasable blocks
Code fetches and data access occur over separate buses
Below 40MHz, Flash access is single cycle

Above 40MHz, the prefetch buffer fetches two 32-bit words/cycle.


No wait states for sequential code.
Branch speculation avoids wait state on some branches
Programmable write and execution protection available
Simple programming interface

Procedure:
Open Code Composer and click Project Import Existing CCS Eclipse Project.
Navigate to C:\TM4C123G_launchpad_workshop\lab8\project then finish.
Expand the project explorer window and click on the main.c and open the main2.txt.
Built and debug the program. After completing the process, set a breakpoint at FlashProgram()
Click the Resume button to run the code
In the CCS menu bar, click View Memory Browser window and enter 0x10000 click Go. The
output can be seen. (FFFFFF)
Click the Resume button the Memory Browser will update, and displays the output
Remove the breakpoint and click the Terminate button to return to the CCS window

Program:
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/flash.h"
int main(void)
{
uint32_t pui32Data[2];
uint32_t pui32Read[2];
pui32Data[0] = 0x12345678;
pui32Data[1] = 0x56789abc;
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|
SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x00);
SysCtlDelay(20000000);
FlashErase(0x10000);
FlashProgram(pui32Data, 0x10000, sizeof(pui32Data));
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x02);
SysCtlDelay(20000000);
while(1)
{

}
}

Build, Download and Run the Flash Programming Code

Click the Debug button to build and download your program to the TM4C123GH6PM memory.
Set a breakpoint on the line containing the FlashProgram() API function call.
Click the Resume button to run the code. Execution will quickly stop at the breakpoint.
On the CCS menu bar, click View Memory Browser. In the provided entry window, enter
0x10000 as shown below and click Go:

Erased flash should read as all ones, since programming flash memory only writes zeros.
Click the Resume button to run the code. The last line of code before the while(1)loop will light the
red LED.
Click the Suspend button. Your Memory Browser will update, displaying your successful write to
flash memory.

Result: Writing to flash is performed

2.WRITING AND READING TO EEPROM


Aim: To perform the writing and reading to EEPROM
Theory:
2KB of memory starting at 0x400AF000 in Peripheral space
Accessible as 512 32-bit words
32 blocks of 16 words (64 bytes) with access protection per block
Built-in wear leveling with endurance of 500K writes
Lock protection option for the whole peripheral as well as per block using 32-bit to 96-bit codes
Interrupt support for write completion to avoid polling
Random and sequential read/write access (4 cycles max/word)
Procedure:
Open Code Composer and click Project Import Existing CCS Eclipse Project.
Copy the program from C:\TM4C123G_launchpad_workshop\lab8\project then finish.
Expand the project explorer window and click on the main.c and open the main3.txt.
Built and debug the program.
Click on the variables and expand. Right click on the first variable and select the Number format to
Hexa. Repeat for all the variables.
Set the breakpoint at the line containing EEPROM Program(). And click the resume button to run
the breakpoint. The blue LED will glow.
Click the Resume button the value can be seen in memory.
Remove the breakpoint and click the Terminate button to return to the CCS window
Program:
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/flash.h"

#include "driverlib/eeprom.h"
int main(void)
{
uint32_t pui32Data[2];
uint32_t pui32Read[2];
pui32Data[0] = 0x12345678;
pui32Data[1] = 0x56789abc;
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|
SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x00);
SysCtlDelay(20000000);
FlashErase(0x10000);
FlashProgram(pui32Data, 0x10000, sizeof(pui32Data));
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x02);
SysCtlDelay(20000000);
SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0);
EEPROMInit();
EEPROMMassErase();
EEPROMRead(pui32Read, 0x0, sizeof(pui32Read));
EEPROMProgram(pui32Data, 0x0, sizeof(pui32Data));
EEPROMRead(pui32Read, 0x0, sizeof(pui32Read));
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x04);
while(1)
{
}

Build, Download and Run the EEPROM Programming Code


Click the Debug button to build and download your program to the TM4C123GH6PM memory.
Click on the Variables tab and expand both of the arrays by clicking the + next to them.
Right-click on the first variables row and select Number Format Hex. Do this for all four variables.

Set a breakpoint on the line containing EEPROMProgram(). We want to verify the previous contents of
the EEPROM.
Click the Resume button to run to the breakpoint.
Since we included the EEPROMMassErase() in the code, the values read from memory should be all Fs
as shown below:

Click the Resume button to run the code from the breakpoint. When the blue LED on
the board lights, click the Suspend button. The values read from memory should now be
the same as those in the write array:

Result: Writing and reading to EEPROM is performed.

You might also like