Skip to content

Commit

Permalink
Squashed 'driver-examples/mss/mss-usb/' content from commit 5224a88
Browse files Browse the repository at this point in the history
git-subtree-dir: driver-examples/mss/mss-usb
git-subtree-split: 5224a883950321378ade97e0a0a222fe077e59a3
  • Loading branch information
Singh-Raghvendra committed Jun 26, 2023
0 parents commit 0611eb1
Show file tree
Hide file tree
Showing 1,090 changed files with 777,984 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@Library('automated-testing-library') _
pipelineBareMetalDriverExamples()
1,254 changes: 1,254 additions & 0 deletions mpfs-usb-device-hid/.cproject

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions mpfs-usb-device-hid/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/Debug/
/LIM-Debug/
/DDR-Release/
/LIM-Release/
/eNVM-Scratchpad-Release/
/.settings*/
*src/boards/icicle-kit-es/fpga_design_config/**
26 changes: 26 additions & 0 deletions mpfs-usb-device-hid/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>mpfs-usb-device-hid</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>
70 changes: 70 additions & 0 deletions mpfs-usb-device-hid/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# PolarFire SoC MSS USB Human Interface Device example

This project demonstrates the use of MSS USB driver stack to easily implement a
human interface device. When connected to a USB host, This feature automatically
moves the mouse pointer horizontally(x-direction) on the desktop to which this
USB port is connected.

This example project and the involved drivers passes the USB-IF USB2.0
compliance test.

## IMPORTANT
Note that the mouse pointer will keep moving in horizontal direction back and
forth till USB port is connected to host device.

# Device Description:



| | |
| :------------------------- | :----------------------------------- |
| `HID Class` | <ul><li> Has one HID class interface at its default configuration. </li> |
| `HS` | <ul><li> operates at high speed with high-speed capable host. When connected to 1.x host or connected through 1.x hub operates at FS automatically. </li> |
| `VID` | <ul><li> 0x1514 (Actel Corp.) </li> |
| `PID` | <ul><li> 0x0001 (Fake) </li> |
| `bcdUSB` | <ul><li> 0x0002 (represents USB2.0) </li> |
| `bcdDevice` | <ul><li> 0x0030 (Fake) </li> |
| `iserialNumber` | <ul><li> HID1234 (Fake) </li> |
| `Remote wakeup` | <ul><li> not supported </li> |
| `Power` | <ul><li> Self powered (Does not use USB bus power) </li> |
| `Device class Code` | <ul><li> 0x03 (HID class) </li> |
| `Device SubClass Code` | <ul><li> 0x00 </li> |
| `Device Protocol Code` | <ul><li> 0x02 </li> |
| `Peripheral Device type` | <ul><li> 0x00 (PDT) </li> |


# Target hardware

This example project can be used on the PolarFire SoC model on PolarFire SoC
FPGA family hardware platforms.

Executing project on PolarFire SoC hardware.

## How to use this example
On connecting Icicle kit J11 to the host PC, you should see 4 COM port
interfaces connected. To use this project configure the COM port **interface1**
as below:
- 115200 baud
- 8 data bits
- 1 stop bit
- no parity
- no flow control

The example project will display instructions over the serial port. A greeting
message and menu instructions are displayed over the UART terminal.

Before compiling, please ensure that you follow the steps provided below (which
are already done in this example project) :-
(1) Copy the "mss_usb_sw_config.h" file from the [platform repository](https://github.com/polarfire-soc/platform/tree/main/platform_config_reference/drivers_config/mss/mss_usb)
and paste it into the board repository
(*boards\icicle-kit-es\platform_config\drivers_config\mss\mss_usb* and
*boards\icicle-kit-es\platform_config_release\drivers_config\mss\mss_usb*).
Then, enable the corresponding USB mode (ex. host and device mode).
(2) In the USB example projects, please add the include path
**#include "drivers_config/mss/mss_usb/mss_usb_sw_config.h"** in the
mss_sw_config file under the boards section (*boards\icicle-kit-es\platform_config\mpfs_hal_config* and *boards\icicle-kit-es\platform_config_release\mpfs_hal_config*).

Build the project and launch the debug configuration named mpfs-usb-device-hid
hw all-harts debug.launch which is configured for PolarFire SoC hardware
platform.

59 changes: 59 additions & 0 deletions mpfs-usb-device-hid/mpfs-usb-device-hid hw all-harts attach.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="ilg.gnumcueclipse.debug.gdbjtag.openocd.launchConfigurationType">
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doContinue" value="true"/>
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doDebugInRam" value="false"/>
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doFirstReset" value="false"/>
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doGdbServerAllocateConsole" value="true"/>
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doGdbServerAllocateTelnetConsole" value="false"/>
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doSecondReset" value="false"/>
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doStartGdbCLient" value="true"/>
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doStartGdbServer" value="true"/>
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.enableSemihosting" value="false"/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.firstResetType" value="init"/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbClientOtherCommands" value="set mem inaccessible-by-default off&#13;&#10;set $target_riscv=1&#13;&#10;set architecture riscv:rv64&#13;&#10;file ${config_name:mpfs-usb-device-hid}/mpfs-usb-device-hid.elf"/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbClientOtherOptions" value=""/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerConnectionAddress" value=""/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerExecutable" value="${openocd_path}/${openocd_executable}"/>
<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerGdbPortNumber" value="3333"/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerLog" value=""/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerOther" value="--command &quot;set DEVICE MPFS&quot;&#13;&#10;--file board/microsemi-riscv.cfg"/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerTclPortNumber" value="6666"/>
<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerTelnetPortNumber" value="4444"/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.otherInitCommands" value=""/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.otherRunCommands" value="thread apply all set $pc=_start"/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.secondResetType" value="init"/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.svdPath" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageFileName" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageOffset" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDevice" value="GNU MCU OpenOCD"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadImage" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadSymbols" value="true"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value=""/>
<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="3333"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setResume" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="e51"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsFileName" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsOffset" value=""/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForImage" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForSymbols" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForImage" value="true"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForSymbols" value="true"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useRemoteTarget" value="true"/>
<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="${cross_prefix}gdb${cross_suffix}"/>
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/>
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="${config_name:mpfs-usb-device-hid}/mpfs-usb-device-hid.elf"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="mpfs-usb-device-hid"/>
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value=""/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/mpfs-usb-device-hid"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
</launchConfiguration>
61 changes: 61 additions & 0 deletions mpfs-usb-device-hid/mpfs-usb-device-hid hw all-harts debug.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="ilg.gnumcueclipse.debug.gdbjtag.openocd.launchConfigurationType">
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doContinue" value="true"/>
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doDebugInRam" value="false"/>
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doFirstReset" value="true"/>
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doGdbServerAllocateConsole" value="true"/>
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doGdbServerAllocateTelnetConsole" value="false"/>
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doSecondReset" value="false"/>
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doStartGdbCLient" value="true"/>
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doStartGdbServer" value="true"/>
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.enableSemihosting" value="false"/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.firstResetType" value="init"/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbClientOtherCommands" value="set $target_riscv=1&#13;&#10;set mem inaccessible-by-default off&#13;&#10;set architecture riscv:rv64&#13;&#10;file ${config_name:mpfs-usb-device-hid}/mpfs-usb-device-hid.elf"/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbClientOtherOptions" value=""/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerConnectionAddress" value=""/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerExecutable" value="${openocd_path}/${openocd_executable}"/>
<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerGdbPortNumber" value="3333"/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerLog" value=""/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerOther" value="--command &quot;set DEVICE MPFS&quot;&#13;&#10;--file board/microsemi-riscv.cfg"/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerTclPortNumber" value="6666"/>
<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerTelnetPortNumber" value="4444"/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.otherInitCommands" value=""/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.otherRunCommands" value="thread apply all set $pc=_start"/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.secondResetType" value="init"/>
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.svdPath" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageFileName" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageOffset" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDevice" value="GNU MCU OpenOCD"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadImage" value="true"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadSymbols" value="true"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value=""/>
<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="3333"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setResume" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="e51"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsFileName" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsOffset" value=""/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForImage" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForSymbols" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForImage" value="true"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForSymbols" value="true"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useRemoteTarget" value="true"/>
<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="${cross_prefix}gdb${cross_suffix}"/>
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/>
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="${config_name:mpfs-usb-device-hid}/mpfs-usb-device-hid.elf"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="mpfs-usb-device-hid"/>
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value=""/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/mpfs-usb-device-hid"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList context=&quot;Context string&quot;/&gt;&#13;&#10;"/>
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
</launchConfiguration>
61 changes: 61 additions & 0 deletions mpfs-usb-device-hid/src/application/hart0/e51.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*******************************************************************************
* Copyright 2023 Microchip FPGA Embedded Systems Solutions.
*
* SPDX-License-Identifier: MIT
*
* Application code running on e51
*
*/

