tests: gadget0: Created a platform/target for Black Magic Probe

This commit is contained in:
dragonmux
2022-08-16 16:08:02 +01:00
committed by Piotr Esden-Tempski
parent f2db2a1c61
commit 8a51b818d5
3 changed files with 152 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
##
## 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 = stm32f1-blackmagic
PROJECT = usb-gadget0-$(BOARD)
BUILD_DIR = bin-$(BOARD)
SHARED_DIR = ../shared
CFILES = main-$(BOARD).c
CFILES += usb-gadget0.c trace.c trace_stdio.c
CFILES += delay.c
VPATH += $(SHARED_DIR)
INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR))
OPENCM3_DIR=../..
OPENCM3_LIB=opencm3_stm32f1
OPENCM3_DEFS=-DSTM32F1
ARCH_FLAGS=-mcpu=cortex-m3 -mthumb
LDSCRIPT=blackmagic.ld
LDFLAGS += -Wl,-gc-sections -Wl,--print-memory-usage -Wl,-Ttext=0x8002000
include ../rules.mk
$(PROJECT).flash: $(PROJECT).elf
@echo " FLASH $<"
$(Q)dfu-util -d 1d50:6018,:6017 -s 0x08002000:leave -D $(realpath $(PROJECT).bin)

View File

@@ -0,0 +1,28 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2022 Rachel Mant <git@dragonmux.network>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* Define memory regions. */
MEMORY
{
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
}
/* Include the common ld script from libopencm3. */
INCLUDE cortex-m-generic.ld

View File

@@ -0,0 +1,80 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2022 Rachel Mant <git@dragonmux.network>
*
* 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/cm3/scs.h>
#include <libopencm3/cm3/scb.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/exti.h>
#include <stdio.h>
#include <stdbool.h>
#include "usb-gadget0.h"
#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
#define LED_PORT GPIOB
#define LED_0 GPIO2
#define LED_1 GPIO10
#define LED_2 GPIO11
#define IRQ_PRI_USB_VBUS (14 << 4)
int main(void)
{
rcc_periph_clock_enable(RCC_GPIOB);
/* LED to indicate boot process */
gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, LED_0 | LED_1 | LED_2);
gpio_clear(LED_PORT, LED_0 | LED_2);
gpio_set(LED_PORT, LED_1);
rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE8_72MHZ]);
rcc_periph_clock_enable(RCC_USB);
rcc_periph_clock_enable(RCC_GPIOA);
/* Configure USB pull-up control */
gpio_clear(GPIOA, GPIO8);
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO8);
/* Make sure we don't accidentally enable the BMP target power */
gpio_set(GPIOB, GPIO1);
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO1);
usbd_device *usbd_dev = gadget0_init(&st_usbfs_v1_usb_driver, "stm32f1-blackmagic");
gpio_set(GPIOA, GPIO8);
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO8);
ER_DPRINTF("bootup complete\n");
gpio_clear(LED_PORT, LED_1);
gpio_set(LED_PORT, LED_0);
while (true) {
gadget0_run(usbd_dev);
}
}