More build improvements and fixed broken examples.
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
# Be silent per default, but 'make V=1' will show all compiler calls.
|
||||
ifneq ($(V),1)
|
||||
Q := @
|
||||
# Do not print "Entering directory ...".
|
||||
MAKEFLAGS += --no-print-directory
|
||||
endif
|
||||
|
||||
# TODO: Add usb_dfu later, doesn't build at the moment.
|
||||
all: fancyblink usb_hid
|
||||
|
||||
fancyblink:
|
||||
@printf " BUILD examples/stm32/lisa-m/fancyblink\n"
|
||||
$(Q)$(MAKE) -C usb_hid
|
||||
|
||||
usb_hid:
|
||||
@printf " BUILD examples/stm32/lisa-m/usb_hid\n"
|
||||
$(Q)$(MAKE) -C usb_hid
|
||||
|
||||
clean:
|
||||
@printf " CLEAN examples/stm32/lisa-m/usb_hid\n"
|
||||
$(Q)$(MAKE) -C usb_hid clean
|
||||
|
||||
.PHONY: fancyblink usb_hid clean
|
||||
|
||||
@@ -173,18 +173,26 @@ static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
||||
}
|
||||
}
|
||||
|
||||
static int usbdfu_control_command(struct usb_setup_data *req,
|
||||
void (**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))
|
||||
{
|
||||
(void)complete;
|
||||
|
||||
if(req->bmRequestType != 0x21)
|
||||
if((req->bmRequestType & 0x7F) != 0x21)
|
||||
return 0; /* Only accept class request */
|
||||
|
||||
|
||||
switch(req->bRequest) {
|
||||
case DFU_DNLOAD:
|
||||
usbdfu_state = STATE_DFU_MANIFEST_SYNC;
|
||||
return 1;
|
||||
if((len == NULL) || (*len == 0)) {
|
||||
usbdfu_state = STATE_DFU_MANIFEST_SYNC;
|
||||
return 1;
|
||||
} else {
|
||||
/* Copy download data for use on GET_STATUS */
|
||||
prog.blocknum = req->wValue;
|
||||
prog.len = *len;
|
||||
memcpy(prog.buf, *buf, *len);
|
||||
usbdfu_state = STATE_DFU_DNLOAD_SYNC;
|
||||
return 1;
|
||||
}
|
||||
case DFU_CLRSTATUS:
|
||||
/* Clear error and return to dfuIDLE */
|
||||
if(usbdfu_state == STATE_DFU_ERROR)
|
||||
@@ -194,19 +202,6 @@ static int usbdfu_control_command(struct usb_setup_data *req,
|
||||
/* Abort returns to dfuIDLE state */
|
||||
usbdfu_state = STATE_DFU_IDLE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int usbdfu_control_read(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
void (**complete)(struct usb_setup_data *req))
|
||||
{
|
||||
|
||||
if(req->bmRequestType != 0xA1)
|
||||
return 0; /* Only accept class request */
|
||||
|
||||
switch(req->bRequest) {
|
||||
case DFU_UPLOAD:
|
||||
/* Upload not supported for now */
|
||||
return 0;
|
||||
@@ -235,26 +230,6 @@ static int usbdfu_control_read(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int usbdfu_control_write(struct usb_setup_data *req, u8 *buf, u16 len,
|
||||
void (**complete)(struct usb_setup_data *req))
|
||||
{
|
||||
(void)complete;
|
||||
|
||||
if(req->bmRequestType != 0x21)
|
||||
return 0; /* Only accept class request */
|
||||
|
||||
if(req->bRequest != DFU_DNLOAD)
|
||||
return 0;
|
||||
|
||||
/* Copy download data for use on GET_STATUS */
|
||||
prog.blocknum = req->wValue;
|
||||
prog.len = len;
|
||||
memcpy(prog.buf, buf, len);
|
||||
usbdfu_state = STATE_DFU_DNLOAD_SYNC;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
@@ -280,11 +255,12 @@ int main(void)
|
||||
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON;
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
||||
|
||||
usbd_init(&dev, &config, usb_strings);
|
||||
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_set_control_buffer_size(sizeof(usbd_control_buffer));
|
||||
usbd_register_control_command_callback(usbdfu_control_command);
|
||||
usbd_register_control_write_callback(usbdfu_control_write);
|
||||
usbd_register_control_read_callback(usbdfu_control_read);
|
||||
usbd_register_control_callback(
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
usbdfu_control_request);
|
||||
|
||||
gpio_set(GPIOA, GPIO15);
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
|
||||
Reference in New Issue
Block a user