#include <stdio.h>
#include <string.h>
#include "mpfs_hal/mss_hal.h"
#include "drivers/mss/mss_mmuart/mss_uart.h"

/* Main function for the hart0(e51 processor).
* Application code running on hart0 is placed here
*
* The hart1 goes into WFI. hart0 brings it out of WFI when it raises the first
* Software interrupt.
*/

const uint8_t g_message3[] =
"\r\nPlease observe UART-1 for application messages\r\n";

void e51(void)
{
/* Clear pending software interrupt in case there was any. */
clear_soft_interrupt();
set_csr(mie, MIP_MSIP);

/* Bring MMUART0 out of reset */
(void) mss_config_clk_rst(MSS_PERIPH_MMUART0, (uint8_t) 1, PERIPHERAL_ON);

MSS_UART_init(&g_mss_uart0_lo,
MSS_UART_115200_BAUD,
MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT);

/* Message on uart0 */
MSS_UART_polled_tx(&g_mss_uart0_lo, g_message3, sizeof(g_message3));

#if (IMAGE_LOADED_BY_BOOTLOADER == 0)

/* Raise software interrupt to wake hart 1 */
raise_soft_interrupt(1U);
__enable_irq();

while (1U)
{
;
}

#endif

/* never return */
}

/* hart0 software interrupt handler */
void Software_h0_IRQHandler(void)
{

}
83 changes: 83 additions & 0 deletions mpfs-usb-device-hid/src/application/hart1/mouse_app.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/***************************************************************************//**
* Copyright 2023 Microchip FPGA Embedded Systems Solutions.
*
* SPDX-License-Identifier: MIT
*
* USB HID Class Mouse Device example application to demonstrate the PolarFire
* SoC MSS USB operations in device mode.
*
* This file uses MSS USB Driver stack (inclusive of USBD-HID class driver) to
* connect to USB Host as USB HID Mouse device.
*
*/

