usb: Add st_usbfs_v2 for f0/l0 devices

Based on previous work, add a new driver for the v2 usb peripheral found on
stm32f0 and l0 devices.

Correspondingly, add a usb gadget zero test suite for the f0.  L0 device level
code isn't yet ready, but will add the test case when it moves in.

Work by Frantisek Burian, Kuldeep
Singh Dhaka, Robin Kreis, fenugrec and zyp on irc, and all those forgotten.
This commit is contained in:
Karl Palsson
2015-10-02 01:30:25 +00:00
parent cffaf1ee60
commit f5eb96caf3
10 changed files with 360 additions and 1 deletions

View File

@@ -0,0 +1,43 @@
##
## This file is part of the libopencm3 project.
##
## This library is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with this library. If not, see <http://www.gnu.org/licenses/>.
##
BOARD = stm32f072disco
PROJECT = usb-gadget0-$(BOARD)
BUILD_DIR = bin-$(BOARD)
SHARED_DIR = ../shared
CFILES = main-$(BOARD).c
CFILES += usb-gadget0.c
VPATH += $(SHARED_DIR)
INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR))
OPENCM3_DIR=../..
### This section can go to an arch shared rules eventually...
LDSCRIPT = ../../lib/stm32/f0/stm32f07xzb.ld
OPENCM3_LIB = opencm3_stm32f0
OPENCM3_DEFS = -DSTM32F0
#FP_FLAGS ?= -mfloat-abi=hard -mfpu=fpv4-sp-d16
ARCH_FLAGS = -mthumb -mcpu=cortex-m0 $(FP_FLAGS)
#OOCD_INTERFACE = stlink-v2
#OOCD_TARGET = stm32f4x
OOCD_FILE = openocd.stm32f072disco.cfg
include ../rules.mk

View File

@@ -0,0 +1,66 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2015 Karl Palsson <karlp@tweak.net.au>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libopencm3/cm3/nvic.h>
#include <libopencm3/stm32/crs.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/flash.h>
#include <libopencm3/stm32/rcc.h>
#include <stdio.h>
#include "usb-gadget0.h"
// no trace on cm0 #define ER_DEBUG
#ifdef ER_DEBUG
#define ER_DPRINTF(fmt, ...) \
do { printf(fmt, ## __VA_ARGS__); } while (0)
#else
#define ER_DPRINTF(fmt, ...) \
do { } while (0)
#endif
#include "trace.h"
void trace_send_blocking8(int stimulus_port, char c) {
(void)stimulus_port;
(void)c;
}
int main(void)
{
rcc_clock_setup_in_hsi48_out_48mhz();
crs_autotrim_usb_enable();
rcc_set_usbclk_source(HSI48);
rcc_set_sysclk_source(HSI48);
/* LED on custom board for boot progress */
rcc_periph_clock_enable(RCC_GPIOC);
gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO7);
gpio_set(GPIOC, GPIO7);
usbd_device *usbd_dev = gadget0_init(&st_usbfs_v2_usb_driver, "stm32f072disco");
ER_DPRINTF("bootup complete\n");
gpio_clear(GPIOC, GPIO7);
while (1) {
usbd_poll(usbd_dev);
}
}

View File

@@ -0,0 +1,14 @@
source [find interface/stlink-v2.cfg]
set WORKAREASIZE 0x4000
source [find target/stm32f0x.cfg]
# serial of my f072 disco board.
hla_serial "Q?o\x06PgHW#$\x16?"
# no trace on cm0
#tpiu config internal swodump.stm32f4disco.log uart off 168000000
# Uncomment to reset on connect, for grabbing under WFI et al
reset_config srst_only srst_nogate
# reset_config srst_only srst_nogate connect_assert_srst

View File

@@ -9,6 +9,7 @@ import unittest
DUT_SERIAL = "stm32f4disco"
#DUT_SERIAL = "stm32f103-generic"
#DUT_SERIAL = "stm32l1-generic"
#DUT_SERIAL = "stm32f072disco"
class find_by_serial(object):
def __init__(self, serial):