SLAU533D September   2013  – April 2017

 

  1.   MSP430F5529 LaunchPad™ Development Kit (MSP‑EXP430F5529LP)
    1.     Trademarks
    2. 1 Getting Started
      1. 1.1 Key Features
      2. 1.2 Kit Contents
      3. 1.3 Out-of-Box Experience
        1. 1.3.1 Step 1: Install a Software Development Platform
        2. 1.3.2 Step 2: Connect the Hardware
        3. 1.3.3 Step 3: Verify the storage volume has been loaded
        4. 1.3.4 Step 4: Open a text editor, and press the buttons
        5. 1.3.5 Step 5: Customize the strings
    3. 2 Hardware
      1. 2.1 Block Diagram
      2. 2.2 Hardware Features
        1. 2.2.1 MSP430F5529
        2. 2.2.2 eZ-FET lite Onboard Emulator
        3. 2.2.3 Integrated Full-Speed USB Hub
        4. 2.2.4 Power
        5. 2.2.5 Clocking
        6. 2.2.6 Application (or "Backchannel") UART
        7. 2.2.7 Emulator and Target Isolation Jumper Block
        8. 2.2.8 Isolation Jumper Block: 3.3-V and 5-V Jumpers
        9. 2.2.9 Isolation Jumper Block: Emulator Connection and Application UART
      3. 2.3 Measure Current Draw of MSP430 MCU
      4. 2.4 Using an External Power Source
        1. 2.4.1 External 3.3-V Power Source
        2. 2.4.2 External 5-V Power Source Without USB Connection
        3. 2.4.3 External 5-V Power Source With USB Connection
      5. 2.5 Using the eZ-FET lite Emulator With a Different Target
      6. 2.6 USB BSL Button
      7. 2.7 BoosterPack Plug-in Module Pinout
      8. 2.8 Design Files
      9. 2.9 Hardware Change Log
    4. 3 Software Examples
      1. 3.1 MSP430 Software Libraries: driverlib and the USB API
      2. 3.2 Viewing the Code
        1. 3.2.1 CCS
        2. 3.2.2 IAR
      3. 3.3 Example Project Software Organization
      4. 3.4 USB Configuration Files
      5. 3.5 Out-of-Box Experience: emulStorageKeyboard
        1. 3.5.1  Flowchart
        2. 3.5.2  Pre-Initialization
        3. 3.5.3  Initialization
          1. 3.5.3.1 Configuring the Keyboard
          2. 3.5.3.2 Configuring the MSC Interface
        4. 3.5.4  Handling SCSI Commands
        5. 3.5.5  LPM0 Entry
        6. 3.5.6  LPM0 Exit
        7. 3.5.7  Emulated Storage Volume
        8. 3.5.8  Sending Data as a USB Keyboard
        9. 3.5.9  Properly Handling USB Unplug Events
        10. 3.5.10 Non-Maskable Interrupt (NMI) Vector
      6. 3.6 Example: simpleUsbBackchannel
        1. 3.6.1 What It Does
        2. 3.6.2 Installing the CDC Interface
        3. 3.6.3 Operating the Example
        4. 3.6.4 Backchannel UART Library: bcUart.c, bcUart.h
        5. 3.6.5 Code Description: Initialization
          1. 3.6.5.1 Stopping the Watchdog
          2. 3.6.5.2 Configuring VCORE
          3. 3.6.5.3 Configuring Clocks
          4. 3.6.5.4 Configuring Ports
          5. 3.6.5.5 Initializing the Backchannel UART
          6. 3.6.5.6 Configuring USB
        6. 3.6.6 Code Description: Main Loop
        7. 3.6.7 Modifying to Use an HID-Datapipe Interface
      7. 3.7 Starting Device Manager
    5. 4 Additional Resources
      1. 4.1 LaunchPad Development Kit Websites
      2. 4.2 Information on the MSP430F5529
      3. 4.3 Download CCS, IAR, mspgcc, or Energia
      4. 4.4 USB Developers Package
      5. 4.5 MSP430Ware and TI Resource Explorer
      6. 4.6 F5529 Code Examples
      7. 4.7 MSP430 Application Notes
      8. 4.8 TI E2E Community
      9. 4.9 Community at Large
    6. 5 FAQs
    7. 6 Schematics
  2.   Revision History

Sending Data as a USB Keyboard

In USB, keyboards are implemented as Human Interface Device (HID) interfaces. Within the USB descriptors reported to the host during enumeration, the application declares itself to contain a keyboard HID interface. It then sends specially formatted HID reports to the host, to tell it about key presses. While no key presses occur, no reports are sent.

Although the word "send" is an easy way to describe it, it is not quite correct. In USB, everything is initiated by the host. What actually happens with HID interfaces is that the USB device prepares a report and makes it available to the host. Then, on a regular interval, the host polls the device to see if it has any reports ready. In the Descriptor Tool, this particular interface was set to have the fastest possible polling interval: 1 ms.

After receiving a report indicating a keystroke, the host assumes the key is held down until a report is later sent to indicate its release. Because of this, the demo application quickly follows every key-press report with a key-release report.

So when a LaunchPad development kit pushbutton press occurs, it sets a flag and wakes main(), had it been sleeping in LPM0. Execution eventually checks the flags associated with the buttons. If the button had been pressed, it calls prepSendingStr() to fetch the target string from the file associated with that button.

// Handle a press of button 1, if it happened if (bButton1Pressed && !charLeftToSend) { prepSendingStr("0:Button1.txt"); bButton1Pressed = FALSE; }

It uses high-level FatFs calls to do this – to mount the volume, open it, read it, and close it. When the string has been obtained, main() assigns the length of that string to charLeftToSend. While this variable is non-zero, it means there are still characters left to transmit to the host.

Later in main(), code evaluates charLeftToSend, and also checks whether a USB report is still waiting to be fetched from the host. If characters still need to be sent, and if the USB HID interface is available, the report is prepared, and USBHID_sendReport() is called to "send" it. A flag bKeyDirIsDown is used to alternate between down-presses and up-presses, to ensure every down-press is followed by an up-press.

if (bUsbSendComplete && charLeftToSend) { if(bKeyDirIsDown) // Will this be a down-press? { KB_addKeypressToReport(btnStr[btnStrLen-charLeftToSend]); bKeyDirIsDown = FALSE; } else // Or will it be an up-press? { KB_addKeyReleaseToReport(btnStr[btnStrLen-charLeftToSend]); bKeyDirIsDown = TRUE; charLeftToSend--; } bUsbSendComplete = FALSE; USBHID_sendReport(KB_getReportPtr(), HID0_INTFNUM); }

USBHID_sendReport() copies the report to the USB endpoint buffer, making it available to the host. HID0_INTFNUM is a value that references this particular HID interface; if additional HID interfaces had been created within this device, this parameter is how code could access them separately. The Descriptor Tool defines an INTFNUM constant for every interface it creates, stored in descriptors.h.

When the host gets around to fetching the report, a USBHID_handleSendCompleted() event is generated.

BYTE USBHID_handleSendCompleted (BYTE intfNum) { bUsbSendComplete = TRUE; return (TRUE); // Returning TRUE wakes the main loop, if it had been } // sleeping.

This is one of the USB event handlers in usbEventHandling.c. These handlers are defined by the API, and the developer can insert code that should execute when those events occur. In this application, the bUsbSendComplete flag is set to TRUE in the handler, and the handler returns TRUE, which wakes main() if it had been sleeping at the LPM0 entry. This allows main() to send the next character, if one is waiting to be sent.