#include "mouse_app.h"
#include "drivers/mss/mss_gpio/mss_gpio.h"
#include "drivers/mss/mss_usb/mss_usb_device.h"
#include "drivers/mss/mss_usb/mss_usb_device_hid.h"

#ifdef __cplusplus
extern "C" {
#endif

#define DELAY_BETWEEN_SENSES 50000u

/*This buffer is passed to the USB driver. When USB drivers are configured to
use internal DMA, the address of this buffer must be modulo-4.Otherwise DMA
Transfer will fail.*/
mss_usbd_hid_report_t report __attribute__ ((aligned (4))) = {0};

/* USB descriptors for HID class mouse enumeration. */
extern mss_usbd_user_descr_cb_t hid_mouse_descriptors_cb;

void
MOUSE_task
(
void
)
{
volatile uint32_t delay;

if(1 == MSS_USBD_HID_tx_done())
{
MSS_USBD_HID_tx_report ((uint8_t*)&report, sizeof(report));
}
else
{
for(delay = 0; delay < DELAY_BETWEEN_SENSES; ++delay)
{
;
}

if(report.x_move < (int8_t)30)
{
++report.x_move;
}
else
{
report.x_move = -30;
}
}
}

void
MOUSE_init
(
void
)
{
/* Assign call-back function handler structure needed by USB Device Core
* driver
*/
MSS_USBD_set_descr_cb_handler(&hid_mouse_descriptors_cb);

/* Initialize HID Class driver. */
MSS_USBD_HID_init(MSS_USB_DEVICE_HS);

/* Initialize USB Device Core driver. */
MSS_USBD_init(MSS_USB_DEVICE_HS);
}

#ifdef __cplusplus
}
#endif
Loading

0 comments on commit 0611eb1

Please sign in to comment.