tests: gadget0: Created a platform/target for Black Magic Probe
This commit is contained in:
committed by
Piotr Esden-Tempski
parent
f2db2a1c61
commit
8a51b818d5
80
tests/gadget-zero/main-stm32f1-blackmagic.c
Normal file
80
tests/gadget-zero/main-stm32f1-blackmagic.c
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user