Merge branch 'master' of git://github.com/libopencm3/libopencm3 into upstream-merge
This commit is contained in:
@@ -45,6 +45,15 @@ LDFLAGS += --static -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group \
|
||||
-L$(TOOLCHAIN_DIR)/lib \
|
||||
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections \
|
||||
$(ARCH_FLAGS) -mfix-cortex-m3-ldrd
|
||||
|
||||
ifneq ($(OPENCM3_DIR),)
|
||||
CFLAGS += -I$(OPENCM3_DIR)/include
|
||||
LDFLAGS += -L$(OPENCM3_DIR)/lib -L$(OPENCM3_DIR)/lib/stm32/f1
|
||||
SCRIPT_DIR = $(OPENCM3_DIR)/share
|
||||
else
|
||||
SCRIPT_DIR = $(shell dirname $(shell readlink -f $(shell which $(PREFIX)-gcc)))/../$(PREFIX)/share
|
||||
endif
|
||||
|
||||
OBJS += $(BINARY).o
|
||||
|
||||
OOCD ?= openocd
|
||||
@@ -53,6 +62,9 @@ OOCD_BOARD ?= olimex_stm32_h103
|
||||
# Black magic probe specific variables
|
||||
# Set the BMP_PORT to a serial port and then BMP is used for flashing
|
||||
BMP_PORT ?=
|
||||
# texane/stlink can be used by uncommenting this...
|
||||
# or defining it in your own makefiles
|
||||
#STLINK_PORT ?= :4242
|
||||
|
||||
# Be silent per default, but 'make V=1' will show all compiler calls.
|
||||
ifneq ($(V),1)
|
||||
@@ -107,6 +119,7 @@ clean:
|
||||
$(Q)rm -f *.srec
|
||||
$(Q)rm -f *.list
|
||||
|
||||
ifeq ($(STLINK_PORT),)
|
||||
ifeq ($(BMP_PORT),)
|
||||
ifeq ($(OOCD_SERIAL),)
|
||||
%.flash: %.hex
|
||||
@@ -140,6 +153,14 @@ else
|
||||
-x $(TOOLCHAIN_DIR)/scripts/black_magic_probe_flash.scr \
|
||||
$(*).elf
|
||||
endif
|
||||
else
|
||||
%.flash: %.elf
|
||||
@echo " GDB $(*).elf (flash)"
|
||||
$(Q)$(GDB) --batch \
|
||||
-ex 'target extended-remote $(STLINK_PORT)' \
|
||||
-x $(SCRIPT_DIR)/libopencm3/scripts/stlink_flash.scr \
|
||||
$(*).elf
|
||||
endif
|
||||
|
||||
.PHONY: images clean
|
||||
|
||||
|
||||
4
examples/stm32/f1/lisa-m-1/can/README
Normal file
4
examples/stm32/f1/lisa-m-1/can/README
Normal file
@@ -0,0 +1,4 @@
|
||||
This test sets up the CAN interface on Lisa/M and transmits 8 bites every
|
||||
100ms. The first byte is being incremented in each cycle. The demo also
|
||||
receives messages and is displaing the first 4 bits of the first byte on the
|
||||
board LEDs.
|
||||
@@ -21,8 +21,8 @@
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/flash.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/stm32/systick.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/cm3/systick.h>
|
||||
#include <libopencm3/stm32/can.h>
|
||||
|
||||
struct can_tx_msg {
|
||||
@@ -106,15 +106,15 @@ void can_setup(void)
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_CANEN);
|
||||
|
||||
AFIO_MAPR = AFIO_MAPR_CAN1_REMAP_PORTB;
|
||||
AFIO_MAPR |= AFIO_MAPR_CAN1_REMAP_PORTB;
|
||||
|
||||
/* Configure CAN pin: RX (input pull-up). */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_INPUT,
|
||||
gpio_set_mode(GPIO_BANK_CAN1_PB_RX, GPIO_MODE_INPUT,
|
||||
GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_CAN1_PB_RX);
|
||||
gpio_set(GPIOB, GPIO_CAN1_PB_RX);
|
||||
|
||||
/* Configure CAN pin: TX. */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
gpio_set_mode(GPIO_BANK_CAN1_PB_TX, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_CAN1_PB_TX);
|
||||
|
||||
/* NVIC setup. */
|
||||
@@ -167,8 +167,10 @@ void sys_tick_handler(void)
|
||||
static int temp32 = 0;
|
||||
static u8 data[8] = {0, 1, 2, 0, 0, 0, 0, 0};
|
||||
|
||||
/* We call this handler every 1ms so 1000ms = 1s on/off. */
|
||||
if (++temp32 != 1000)
|
||||
/* We call this handler every 1ms so 100ms = 1s
|
||||
* Resulting in 100Hz message frequency.
|
||||
*/
|
||||
if (++temp32 != 100)
|
||||
return;
|
||||
|
||||
temp32 = 0;
|
||||
|
||||
@@ -164,11 +164,12 @@ static const char *usb_strings[] = {
|
||||
"DEMO",
|
||||
};
|
||||
|
||||
static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
||||
static int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||
{
|
||||
(void)complete;
|
||||
(void)buf;
|
||||
(void)usbd_dev;
|
||||
|
||||
switch (req->bRequest) {
|
||||
case USB_CDC_REQ_SET_CONTROL_LINE_STATE: {
|
||||
@@ -200,15 +201,15 @@ static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void cdcacm_data_rx_cb(u8 ep)
|
||||
static void cdcacm_data_rx_cb(usbd_device *usbd_dev, u8 ep)
|
||||
{
|
||||
(void)ep;
|
||||
|
||||
char buf[64];
|
||||
int len = usbd_ep_read_packet(0x01, buf, 64);
|
||||
int len = usbd_ep_read_packet(usbd_dev, 0x01, buf, 64);
|
||||
|
||||
if (len) {
|
||||
while (usbd_ep_write_packet(0x82, buf, len) == 0)
|
||||
while (usbd_ep_write_packet(usbd_dev, 0x82, buf, len) == 0)
|
||||
;
|
||||
buf[len] = 0;
|
||||
}
|
||||
@@ -216,15 +217,16 @@ static void cdcacm_data_rx_cb(u8 ep)
|
||||
gpio_toggle(GPIOC, GPIO5);
|
||||
}
|
||||
|
||||
static void cdcacm_set_config(u16 wValue)
|
||||
static void cdcacm_set_config(usbd_device *usbd_dev, u16 wValue)
|
||||
{
|
||||
(void)wValue;
|
||||
|
||||
usbd_ep_setup(0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb);
|
||||
usbd_ep_setup(0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
|
||||
usbd_ep_setup(0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
||||
usbd_ep_setup(usbd_dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb);
|
||||
usbd_ep_setup(usbd_dev, 0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
|
||||
usbd_ep_setup(usbd_dev, 0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
||||
|
||||
usbd_register_control_callback(
|
||||
usbd_dev,
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
cdcacm_control_request);
|
||||
@@ -234,6 +236,8 @@ int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
usbd_device *usbd_dev;
|
||||
|
||||
rcc_clock_setup_in_hsi_out_48mhz();
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
@@ -246,13 +250,13 @@ int main(void)
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO5);
|
||||
|
||||
usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_register_set_config_callback(cdcacm_set_config);
|
||||
usbd_dev = usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_register_set_config_callback(usbd_dev, cdcacm_set_config);
|
||||
|
||||
for (i = 0; i < 0x800000; i++)
|
||||
__asm__("nop");
|
||||
gpio_clear(GPIOC, GPIO2);
|
||||
|
||||
while (1)
|
||||
usbd_poll();
|
||||
usbd_poll(usbd_dev);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/f1/flash.h>
|
||||
#include <libopencm3/stm32/f1/scb.h>
|
||||
#include <libopencm3/cm3/scb.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include <libopencm3/usb/dfu.h>
|
||||
|
||||
@@ -130,10 +130,11 @@ static u8 usbdfu_getstatus(u32 *bwPollTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
||||
static void usbdfu_getstatus_complete(usbd_device *usbd_dev, struct usb_setup_data *req)
|
||||
{
|
||||
int i;
|
||||
(void)req;
|
||||
(void)usbd_dev;
|
||||
|
||||
switch (usbdfu_state) {
|
||||
case STATE_DFU_DNBUSY:
|
||||
@@ -166,9 +167,11 @@ static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
||||
}
|
||||
}
|
||||
|
||||
static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
||||
static int usbdfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||
{
|
||||
(void)usbd_dev;
|
||||
|
||||
if ((req->bmRequestType & 0x7F) != 0x21)
|
||||
return 0; /* Only accept class request. */
|
||||
|
||||
@@ -221,6 +224,8 @@ static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
|
||||
int main(void)
|
||||
{
|
||||
usbd_device *usbd_dev;
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
|
||||
if (!gpio_get(GPIOA, GPIO10)) {
|
||||
@@ -245,9 +250,10 @@ int main(void)
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO2);
|
||||
|
||||
usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_set_control_buffer_size(sizeof(usbd_control_buffer));
|
||||
usbd_dev = usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_set_control_buffer_size(usbd_dev, sizeof(usbd_control_buffer));
|
||||
usbd_register_control_callback(
|
||||
usbd_dev,
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
usbdfu_control_request);
|
||||
@@ -255,5 +261,5 @@ int main(void)
|
||||
gpio_clear(GPIOC, GPIO2);
|
||||
|
||||
while (1)
|
||||
usbd_poll();
|
||||
usbd_poll(usbd_dev);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/systick.h>
|
||||
#include <libopencm3/cm3/systick.h>
|
||||
#include <libopencm3/stm32/spi.h>
|
||||
#include <libopencm3/stm32/otg_fs.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
@@ -32,10 +32,12 @@
|
||||
#define INCLUDE_DFU_INTERFACE
|
||||
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
#include <libopencm3/stm32/f1/scb.h>
|
||||
#include <libopencm3/cm3/scb.h>
|
||||
#include <libopencm3/usb/dfu.h>
|
||||
#endif
|
||||
|
||||
static usbd_device *usbd_dev;
|
||||
|
||||
const struct usb_device_descriptor dev = {
|
||||
.bLength = USB_DT_DEVICE_SIZE,
|
||||
.bDescriptorType = USB_DT_DEVICE,
|
||||
@@ -173,10 +175,11 @@ static const char *usb_strings[] = {
|
||||
"DEMO",
|
||||
};
|
||||
|
||||
static int hid_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
void (**complete)(struct usb_setup_data *req))
|
||||
static int hid_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||
{
|
||||
(void)complete;
|
||||
(void)usbd_dev;
|
||||
|
||||
if((req->bmRequestType != 0x81) ||
|
||||
(req->bRequest != USB_REQ_GET_DESCRIPTOR) ||
|
||||
@@ -191,9 +194,10 @@ static int hid_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
}
|
||||
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
static void dfu_detach_complete(struct usb_setup_data *req)
|
||||
static void dfu_detach_complete(usbd_device *usbd_dev, struct usb_setup_data *req)
|
||||
{
|
||||
(void)req;
|
||||
(void)usbd_dev;
|
||||
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
@@ -202,11 +206,12 @@ static void dfu_detach_complete(struct usb_setup_data *req)
|
||||
scb_reset_core();
|
||||
}
|
||||
|
||||
static int dfu_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
void (**complete)(struct usb_setup_data *req))
|
||||
static int dfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||
{
|
||||
(void)buf;
|
||||
(void)len;
|
||||
(void)usbd_dev;
|
||||
|
||||
if ((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH))
|
||||
return 0; /* Only accept class request. */
|
||||
@@ -217,18 +222,20 @@ static int dfu_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
}
|
||||
#endif
|
||||
|
||||
static void hid_set_config(u16 wValue)
|
||||
static void hid_set_config(usbd_device *usbd_dev, u16 wValue)
|
||||
{
|
||||
(void)wValue;
|
||||
|
||||
usbd_ep_setup(0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL);
|
||||
usbd_ep_setup(usbd_dev, 0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL);
|
||||
|
||||
usbd_register_control_callback(
|
||||
usbd_dev,
|
||||
USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
hid_control_request);
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
usbd_register_control_callback(
|
||||
usbd_dev,
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
dfu_control_request);
|
||||
@@ -329,8 +336,8 @@ int main(void)
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO2);
|
||||
|
||||
usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_register_set_config_callback(hid_set_config);
|
||||
usbd_dev = usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_register_set_config_callback(usbd_dev, hid_set_config);
|
||||
|
||||
/* Delay some seconds to show that pull-up switch works. */
|
||||
for (i = 0; i < 0x800000; i++)
|
||||
@@ -345,7 +352,7 @@ int main(void)
|
||||
// OTG_FS_GCCFG &= ~OTG_FS_GCCFG_VBUSBSEN;
|
||||
|
||||
while (1)
|
||||
usbd_poll();
|
||||
usbd_poll(usbd_dev);
|
||||
}
|
||||
|
||||
void sys_tick_handler(void)
|
||||
@@ -357,5 +364,5 @@ void sys_tick_handler(void)
|
||||
buf[1] = x >> 9;
|
||||
buf[2] = y >> 9;
|
||||
|
||||
usbd_ep_write_packet(0x81, buf, 4);
|
||||
usbd_ep_write_packet(usbd_dev, 0x81, buf, 4);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
##
|
||||
|
||||
BINARY = adc_injec
|
||||
|
||||
# Comment the following line if you _don't_ have luftboot flashed!
|
||||
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||
CFLAGS += -std=c99
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
##
|
||||
|
||||
BINARY = adc_injec_timtrig
|
||||
|
||||
# Comment the following line if you _don't_ have luftboot flashed!
|
||||
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||
CFLAGS += -std=c99
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
##
|
||||
|
||||
BINARY = adc_injec_timtrig_irq
|
||||
|
||||
# Comment the following line if you _don't_ have luftboot flashed!
|
||||
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||
CFLAGS += -std=c99
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <libopencm3/stm32/f1/adc.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/timer.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
|
||||
volatile u16 temperature = 0;
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
##
|
||||
|
||||
BINARY = adc_injec_timtrig_irq_4ch
|
||||
|
||||
# Comment the following line if you _don't_ have luftboot flashed!
|
||||
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||
CFLAGS += -std=c99
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <libopencm3/stm32/f1/adc.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/timer.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
|
||||
volatile u16 temperature = 0;
|
||||
volatile u16 v_refint = 0;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
##
|
||||
|
||||
BINARY = adc
|
||||
|
||||
# Comment the following line if you _don't_ have luftboot flashed!
|
||||
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||
CFLAGS += -std=c99
|
||||
|
||||
28
examples/stm32/f1/lisa-m-2/can/Makefile
Normal file
28
examples/stm32/f1/lisa-m-2/can/Makefile
Normal file
@@ -0,0 +1,28 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = can
|
||||
|
||||
# Comment the following line if you _don't_ have luftboot flashed!
|
||||
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||
CFLAGS += -std=c99
|
||||
LDSCRIPT = ../lisa-m.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
4
examples/stm32/f1/lisa-m-2/can/README
Normal file
4
examples/stm32/f1/lisa-m-2/can/README
Normal file
@@ -0,0 +1,4 @@
|
||||
This test sets up the CAN interface on Lisa/M and transmits 8 bites every
|
||||
100ms. The first byte is being incremented in each cycle. The demo also
|
||||
receives messages and is displaing the first 4 bits of the first byte on the
|
||||
board LEDs.
|
||||
234
examples/stm32/f1/lisa-m-2/can/can.c
Normal file
234
examples/stm32/f1/lisa-m-2/can/can.c
Normal file
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
* Copyright (C) 2010-2011 Piotr Esden-Tempski <piotr@esden.net>
|
||||
*
|
||||
* 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/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/flash.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/cm3/systick.h>
|
||||
#include <libopencm3/stm32/can.h>
|
||||
|
||||
struct can_tx_msg {
|
||||
u32 std_id;
|
||||
u32 ext_id;
|
||||
u8 ide;
|
||||
u8 rtr;
|
||||
u8 dlc;
|
||||
u8 data[8];
|
||||
};
|
||||
|
||||
struct can_rx_msg {
|
||||
u32 std_id;
|
||||
u32 ext_id;
|
||||
u8 ide;
|
||||
u8 rtr;
|
||||
u8 dlc;
|
||||
u8 data[8];
|
||||
u8 fmi;
|
||||
};
|
||||
|
||||
struct can_tx_msg can_tx_msg;
|
||||
struct can_rx_msg can_rx_msg;
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Enable Alternate Function clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||
|
||||
/* Enable GPIOA clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
|
||||
/* Enable GPIOB clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
|
||||
/* Enable GPIOC clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
|
||||
/* Preconfigure LEDs. */
|
||||
gpio_set(GPIOA, GPIO8); /* LED1 off */
|
||||
gpio_set(GPIOB, GPIO4); /* LED2 off */
|
||||
gpio_set(GPIOC, GPIO2); /* LED3 off */
|
||||
gpio_set(GPIOC, GPIO5); /* LED4 off */
|
||||
gpio_set(GPIOC, GPIO15); /* LED5 off */
|
||||
|
||||
/* Configure LED GPIOOs. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO8);
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO4);
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO2);
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO5);
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
||||
|
||||
/* Configure PB4 as GPIO. */
|
||||
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST;
|
||||
|
||||
}
|
||||
|
||||
void systick_setup(void)
|
||||
{
|
||||
/* 72MHz / 8 => 9000000 counts per second */
|
||||
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
|
||||
|
||||
/* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */
|
||||
systick_set_reload(9000);
|
||||
|
||||
systick_interrupt_enable();
|
||||
|
||||
/* Start counting. */
|
||||
systick_counter_enable();
|
||||
}
|
||||
|
||||
void can_setup(void)
|
||||
{
|
||||
/* Enable peripheral clocks. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_CAN1EN);
|
||||
|
||||
AFIO_MAPR |= AFIO_MAPR_CAN1_REMAP_PORTB;
|
||||
|
||||
/* Configure CAN pin: RX (input pull-up). */
|
||||
gpio_set_mode(GPIO_BANK_CAN1_PB_RX, GPIO_MODE_INPUT,
|
||||
GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_CAN1_PB_RX);
|
||||
gpio_set(GPIO_BANK_CAN1_PB_RX, GPIO_CAN1_PB_RX);
|
||||
|
||||
/* Configure CAN pin: TX. */
|
||||
gpio_set_mode(GPIO_BANK_CAN1_PB_TX, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_CAN1_PB_TX);
|
||||
|
||||
/* NVIC setup. */
|
||||
nvic_enable_irq(NVIC_USB_LP_CAN_RX0_IRQ);
|
||||
nvic_set_priority(NVIC_USB_LP_CAN_RX0_IRQ, 1);
|
||||
|
||||
/* Reset CAN. */
|
||||
can_reset(CAN1);
|
||||
|
||||
/* CAN cell init. */
|
||||
if (can_init(CAN1,
|
||||
false, /* TTCM: Time triggered comm mode? */
|
||||
true, /* ABOM: Automatic bus-off management? */
|
||||
false, /* AWUM: Automatic wakeup mode? */
|
||||
false, /* NART: No automatic retransmission? */
|
||||
false, /* RFLM: Receive FIFO locked mode? */
|
||||
false, /* TXFP: Transmit FIFO priority? */
|
||||
CAN_BTR_SJW_1TQ,
|
||||
CAN_BTR_TS1_3TQ,
|
||||
CAN_BTR_TS2_4TQ,
|
||||
12)) /* BRP+1: Baud rate prescaler */
|
||||
{
|
||||
gpio_set(GPIOA, GPIO8); /* LED1 off */
|
||||
gpio_set(GPIOB, GPIO4); /* LED2 off */
|
||||
gpio_set(GPIOC, GPIO2); /* LED3 off */
|
||||
gpio_clear(GPIOC, GPIO5); /* LED4 on */
|
||||
gpio_set(GPIOC, GPIO15); /* LED5 off */
|
||||
|
||||
/* Die because we failed to initialize. */
|
||||
while (1)
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
/* CAN filter 0 init. */
|
||||
can_filter_id_mask_32bit_init(CAN1,
|
||||
0, /* Filter ID */
|
||||
0, /* CAN ID */
|
||||
0, /* CAN ID mask */
|
||||
0, /* FIFO assignment (here: FIFO0) */
|
||||
true); /* Enable the filter. */
|
||||
|
||||
/* Enable CAN RX interrupt. */
|
||||
can_enable_irq(CAN1, CAN_IER_FMPIE0);
|
||||
}
|
||||
|
||||
void sys_tick_handler(void)
|
||||
{
|
||||
static int temp32 = 0;
|
||||
static u8 data[8] = {0, 1, 2, 0, 0, 0, 0, 0};
|
||||
|
||||
/* We call this handler every 1ms so every 100ms = 0.1s
|
||||
* resulting in 100Hz message rate.
|
||||
*/
|
||||
if (++temp32 != 100)
|
||||
return;
|
||||
|
||||
temp32 = 0;
|
||||
|
||||
/* Transmit CAN frame. */
|
||||
data[0]++;
|
||||
if (can_transmit(CAN1,
|
||||
0, /* (EX/ST)ID: CAN ID */
|
||||
false, /* IDE: CAN ID extended? */
|
||||
false, /* RTR: Request transmit? */
|
||||
8, /* DLC: Data length */
|
||||
data) == -1)
|
||||
{
|
||||
gpio_set(GPIOA, GPIO8); /* LED1 off */
|
||||
gpio_set(GPIOB, GPIO4); /* LED2 off */
|
||||
gpio_set(GPIOC, GPIO2); /* LED3 off */
|
||||
gpio_set(GPIOC, GPIO5); /* LED4 off */
|
||||
gpio_clear(GPIOC, GPIO15); /* LED5 on */
|
||||
}
|
||||
}
|
||||
|
||||
void usb_lp_can_rx0_isr(void)
|
||||
{
|
||||
u32 id, fmi;
|
||||
bool ext, rtr;
|
||||
u8 length, data[8];
|
||||
|
||||
can_receive(CAN1, 0, false, &id, &ext, &rtr, &fmi, &length, data);
|
||||
|
||||
if (data[0] & 1)
|
||||
gpio_clear(GPIOA, GPIO8);
|
||||
else
|
||||
gpio_set(GPIOA, GPIO8);
|
||||
|
||||
if (data[0] & 2)
|
||||
gpio_clear(GPIOB, GPIO4);
|
||||
else
|
||||
gpio_set(GPIOB, GPIO4);
|
||||
|
||||
if (data[0] & 4)
|
||||
gpio_clear(GPIOC, GPIO2);
|
||||
else
|
||||
gpio_set(GPIOC, GPIO2);
|
||||
|
||||
if (data[0] & 8)
|
||||
gpio_clear(GPIOC, GPIO5);
|
||||
else
|
||||
gpio_set(GPIOC, GPIO5);
|
||||
|
||||
can_fifo_release(CAN1, 0);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_12mhz_out_72mhz();
|
||||
gpio_setup();
|
||||
can_setup();
|
||||
systick_setup();
|
||||
|
||||
while (1); /* Halt. */
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
BINARY = fancyblink
|
||||
|
||||
# Comment the following line if you _don't_ have luftboot flashed!
|
||||
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||
CFLAGS += -std=c99
|
||||
LDSCRIPT = ../lisa-m.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
BINARY = usart
|
||||
|
||||
# Comment the following line if you _don't_ have luftboot flashed!
|
||||
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||
CFLAGS += -std=c99
|
||||
LDSCRIPT = ../lisa-m.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
BINARY = usart_dma
|
||||
|
||||
# Comment the following line if you _don't_ have luftboot flashed!
|
||||
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||
CFLAGS += -std=c99
|
||||
LDSCRIPT = ../lisa-m.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/f1/dma.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
BINARY = usart_irq
|
||||
|
||||
# Comment the following line if you _don't_ have luftboot flashed!
|
||||
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||
CFLAGS += -std=c99
|
||||
LDSCRIPT = ../lisa-m.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
BINARY = usart_irq_printf
|
||||
|
||||
# Comment the following line if you _don't_ have luftboot flashed!
|
||||
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||
CFLAGS += -std=c99
|
||||
LDSCRIPT = ../lisa-m.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/stm32/systick.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/cm3/systick.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
BINARY = usart_printf
|
||||
|
||||
# Comment the following line if you _don't_ have luftboot flashed!
|
||||
LDFLAGS += -Wl,-Ttext=0x8002000
|
||||
CFLAGS += -std=c99
|
||||
LDSCRIPT = ../lisa-m.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
25
examples/stm32/f1/obldc-strip/can/Makefile
Normal file
25
examples/stm32/f1/obldc-strip/can/Makefile
Normal file
@@ -0,0 +1,25 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = can
|
||||
|
||||
LDSCRIPT = ../obldc-strip.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
4
examples/stm32/f1/obldc-strip/can/README
Normal file
4
examples/stm32/f1/obldc-strip/can/README
Normal file
@@ -0,0 +1,4 @@
|
||||
This test sets up the CAN interface on Lisa/M and transmits 8 bites every
|
||||
100ms. The first byte is being incremented in each cycle. The demo also
|
||||
receives messages and is displaing the first 4 bits of the first byte on the
|
||||
board LEDs.
|
||||
202
examples/stm32/f1/obldc-strip/can/can.c
Normal file
202
examples/stm32/f1/obldc-strip/can/can.c
Normal file
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2012 Piotr Esden-Tempski <piotr@esden.net>
|
||||
*
|
||||
* 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/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/flash.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/cm3/systick.h>
|
||||
#include <libopencm3/stm32/can.h>
|
||||
|
||||
struct can_tx_msg {
|
||||
u32 std_id;
|
||||
u32 ext_id;
|
||||
u8 ide;
|
||||
u8 rtr;
|
||||
u8 dlc;
|
||||
u8 data[8];
|
||||
};
|
||||
|
||||
struct can_rx_msg {
|
||||
u32 std_id;
|
||||
u32 ext_id;
|
||||
u8 ide;
|
||||
u8 rtr;
|
||||
u8 dlc;
|
||||
u8 data[8];
|
||||
u8 fmi;
|
||||
};
|
||||
|
||||
struct can_tx_msg can_tx_msg;
|
||||
struct can_rx_msg can_rx_msg;
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Enable Alternate Function clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||
|
||||
/* Enable GPIOB clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
|
||||
/* Preconfigure LEDs. */
|
||||
gpio_set(GPIOB, GPIO4); /* LED green off */
|
||||
gpio_set(GPIOB, GPIO5); /* LED red off */
|
||||
|
||||
/* Configure LED GPIOs. */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO4);
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO5);
|
||||
|
||||
/* Configure PB4 as GPIO. */
|
||||
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST;
|
||||
|
||||
}
|
||||
|
||||
void systick_setup(void)
|
||||
{
|
||||
/* 64MHz / 8 => 8000000 counts per second */
|
||||
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
|
||||
|
||||
/* 8000000/8000 = 1000 overflows per second - every 1ms one interrupt */
|
||||
systick_set_reload(8000);
|
||||
|
||||
systick_interrupt_enable();
|
||||
|
||||
/* Start counting. */
|
||||
systick_counter_enable();
|
||||
}
|
||||
|
||||
void can_setup(void)
|
||||
{
|
||||
/* Enable peripheral clocks. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_CAN1EN);
|
||||
|
||||
AFIO_MAPR |= AFIO_MAPR_CAN1_REMAP_PORTB;
|
||||
|
||||
/* Configure CAN pin: RX (input pull-up). */
|
||||
gpio_set_mode(GPIO_BANK_CAN1_PB_RX, GPIO_MODE_INPUT,
|
||||
GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_CAN1_PB_RX);
|
||||
gpio_set(GPIO_BANK_CAN1_PB_RX, GPIO_CAN1_PB_RX);
|
||||
|
||||
/* Configure CAN pin: TX. */
|
||||
gpio_set_mode(GPIO_BANK_CAN1_PB_TX, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_CAN1_PB_TX);
|
||||
|
||||
/* NVIC setup. */
|
||||
nvic_enable_irq(NVIC_USB_LP_CAN_RX0_IRQ);
|
||||
nvic_set_priority(NVIC_USB_LP_CAN_RX0_IRQ, 1);
|
||||
|
||||
/* Reset CAN. */
|
||||
can_reset(CAN1);
|
||||
|
||||
/* CAN cell init.
|
||||
* Setting the bitrate to 1MBit. APB1 = 32MHz,
|
||||
* prescaler = 2 -> 16MHz time quanta frequency.
|
||||
* 1tq sync + 9tq bit segment1 (TS1) + 6tq bit segment2 (TS2) =
|
||||
* 16time quanto per bit period, therefor 16MHz/16 = 1MHz
|
||||
*/
|
||||
if (can_init(CAN1,
|
||||
false, /* TTCM: Time triggered comm mode? */
|
||||
true, /* ABOM: Automatic bus-off management? */
|
||||
false, /* AWUM: Automatic wakeup mode? */
|
||||
false, /* NART: No automatic retransmission? */
|
||||
false, /* RFLM: Receive FIFO locked mode? */
|
||||
false, /* TXFP: Transmit FIFO priority? */
|
||||
CAN_BTR_SJW_1TQ,
|
||||
CAN_BTR_TS1_9TQ,
|
||||
CAN_BTR_TS2_6TQ,
|
||||
2)) /* BRP+1: Baud rate prescaler */
|
||||
{
|
||||
gpio_clear(GPIOB, GPIO4); /* LED green on */
|
||||
gpio_set(GPIOB, GPIO5); /* LED red off */
|
||||
|
||||
/* Die because we failed to initialize. */
|
||||
while (1)
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
/* CAN filter 0 init. */
|
||||
can_filter_id_mask_32bit_init(CAN1,
|
||||
0, /* Filter ID */
|
||||
0, /* CAN ID */
|
||||
0, /* CAN ID mask */
|
||||
0, /* FIFO assignment (here: FIFO0) */
|
||||
true); /* Enable the filter. */
|
||||
|
||||
/* Enable CAN RX interrupt. */
|
||||
can_enable_irq(CAN1, CAN_IER_FMPIE0);
|
||||
}
|
||||
|
||||
void sys_tick_handler(void)
|
||||
{
|
||||
static u8 data[8] = {0, 1, 2, 0, 0, 0, 0, 0};
|
||||
|
||||
/* We call this handler every 1ms so every 1ms = 0.001s
|
||||
* resulting in 1000Hz message rate.
|
||||
*/
|
||||
|
||||
/* Transmit CAN frame. */
|
||||
data[0]++;
|
||||
if (can_transmit(CAN1,
|
||||
0, /* (EX/ST)ID: CAN ID */
|
||||
false, /* IDE: CAN ID extended? */
|
||||
false, /* RTR: Request transmit? */
|
||||
8, /* DLC: Data length */
|
||||
data) == -1)
|
||||
{
|
||||
gpio_set(GPIOB, GPIO4); /* LED green off */
|
||||
gpio_clear(GPIOB, GPIO5); /* LED red on */
|
||||
}
|
||||
}
|
||||
|
||||
void usb_lp_can_rx0_isr(void)
|
||||
{
|
||||
u32 id, fmi;
|
||||
bool ext, rtr;
|
||||
u8 length, data[8];
|
||||
|
||||
can_receive(CAN1, 0, false, &id, &ext, &rtr, &fmi, &length, data);
|
||||
|
||||
if (data[0] & 0x40)
|
||||
gpio_clear(GPIOB, GPIO4);
|
||||
else
|
||||
gpio_set(GPIOB, GPIO4);
|
||||
|
||||
if (data[0] & 0x80)
|
||||
gpio_clear(GPIOB, GPIO5);
|
||||
else
|
||||
gpio_set(GPIOB, GPIO5);
|
||||
|
||||
can_fifo_release(CAN1, 0);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
rcc_clock_setup_in_hsi_out_64mhz();
|
||||
gpio_setup();
|
||||
can_setup();
|
||||
systick_setup();
|
||||
|
||||
while (1); /* Halt. */
|
||||
|
||||
return 0;
|
||||
}
|
||||
25
examples/stm32/f1/obldc-strip/led/Makefile
Normal file
25
examples/stm32/f1/obldc-strip/led/Makefile
Normal file
@@ -0,0 +1,25 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = led
|
||||
|
||||
LDSCRIPT = ../obldc-strip.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
65
examples/stm32/f1/obldc-strip/led/led.c
Normal file
65
examples/stm32/f1/obldc-strip/led/led.c
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2012 Piotr Esden-Tempski <piotr@esden.net>
|
||||
*
|
||||
* 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/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
/* Set STM32 to 64 MHz. */
|
||||
rcc_clock_setup_in_hsi_out_64mhz();
|
||||
|
||||
/* Enable alternate function peripheral clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||
|
||||
/* Enable GPIOB clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
|
||||
/* Configure PB4 as GPIO. */
|
||||
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST;
|
||||
|
||||
/* Set GPIO4 and 5 (in GPIO port B) to 'output push-pull'. */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO4 | GPIO5);
|
||||
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
clock_setup();
|
||||
gpio_setup();
|
||||
|
||||
/* Blink the LEDs on the board. */
|
||||
while (1) {
|
||||
gpio_toggle(GPIOB, GPIO4); /* LED on/off */
|
||||
for (i = 0; i < 8000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
gpio_toggle(GPIOB, GPIO5); /* LED on/off */
|
||||
for (i = 0; i < 8000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
31
examples/stm32/f1/obldc-strip/obldc-strip.ld
Normal file
31
examples/stm32/f1/obldc-strip/obldc-strip.ld
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for Open-BLDC (STM32F103CBT6, 128K flash, 20K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32f1.ld
|
||||
|
||||
25
examples/stm32/f1/obldc-strip/systick/Makefile
Normal file
25
examples/stm32/f1/obldc-strip/systick/Makefile
Normal file
@@ -0,0 +1,25 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = systick
|
||||
|
||||
LDSCRIPT = ../obldc-strip.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
81
examples/stm32/f1/obldc-strip/systick/systick.c
Normal file
81
examples/stm32/f1/obldc-strip/systick/systick.c
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2012 Piotr Esden-Tempski <piotr@esden.net>
|
||||
*
|
||||
* 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/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/flash.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/cm3/systick.h>
|
||||
|
||||
u32 temp32;
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Enable alternate function peripheral clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||
|
||||
/* Enable GPIOB clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
|
||||
gpio_clear(GPIOB, GPIO4); /* LED green on */
|
||||
gpio_set(GPIOB, GPIO5); /* LED red off */
|
||||
|
||||
/* Set GPIO4/5 (in GPIO port B) to 'output push-pull' for the LEDs. */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO4);
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO5);
|
||||
|
||||
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST;
|
||||
}
|
||||
|
||||
void sys_tick_handler(void)
|
||||
{
|
||||
temp32++;
|
||||
|
||||
/* We call this handler every 1ms so 1000ms = 1s on/off. */
|
||||
if (temp32 == 1000) {
|
||||
gpio_toggle(GPIOB, GPIO4); /* LED green on/off */
|
||||
gpio_toggle(GPIOB, GPIO5); /* LED red on/off */
|
||||
temp32 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
rcc_clock_setup_in_hsi_out_64mhz();
|
||||
gpio_setup();
|
||||
|
||||
temp32 = 0;
|
||||
|
||||
/* 64MHz / 8 => 8000000 counts per second */
|
||||
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
|
||||
|
||||
/* 8000000/8000 = 1000 overflows per second - every 1ms one interrupt */
|
||||
systick_set_reload(8000);
|
||||
|
||||
systick_interrupt_enable();
|
||||
|
||||
/* Start counting. */
|
||||
systick_counter_enable();
|
||||
|
||||
while (1); /* Halt. */
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -21,8 +21,8 @@
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/flash.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/stm32/systick.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/cm3/systick.h>
|
||||
#include <libopencm3/stm32/can.h>
|
||||
|
||||
struct can_tx_msg {
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/flash.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/stm32/systick.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/cm3/systick.h>
|
||||
|
||||
u32 temp32;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/timer.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/stm32/spi.h>
|
||||
#include "./dogm128.h"
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include <libopencm3/stm32/f1/rtc.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/pwr.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/flash.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/stm32/systick.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/cm3/systick.h>
|
||||
|
||||
u32 temp32;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <libopencm3/stm32/f1/flash.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/timer.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
|
||||
@@ -164,11 +164,12 @@ static const char *usb_strings[] = {
|
||||
"DEMO",
|
||||
};
|
||||
|
||||
static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
||||
static int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||
{
|
||||
(void)complete;
|
||||
(void)buf;
|
||||
(void)usbd_dev;
|
||||
|
||||
switch(req->bRequest) {
|
||||
case USB_CDC_REQ_SET_CONTROL_LINE_STATE: {
|
||||
@@ -200,28 +201,29 @@ static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void cdcacm_data_rx_cb(u8 ep)
|
||||
static void cdcacm_data_rx_cb(usbd_device *usbd_dev, u8 ep)
|
||||
{
|
||||
(void)ep;
|
||||
|
||||
char buf[64];
|
||||
int len = usbd_ep_read_packet(0x01, buf, 64);
|
||||
int len = usbd_ep_read_packet(usbd_dev, 0x01, buf, 64);
|
||||
|
||||
if (len) {
|
||||
usbd_ep_write_packet(0x82, buf, len);
|
||||
usbd_ep_write_packet(usbd_dev, 0x82, buf, len);
|
||||
buf[len] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void cdcacm_set_config(u16 wValue)
|
||||
static void cdcacm_set_config(usbd_device *usbd_dev, u16 wValue)
|
||||
{
|
||||
(void)wValue;
|
||||
|
||||
usbd_ep_setup(0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb);
|
||||
usbd_ep_setup(0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
|
||||
usbd_ep_setup(0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
||||
usbd_ep_setup(usbd_dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb);
|
||||
usbd_ep_setup(usbd_dev, 0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
|
||||
usbd_ep_setup(usbd_dev, 0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
||||
|
||||
usbd_register_control_callback(
|
||||
usbd_dev,
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
cdcacm_control_request);
|
||||
@@ -229,6 +231,8 @@ static void cdcacm_set_config(u16 wValue)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
usbd_device *usbd_dev;
|
||||
|
||||
rcc_clock_setup_in_hsi_out_48mhz();
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
@@ -238,13 +242,13 @@ int main(void)
|
||||
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
||||
|
||||
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_register_set_config_callback(cdcacm_set_config);
|
||||
usbd_dev = usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_register_set_config_callback(usbd_dev, cdcacm_set_config);
|
||||
|
||||
gpio_set(GPIOA, GPIO15);
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
||||
|
||||
while (1)
|
||||
usbd_poll();
|
||||
usbd_poll(usbd_dev);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/f1/flash.h>
|
||||
#include <libopencm3/stm32/f1/scb.h>
|
||||
#include <libopencm3/cm3/scb.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include <libopencm3/usb/dfu.h>
|
||||
|
||||
@@ -130,10 +130,11 @@ static u8 usbdfu_getstatus(u32 *bwPollTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
||||
static void usbdfu_getstatus_complete(usbd_device *usbd_dev, struct usb_setup_data *req)
|
||||
{
|
||||
int i;
|
||||
(void)req;
|
||||
(void)usbd_dev;
|
||||
|
||||
switch (usbdfu_state) {
|
||||
case STATE_DFU_DNBUSY:
|
||||
@@ -166,9 +167,11 @@ static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
||||
}
|
||||
}
|
||||
|
||||
static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
||||
static int usbdfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||
{
|
||||
(void)usbd_dev;
|
||||
|
||||
if ((req->bmRequestType & 0x7F) != 0x21)
|
||||
return 0; /* Only accept class request. */
|
||||
|
||||
@@ -221,6 +224,8 @@ static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
|
||||
int main(void)
|
||||
{
|
||||
usbd_device *usbd_dev;
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
|
||||
if (!gpio_get(GPIOA, GPIO10)) {
|
||||
@@ -246,9 +251,10 @@ int main(void)
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_OTGFSEN);
|
||||
|
||||
usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_set_control_buffer_size(sizeof(usbd_control_buffer));
|
||||
usbd_dev = usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_set_control_buffer_size(usbd_dev, sizeof(usbd_control_buffer));
|
||||
usbd_register_control_callback(
|
||||
usbd_dev,
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
usbdfu_control_request);
|
||||
@@ -258,5 +264,5 @@ int main(void)
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
||||
|
||||
while (1)
|
||||
usbd_poll();
|
||||
usbd_poll(usbd_dev);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/systick.h>
|
||||
#include <libopencm3/cm3/systick.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include <libopencm3/usb/hid.h>
|
||||
|
||||
@@ -28,10 +28,12 @@
|
||||
#define INCLUDE_DFU_INTERFACE
|
||||
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
#include <libopencm3/stm32/f1/scb.h>
|
||||
#include <libopencm3/cm3/scb.h>
|
||||
#include <libopencm3/usb/dfu.h>
|
||||
#endif
|
||||
|
||||
static usbd_device *usbd_dev;
|
||||
|
||||
const struct usb_device_descriptor dev = {
|
||||
.bLength = USB_DT_DEVICE_SIZE,
|
||||
.bDescriptorType = USB_DT_DEVICE,
|
||||
@@ -169,10 +171,11 @@ static const char *usb_strings[] = {
|
||||
"DEMO",
|
||||
};
|
||||
|
||||
static int hid_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
void (**complete)(struct usb_setup_data *req))
|
||||
static int hid_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||
{
|
||||
(void)complete;
|
||||
(void)usbd_dev;
|
||||
|
||||
if((req->bmRequestType != 0x81) ||
|
||||
(req->bRequest != USB_REQ_GET_DESCRIPTOR) ||
|
||||
@@ -187,9 +190,10 @@ static int hid_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
}
|
||||
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
static void dfu_detach_complete(struct usb_setup_data *req)
|
||||
static void dfu_detach_complete(usbd_device *usbd_dev, struct usb_setup_data *req)
|
||||
{
|
||||
(void)req;
|
||||
(void)usbd_dev;
|
||||
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
@@ -198,11 +202,12 @@ static void dfu_detach_complete(struct usb_setup_data *req)
|
||||
scb_reset_core();
|
||||
}
|
||||
|
||||
static int dfu_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
void (**complete)(struct usb_setup_data *req))
|
||||
static int dfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||
{
|
||||
(void)buf;
|
||||
(void)len;
|
||||
(void)usbd_dev;
|
||||
|
||||
if ((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH))
|
||||
return 0; /* Only accept class request. */
|
||||
@@ -213,18 +218,21 @@ static int dfu_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
}
|
||||
#endif
|
||||
|
||||
static void hid_set_config(u16 wValue)
|
||||
static void hid_set_config(usbd_device *usbd_dev, u16 wValue)
|
||||
{
|
||||
(void)wValue;
|
||||
(void)usbd_dev;
|
||||
|
||||
usbd_ep_setup(0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL);
|
||||
usbd_ep_setup(usbd_dev, 0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL);
|
||||
|
||||
usbd_register_control_callback(
|
||||
usbd_dev,
|
||||
USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
hid_control_request);
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
usbd_register_control_callback(
|
||||
usbd_dev,
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
dfu_control_request);
|
||||
@@ -246,15 +254,15 @@ int main(void)
|
||||
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON;
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
||||
|
||||
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_register_set_config_callback(hid_set_config);
|
||||
usbd_dev = usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_register_set_config_callback(usbd_dev, hid_set_config);
|
||||
|
||||
gpio_set(GPIOA, GPIO15);
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
||||
|
||||
while (1)
|
||||
usbd_poll();
|
||||
usbd_poll(usbd_dev);
|
||||
}
|
||||
|
||||
void sys_tick_handler(void)
|
||||
@@ -270,5 +278,5 @@ void sys_tick_handler(void)
|
||||
if (x < -30)
|
||||
dir = -dir;
|
||||
|
||||
usbd_ep_write_packet(0x81, buf, 4);
|
||||
usbd_ep_write_packet(usbd_dev, 0x81, buf, 4);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/stm32/exti.h>
|
||||
|
||||
u16 exti_line_state;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/stm32/exti.h>
|
||||
|
||||
u16 exti_line_state;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/stm32/exti.h>
|
||||
|
||||
#define FALLING 0
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/timer.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/stm32/exti.h>
|
||||
|
||||
#define FALLING 0
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/timer.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/stm32/exti.h>
|
||||
|
||||
u16 frequency_sequence[18] = {
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/stm32/systick.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <libopencm3/cm3/systick.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ static const struct usb_device_descriptor dev = {
|
||||
};
|
||||
|
||||
/*
|
||||
* This notification endpoint isn't implemented. According to CDC spec its
|
||||
* This notification endpoint isn't implemented. According to CDC spec its
|
||||
* optional, but its absence causes a NULL pointer dereference in Linux
|
||||
* cdc_acm driver.
|
||||
*/
|
||||
@@ -83,7 +83,7 @@ static const struct {
|
||||
.bcdCDC = 0x0110,
|
||||
},
|
||||
.call_mgmt = {
|
||||
.bFunctionLength =
|
||||
.bFunctionLength =
|
||||
sizeof(struct usb_cdc_call_management_descriptor),
|
||||
.bDescriptorType = CS_INTERFACE,
|
||||
.bDescriptorSubtype = USB_CDC_TYPE_CALL_MANAGEMENT,
|
||||
@@ -101,7 +101,7 @@ static const struct {
|
||||
.bDescriptorType = CS_INTERFACE,
|
||||
.bDescriptorSubtype = USB_CDC_TYPE_UNION,
|
||||
.bControlInterface = 0,
|
||||
.bSubordinateInterface0 = 1,
|
||||
.bSubordinateInterface0 = 1,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -164,11 +164,12 @@ static const char *usb_strings[] = {
|
||||
"DEMO",
|
||||
};
|
||||
|
||||
static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
||||
static int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||
{
|
||||
(void)complete;
|
||||
(void)buf;
|
||||
(void)usbd_dev;
|
||||
|
||||
switch (req->bRequest) {
|
||||
case USB_CDC_REQ_SET_CONTROL_LINE_STATE: {
|
||||
@@ -199,28 +200,31 @@ static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void cdcacm_data_rx_cb(u8 ep)
|
||||
static void cdcacm_data_rx_cb(usbd_device *usbd_dev, u8 ep)
|
||||
{
|
||||
(void)ep;
|
||||
(void)usbd_dev;
|
||||
|
||||
char buf[64];
|
||||
int len = usbd_ep_read_packet(0x01, buf, 64);
|
||||
int len = usbd_ep_read_packet(usbd_dev, 0x01, buf, 64);
|
||||
|
||||
if (len) {
|
||||
usbd_ep_write_packet(0x82, buf, len);
|
||||
usbd_ep_write_packet(usbd_dev, 0x82, buf, len);
|
||||
buf[len] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void cdcacm_set_config(u16 wValue)
|
||||
static void cdcacm_set_config(usbd_device *usbd_dev, u16 wValue)
|
||||
{
|
||||
(void)wValue;
|
||||
(void)usbd_dev;
|
||||
|
||||
usbd_ep_setup(0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb);
|
||||
usbd_ep_setup(0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
|
||||
usbd_ep_setup(0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
||||
usbd_ep_setup(usbd_dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb);
|
||||
usbd_ep_setup(usbd_dev, 0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
|
||||
usbd_ep_setup(usbd_dev, 0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
||||
|
||||
usbd_register_control_callback(
|
||||
usbd_dev,
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
cdcacm_control_request);
|
||||
@@ -230,6 +234,8 @@ int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
usbd_device *usbd_dev;
|
||||
|
||||
rcc_clock_setup_in_hsi_out_48mhz();
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
@@ -238,13 +244,13 @@ int main(void)
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO11);
|
||||
|
||||
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_register_set_config_callback(cdcacm_set_config);
|
||||
usbd_dev = usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_register_set_config_callback(usbd_dev, cdcacm_set_config);
|
||||
|
||||
for (i = 0; i < 0x800000; i++)
|
||||
__asm__("nop");
|
||||
gpio_clear(GPIOC, GPIO11);
|
||||
|
||||
while (1)
|
||||
usbd_poll();
|
||||
usbd_poll(usbd_dev);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/f1/flash.h>
|
||||
#include <libopencm3/stm32/f1/scb.h>
|
||||
#include <libopencm3/cm3/scb.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include <libopencm3/usb/dfu.h>
|
||||
|
||||
@@ -114,8 +114,10 @@ static const char *usb_strings[] = {
|
||||
"@Internal Flash /0x08000000/8*001Ka,56*001Kg",
|
||||
};
|
||||
|
||||
static u8 usbdfu_getstatus(u32 *bwPollTimeout)
|
||||
static u8 usbdfu_getstatus(usbd_device *usbd_dev, u32 *bwPollTimeout)
|
||||
{
|
||||
(void)usbd_dev;
|
||||
|
||||
switch (usbdfu_state) {
|
||||
case STATE_DFU_DNLOAD_SYNC:
|
||||
usbdfu_state = STATE_DFU_DNBUSY;
|
||||
@@ -130,10 +132,11 @@ static u8 usbdfu_getstatus(u32 *bwPollTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
||||
static void usbdfu_getstatus_complete(usbd_device *usbd_dev, struct usb_setup_data *req)
|
||||
{
|
||||
int i;
|
||||
(void)req;
|
||||
(void)usbd_dev;
|
||||
|
||||
switch (usbdfu_state) {
|
||||
case STATE_DFU_DNBUSY:
|
||||
@@ -166,8 +169,8 @@ static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
||||
}
|
||||
}
|
||||
|
||||
static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
||||
static int usbdfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||
{
|
||||
if ((req->bmRequestType & 0x7F) != 0x21)
|
||||
return 0; /* Only accept class request. */
|
||||
@@ -199,7 +202,7 @@ static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
return 0;
|
||||
case DFU_GETSTATUS: {
|
||||
u32 bwPollTimeout = 0; /* 24-bit integer in DFU class spec */
|
||||
(*buf)[0] = usbdfu_getstatus(&bwPollTimeout);
|
||||
(*buf)[0] = usbdfu_getstatus(usbd_dev, &bwPollTimeout);
|
||||
(*buf)[1] = bwPollTimeout & 0xFF;
|
||||
(*buf)[2] = (bwPollTimeout >> 8) & 0xFF;
|
||||
(*buf)[3] = (bwPollTimeout >> 16) & 0xFF;
|
||||
@@ -221,6 +224,8 @@ static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
|
||||
int main(void)
|
||||
{
|
||||
usbd_device *usbd_dev;
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
|
||||
if (!gpio_get(GPIOA, GPIO10)) {
|
||||
@@ -244,9 +249,10 @@ int main(void)
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO11);
|
||||
gpio_set(GPIOC, GPIO11);
|
||||
|
||||
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_set_control_buffer_size(sizeof(usbd_control_buffer));
|
||||
usbd_dev = usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_set_control_buffer_size(usbd_dev, sizeof(usbd_control_buffer));
|
||||
usbd_register_control_callback(
|
||||
usbd_dev,
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
usbdfu_control_request);
|
||||
@@ -254,5 +260,5 @@ int main(void)
|
||||
gpio_clear(GPIOC, GPIO11);
|
||||
|
||||
while (1)
|
||||
usbd_poll();
|
||||
usbd_poll(usbd_dev);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/systick.h>
|
||||
#include <libopencm3/cm3/systick.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include <libopencm3/usb/hid.h>
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#define INCLUDE_DFU_INTERFACE
|
||||
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
#include <libopencm3/stm32/f1/scb.h>
|
||||
#include <libopencm3/cm3/scb.h>
|
||||
#include <libopencm3/usb/dfu.h>
|
||||
#endif
|
||||
|
||||
@@ -169,10 +169,11 @@ static const char *usb_strings[] = {
|
||||
"DEMO",
|
||||
};
|
||||
|
||||
static int hid_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
void (**complete)(struct usb_setup_data *req))
|
||||
static int hid_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||
{
|
||||
(void)complete;
|
||||
(void)usbd_dev;
|
||||
|
||||
if ((req->bmRequestType != 0x81) ||
|
||||
(req->bRequest != USB_REQ_GET_DESCRIPTOR) ||
|
||||
@@ -187,9 +188,10 @@ static int hid_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
}
|
||||
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
static void dfu_detach_complete(struct usb_setup_data *req)
|
||||
static void dfu_detach_complete(usbd_device *usbd_dev, struct usb_setup_data *req)
|
||||
{
|
||||
(void)req;
|
||||
(void)usbd_dev;
|
||||
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
@@ -198,11 +200,12 @@ static void dfu_detach_complete(struct usb_setup_data *req)
|
||||
scb_reset_core();
|
||||
}
|
||||
|
||||
static int dfu_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
void (**complete)(struct usb_setup_data *req))
|
||||
static int dfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||
{
|
||||
(void)buf;
|
||||
(void)len;
|
||||
(void)usbd_dev;
|
||||
|
||||
if ((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH))
|
||||
return 0; /* Only accept class request. */
|
||||
@@ -213,18 +216,21 @@ static int dfu_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
}
|
||||
#endif
|
||||
|
||||
static void hid_set_config(u16 wValue)
|
||||
static void hid_set_config(usbd_device *usbd_dev, u16 wValue)
|
||||
{
|
||||
(void)wValue;
|
||||
(void)usbd_dev;
|
||||
|
||||
usbd_ep_setup(0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL);
|
||||
usbd_ep_setup(usbd_dev, 0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL);
|
||||
|
||||
usbd_register_control_callback(
|
||||
usbd_dev,
|
||||
USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
hid_control_request);
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
usbd_register_control_callback(
|
||||
usbd_dev,
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
dfu_control_request);
|
||||
@@ -240,6 +246,8 @@ int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
usbd_device *usbd_dev;
|
||||
|
||||
rcc_clock_setup_in_hsi_out_48mhz();
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
@@ -248,8 +256,8 @@ int main(void)
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO11);
|
||||
|
||||
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_register_set_config_callback(hid_set_config);
|
||||
usbd_dev = usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_register_set_config_callback(usbd_dev, hid_set_config);
|
||||
|
||||
for (i = 0; i < 0x80000; i++)
|
||||
__asm__("nop");
|
||||
@@ -257,9 +265,10 @@ int main(void)
|
||||
gpio_clear(GPIOC, GPIO11);
|
||||
|
||||
while (1)
|
||||
usbd_poll();
|
||||
usbd_poll(usbd_dev);
|
||||
}
|
||||
|
||||
#if 0 /* is this used? */
|
||||
void sys_tick_handler(void)
|
||||
{
|
||||
static int x = 0;
|
||||
@@ -273,5 +282,6 @@ void sys_tick_handler(void)
|
||||
if (x < -30)
|
||||
dir = -dir;
|
||||
|
||||
usbd_ep_write_packet(0x81, buf, 4);
|
||||
usbd_ep_write_packet(usbd_dev, 0x81, buf, 4);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/f1/flash.h>
|
||||
#include <libopencm3/stm32/f1/scb.h>
|
||||
#include <libopencm3/cm3/scb.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include <libopencm3/usb/dfu.h>
|
||||
|
||||
@@ -114,8 +114,10 @@ static const char *usb_strings[] = {
|
||||
"@Internal Flash /0x08000000/8*001Ka,56*001Kg",
|
||||
};
|
||||
|
||||
static u8 usbdfu_getstatus(u32 *bwPollTimeout)
|
||||
static u8 usbdfu_getstatus(usbd_device *usbd_dev, u32 *bwPollTimeout)
|
||||
{
|
||||
(void)usbd_dev;
|
||||
|
||||
switch (usbdfu_state) {
|
||||
case STATE_DFU_DNLOAD_SYNC:
|
||||
usbdfu_state = STATE_DFU_DNBUSY;
|
||||
@@ -130,10 +132,11 @@ static u8 usbdfu_getstatus(u32 *bwPollTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
||||
static void usbdfu_getstatus_complete(usbd_device *usbd_dev, struct usb_setup_data *req)
|
||||
{
|
||||
int i;
|
||||
(void)req;
|
||||
(void)usbd_dev;
|
||||
|
||||
switch (usbdfu_state) {
|
||||
case STATE_DFU_DNBUSY:
|
||||
@@ -166,8 +169,8 @@ static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
||||
}
|
||||
}
|
||||
|
||||
static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
||||
static int usbdfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||
{
|
||||
if ((req->bmRequestType & 0x7F) != 0x21)
|
||||
return 0; /* Only accept class request. */
|
||||
@@ -199,7 +202,7 @@ static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
return 0;
|
||||
case DFU_GETSTATUS: {
|
||||
u32 bwPollTimeout = 0; /* 24-bit integer in DFU class spec */
|
||||
(*buf)[0] = usbdfu_getstatus(&bwPollTimeout);
|
||||
(*buf)[0] = usbdfu_getstatus(usbd_dev, &bwPollTimeout);
|
||||
(*buf)[1] = bwPollTimeout & 0xFF;
|
||||
(*buf)[2] = (bwPollTimeout >> 8) & 0xFF;
|
||||
(*buf)[3] = (bwPollTimeout >> 16) & 0xFF;
|
||||
@@ -221,6 +224,8 @@ static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
|
||||
int main(void)
|
||||
{
|
||||
usbd_device *usbd_dev;
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
|
||||
if (!gpio_get(GPIOA, GPIO10)) {
|
||||
@@ -244,9 +249,10 @@ int main(void)
|
||||
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON;
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
||||
|
||||
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_set_control_buffer_size(sizeof(usbd_control_buffer));
|
||||
usbd_dev = usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_set_control_buffer_size(usbd_dev, sizeof(usbd_control_buffer));
|
||||
usbd_register_control_callback(
|
||||
usbd_dev,
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
usbdfu_control_request);
|
||||
@@ -256,5 +262,5 @@ int main(void)
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
||||
|
||||
while (1)
|
||||
usbd_poll();
|
||||
usbd_poll(usbd_dev);
|
||||
}
|
||||
|
||||
@@ -75,16 +75,17 @@ const char *usb_strings[] = {
|
||||
"1001",
|
||||
};
|
||||
|
||||
static int simple_control_callback(struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
||||
static int simple_control_callback(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
|
||||
{
|
||||
(void)buf;
|
||||
(void)len;
|
||||
(void)complete;
|
||||
(void)usbd_dev;
|
||||
|
||||
if (req->bmRequestType != 0x40)
|
||||
return 0; /* Only accept vendor request. */
|
||||
|
||||
|
||||
if (req->wValue & 1)
|
||||
gpio_set(GPIOC, GPIO6);
|
||||
else
|
||||
@@ -95,6 +96,8 @@ static int simple_control_callback(struct usb_setup_data *req, u8 **buf,
|
||||
|
||||
int main(void)
|
||||
{
|
||||
usbd_device *usbd_dev;
|
||||
|
||||
rcc_clock_setup_in_hse_8mhz_out_72mhz();
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
@@ -105,13 +108,14 @@ int main(void)
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
|
||||
|
||||
usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_dev = usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_register_control_callback(
|
||||
usbd_dev,
|
||||
USB_REQ_TYPE_VENDOR,
|
||||
USB_REQ_TYPE_TYPE,
|
||||
simple_control_callback);
|
||||
|
||||
while (1)
|
||||
usbd_poll();
|
||||
usbd_poll(usbd_dev);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <libopencm3/stm32/f1/rtc.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/pwr.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/cm3/nvic.h>
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user