mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Merge pull request #2467 from openmv/dfu_bootloader
bootloader: Add new TinyUSB-based DFU bootloader.
This commit is contained in:
commit
28115f2d93
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -8,3 +8,6 @@
|
||||
[submodule "src/lib/tflm/libtflm"]
|
||||
path = src/lib/tflm/libtflm
|
||||
url = https://github.com/openmv/libtflm.git
|
||||
[submodule "src/lib/tinyusb"]
|
||||
path = src/lib/tinyusb
|
||||
url = https://github.com/hathach/tinyusb
|
||||
|
||||
@ -51,6 +51,7 @@ BUILD=$(TOP_DIR)/build
|
||||
TOOLS=$(TOP_DIR)/../tools
|
||||
FW_DIR=$(BUILD)/bin
|
||||
OMV_DIR=omv
|
||||
BOOT_DIR=boot
|
||||
CUBEAI_DIR=stm32cubeai
|
||||
CMSIS_DIR=hal/cmsis
|
||||
MICROPY_DIR=micropython
|
||||
|
||||
50
src/boot/Makefile
Normal file
50
src/boot/Makefile
Normal file
@ -0,0 +1,50 @@
|
||||
# Copyright (C) 2023-2024 OpenMV, LLC.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Any redistribution, use, or modification in source or binary form
|
||||
# is done solely for personal benefit and not for any commercial
|
||||
# purpose or for monetary gain. For commercial licensing options,
|
||||
# please contact openmv@openmv.io
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE LICENSOR AND COPYRIGHT OWNER "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR OR COPYRIGHT
|
||||
# OWNER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
# Bootloader Makefile
|
||||
|
||||
# Directories
|
||||
TOP_DIR ?= $(shell pwd)
|
||||
BUILD ?= $(TOP_DIR)/build
|
||||
|
||||
BOOT_DIR=boot
|
||||
PORT_DIR=ports/$(PORT)
|
||||
TINYUSB_DIR=lib/tinyusb
|
||||
PORT_LOWER:= $(shell echo $(PORT) | tr '[:upper:]' '[:lower:]')
|
||||
|
||||
CFLAGS = -MMD
|
||||
# Debugging/Optimization
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS = -Og -ggdb3
|
||||
else
|
||||
CFLAGS = -O2 -DNDEBUG
|
||||
endif
|
||||
|
||||
# Include the port Makefile.
|
||||
include $(PORT_DIR)/$(PORT_LOWER)_port.mk
|
||||
153
src/boot/common/desc.c
Normal file
153
src/boot/common/desc.c
Normal file
@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (C) 2023-2024 OpenMV, LLC.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Any redistribution, use, or modification in source or binary form
|
||||
* is done solely for personal benefit and not for any commercial
|
||||
* purpose or for monetary gain. For commercial licensing options,
|
||||
* please contact openmv@openmv.io
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE LICENSOR AND COPYRIGHT OWNER "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR OR COPYRIGHT
|
||||
* OWNER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* USB descriptors.
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "omv_bootconfig.h"
|
||||
|
||||
#define STR_DESC_MAX_LEN (32)
|
||||
#define STR_DESC_COUNT (sizeof(desc_string) / sizeof(desc_string[0]))
|
||||
|
||||
#define DFU_DESC_ALT_COUNT OMV_BOOT_PARTITIONS_COUNT
|
||||
#define DFU_DESC_FUNC_ATTR (DFU_ATTR_CAN_UPLOAD | DFU_ATTR_CAN_DOWNLOAD | DFU_ATTR_MANIFESTATION_TOLERANT)
|
||||
|
||||
#define CFG_DESC_ITF_DFU (0)
|
||||
#define CFG_DESC_ITF_COUNT (1)
|
||||
#define CFG_DESC_TOTAL_SIZE (TUD_CONFIG_DESC_LEN + TUD_DFU_DESC_LEN(DFU_DESC_ALT_COUNT))
|
||||
|
||||
static char const *desc_string[] = {
|
||||
"\x09\x04", // 0: English (0x0409)
|
||||
"OpenMV", // 1: Manufacturer
|
||||
"OpenMV Camera (DFU Mode)", // 2: Product
|
||||
OMV_BOOT_PARTITIONS_STR,
|
||||
};
|
||||
|
||||
static tusb_desc_device_t const desc_device = {
|
||||
.bLength = sizeof(tusb_desc_device_t),
|
||||
.bDescriptorType = TUSB_DESC_DEVICE,
|
||||
.bcdUSB = 0x0200,
|
||||
.bDeviceClass = 0x00,
|
||||
.bDeviceSubClass = 0x00,
|
||||
.bDeviceProtocol = 0x00,
|
||||
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
|
||||
.idVendor = OMV_BOOT_VID,
|
||||
.idProduct = OMV_BOOT_PID,
|
||||
.bcdDevice = 0x0200,
|
||||
.iManufacturer = 0x01,
|
||||
.iProduct = 0x02,
|
||||
.iSerialNumber = 0x03,
|
||||
.bNumConfigurations = 0x01
|
||||
};
|
||||
|
||||
#if (CFG_TUD_MAX_SPEED == OPT_MODE_HIGH_SPEED)
|
||||
// Device qualifier descriptor for high-speed devices.
|
||||
const tusb_desc_device_qualifier_t desc_device_qualifier = {
|
||||
.bLength = sizeof(tusb_desc_device_qualifier_t),
|
||||
.bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
|
||||
.bcdUSB = 0x0200,
|
||||
.bDeviceClass = 0x00,
|
||||
.bDeviceSubClass = 0x00,
|
||||
.bDeviceProtocol = 0x00,
|
||||
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
|
||||
.bNumConfigurations = 0x01,
|
||||
.bReserved = 0x00,
|
||||
};
|
||||
#endif
|
||||
|
||||
static uint8_t const desc_config[] = {
|
||||
// Config number, interface count, string index, total length, attribute, power in mA
|
||||
TUD_CONFIG_DESCRIPTOR(1, CFG_DESC_ITF_COUNT, 0, CFG_DESC_TOTAL_SIZE, 0x00, 500),
|
||||
|
||||
// Interface number, Alternate count, starting string index, attributes, detach timeout, transfer size
|
||||
TUD_DFU_DESCRIPTOR(CFG_DESC_ITF_DFU, DFU_DESC_ALT_COUNT, 4, DFU_DESC_FUNC_ATTR, 1000, CFG_TUD_DFU_XFER_BUFSIZE),
|
||||
};
|
||||
|
||||
uint8_t const *tud_descriptor_device_cb(void) {
|
||||
return (uint8_t const *) &desc_device;
|
||||
}
|
||||
|
||||
#if (CFG_TUD_MAX_SPEED == OPT_MODE_HIGH_SPEED)
|
||||
uint8_t const *tud_descriptor_device_qualifier_cb(void) {
|
||||
return (uint8_t const *) &desc_device_qualifier;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint8_t const *tud_descriptor_configuration_cb(uint8_t index) {
|
||||
return desc_config;
|
||||
}
|
||||
|
||||
uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
||||
size_t desc_len = 0;
|
||||
static uint16_t desc_str[STR_DESC_MAX_LEN + 1]; // + 1 for string type
|
||||
|
||||
uint8_t uid[12] = {0};
|
||||
char hex_buf[sizeof(uid) * 2] = {0};
|
||||
const char hex_chars[] = "0123456789ABCDEF";
|
||||
const char *str = NULL;
|
||||
|
||||
if (index == 0) {
|
||||
// Language ID
|
||||
desc_len = 1;
|
||||
memcpy(&desc_str[1], desc_string[0], 2);
|
||||
} else if (index == 3) {
|
||||
// Serial number
|
||||
if (port_get_uid(uid) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
for (size_t i = 0; i < sizeof(uid); i++) {
|
||||
hex_buf[i * 2] = hex_chars[(uid[i] & 0xF0) >> 4];
|
||||
hex_buf[i * 2 + 1] = hex_chars[uid[i] & 0x0F];
|
||||
}
|
||||
str = hex_buf;
|
||||
desc_len = sizeof(uid) * 2;
|
||||
} else if (index < STR_DESC_COUNT) {
|
||||
// Other.
|
||||
str = desc_string[index];
|
||||
desc_len = strlen(str);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Check max string descriptor length.
|
||||
if (desc_len > STR_DESC_MAX_LEN) {
|
||||
desc_len = STR_DESC_MAX_LEN;
|
||||
}
|
||||
|
||||
// Convert to UTF-16
|
||||
for (size_t i = 0; i < desc_len; i++) {
|
||||
desc_str[1 + i] = str[i];
|
||||
}
|
||||
|
||||
// First byte is the length (including the header), the second byte is string type.
|
||||
desc_str[0] = (uint16_t) ((TUSB_DESC_STRING << 8) | (2 * desc_len + 2));
|
||||
return desc_str;
|
||||
}
|
||||
114
src/boot/common/dfu.c
Normal file
114
src/boot/common/dfu.c
Normal file
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (C) 2023-2024 OpenMV, LLC.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Any redistribution, use, or modification in source or binary form
|
||||
* is done solely for personal benefit and not for any commercial
|
||||
* purpose or for monetary gain. For commercial licensing options,
|
||||
* please contact openmv@openmv.io
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE LICENSOR AND COPYRIGHT OWNER "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR OR COPYRIGHT
|
||||
* OWNER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* DFU callbacks implementations.
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "omv_bootconfig.h"
|
||||
|
||||
extern bool tud_dfu_detached;
|
||||
|
||||
// Invoked when a DFU_DETACH request is received.
|
||||
void tud_dfu_detach_cb(void) {
|
||||
tud_dfu_detached = true;
|
||||
}
|
||||
|
||||
// Invoked before tud_dfu_download_cb() (state=DFU_DNBUSY)
|
||||
// or before tud_dfu_manifest_cb() (state=DFU_MANIFEST).
|
||||
uint32_t tud_dfu_get_timeout_cb(uint8_t itf, uint8_t state) {
|
||||
tud_dfu_detached = false;
|
||||
|
||||
if (state == DFU_DNBUSY) {
|
||||
if (itf < 3) {
|
||||
return 0;
|
||||
} else {
|
||||
return 100;
|
||||
}
|
||||
} else if (state == DFU_MANIFEST) {
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Invoked when DFU_DNLOAD is received followed by DFU_GETSTATUS (state=DFU_DNBUSY).
|
||||
void tud_dfu_download_cb(uint8_t itf, uint16_t block, uint8_t const *src, uint16_t size) {
|
||||
const partition_t *p = &OMV_BOOT_PARTITIONS[itf];
|
||||
uint8_t *dst = (uint8_t *) (p->start + (block * CFG_TUD_DFU_XFER_BUFSIZE));
|
||||
|
||||
// Check if partition is writable.
|
||||
if (p->rdonly) {
|
||||
return tud_dfu_finish_flashing(DFU_STATUS_ERR_WRITE);
|
||||
}
|
||||
|
||||
// Allow writes to this region.
|
||||
if (block == 0) {
|
||||
port_mpu_protect(p, false);
|
||||
}
|
||||
|
||||
if ((uint32_t) dst + size > p->limit) {
|
||||
return tud_dfu_finish_flashing(DFU_STATUS_ERR_ADDRESS);
|
||||
}
|
||||
|
||||
if (port_flash_write(p->type, (uint32_t) dst, src, size) == 0) {
|
||||
tud_dfu_finish_flashing(DFU_STATUS_OK);
|
||||
} else {
|
||||
tud_dfu_finish_flashing(DFU_STATUS_ERR_WRITE);
|
||||
}
|
||||
}
|
||||
|
||||
// Invoked when the download process is complete, i.e.,
|
||||
// DFU_DNLOAD followed by DFU_GETSTATUS (state=Manifest).
|
||||
void tud_dfu_manifest_cb(uint8_t itf) {
|
||||
port_mpu_protect(&OMV_BOOT_PARTITIONS[itf], true);
|
||||
return tud_dfu_finish_flashing(DFU_STATUS_OK);
|
||||
}
|
||||
|
||||
// Invoked when DFU_UPLOAD request is received.
|
||||
uint16_t tud_dfu_upload_cb(uint8_t itf, uint16_t block, uint8_t *dst, uint16_t size) {
|
||||
const partition_t *p = &OMV_BOOT_PARTITIONS[itf];
|
||||
uint8_t *src = (uint8_t *) (p->start + (block * CFG_TUD_DFU_XFER_BUFSIZE));
|
||||
|
||||
if ((uint32_t) src + size > p->limit) {
|
||||
// Respond with a short frame to indicate EOF to the host.
|
||||
size = 4;
|
||||
memset(dst, 0, size);
|
||||
} else if (port_flash_read(p->type, (uint32_t) src, dst, size) != 0) {
|
||||
size = 0;
|
||||
}
|
||||
|
||||
if (size) {
|
||||
tud_dfu_finish_flashing(DFU_STATUS_OK);
|
||||
} else {
|
||||
tud_dfu_finish_flashing(DFU_STATUS_ERR_FILE);
|
||||
}
|
||||
tud_dfu_detached = false;
|
||||
return size;
|
||||
}
|
||||
85
src/boot/common/main.c
Normal file
85
src/boot/common/main.c
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2023-2024 OpenMV, LLC.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Any redistribution, use, or modification in source or binary form
|
||||
* is done solely for personal benefit and not for any commercial
|
||||
* purpose or for monetary gain. For commercial licensing options,
|
||||
* please contact openmv@openmv.io
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE LICENSOR AND COPYRIGHT OWNER "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR OR COPYRIGHT
|
||||
* OWNER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* DFU bootloader main.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "omv_bootconfig.h"
|
||||
|
||||
bool tud_dfu_detached = true;
|
||||
|
||||
int main(void) {
|
||||
// Initialize low-level sub-systems.
|
||||
port_init();
|
||||
|
||||
// Initialize TinyUSB.
|
||||
tusb_init();
|
||||
|
||||
uint32_t start_ms = port_ticks_ms();
|
||||
|
||||
while (true) {
|
||||
// Poll TinyUSB.
|
||||
tud_task();
|
||||
// Wait for the device to be connected and configured.
|
||||
if (tud_mounted() || (port_ticks_ms() - start_ms) > 500) {
|
||||
break;
|
||||
}
|
||||
port_led_blink(150);
|
||||
}
|
||||
|
||||
// Restart timeout.
|
||||
start_ms = port_ticks_ms();
|
||||
|
||||
while (tud_mounted()) {
|
||||
// Poll TinyUSB.
|
||||
tud_task();
|
||||
// Wait for first DFU command.
|
||||
if (tud_dfu_detached && ((port_ticks_ms() - start_ms) > OMV_BOOT_DFU_TIMEOUT)) {
|
||||
// Timeout, jump to main app.
|
||||
break;
|
||||
}
|
||||
if (!tud_dfu_detached) {
|
||||
port_led_blink(150);
|
||||
} else {
|
||||
port_led_blink(250);
|
||||
}
|
||||
}
|
||||
|
||||
// Disconnect USB device.
|
||||
tud_disconnect();
|
||||
|
||||
// Deinitialize low-level sub-systems.
|
||||
port_deinit();
|
||||
|
||||
// JUMP!
|
||||
((void (*) (void)) (*((uint32_t *) (OMV_BOOT_JUMP_ADDR + 4)))) ();
|
||||
}
|
||||
86
src/boot/common/port.h
Normal file
86
src/boot/common/port.h
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2023-2024 OpenMV, LLC.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Any redistribution, use, or modification in source or binary form
|
||||
* is done solely for personal benefit and not for any commercial
|
||||
* purpose or for monetary gain. For commercial licensing options,
|
||||
* please contact openmv@openmv.io
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE LICENSOR AND COPYRIGHT OWNER "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR OR COPYRIGHT
|
||||
* OWNER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Bootloader common types and functions for ports to implement.
|
||||
*/
|
||||
#ifndef __OMV_BOOT_PORT_H__
|
||||
#define __OMV_BOOT_PORT_H__
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "tusb.h"
|
||||
#include "tusb_config.h"
|
||||
#include "class/dfu/dfu.h"
|
||||
#include "class/dfu/dfu_device.h"
|
||||
|
||||
typedef struct pin {
|
||||
void *gpio;
|
||||
uint16_t port;
|
||||
uint16_t pin;
|
||||
uint16_t alt;
|
||||
uint16_t pad;
|
||||
uint16_t mode;
|
||||
uint16_t pull;
|
||||
uint16_t speed;
|
||||
} pin_t;
|
||||
|
||||
typedef enum {
|
||||
PIN_MODE_INPUT,
|
||||
PIN_MODE_OUTPUT
|
||||
} pin_mode_t;
|
||||
|
||||
// DFU partition entry.
|
||||
typedef struct {
|
||||
int32_t region;
|
||||
uint32_t rdonly;
|
||||
uintptr_t start;
|
||||
uintptr_t limit;
|
||||
uint32_t attr;
|
||||
uint32_t type;
|
||||
} partition_t;
|
||||
|
||||
typedef enum {
|
||||
PTYPE_AXI_FLASH,
|
||||
PTYPE_SPI_FLASH,
|
||||
} partition_type_t;
|
||||
|
||||
int port_init(void);
|
||||
int port_deinit(void);
|
||||
int port_get_uid(uint8_t *buf);
|
||||
void port_mpu_protect(const partition_t *p, bool enable);
|
||||
uint32_t port_ticks_ms();
|
||||
void port_delay_ms(uint32_t ms);
|
||||
void port_pin_mode(uint32_t pin, uint32_t mode);
|
||||
uint32_t port_pin_read(uint32_t pin);
|
||||
void port_pin_write(uint32_t pin, uint32_t state);
|
||||
void port_led_blink(uint32_t interval_ms);
|
||||
int port_flash_read(uint32_t ptype, uint32_t addr, uint8_t *buf, uint32_t size);
|
||||
int port_flash_write(uint32_t ptype, uint32_t addr, const uint8_t *buf, uint32_t size);
|
||||
#endif // __OMV_BOOT_PORT_H__
|
||||
@ -13,19 +13,16 @@
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
#include "omv_boardconfig.h"
|
||||
#include "omv_bootconfig.h"
|
||||
|
||||
/* Specify the memory areas */
|
||||
MEMORY
|
||||
{
|
||||
DTCM (xrw) : ORIGIN = OMV_DTCM_ORIGIN, LENGTH = OMV_DTCM_LENGTH
|
||||
RAM (xrw) : ORIGIN = OMV_SRAM1_ORIGIN, LENGTH = OMV_SRAM1_LENGTH
|
||||
FLASH_TEXT (rx) : ORIGIN = OMV_BOOT_FLASH_ORIGIN, LENGTH = OMV_BOOT_FLASH_LENGTH
|
||||
RAM (rwx): ORIGIN = OMV_DTCM_ORIGIN, LENGTH = OMV_DTCM_LENGTH
|
||||
ROM (rx) : ORIGIN = OMV_FLASH_BOOT_ORIGIN, LENGTH = OMV_FLASH_BOOT_LENGTH
|
||||
}
|
||||
|
||||
_estack = ORIGIN(DTCM) + LENGTH(DTCM);
|
||||
_ram_end = ORIGIN(DTCM) + LENGTH(DTCM);
|
||||
_stack_size = (4K); /* minimum amount of stack */
|
||||
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
|
||||
_stack_size = 16K;
|
||||
|
||||
/* Define output sections */
|
||||
SECTIONS
|
||||
@ -43,7 +40,7 @@ SECTIONS
|
||||
. = ALIGN(4);
|
||||
_etext = .; /* define a global symbols at end of code */
|
||||
_exit = .;
|
||||
} >FLASH_TEXT
|
||||
} >ROM
|
||||
|
||||
/* used by the startup to initialize data */
|
||||
_sidata = LOADADDR(.data);
|
||||
@ -59,7 +56,7 @@ SECTIONS
|
||||
|
||||
. = ALIGN(4);
|
||||
_edata = .; /* define a global symbol at data end */
|
||||
} >DTCM AT> FLASH_TEXT
|
||||
} >RAM AT> ROM
|
||||
|
||||
/* Uninitialized data section */
|
||||
. = ALIGN(4);
|
||||
@ -72,7 +69,7 @@ SECTIONS
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
_ebss = .; // define a global symbol at bss end
|
||||
} >DTCM
|
||||
} >RAM
|
||||
|
||||
/* Make sure there is enough RAM the stack and FS cache */
|
||||
.stack :
|
||||
@ -80,7 +77,8 @@ SECTIONS
|
||||
. = ALIGN(4);
|
||||
. = . + _stack_size;
|
||||
. = ALIGN(4);
|
||||
} >DTCM
|
||||
_estack = .;
|
||||
} >RAM
|
||||
|
||||
.ARM.attributes 0 : { *(.ARM.attributes) }
|
||||
}
|
||||
152
src/boot/ports/stm32/stm32_flash.c
Normal file
152
src/boot/ports/stm32/stm32_flash.c
Normal file
@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (C) 2023-2024 OpenMV, LLC.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Any redistribution, use, or modification in source or binary form
|
||||
* is done solely for personal benefit and not for any commercial
|
||||
* purpose or for monetary gain. For commercial licensing options,
|
||||
* please contact openmv@openmv.io
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE LICENSOR AND COPYRIGHT OWNER "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR OR COPYRIGHT
|
||||
* OWNER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* DFU bootloader SPI flash driver.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include STM32_HAL_H
|
||||
|
||||
#include "omv_boardconfig.h"
|
||||
#include "omv_bootconfig.h"
|
||||
#include "stm32_flash.h"
|
||||
|
||||
#if OMV_BOOT_AXI_FLASH_ENABLE
|
||||
|
||||
#if defined(MCU_SERIES_H7)
|
||||
#define FLASH_WORD_SIZE 32
|
||||
#define FLASH_WORD_GET(x) ((uint32_t) x)
|
||||
#else
|
||||
#define FLASH_WORD_SIZE 4
|
||||
#define FLASH_WORD_GET(x) *((uint32_t *) x)
|
||||
#endif
|
||||
|
||||
#if defined(MCU_SERIES_F7)
|
||||
#define FLASH_FLAG_PGSERR (FLASH_FLAG_ERSERR)
|
||||
#endif
|
||||
|
||||
#if defined(MCU_SERIES_F4)
|
||||
static const uint32_t flash_sectors[] = {
|
||||
0x08000000, 0x08004000, 0x08008000, 0x0800C000,
|
||||
0x08010000, 0x08020000, 0x08040000, 0x08060000,
|
||||
0x08080000, 0x080A0000, 0x080C0000, 0x080E0000
|
||||
};
|
||||
#elif defined(MCU_SERIES_F7)
|
||||
static const uint32_t flash_sectors[] = {
|
||||
0x08000000, 0x08008000, 0x08010000, 0x08018000,
|
||||
0x08020000, 0x08040000, 0x08080000, 0x080C0000,
|
||||
0x08100000, 0x08140000, 0x08180000, 0x081C0000
|
||||
};
|
||||
#elif defined(MCU_SERIES_H7)
|
||||
static const uint32_t flash_sectors[] = {
|
||||
0x08000000, 0x08020000, 0x08040000, 0x08060000,
|
||||
0x08080000, 0x080A0000, 0x080C0000, 0x080E0000,
|
||||
0x08100000, 0x08120000, 0x08140000, 0x08160000,
|
||||
0x08180000, 0x081A0000, 0x081C0000, 0x081E0000
|
||||
};
|
||||
#else
|
||||
#error MCU not specified!
|
||||
#endif
|
||||
|
||||
#define OMV_BOOT_FLASH_SECTORS_COUNT (sizeof(flash_sectors) / sizeof(flash_sectors[0]))
|
||||
|
||||
static int axi_flash_erase(uint32_t sector) {
|
||||
uint32_t error = 0;
|
||||
|
||||
FLASH_EraseInitTypeDef EraseInitStruct;
|
||||
EraseInitStruct.NbSectors = 1;
|
||||
EraseInitStruct.TypeErase = TYPEERASE_SECTORS;
|
||||
EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3;
|
||||
#if defined(MCU_SERIES_F4) || defined(MCU_SERIES_F7)
|
||||
EraseInitStruct.Sector = sector;
|
||||
#elif defined(MCU_SERIES_H7)
|
||||
EraseInitStruct.Sector = (sector % 8);
|
||||
EraseInitStruct.Banks = (sector < 8) ? FLASH_BANK_1 : FLASH_BANK_2;
|
||||
#endif
|
||||
|
||||
// Unlock flash
|
||||
HAL_FLASH_Unlock();
|
||||
|
||||
#if defined(MCU_SERIES_H7)
|
||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS_BANK1 | FLASH_FLAG_ALL_ERRORS_BANK2);
|
||||
#else
|
||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
|
||||
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
|
||||
#endif
|
||||
|
||||
// Erase the sector
|
||||
if (HAL_FLASHEx_Erase(&EraseInitStruct, &error) != HAL_OK) {
|
||||
HAL_FLASH_Lock();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Lock the flash
|
||||
HAL_FLASH_Lock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int axi_flash_read(uint32_t addr, uint8_t *buf, size_t size) {
|
||||
memcpy(buf, (void *) addr, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int axi_flash_write(uint32_t addr, const uint8_t *buf, size_t size) {
|
||||
// If at a block boundary, erase the block first.
|
||||
for (size_t i = 0; i < OMV_BOOT_FLASH_SECTORS_COUNT; i++) {
|
||||
if (addr == flash_sectors[i]) {
|
||||
if (axi_flash_erase(i) != 0) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Unlock flash
|
||||
HAL_FLASH_Unlock();
|
||||
|
||||
for (int i = 0; i < size / FLASH_WORD_SIZE; i++, addr += FLASH_WORD_SIZE, buf += FLASH_WORD_SIZE) {
|
||||
if (HAL_FLASH_Program(TYPEPROGRAM_WORD, addr, FLASH_WORD_GET(buf)) != HAL_OK) {
|
||||
HAL_FLASH_Lock(); // Lock the flash
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (size % FLASH_WORD_SIZE) {
|
||||
uint8_t tmp[FLASH_WORD_SIZE] = {0};
|
||||
memcpy(tmp, buf, size % FLASH_WORD_SIZE);
|
||||
if (HAL_FLASH_Program(TYPEPROGRAM_WORD, addr, FLASH_WORD_GET(tmp)) != HAL_OK) {
|
||||
HAL_FLASH_Lock(); // Lock the flash
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
HAL_FLASH_Lock();
|
||||
return 0;
|
||||
}
|
||||
#endif // OMV_BOOT_AXI_FLASH_ENABLE
|
||||
40
src/boot/ports/stm32/stm32_flash.h
Normal file
40
src/boot/ports/stm32/stm32_flash.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2023-2024 OpenMV, LLC.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Any redistribution, use, or modification in source or binary form
|
||||
* is done solely for personal benefit and not for any commercial
|
||||
* purpose or for monetary gain. For commercial licensing options,
|
||||
* please contact openmv@openmv.io
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE LICENSOR AND COPYRIGHT OWNER "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR OR COPYRIGHT
|
||||
* OWNER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* STM32 Flash driver.
|
||||
*/
|
||||
#ifndef __STM32_FLASH_H__
|
||||
#define __STM32_FLASH_H__
|
||||
int axi_flash_read(uint32_t addr, uint8_t *buf, size_t size);
|
||||
int axi_flash_write(uint32_t addr, const uint8_t *buf, size_t size);
|
||||
int spi_flash_read(uint32_t addr, uint8_t *buf, uint32_t size);
|
||||
int spi_flash_write(uint32_t addr, const uint8_t *buf, uint32_t size);
|
||||
int spi_flash_deinit();
|
||||
#endif //__STM32_FLASH_H__
|
||||
261
src/boot/ports/stm32/stm32_port.c
Normal file
261
src/boot/ports/stm32/stm32_port.c
Normal file
@ -0,0 +1,261 @@
|
||||
/*
|
||||
* Copyright (C) 2023-2024 OpenMV, LLC.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Any redistribution, use, or modification in source or binary form
|
||||
* is done solely for personal benefit and not for any commercial
|
||||
* purpose or for monetary gain. For commercial licensing options,
|
||||
* please contact openmv@openmv.io
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE LICENSOR AND COPYRIGHT OWNER "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR OR COPYRIGHT
|
||||
* OWNER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* DFU bootloader STM32 port.
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include STM32_HAL_H
|
||||
#include "omv_boardconfig.h"
|
||||
#include "omv_bootconfig.h"
|
||||
#include "stm32_flash.h"
|
||||
|
||||
#ifdef USE_USB_FS
|
||||
#define USB_IRQ_Handler OTG_FS_IRQHandler
|
||||
#else
|
||||
#define USB_IRQ_Handler OTG_HS_IRQHandler
|
||||
#endif
|
||||
|
||||
static volatile uint32_t ticks_ms;
|
||||
extern void SystemClock_Config(void);
|
||||
|
||||
void SysTick_Handler(void) {
|
||||
ticks_ms += 1;
|
||||
}
|
||||
|
||||
void OTG_FS_IRQHandler(void) {
|
||||
tud_int_handler(0);
|
||||
}
|
||||
|
||||
void OTG_HS_IRQHandler(void) {
|
||||
tud_int_handler(1);
|
||||
}
|
||||
|
||||
int port_init(void) {
|
||||
HAL_Init();
|
||||
|
||||
// Set the system clock
|
||||
SystemClock_Config();
|
||||
|
||||
// Config Systick
|
||||
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
|
||||
|
||||
// Enable GPIO clocks
|
||||
__GPIOA_CLK_ENABLE();
|
||||
__GPIOB_CLK_ENABLE();
|
||||
__GPIOC_CLK_ENABLE();
|
||||
__GPIOD_CLK_ENABLE();
|
||||
__GPIOE_CLK_ENABLE();
|
||||
#ifdef OMV_GPIO_PORT_F_ENABLE
|
||||
__GPIOF_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef OMV_GPIO_PORT_G_ENABLE
|
||||
__GPIOG_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef OMV_GPIO_PORT_H_ENABLE
|
||||
__GPIOH_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef OMV_GPIO_PORT_I_ENABLE
|
||||
__GPIOI_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef OMV_GPIO_PORT_J_ENABLE
|
||||
__GPIOJ_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef OMV_GPIO_PORT_K_ENABLE
|
||||
__GPIOK_CLK_ENABLE();
|
||||
#endif
|
||||
|
||||
// Configure I/O pins.
|
||||
for (size_t i = 0; i < OMV_BOOT_PINS_COUNT; i++) {
|
||||
const pin_t *pin = &omv_boot_pins[i];
|
||||
GPIO_InitTypeDef pin_config = {
|
||||
.Pin = pin->pin,
|
||||
.Pull = pin->pull,
|
||||
.Speed = pin->speed,
|
||||
.Mode = pin->mode,
|
||||
.Alternate = pin->alt,
|
||||
};
|
||||
HAL_GPIO_Init(pin->gpio, &pin_config);
|
||||
}
|
||||
|
||||
// Turn off LED.
|
||||
port_pin_write(OMV_BOOT_LED_PIN, false);
|
||||
|
||||
// Enable USB clocks.
|
||||
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
|
||||
__HAL_RCC_USB_OTG_FS_CLK_SLEEP_ENABLE();
|
||||
|
||||
// Configure and enable USB IRQ.
|
||||
HAL_NVIC_SetPriority(OTG_FS_IRQn, 6, 0);
|
||||
NVIC_ClearPendingIRQ(OTG_FS_IRQn);
|
||||
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int port_deinit(void) {
|
||||
// Disable USB IRQ.
|
||||
HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
|
||||
NVIC_ClearPendingIRQ(OTG_FS_IRQn);
|
||||
|
||||
// Deinitialize SPI Flash.
|
||||
#if OMV_BOOT_SPI_FLASH_ENABLE
|
||||
spi_flash_deinit();
|
||||
#endif
|
||||
|
||||
// Deinit all I/O pins.
|
||||
for (size_t i = 0; i < OMV_BOOT_PINS_COUNT; i++) {
|
||||
const pin_t *pin = &omv_boot_pins[i];
|
||||
HAL_GPIO_DeInit(pin->gpio, pin->pin);
|
||||
}
|
||||
|
||||
// Disable USB clocks.
|
||||
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
|
||||
__HAL_RCC_USB_OTG_FS_CLK_SLEEP_DISABLE();
|
||||
|
||||
// Disable GPIO clocks.
|
||||
__GPIOA_CLK_DISABLE();
|
||||
__GPIOB_CLK_DISABLE();
|
||||
__GPIOC_CLK_DISABLE();
|
||||
__GPIOD_CLK_DISABLE();
|
||||
__GPIOE_CLK_DISABLE();
|
||||
#ifdef OMV_GPIO_PORT_F_ENABLE
|
||||
__GPIOF_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef OMV_GPIO_PORT_G_ENABLE
|
||||
__GPIOG_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef OMV_GPIO_PORT_H_ENABLE
|
||||
__GPIOH_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef OMV_GPIO_PORT_I_ENABLE
|
||||
__GPIOI_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef OMV_GPIO_PORT_J_ENABLE
|
||||
__GPIOJ_CLK_DISABLE();
|
||||
#endif
|
||||
#ifdef OMV_GPIO_PORT_K_ENABLE
|
||||
__GPIOK_CLK_DISABLE();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int port_get_uid(uint8_t *buf) {
|
||||
((uint32_t *) buf)[0] = __REV(*((uint32_t *) (OMV_BOARD_UID_ADDR + 8)));
|
||||
((uint32_t *) buf)[1] = __REV(*((uint32_t *) (OMV_BOARD_UID_ADDR + 4)));
|
||||
((uint32_t *) buf)[2] = __REV(*((uint32_t *) (OMV_BOARD_UID_ADDR + 0)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void port_mpu_protect(const partition_t *p, bool enable) {
|
||||
|
||||
}
|
||||
|
||||
uint32_t port_ticks_ms() {
|
||||
return ticks_ms;
|
||||
}
|
||||
|
||||
void port_delay_ms(uint32_t ms) {
|
||||
uint32_t start_ms = port_ticks_ms();
|
||||
while ((port_ticks_ms() - start_ms) < ms) {
|
||||
__WFI();
|
||||
}
|
||||
}
|
||||
|
||||
void port_pin_mode(uint32_t pin, uint32_t mode) {
|
||||
const pin_t *p = &omv_boot_pins[pin];
|
||||
GPIO_InitTypeDef pin_config;
|
||||
pin_config.Pin = p->pin;
|
||||
pin_config.Pull = GPIO_PULLUP;
|
||||
pin_config.Speed = GPIO_SPEED_LOW;
|
||||
if (mode == PIN_MODE_OUTPUT) {
|
||||
pin_config.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
} else {
|
||||
pin_config.Mode = GPIO_MODE_INPUT;
|
||||
}
|
||||
HAL_GPIO_Init(p->gpio, &pin_config);
|
||||
}
|
||||
|
||||
void port_pin_write(uint32_t pin, uint32_t state) {
|
||||
const pin_t *p = &omv_boot_pins[pin];
|
||||
if (state) {
|
||||
HAL_GPIO_WritePin(p->gpio, p->pin, GPIO_PIN_RESET);
|
||||
} else {
|
||||
HAL_GPIO_WritePin(p->gpio, p->pin, GPIO_PIN_SET);
|
||||
}
|
||||
}
|
||||
|
||||
void port_led_blink(uint32_t interval_ms) {
|
||||
static uint32_t start_ms = 0;
|
||||
static uint32_t led_state = 0;
|
||||
|
||||
if ((port_ticks_ms() - start_ms) < interval_ms) {
|
||||
return;
|
||||
}
|
||||
|
||||
led_state ^= 1;
|
||||
port_pin_write(OMV_BOOT_LED_PIN, led_state);
|
||||
start_ms += interval_ms;
|
||||
}
|
||||
|
||||
int port_flash_read(uint32_t ptype, uint32_t addr, uint8_t *buf, uint32_t size) {
|
||||
#if OMV_BOOT_AXI_FLASH_ENABLE
|
||||
if (ptype == PTYPE_AXI_FLASH) {
|
||||
return axi_flash_read(addr, buf, size);
|
||||
}
|
||||
#endif
|
||||
#if OMV_BOOT_SPI_FLASH_ENABLE
|
||||
if (ptype == PTYPE_SPI_FLASH) {
|
||||
return spi_flash_read(addr, buf, size);
|
||||
}
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
int port_flash_write(uint32_t ptype, uint32_t addr, const uint8_t *buf, uint32_t size) {
|
||||
#if OMV_BOOT_AXI_FLASH_ENABLE
|
||||
if (ptype == PTYPE_AXI_FLASH) {
|
||||
return axi_flash_write(addr, buf, size);
|
||||
}
|
||||
#endif
|
||||
#if OMV_BOOT_SPI_FLASH_ENABLE
|
||||
if (ptype == PTYPE_SPI_FLASH) {
|
||||
return spi_flash_write(addr, buf, size);
|
||||
}
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
void __attribute__((noreturn)) __fatal_error() {
|
||||
while (1) {
|
||||
port_led_blink(50);
|
||||
}
|
||||
}
|
||||
177
src/boot/ports/stm32/stm32_port.mk
Normal file
177
src/boot/ports/stm32/stm32_port.mk
Normal file
@ -0,0 +1,177 @@
|
||||
# Copyright (C) 2023-2024 OpenMV, LLC.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Any redistribution, use, or modification in source or binary form
|
||||
# is done solely for personal benefit and not for any commercial
|
||||
# purpose or for monetary gain. For commercial licensing options,
|
||||
# please contact openmv@openmv.io
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE LICENSOR AND COPYRIGHT OWNER "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR OR COPYRIGHT
|
||||
# OWNER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
# Include OpenMV board config first to set the port.
|
||||
include $(OMV_BOARD_CONFIG_DIR)/omv_boardconfig.mk
|
||||
|
||||
LDSCRIPT ?= stm32
|
||||
SYSTEM ?= st/system_stm32fxxx
|
||||
STARTUP ?= st/startup_$(shell echo $(MCU) | tr '[:upper:]' '[:lower:]')
|
||||
FIRMWARE := bootloader
|
||||
MCU_SERIES_LOWER := $(shell echo $(MCU_SERIES) | tr '[:upper:]' '[:lower:]')
|
||||
|
||||
# Compiler Flags
|
||||
CFLAGS += -std=gnu99 \
|
||||
-Wall \
|
||||
-Werror \
|
||||
-Warray-bounds \
|
||||
-nostartfiles \
|
||||
-fdata-sections \
|
||||
-ffunction-sections \
|
||||
-fno-inline-small-functions \
|
||||
-fsingle-precision-constant \
|
||||
-Wdouble-promotion \
|
||||
-mthumb \
|
||||
-mcpu=$(CPU) \
|
||||
-mtune=$(CPU) \
|
||||
-mfpu=$(FPU) \
|
||||
-mfloat-abi=hard \
|
||||
-D$(CFLAGS_MCU)
|
||||
|
||||
# Linker Flags
|
||||
LDFLAGS = -mthumb \
|
||||
-mcpu=$(CPU) \
|
||||
-mfpu=$(FPU) \
|
||||
-mfloat-abi=hard \
|
||||
-mabi=aapcs-linux \
|
||||
-Wl,--print-memory-usage \
|
||||
-Wl,--gc-sections \
|
||||
-Wl,-T$(BUILD)/$(LDSCRIPT).lds \
|
||||
-Wl,-Map=$(BUILD)/$(FIRMWARE).map
|
||||
|
||||
CFLAGS += -D$(MCU) \
|
||||
-D$(TARGET) \
|
||||
-DARM_NN_TRUNCATE \
|
||||
-D__FPU_PRESENT=1 \
|
||||
-D__VFP_FP__ \
|
||||
-DUSE_DEVICE_MODE \
|
||||
-DHSE_VALUE=$(OMV_HSE_VALUE)\
|
||||
-DVECT_TAB_OFFSET=0 \
|
||||
-DOMV_BOOT_JUMP_ADDR=$(MAIN_APP_ADDR) \
|
||||
-DSTM32_HAL_H=$(HAL_INC) \
|
||||
-DCMSIS_MCU_H=$(CMSIS_MCU_H) \
|
||||
-DUSE_FULL_LL_DRIVER \
|
||||
$(OMV_BOARD_EXTRA_CFLAGS)
|
||||
|
||||
CFLAGS += -I$(OMV_BOARD_CONFIG_DIR) \
|
||||
-I$(TOP_DIR)/$(BOOT_DIR)/common \
|
||||
-I$(TOP_DIR)/$(BOOT_DIR)/$(PORT_DIR) \
|
||||
-I$(TOP_DIR)/$(CMSIS_DIR)/include \
|
||||
-I$(TOP_DIR)/$(CMSIS_DIR)/include/ \
|
||||
-I$(TOP_DIR)/$(CMSIS_DIR)/include/st \
|
||||
-I$(TOP_DIR)/$(HAL_DIR)/include/ \
|
||||
-I$(TOP_DIR)/$(HAL_DIR)/include/Legacy/ \
|
||||
-I$(TOP_DIR)/$(TINYUSB_DIR)/src
|
||||
|
||||
SRC_C += $(addprefix common/, \
|
||||
desc.c \
|
||||
dfu.c \
|
||||
main.c \
|
||||
)
|
||||
|
||||
SRC_C += $(addprefix $(PORT_DIR)/, \
|
||||
stm32_port.c \
|
||||
stm32_qspi.c \
|
||||
stm32_flash.c \
|
||||
)
|
||||
|
||||
SRC_C += $(addprefix $(TINYUSB_DIR)/, \
|
||||
src/tusb.c \
|
||||
src/class/dfu/dfu_device.c \
|
||||
src/common/tusb_fifo.c \
|
||||
src/device/usbd.c \
|
||||
src/device/usbd_control.c \
|
||||
src/portable/synopsys/dwc2/dcd_dwc2.c \
|
||||
)
|
||||
|
||||
SRC_C += $(addprefix $(CMSIS_DIR)/src/,\
|
||||
$(STARTUP).o \
|
||||
$(SYSTEM).o \
|
||||
)
|
||||
|
||||
SRC_C += $(addprefix $(HAL_DIR)/src/,\
|
||||
$(MCU_SERIES_LOWER)_hal.c \
|
||||
$(MCU_SERIES_LOWER)_hal_cortex.c \
|
||||
$(MCU_SERIES_LOWER)_hal_flash.c \
|
||||
$(MCU_SERIES_LOWER)_hal_flash_ex.c \
|
||||
$(MCU_SERIES_LOWER)_hal_gpio.c \
|
||||
$(MCU_SERIES_LOWER)_hal_pwr.c \
|
||||
$(MCU_SERIES_LOWER)_hal_pwr_ex.c \
|
||||
$(MCU_SERIES_LOWER)_hal_rcc.c \
|
||||
$(MCU_SERIES_LOWER)_hal_rcc_ex.c \
|
||||
$(MCU_SERIES_LOWER)_hal_rng.c \
|
||||
$(MCU_SERIES_LOWER)_hal_qspi.c \
|
||||
$(MCU_SERIES_LOWER)_ll_rcc.c \
|
||||
$(MCU_SERIES_LOWER)_ll_usb.c \
|
||||
)
|
||||
|
||||
# Firmware objects
|
||||
OBJS += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
|
||||
OBJS += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
|
||||
OBJS_DIR = $(sort $(dir $(OBJS)))
|
||||
|
||||
all: $(FIRMWARE)
|
||||
$(SIZE) $(FW_DIR)/$(FIRMWARE).elf
|
||||
|
||||
$(OBJS_DIR):
|
||||
$(MKDIR) -p $@
|
||||
|
||||
$(BUILD)/%.o : %.c
|
||||
$(ECHO) "CC $<"
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
$(BUILD)/$(HAL_DIR)/%.o : $(TOP_DIR)/$(HAL_DIR)/%.c
|
||||
$(ECHO) "CC $(shell realpath --relative-to=pwd $<)"
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
$(BUILD)/$(CMSIS_DIR)/%.o : $(TOP_DIR)/$(CMSIS_DIR)/%.c
|
||||
$(ECHO) "CC $(shell realpath --relative-to=pwd $<)"
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
$(BUILD)/$(CMSIS_DIR)/%.o : $(TOP_DIR)/$(CMSIS_DIR)/%.s
|
||||
$(ECHO) "AS $(shell realpath --relative-to=pwd $<)"
|
||||
$(AS) $(AFLAGS) $< -o $@
|
||||
|
||||
$(BUILD)/$(TINYUSB_DIR)/%.o : $(TOP_DIR)/$(TINYUSB_DIR)/%.c
|
||||
$(ECHO) "CC $(shell realpath --relative-to=pwd $<)"
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
$(BUILD)/%.o : %.s
|
||||
$(ECHO) "AS $<"
|
||||
$(AS) $(AFLAGS) $< -o $@
|
||||
|
||||
FIRMWARE_OBJS: | $(OBJS_DIR) $(OBJS)
|
||||
|
||||
$(FIRMWARE): FIRMWARE_OBJS
|
||||
$(CPP) -P -E -DBOOTLOADER -DLINKER_SCRIPT -I$(OMV_BOARD_CONFIG_DIR) \
|
||||
$(PORT_DIR)/$(LDSCRIPT).ld.S > $(BUILD)/$(LDSCRIPT).lds
|
||||
$(CC) $(LDFLAGS) $(OBJS) -o $(FW_DIR)/$(FIRMWARE).elf
|
||||
$(OBJCOPY) -Obinary $(FW_DIR)/$(FIRMWARE).elf $(FW_DIR)/$(FIRMWARE).bin
|
||||
|
||||
-include $(OBJS:%.o=%.d)
|
||||
475
src/boot/ports/stm32/stm32_qspi.c
Normal file
475
src/boot/ports/stm32/stm32_qspi.c
Normal file
@ -0,0 +1,475 @@
|
||||
/*
|
||||
* Copyright (C) 2023-2024 OpenMV, LLC.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Any redistribution, use, or modification in source or binary form
|
||||
* is done solely for personal benefit and not for any commercial
|
||||
* purpose or for monetary gain. For commercial licensing options,
|
||||
* please contact openmv@openmv.io
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE LICENSOR AND COPYRIGHT OWNER "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR OR COPYRIGHT
|
||||
* OWNER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* STM32 QSPI Flash driver.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include STM32_HAL_H
|
||||
#include "omv_boardconfig.h"
|
||||
#include "omv_bootconfig.h"
|
||||
#include "stm32_flash.h"
|
||||
|
||||
#if OMV_BOOT_QSPI_FLASH_SIZE
|
||||
|
||||
#define QSPI_PAGE_SIZE (0x100) // 256Bytes pages.
|
||||
#define QSPI_BLOCK_SIZE (0x10000) // 64KBytes blocks.
|
||||
|
||||
#define QSPI_COMMAND_TIMEOUT (1000)
|
||||
#define QSPI_SECTOR_ERASE_TIMEOUT (400)
|
||||
#define QSPI_BLOCK_ERASE_TIMEOUT (2000)
|
||||
#define QSPI_CHIP_ERASE_TIMEOUT (400000)
|
||||
|
||||
#define QSPI_CMD_RESET_ENABLE (0x66)
|
||||
#define QSPI_CMD_RESET_MEMORY (0x99)
|
||||
|
||||
#define QSPI_CMD_READ_QUAD (0xEC)
|
||||
#define QSPI_CMD_PROG_QUAD (0x34)
|
||||
#define QSPI_CMD_QUAD_DUMMY (6)
|
||||
|
||||
#define QSPI_CMD_BLOCK_ERASE (0xDC)
|
||||
#define QSPI_CMD_CHIP_ERASE (0xC7)
|
||||
|
||||
#define QSPI_CMD_ADDR4_ENABLE (0xB7)
|
||||
#define QSPI_CMD_ADDR4_DISABLE (0xE9)
|
||||
|
||||
#define QSPI_CMD_WRITE_ENABLE (0x06)
|
||||
#define QSPI_CMD_WRITE_DISABLE (0x04)
|
||||
|
||||
#define QSPI_CMD_READ_STATUS_REG (0x05)
|
||||
#define QSPI_CMD_WRITE_STATUS_REG (0x01)
|
||||
|
||||
#define QSPI_SR_WIP_MASK (1 << 0)
|
||||
#define QSPI_SR_WEL_MASK (1 << 1)
|
||||
|
||||
static QSPI_HandleTypeDef qspi = {0};
|
||||
|
||||
static int qspi_flash_reset();
|
||||
static int qspi_flash_addr_4byte(bool);
|
||||
static int qspi_flash_poll_status_flag(uint32_t, uint32_t, uint32_t);
|
||||
|
||||
static int qspi_flash_init() {
|
||||
if (qspi.Instance != NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
qspi.Instance = QUADSPI;
|
||||
qspi.Init.ClockPrescaler = 1; // clock = 200MHz / (1+1) = 100MHz
|
||||
qspi.Init.FifoThreshold = 3;
|
||||
qspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_HALFCYCLE;
|
||||
qspi.Init.FlashSize = __builtin_ctz(OMV_BOOT_QSPI_FLASH_SIZE) - 1;
|
||||
qspi.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_2_CYCLE;
|
||||
qspi.Init.ClockMode = QSPI_CLOCK_MODE_0;
|
||||
qspi.Init.FlashID = QSPI_FLASH_ID_1;
|
||||
qspi.Init.DualFlash = QSPI_DUALFLASH_DISABLE;
|
||||
|
||||
// Reset QSPI.
|
||||
HAL_QSPI_DeInit(&qspi);
|
||||
__HAL_RCC_QSPI_FORCE_RESET();
|
||||
__HAL_RCC_QSPI_RELEASE_RESET();
|
||||
|
||||
// Enable QSPI clock.
|
||||
__HAL_RCC_QSPI_CLK_ENABLE();
|
||||
|
||||
// Initialize the QSPI
|
||||
if (HAL_QSPI_Init(&qspi) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Reset the QSPI
|
||||
if (qspi_flash_reset() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Enable 4-byte address mode.
|
||||
if (qspi_flash_addr_4byte(true) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;//qspi_flash_memory_test();
|
||||
}
|
||||
|
||||
static int qspi_flash_reset() {
|
||||
QSPI_CommandTypeDef command = {
|
||||
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
|
||||
.AddressMode = QSPI_ADDRESS_NONE,
|
||||
.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE,
|
||||
.DataMode = QSPI_DATA_NONE,
|
||||
.DummyCycles = 0,
|
||||
.DdrMode = QSPI_DDR_MODE_DISABLE,
|
||||
.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY,
|
||||
.SIOOMode = QSPI_SIOO_INST_EVERY_CMD,
|
||||
};
|
||||
|
||||
command.Instruction = QSPI_CMD_RESET_ENABLE;
|
||||
if (HAL_QSPI_Command(&qspi, &command, QSPI_COMMAND_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
command.Instruction = QSPI_CMD_RESET_MEMORY;
|
||||
if (HAL_QSPI_Command(&qspi, &command, QSPI_COMMAND_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qspi_flash_poll_status_flag(QSPI_SR_WIP_MASK, 0, QSPI_COMMAND_TIMEOUT) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qspi_flash_write_enable() {
|
||||
QSPI_CommandTypeDef command = {
|
||||
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
|
||||
.Instruction = QSPI_CMD_WRITE_ENABLE,
|
||||
.AddressMode = QSPI_ADDRESS_NONE,
|
||||
.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE,
|
||||
.DataMode = QSPI_DATA_NONE,
|
||||
.DummyCycles = 0,
|
||||
.DdrMode = QSPI_DDR_MODE_DISABLE,
|
||||
.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY,
|
||||
.SIOOMode = QSPI_SIOO_INST_EVERY_CMD,
|
||||
};
|
||||
|
||||
if (HAL_QSPI_Command(&qspi, &command, QSPI_COMMAND_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qspi_flash_poll_status_flag(QSPI_SR_WEL_MASK, QSPI_SR_WEL_MASK, QSPI_COMMAND_TIMEOUT) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qspi_flash_addr_4byte(bool enable) {
|
||||
QSPI_CommandTypeDef command = {
|
||||
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
|
||||
.AddressMode = QSPI_ADDRESS_NONE,
|
||||
.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE,
|
||||
.DataMode = QSPI_DATA_NONE,
|
||||
.DummyCycles = 0,
|
||||
.DdrMode = QSPI_DDR_MODE_DISABLE,
|
||||
.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY,
|
||||
.SIOOMode = QSPI_SIOO_INST_EVERY_CMD,
|
||||
.Instruction = enable ? QSPI_CMD_ADDR4_ENABLE : QSPI_CMD_ADDR4_DISABLE,
|
||||
};
|
||||
|
||||
if (qspi_flash_write_enable() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (HAL_QSPI_Command(&qspi, &command, QSPI_COMMAND_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qspi_flash_poll_status_flag(QSPI_SR_WIP_MASK, 0, QSPI_COMMAND_TIMEOUT) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qspi_flash_poll_status_flag(uint32_t mask, uint32_t match, uint32_t timeout) {
|
||||
QSPI_AutoPollingTypeDef config = {
|
||||
.Mask = mask,
|
||||
.Match = match,
|
||||
.MatchMode = QSPI_MATCH_MODE_AND,
|
||||
.Interval = 0x10,
|
||||
.AutomaticStop = QSPI_AUTOMATIC_STOP_ENABLE,
|
||||
.StatusBytesSize = 1
|
||||
};
|
||||
|
||||
QSPI_CommandTypeDef command = {
|
||||
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
|
||||
.Instruction = QSPI_CMD_READ_STATUS_REG,
|
||||
.AddressMode = QSPI_ADDRESS_NONE,
|
||||
.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE,
|
||||
.DataMode = QSPI_DATA_1_LINE,
|
||||
.DummyCycles = 0,
|
||||
.DdrMode = QSPI_DDR_MODE_DISABLE,
|
||||
.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY,
|
||||
.SIOOMode = QSPI_SIOO_INST_EVERY_CMD
|
||||
};
|
||||
|
||||
if (HAL_QSPI_AutoPolling(&qspi, &command, &config, timeout) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qspi_flash_erase_chip() {
|
||||
QSPI_CommandTypeDef command = {
|
||||
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
|
||||
.Instruction = QSPI_CMD_CHIP_ERASE,
|
||||
.AddressMode = QSPI_ADDRESS_NONE,
|
||||
.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE,
|
||||
.DataMode = QSPI_DATA_NONE,
|
||||
.DummyCycles = 0,
|
||||
.DdrMode = QSPI_DDR_MODE_DISABLE,
|
||||
.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY,
|
||||
.SIOOMode = QSPI_SIOO_INST_EVERY_CMD,
|
||||
};
|
||||
|
||||
if (qspi.Instance == NULL && qspi_flash_init() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qspi_flash_write_enable(&qspi) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (HAL_QSPI_Command(&qspi, &command, QSPI_COMMAND_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qspi_flash_poll_status_flag(QSPI_SR_WIP_MASK, 0, QSPI_CHIP_ERASE_TIMEOUT) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qspi_flash_erase_block(uint32_t addr) {
|
||||
QSPI_CommandTypeDef command = {
|
||||
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
|
||||
.Instruction = QSPI_CMD_BLOCK_ERASE,
|
||||
.AddressMode = QSPI_ADDRESS_1_LINE,
|
||||
.AddressSize = QSPI_ADDRESS_32_BITS,
|
||||
.Address = addr,
|
||||
.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE,
|
||||
.DataMode = QSPI_DATA_NONE,
|
||||
.DummyCycles = 0,
|
||||
.DdrMode = QSPI_DDR_MODE_DISABLE,
|
||||
.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY,
|
||||
.SIOOMode = QSPI_SIOO_INST_EVERY_CMD,
|
||||
};
|
||||
|
||||
if (qspi.Instance == NULL && qspi_flash_init() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qspi_flash_write_enable(&qspi) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (HAL_QSPI_Command(&qspi, &command, QSPI_COMMAND_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qspi_flash_poll_status_flag(QSPI_SR_WIP_MASK, 0, QSPI_BLOCK_ERASE_TIMEOUT) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __attribute__((optimize("O0"))) qspi_flash_memory_test() {
|
||||
uint8_t buf[QSPI_PAGE_SIZE];
|
||||
uint8_t pat[QSPI_PAGE_SIZE];
|
||||
|
||||
uint32_t n_pages = OMV_BOOT_QSPI_FLASH_SIZE / QSPI_PAGE_SIZE;
|
||||
uint32_t n_blocks = OMV_BOOT_QSPI_FLASH_SIZE / QSPI_BLOCK_SIZE;
|
||||
|
||||
if (qspi.Instance == NULL || qspi_flash_init() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < QSPI_PAGE_SIZE; i++) {
|
||||
pat[i] = ((i % 2) == 0) ? 0xaa : 0x55;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0, addr = 0; i < n_blocks; i++, addr += QSPI_BLOCK_SIZE) {
|
||||
if (qspi_flash_erase_block(addr) != 0) {
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t i = 0, addr = 0; i < n_pages; i++, addr += QSPI_PAGE_SIZE) {
|
||||
if (spi_flash_write(addr, pat, QSPI_PAGE_SIZE) != 0) {
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t i = 0, addr = 0; i < n_pages; i++, addr += QSPI_PAGE_SIZE) {
|
||||
memset(buf, 0, QSPI_PAGE_SIZE);
|
||||
if (spi_flash_read(addr, buf, QSPI_PAGE_SIZE) != 0) {
|
||||
return -4;
|
||||
}
|
||||
if (memcmp(buf, pat, QSPI_PAGE_SIZE) != 0) {
|
||||
return -5;
|
||||
}
|
||||
}
|
||||
|
||||
if (qspi_flash_erase_chip() != 0) {
|
||||
return -6;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qspi_flash_read_page(uint32_t addr, uint8_t *buf, uint32_t size) {
|
||||
QSPI_CommandTypeDef command = {
|
||||
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
|
||||
.Instruction = QSPI_CMD_READ_QUAD,
|
||||
.AddressMode = QSPI_ADDRESS_4_LINES,
|
||||
.AddressSize = QSPI_ADDRESS_32_BITS,
|
||||
.Address = addr,
|
||||
.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE,
|
||||
.DataMode = QSPI_DATA_4_LINES,
|
||||
.DummyCycles = QSPI_CMD_QUAD_DUMMY,
|
||||
.NbData = size,
|
||||
.DdrMode = QSPI_DDR_MODE_DISABLE,
|
||||
.DdrHoldHalfCycle = QSPI_DDR_HHC_HALF_CLK_DELAY,
|
||||
.SIOOMode = QSPI_SIOO_INST_EVERY_CMD
|
||||
};
|
||||
|
||||
if (qspi.Instance == NULL && qspi_flash_init() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (HAL_QSPI_Command(&qspi, &command, QSPI_COMMAND_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (HAL_QSPI_Receive(&qspi, buf, QSPI_COMMAND_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qspi_flash_write_page(uint32_t addr, const uint8_t *buf, uint32_t size) {
|
||||
QSPI_CommandTypeDef command = {
|
||||
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
|
||||
.Instruction = QSPI_CMD_PROG_QUAD,
|
||||
.Address = addr,
|
||||
.AddressMode = QSPI_ADDRESS_1_LINE,
|
||||
.AddressSize = QSPI_ADDRESS_32_BITS,
|
||||
.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE,
|
||||
.NbData = size,
|
||||
.DataMode = QSPI_DATA_4_LINES,
|
||||
.DummyCycles = 0,
|
||||
.DdrMode = QSPI_DDR_MODE_DISABLE,
|
||||
.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY,
|
||||
.SIOOMode = QSPI_SIOO_INST_EVERY_CMD
|
||||
};
|
||||
|
||||
// Address must be page-aligned and the size <= page size.
|
||||
if ((addr % QSPI_PAGE_SIZE) != 0 ||
|
||||
size <= 0 || size > QSPI_PAGE_SIZE) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qspi.Instance == NULL && qspi_flash_init() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Enable write operations
|
||||
if (qspi_flash_write_enable(&qspi) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Configure the command
|
||||
if (HAL_QSPI_Command(&qspi, &command, QSPI_COMMAND_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Transmit the data
|
||||
if (HAL_QSPI_Transmit(&qspi, (uint8_t *) buf, QSPI_COMMAND_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Poll the status register.
|
||||
if (qspi_flash_poll_status_flag(QSPI_SR_WIP_MASK, 0, QSPI_COMMAND_TIMEOUT) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int spi_flash_read(uint32_t addr, uint8_t *buf, uint32_t size) {
|
||||
for (size_t i = 0; i < size / QSPI_PAGE_SIZE; i++) {
|
||||
if (qspi_flash_read_page(addr, buf, QSPI_PAGE_SIZE) != 0) {
|
||||
return -1;
|
||||
}
|
||||
buf += QSPI_PAGE_SIZE;
|
||||
addr += QSPI_PAGE_SIZE;
|
||||
}
|
||||
|
||||
if ((size % QSPI_PAGE_SIZE)) {
|
||||
if (qspi_flash_read_page(addr, buf, (size % QSPI_PAGE_SIZE)) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int spi_flash_write(uint32_t addr, const uint8_t *buf, uint32_t size) {
|
||||
// If at a block boundary, erase the block first.
|
||||
if ((addr % QSPI_BLOCK_SIZE) == 0) {
|
||||
if (qspi_flash_erase_block(addr) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < size / QSPI_PAGE_SIZE; i++) {
|
||||
if (qspi_flash_write_page(addr, buf, QSPI_PAGE_SIZE) != 0) {
|
||||
return -1;
|
||||
}
|
||||
buf += QSPI_PAGE_SIZE;
|
||||
addr += QSPI_PAGE_SIZE;
|
||||
}
|
||||
|
||||
if ((size % QSPI_PAGE_SIZE)) {
|
||||
if (qspi_flash_write_page(addr, buf, (size % QSPI_PAGE_SIZE)) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int spi_flash_deinit() {
|
||||
if (qspi.Instance != NULL) {
|
||||
HAL_QSPI_DeInit(&qspi);
|
||||
qspi.Instance = NULL;
|
||||
}
|
||||
|
||||
// Reset QSPI.
|
||||
__HAL_RCC_QSPI_FORCE_RESET();
|
||||
__HAL_RCC_QSPI_RELEASE_RESET();
|
||||
|
||||
// Disable QSPI clock.
|
||||
__HAL_RCC_QSPI_CLK_DISABLE();
|
||||
memset(&qspi, 0, sizeof(QSPI_HandleTypeDef));
|
||||
return 0;
|
||||
}
|
||||
#endif // OMV_BOOT_QSPI_FLASH_SIZE
|
||||
46
src/boot/ports/stm32/tusb_config.h
Normal file
46
src/boot/ports/stm32/tusb_config.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2023-2024 OpenMV, LLC.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Any redistribution, use, or modification in source or binary form
|
||||
* is done solely for personal benefit and not for any commercial
|
||||
* purpose or for monetary gain. For commercial licensing options,
|
||||
* please contact openmv@openmv.io
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE LICENSOR AND COPYRIGHT OWNER "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR OR COPYRIGHT
|
||||
* OWNER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* TinyUSB config.
|
||||
*/
|
||||
#ifndef __STM32_TUSB_CONFIG_H__
|
||||
#define __STM32_TUSB_CONFIG_H__
|
||||
// Common configuration
|
||||
#define CFG_TUSB_OS OPT_OS_NONE
|
||||
#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_FULL_SPEED)
|
||||
|
||||
// Device stack configuration.
|
||||
#define CFG_TUD_ENABLED (1)
|
||||
#define CFG_TUD_DFU (1)
|
||||
#define CFG_TUD_ENDPOINT0_SIZE (64)
|
||||
#define CFG_TUD_DFU_XFER_BUFSIZE (4096)
|
||||
|
||||
#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(256)))
|
||||
#endif //__STM32_TUSB_CONFIG_H__
|
||||
1
src/lib/tinyusb
Submodule
1
src/lib/tinyusb
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 5217cee5de4cd555018da90f9f1bcc87fb1c1d3a
|
||||
@ -1 +1 @@
|
||||
Subproject commit e2299613283189142c2ec54d90ccceaf57d88767
|
||||
Subproject commit 762552586b79e7b8bc4a2b64a45498ca2768ef53
|
||||
@ -106,8 +106,10 @@
|
||||
#define OMV_SRAM2_LENGTH 32K
|
||||
|
||||
// Flash configuration.
|
||||
#define OMV_FLASH_FFS_ORIGIN 0x08004000
|
||||
#define OMV_FLASH_FFS_LENGTH 48K
|
||||
#define OMV_FLASH_BOOT_ORIGIN 0x08000000
|
||||
#define OMV_FLASH_BOOT_LENGTH 32K
|
||||
#define OMV_FLASH_FFS_ORIGIN 0x08008000
|
||||
#define OMV_FLASH_FFS_LENGTH 32K
|
||||
#define OMV_FLASH_TXT_ORIGIN 0x08010000
|
||||
#define OMV_FLASH_TXT_LENGTH 960K
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
MCU=STM32F427xx
|
||||
MCU_SERIES=STM32F4xx
|
||||
CPU=cortex-m4
|
||||
FPU=fpv4-sp-d16
|
||||
PORT=stm32
|
||||
@ -6,7 +7,7 @@ HAL_DIR=hal/stm32/f4
|
||||
HAL_INC='<stm32f4xx_hal.h>'
|
||||
CMSIS_MCU_H='<stm32f427xx.h>'
|
||||
CFLAGS_MCU=MCU_SERIES_F4
|
||||
OMV_BOARD_EXTRA_CFLAGS=-DUSE_USB_FS
|
||||
OMV_BOARD_EXTRA_CFLAGS=-DCFG_TUSB_MCU=OPT_MCU_STM32F4
|
||||
VECT_TAB_OFFSET=0x10000
|
||||
MAIN_APP_ADDR=0x08010000
|
||||
OMV_HSE_VALUE=12000000
|
||||
|
||||
@ -1,29 +1,57 @@
|
||||
/*
|
||||
* This file is part of the OpenMV project.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Copyright (c) 2013-2022 Ibrahim Abdelkader <iabdalkader@openmv.io>
|
||||
* Copyright (c) 2013-2022 Kwabena W. Agyeman <kwagyeman@openmv.io>
|
||||
* Copyright (C) 2013-2024 OpenMV, LLC.
|
||||
*
|
||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* Board configuration and pin definitions.
|
||||
*/
|
||||
/* *INDENT-OFF* */
|
||||
#ifndef __OMV_BOOTCONFIG_H__
|
||||
#define __OMV_BOOTCONFIG_H__
|
||||
#include STM32_HAL_H
|
||||
#include "port.h"
|
||||
|
||||
// Bootloader version.
|
||||
#define OMV_BOOT_VERSION (0xABCD0003)
|
||||
// Misc config.
|
||||
#define OMV_BOOT_VID (0x37C5)
|
||||
#define OMV_BOOT_PID (0x9202)
|
||||
#define OMV_BOOT_DFU_TIMEOUT (1500)
|
||||
#define OMV_BOOT_LED_PIN (0) // index in omv_boot_pins
|
||||
|
||||
// Bootloader LED GPIO config.
|
||||
#define OMV_BOOT_LED_PIN (GPIO_PIN_2)
|
||||
#define OMV_BOOT_LED_PORT (GPIOC)
|
||||
// Flash config
|
||||
#define OMV_BOOT_AXI_FLASH_ENABLE (1)
|
||||
|
||||
// Flash layout for the bootloader.
|
||||
// Flash FS sector, main FW sector, max sector.
|
||||
#define OMV_BOOT_FLASH_LAYOUT {1, 4, 11}
|
||||
|
||||
// Flash configuration.
|
||||
#define OMV_BOOT_FLASH_ORIGIN 0x08000000
|
||||
#define OMV_BOOT_FLASH_LENGTH 16K
|
||||
// Boot I/O pins.
|
||||
static const pin_t omv_boot_pins[] = {
|
||||
{ .gpio = GPIOC, .pin = GPIO_PIN_2, .speed = GPIO_SPEED_LOW, .mode = GPIO_MODE_OUTPUT_PP, .pull = GPIO_PULLUP }, // LED
|
||||
{ .gpio = GPIOA, .pin = GPIO_PIN_9, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_INPUT, .pull = GPIO_NOPULL }, // VBUS
|
||||
{ .gpio = GPIOA, .pin = GPIO_PIN_11, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF10_OTG_FS }, // DM
|
||||
{ .gpio = GPIOA, .pin = GPIO_PIN_12, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF10_OTG_FS }, // DP
|
||||
};
|
||||
#define OMV_BOOT_PINS_COUNT (sizeof(omv_boot_pins) / sizeof(omv_boot_pins[0]))
|
||||
|
||||
// Boot partitions.
|
||||
static const partition_t OMV_BOOT_PARTITIONS[] = {
|
||||
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08008000, .limit = 0x8010000, .attr = 0 }, // FFS
|
||||
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08010000, .limit = 0x08100000, .attr = 0 }, // Firmware
|
||||
};
|
||||
#define OMV_BOOT_PARTITIONS_COUNT 2 // Must be a literal
|
||||
#define OMV_BOOT_PARTITIONS_STR "FILESYSTEM", "FIRMWARE"
|
||||
#endif //__OMV_BOOTCONFIG_H__
|
||||
|
||||
@ -105,6 +105,8 @@
|
||||
#define OMV_SRAM1_LENGTH 384K
|
||||
|
||||
// Flash configuration.
|
||||
#define OMV_FLASH_BOOT_ORIGIN 0x08000000
|
||||
#define OMV_FLASH_BOOT_LENGTH 32K
|
||||
#define OMV_FLASH_FFS_ORIGIN 0x08008000
|
||||
#define OMV_FLASH_FFS_LENGTH 96K
|
||||
#define OMV_FLASH_TXT_ORIGIN 0x08020000
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
MCU=STM32F765xx
|
||||
MCU_SERIES=STM32F7xx
|
||||
CPU=cortex-m7
|
||||
FPU=fpv5-sp-d16
|
||||
PORT=stm32
|
||||
@ -6,7 +7,7 @@ HAL_DIR=hal/stm32/f7
|
||||
HAL_INC='<stm32f7xx_hal.h>'
|
||||
CMSIS_MCU_H='<stm32f765xx.h>'
|
||||
CFLAGS_MCU=MCU_SERIES_F7
|
||||
OMV_BOARD_EXTRA_CFLAGS=-DUSE_USB_FS
|
||||
OMV_BOARD_EXTRA_CFLAGS=-DCFG_TUSB_MCU=OPT_MCU_STM32F7
|
||||
VECT_TAB_OFFSET=0x20000
|
||||
MAIN_APP_ADDR=0x08020000
|
||||
OMV_HSE_VALUE=12000000
|
||||
|
||||
@ -1,29 +1,57 @@
|
||||
/*
|
||||
* This file is part of the OpenMV project.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Copyright (c) 2013-2022 Ibrahim Abdelkader <iabdalkader@openmv.io>
|
||||
* Copyright (c) 2013-2022 Kwabena W. Agyeman <kwagyeman@openmv.io>
|
||||
* Copyright (C) 2013-2024 OpenMV, LLC.
|
||||
*
|
||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* Board configuration and pin definitions.
|
||||
*/
|
||||
// *INDENT-OFF*
|
||||
#ifndef __OMV_BOOTCONFIG_H__
|
||||
#define __OMV_BOOTCONFIG_H__
|
||||
#include STM32_HAL_H
|
||||
#include "port.h"
|
||||
|
||||
// Bootloader version.
|
||||
#define OMV_BOOT_VERSION (0xABCD0003)
|
||||
// Misc config.
|
||||
#define OMV_BOOT_VID (0x37C5)
|
||||
#define OMV_BOOT_PID (0x9203)
|
||||
#define OMV_BOOT_DFU_TIMEOUT (1500)
|
||||
#define OMV_BOOT_LED_PIN (0) // index in omv_boot_pins
|
||||
|
||||
// Bootloader LED GPIO config.
|
||||
#define OMV_BOOT_LED_PIN (GPIO_PIN_1)
|
||||
#define OMV_BOOT_LED_PORT (GPIOC)
|
||||
// Flash config.
|
||||
#define OMV_BOOT_AXI_FLASH_ENABLE (1)
|
||||
|
||||
// Flash layout for the bootloader.
|
||||
// Flash FS sector, main FW sector, max sector.
|
||||
#define OMV_BOOT_FLASH_LAYOUT {1, 4, 11}
|
||||
|
||||
// Flash configuration.
|
||||
#define OMV_BOOT_FLASH_ORIGIN 0x08000000
|
||||
#define OMV_BOOT_FLASH_LENGTH 32K
|
||||
// Boot I/O pins.
|
||||
static const pin_t omv_boot_pins[] = {
|
||||
{ .gpio = GPIOC, .pin = GPIO_PIN_1, .speed = GPIO_SPEED_LOW, .mode = GPIO_MODE_OUTPUT_PP, .pull = GPIO_PULLUP }, // LED
|
||||
{ .gpio = GPIOA, .pin = GPIO_PIN_9, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_INPUT, .pull = GPIO_NOPULL }, // VBUS
|
||||
{ .gpio = GPIOA, .pin = GPIO_PIN_11, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF10_OTG_FS }, // DM
|
||||
{ .gpio = GPIOA, .pin = GPIO_PIN_12, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF10_OTG_FS }, // DP
|
||||
};
|
||||
#define OMV_BOOT_PINS_COUNT (sizeof(omv_boot_pins) / sizeof(omv_boot_pins[0]))
|
||||
|
||||
// Boot partitions.
|
||||
static const partition_t OMV_BOOT_PARTITIONS[] = {
|
||||
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08008000, .limit = 0x08020000, .attr = 0 }, // FFS
|
||||
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08020000, .limit = 0x08200000, .attr = 0 }, // FIRMWARE
|
||||
};
|
||||
#define OMV_BOOT_PARTITIONS_COUNT 2 // Must be a literal
|
||||
#define OMV_BOOT_PARTITIONS_STR "FILESYSTEM", "FIRMWARE"
|
||||
#endif //__OMV_BOOTCONFIG_H__
|
||||
|
||||
@ -169,6 +169,8 @@
|
||||
#define OMV_AXI_SRAM_LENGTH 512K
|
||||
|
||||
// Flash configuration.
|
||||
#define OMV_FLASH_BOOT_ORIGIN 0x08000000
|
||||
#define OMV_FLASH_BOOT_LENGTH 128K
|
||||
#define OMV_FLASH_FFS_ORIGIN 0x08020000
|
||||
#define OMV_FLASH_FFS_LENGTH 128K
|
||||
#define OMV_FLASH_TXT_ORIGIN 0x08040000
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
MCU=STM32H743xx
|
||||
MCU_SERIES=STM32H7xx
|
||||
CPU=cortex-m7
|
||||
FPU=fpv5-sp-d16
|
||||
PORT=stm32
|
||||
@ -6,7 +7,7 @@ HAL_DIR=hal/stm32/h7
|
||||
HAL_INC='<stm32h7xx_hal.h>'
|
||||
CMSIS_MCU_H='<stm32h743xx.h>'
|
||||
CFLAGS_MCU=MCU_SERIES_H7
|
||||
OMV_BOARD_EXTRA_CFLAGS=-DUSE_USB_FS
|
||||
OMV_BOARD_EXTRA_CFLAGS=-DCFG_TUSB_MCU=OPT_MCU_STM32H7
|
||||
VECT_TAB_OFFSET=0x40000
|
||||
MAIN_APP_ADDR=0x08040000
|
||||
OMV_HSE_VALUE=12000000
|
||||
|
||||
@ -1,29 +1,57 @@
|
||||
/*
|
||||
* This file is part of the OpenMV project.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Copyright (c) 2013-2022 Ibrahim Abdelkader <iabdalkader@openmv.io>
|
||||
* Copyright (c) 2013-2022 Kwabena W. Agyeman <kwagyeman@openmv.io>
|
||||
* Copyright (C) 2013-2024 OpenMV, LLC.
|
||||
*
|
||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* Board configuration and pin definitions.
|
||||
*/
|
||||
// *INDENT-OFF*
|
||||
#ifndef __OMV_BOOTCONFIG_H__
|
||||
#define __OMV_BOOTCONFIG_H__
|
||||
#include STM32_HAL_H
|
||||
#include "port.h"
|
||||
|
||||
// Bootloader version.
|
||||
#define OMV_BOOT_VERSION (0xABCD0003)
|
||||
// Misc config.
|
||||
#define OMV_BOOT_VID (0x37C5)
|
||||
#define OMV_BOOT_PID (0x9204)
|
||||
#define OMV_BOOT_DFU_TIMEOUT (1500)
|
||||
#define OMV_BOOT_LED_PIN (0) // index in omv_boot_pins
|
||||
|
||||
// Bootloader LED GPIO config.
|
||||
#define OMV_BOOT_LED_PIN (GPIO_PIN_1)
|
||||
#define OMV_BOOT_LED_PORT (GPIOC)
|
||||
// Flash config.
|
||||
#define OMV_BOOT_AXI_FLASH_ENABLE (1)
|
||||
|
||||
// Flash layout for the bootloader.
|
||||
// Flash FS sector, main FW sector, max sector.
|
||||
#define OMV_BOOT_FLASH_LAYOUT {1, 2, 15}
|
||||
|
||||
// Flash configuration.
|
||||
#define OMV_BOOT_FLASH_ORIGIN 0x08000000
|
||||
#define OMV_BOOT_FLASH_LENGTH 128K
|
||||
// Boot I/O pins.
|
||||
static const pin_t omv_boot_pins[] = {
|
||||
{ .gpio = GPIOC, .pin = GPIO_PIN_1, .speed = GPIO_SPEED_LOW, .mode = GPIO_MODE_OUTPUT_PP, .pull = GPIO_PULLUP }, // LED
|
||||
{ .gpio = GPIOA, .pin = GPIO_PIN_9, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_INPUT, .pull = GPIO_NOPULL }, // VBUS
|
||||
{ .gpio = GPIOA, .pin = GPIO_PIN_11, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF10_OTG_FS }, // DM
|
||||
{ .gpio = GPIOA, .pin = GPIO_PIN_12, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF10_OTG_FS }, // DP
|
||||
};
|
||||
#define OMV_BOOT_PINS_COUNT (sizeof(omv_boot_pins) / sizeof(omv_boot_pins[0]))
|
||||
|
||||
// Boot partitions.
|
||||
static const partition_t OMV_BOOT_PARTITIONS[] = {
|
||||
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08020000, .limit = 0x08040000, .attr = 0 }, // FFS
|
||||
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08040000, .limit = 0x08200000, .attr = 0 }, // FIRMWARE
|
||||
};
|
||||
#define OMV_BOOT_PARTITIONS_COUNT 2 // Must be a literal
|
||||
#define OMV_BOOT_PARTITIONS_STR "FILESYSTEM", "FIRMWARE"
|
||||
#endif //__OMV_BOOTCONFIG_H__
|
||||
|
||||
@ -163,6 +163,8 @@
|
||||
#define OMV_DRAM_LENGTH 32M
|
||||
|
||||
// Flash configuration.
|
||||
#define OMV_FLASH_BOOT_ORIGIN 0x08000000
|
||||
#define OMV_FLASH_BOOT_LENGTH 128K
|
||||
#define OMV_FLASH_FFS_ORIGIN 0x08020000
|
||||
#define OMV_FLASH_FFS_LENGTH 128K
|
||||
#define OMV_FLASH_TXT_ORIGIN 0x08040000
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
MCU=STM32H743xx
|
||||
MCU_SERIES=STM32H7xx
|
||||
CPU=cortex-m7
|
||||
FPU=fpv5-sp-d16
|
||||
PORT=stm32
|
||||
@ -6,7 +7,7 @@ HAL_DIR=hal/stm32/h7
|
||||
HAL_INC='<stm32h7xx_hal.h>'
|
||||
CMSIS_MCU_H='<stm32h743xx.h>'
|
||||
CFLAGS_MCU=MCU_SERIES_H7
|
||||
OMV_BOARD_EXTRA_CFLAGS=-DUSE_USB_FS
|
||||
OMV_BOARD_EXTRA_CFLAGS=-DCFG_TUSB_MCU=OPT_MCU_STM32H7
|
||||
VECT_TAB_OFFSET=0x40000
|
||||
MAIN_APP_ADDR=0x08040000
|
||||
OMV_HSE_VALUE=12000000
|
||||
|
||||
@ -1,77 +1,66 @@
|
||||
/*
|
||||
* This file is part of the OpenMV project.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Copyright (c) 2013-2022 Ibrahim Abdelkader <iabdalkader@openmv.io>
|
||||
* Copyright (c) 2013-2022 Kwabena W. Agyeman <kwagyeman@openmv.io>
|
||||
* Copyright (C) 2013-2024 OpenMV, LLC.
|
||||
*
|
||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* Board configuration and pin definitions.
|
||||
*/
|
||||
// *INDENT-OFF*
|
||||
#ifndef __OMV_BOOTCONFIG_H__
|
||||
#define __OMV_BOOTCONFIG_H__
|
||||
#include STM32_HAL_H
|
||||
#include "port.h"
|
||||
|
||||
// Bootloader version.
|
||||
#define OMV_BOOT_VERSION (0xABCD0003)
|
||||
// Misc config.
|
||||
#define OMV_BOOT_VID (0x37C5)
|
||||
#define OMV_BOOT_PID (0x924A)
|
||||
#define OMV_BOOT_DFU_TIMEOUT (1500)
|
||||
#define OMV_BOOT_LED_PIN (0) // index in omv_boot_pins
|
||||
|
||||
// Bootloader LED GPIO config.
|
||||
#define OMV_BOOT_LED_PIN (GPIO_PIN_1)
|
||||
#define OMV_BOOT_LED_PORT (GPIOC)
|
||||
// Flash config.
|
||||
#define OMV_BOOT_AXI_FLASH_ENABLE (1)
|
||||
#define OMV_BOOT_SPI_FLASH_ENABLE (1)
|
||||
#define OMV_BOOT_QSPI_FLASH_SIZE (0x2000000) // Must always be a power of 2.
|
||||
|
||||
// Flash layout for the bootloader.
|
||||
// Flash FS sector, main FW sector, max sector.
|
||||
#define OMV_BOOT_FLASH_LAYOUT {1, 2, 15}
|
||||
|
||||
// Flash configuration.
|
||||
#define OMV_BOOT_FLASH_ORIGIN 0x08000000
|
||||
#define OMV_BOOT_FLASH_LENGTH 128K
|
||||
|
||||
// QSPI Flash layout for the bootloader.
|
||||
// First block, maximum block, block size in bytes.
|
||||
#define OMV_BOOT_QSPIF_LAYOUT {0, 511, 64 * 1024}
|
||||
|
||||
// QSPI flash configuration for the bootloader.
|
||||
#define OMV_BOOT_QSPIF_SIZE_BITS (25) // 2**25 == 32MBytes.
|
||||
#define OMV_BOOT_QSPIF_SR_WIP_MASK (1 << 0)
|
||||
#define OMV_BOOT_QSPIF_SR_WEL_MASK (1 << 1)
|
||||
#define OMV_BOOT_QSPIF_READ_QUADIO_DCYC (6)
|
||||
|
||||
#define OMV_BOOT_QSPIF_PAGE_SIZE (0x100) // 256 bytes pages.
|
||||
#define OMV_BOOT_QSPIF_NUM_PAGES (0x20000) // 131072 pages of 256 bytes
|
||||
|
||||
#define OMV_BOOT_QSPIF_SECTOR_SIZE (0x1000) // 4K bytes sectors.
|
||||
#define OMV_BOOT_QSPIF_NUM_SECTORS (0x2000) // 8192 sectors of 4K bytes
|
||||
|
||||
#define OMV_BOOT_QSPIF_BLOCK_SIZE (0x10000) // 64K bytes blocks.
|
||||
#define OMV_BOOT_QSPIF_NUM_BLOCKS (0x200) // 512 blocks of 64K bytes
|
||||
|
||||
#define OMV_BOOT_QSPIF_CLK_PIN (GPIO_PIN_10)
|
||||
#define OMV_BOOT_QSPIF_CLK_PORT (GPIOF)
|
||||
#define OMV_BOOT_QSPIF_CLK_ALT (GPIO_AF9_QUADSPI)
|
||||
|
||||
#define OMV_BOOT_QSPIF_CS_PIN (GPIO_PIN_6)
|
||||
#define OMV_BOOT_QSPIF_CS_PORT (GPIOG)
|
||||
#define OMV_BOOT_QSPIF_CS_ALT (GPIO_AF10_QUADSPI)
|
||||
|
||||
#define OMV_BOOT_QSPIF_D0_PIN (GPIO_PIN_8)
|
||||
#define OMV_BOOT_QSPIF_D0_PORT (GPIOF)
|
||||
#define OMV_BOOT_QSPIF_D0_ALT (GPIO_AF10_QUADSPI)
|
||||
|
||||
#define OMV_BOOT_QSPIF_D1_PIN (GPIO_PIN_9)
|
||||
#define OMV_BOOT_QSPIF_D1_PORT (GPIOF)
|
||||
#define OMV_BOOT_QSPIF_D1_ALT (GPIO_AF10_QUADSPI)
|
||||
|
||||
#define OMV_BOOT_QSPIF_D2_PIN (GPIO_PIN_7)
|
||||
#define OMV_BOOT_QSPIF_D2_PORT (GPIOF)
|
||||
#define OMV_BOOT_QSPIF_D2_ALT (GPIO_AF9_QUADSPI)
|
||||
|
||||
#define OMV_BOOT_QSPIF_D3_PIN (GPIO_PIN_6)
|
||||
#define OMV_BOOT_QSPIF_D3_PORT (GPIOF)
|
||||
#define OMV_BOOT_QSPIF_D3_ALT (GPIO_AF9_QUADSPI)
|
||||
|
||||
#define OMV_BOOT_QSPIF_CLK_ENABLE() __HAL_RCC_QSPI_CLK_ENABLE()
|
||||
#define OMV_BOOT_QSPIF_CLK_DISABLE() __HAL_RCC_QSPI_CLK_DISABLE()
|
||||
#define OMV_BOOT_QSPIF_FORCE_RESET() __HAL_RCC_QSPI_FORCE_RESET()
|
||||
#define OMV_BOOT_QSPIF_RELEASE_RESET() __HAL_RCC_QSPI_RELEASE_RESET()
|
||||
// Boot I/O pins.
|
||||
static const pin_t omv_boot_pins[] = {
|
||||
{ .gpio = GPIOC, .pin = GPIO_PIN_1, .speed = GPIO_SPEED_LOW, .mode = GPIO_MODE_OUTPUT_PP, .pull = GPIO_PULLUP }, // LED
|
||||
{ .gpio = GPIOA, .pin = GPIO_PIN_9, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_INPUT, .pull = GPIO_NOPULL }, // VBUS
|
||||
{ .gpio = GPIOA, .pin = GPIO_PIN_11, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF10_OTG_FS }, // DM
|
||||
{ .gpio = GPIOA, .pin = GPIO_PIN_12, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF10_OTG_FS }, // DP
|
||||
{ .gpio = GPIOF, .pin = GPIO_PIN_10, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF9_QUADSPI }, // CLK
|
||||
{ .gpio = GPIOG, .pin = GPIO_PIN_6, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF10_QUADSPI }, // CS
|
||||
{ .gpio = GPIOF, .pin = GPIO_PIN_8, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF10_QUADSPI }, // D0
|
||||
{ .gpio = GPIOF, .pin = GPIO_PIN_9, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF10_QUADSPI }, // D1
|
||||
{ .gpio = GPIOF, .pin = GPIO_PIN_7, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF9_QUADSPI }, // D2
|
||||
{ .gpio = GPIOF, .pin = GPIO_PIN_6, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF9_QUADSPI }, // D3
|
||||
};
|
||||
#define OMV_BOOT_PINS_COUNT (sizeof(omv_boot_pins) / sizeof(omv_boot_pins[0]))
|
||||
|
||||
// Boot partitions.
|
||||
static const partition_t OMV_BOOT_PARTITIONS[] = {
|
||||
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08020000, .limit = 0x08040000, .attr = 0 }, // FFS
|
||||
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08040000, .limit = 0x08200000, .attr = 0 }, // FIRMWARE
|
||||
{ .type = PTYPE_SPI_FLASH, .region = -1, .rdonly = 0, .start = 0x00000000, .limit = 0x02000000, .attr = 0 }, // QSPI
|
||||
};
|
||||
#define OMV_BOOT_PARTITIONS_COUNT 3 // Must be a literal
|
||||
#define OMV_BOOT_PARTITIONS_STR "FILESYSTEM", "FIRMWARE", "SPI_FLASH"
|
||||
#endif //__OMV_BOOTCONFIG_H__
|
||||
|
||||
@ -154,6 +154,8 @@
|
||||
#define OMV_DRAM_LENGTH 64M
|
||||
|
||||
// Flash configuration.
|
||||
#define OMV_FLASH_BOOT_ORIGIN 0x08000000
|
||||
#define OMV_FLASH_BOOT_LENGTH 128K
|
||||
#define OMV_FLASH_FFS_ORIGIN 0x08020000
|
||||
#define OMV_FLASH_FFS_LENGTH 128K
|
||||
#define OMV_FLASH_TXT_ORIGIN 0x08040000
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
MCU=STM32H743xx
|
||||
MCU_SERIES=STM32H7xx
|
||||
CPU=cortex-m7
|
||||
FPU=fpv5-sp-d16
|
||||
PORT=stm32
|
||||
@ -6,7 +7,7 @@ HAL_DIR=hal/stm32/h7
|
||||
HAL_INC='<stm32h7xx_hal.h>'
|
||||
CMSIS_MCU_H='<stm32h743xx.h>'
|
||||
CFLAGS_MCU=MCU_SERIES_H7
|
||||
OMV_BOARD_EXTRA_CFLAGS=-DUSE_USB_FS
|
||||
OMV_BOARD_EXTRA_CFLAGS=-DCFG_TUSB_MCU=OPT_MCU_STM32H7
|
||||
VECT_TAB_OFFSET=0x40000
|
||||
MAIN_APP_ADDR=0x08040000
|
||||
OMV_HSE_VALUE=12000000
|
||||
|
||||
@ -1,77 +1,66 @@
|
||||
/*
|
||||
* This file is part of the OpenMV project.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Copyright (c) 2013-2022 Ibrahim Abdelkader <iabdalkader@openmv.io>
|
||||
* Copyright (c) 2013-2022 Kwabena W. Agyeman <kwagyeman@openmv.io>
|
||||
* Copyright (C) 2013-2024 OpenMV, LLC.
|
||||
*
|
||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* Board configuration and pin definitions.
|
||||
*/
|
||||
// *INDENT-OFF*
|
||||
#ifndef __OMV_BOOTCONFIG_H__
|
||||
#define __OMV_BOOTCONFIG_H__
|
||||
#include STM32_HAL_H
|
||||
#include "port.h"
|
||||
|
||||
// Bootloader version.
|
||||
#define OMV_BOOT_VERSION (0xABCD0003)
|
||||
// Misc config.
|
||||
#define OMV_BOOT_VID (0x37C5)
|
||||
#define OMV_BOOT_PID (0x9205)
|
||||
#define OMV_BOOT_DFU_TIMEOUT (1500)
|
||||
#define OMV_BOOT_LED_PIN (0) // index in omv_boot_pins
|
||||
|
||||
// Bootloader LED GPIO config.
|
||||
#define OMV_BOOT_LED_PIN (GPIO_PIN_1)
|
||||
#define OMV_BOOT_LED_PORT (GPIOC)
|
||||
// Flash config.
|
||||
#define OMV_BOOT_AXI_FLASH_ENABLE (1)
|
||||
#define OMV_BOOT_SPI_FLASH_ENABLE (1)
|
||||
#define OMV_BOOT_QSPI_FLASH_SIZE (0x2000000) // Must always be a power of 2.
|
||||
|
||||
// Flash layout for the bootloader.
|
||||
// Flash FS sector, main FW sector, max sector.
|
||||
#define OMV_BOOT_FLASH_LAYOUT {1, 2, 15}
|
||||
|
||||
// Flash configuration.
|
||||
#define OMV_BOOT_FLASH_ORIGIN 0x08000000
|
||||
#define OMV_BOOT_FLASH_LENGTH 128K
|
||||
|
||||
// QSPI Flash layout for the bootloader.
|
||||
// First block, maximum block, block size in bytes.
|
||||
#define OMV_BOOT_QSPIF_LAYOUT {0, 511, 64 * 1024}
|
||||
|
||||
// QSPI Flash configuration.
|
||||
#define OMV_BOOT_QSPIF_SIZE_BITS (25) // 2**25 == 32MBytes.
|
||||
#define OMV_BOOT_QSPIF_SR_WIP_MASK (1 << 0)
|
||||
#define OMV_BOOT_QSPIF_SR_WEL_MASK (1 << 1)
|
||||
#define OMV_BOOT_QSPIF_READ_QUADIO_DCYC (6)
|
||||
|
||||
#define OMV_BOOT_QSPIF_PAGE_SIZE (0x100) // 256 bytes pages.
|
||||
#define OMV_BOOT_QSPIF_NUM_PAGES (0x20000) // 131072 pages of 256 bytes
|
||||
|
||||
#define OMV_BOOT_QSPIF_SECTOR_SIZE (0x1000) // 4K bytes sectors.
|
||||
#define OMV_BOOT_QSPIF_NUM_SECTORS (0x2000) // 8192 sectors of 4K bytes
|
||||
|
||||
#define OMV_BOOT_QSPIF_BLOCK_SIZE (0x10000) // 64K bytes blocks.
|
||||
#define OMV_BOOT_QSPIF_NUM_BLOCKS (0x200) // 512 blocks of 64K bytes
|
||||
|
||||
#define OMV_BOOT_QSPIF_CLK_PIN (GPIO_PIN_10)
|
||||
#define OMV_BOOT_QSPIF_CLK_PORT (GPIOF)
|
||||
#define OMV_BOOT_QSPIF_CLK_ALT (GPIO_AF9_QUADSPI)
|
||||
|
||||
#define OMV_BOOT_QSPIF_CS_PIN (GPIO_PIN_6)
|
||||
#define OMV_BOOT_QSPIF_CS_PORT (GPIOG)
|
||||
#define OMV_BOOT_QSPIF_CS_ALT (GPIO_AF10_QUADSPI)
|
||||
|
||||
#define OMV_BOOT_QSPIF_D0_PIN (GPIO_PIN_8)
|
||||
#define OMV_BOOT_QSPIF_D0_PORT (GPIOF)
|
||||
#define OMV_BOOT_QSPIF_D0_ALT (GPIO_AF10_QUADSPI)
|
||||
|
||||
#define OMV_BOOT_QSPIF_D1_PIN (GPIO_PIN_9)
|
||||
#define OMV_BOOT_QSPIF_D1_PORT (GPIOF)
|
||||
#define OMV_BOOT_QSPIF_D1_ALT (GPIO_AF10_QUADSPI)
|
||||
|
||||
#define OMV_BOOT_QSPIF_D2_PIN (GPIO_PIN_7)
|
||||
#define OMV_BOOT_QSPIF_D2_PORT (GPIOF)
|
||||
#define OMV_BOOT_QSPIF_D2_ALT (GPIO_AF9_QUADSPI)
|
||||
|
||||
#define OMV_BOOT_QSPIF_D3_PIN (GPIO_PIN_6)
|
||||
#define OMV_BOOT_QSPIF_D3_PORT (GPIOF)
|
||||
#define OMV_BOOT_QSPIF_D3_ALT (GPIO_AF9_QUADSPI)
|
||||
|
||||
#define OMV_BOOT_QSPIF_CLK_ENABLE() __HAL_RCC_QSPI_CLK_ENABLE()
|
||||
#define OMV_BOOT_QSPIF_CLK_DISABLE() __HAL_RCC_QSPI_CLK_DISABLE()
|
||||
#define OMV_BOOT_QSPIF_FORCE_RESET() __HAL_RCC_QSPI_FORCE_RESET()
|
||||
#define OMV_BOOT_QSPIF_RELEASE_RESET() __HAL_RCC_QSPI_RELEASE_RESET()
|
||||
// Boot I/O pins.
|
||||
static const pin_t omv_boot_pins[] = {
|
||||
{ .gpio = GPIOC, .pin = GPIO_PIN_1, .speed = GPIO_SPEED_LOW, .mode = GPIO_MODE_OUTPUT_PP, .pull = GPIO_PULLUP }, // LED
|
||||
{ .gpio = GPIOA, .pin = GPIO_PIN_9, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_INPUT, .pull = GPIO_NOPULL }, // VBUS
|
||||
{ .gpio = GPIOA, .pin = GPIO_PIN_11, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF10_OTG_FS }, // DM
|
||||
{ .gpio = GPIOA, .pin = GPIO_PIN_12, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF10_OTG_FS }, // DP
|
||||
{ .gpio = GPIOF, .pin = GPIO_PIN_10, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF9_QUADSPI }, // CLK
|
||||
{ .gpio = GPIOG, .pin = GPIO_PIN_6, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF10_QUADSPI }, // CS
|
||||
{ .gpio = GPIOF, .pin = GPIO_PIN_8, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF10_QUADSPI }, // D0
|
||||
{ .gpio = GPIOF, .pin = GPIO_PIN_9, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF10_QUADSPI }, // D1
|
||||
{ .gpio = GPIOF, .pin = GPIO_PIN_7, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF9_QUADSPI }, // D2
|
||||
{ .gpio = GPIOF, .pin = GPIO_PIN_6, .speed = GPIO_SPEED_HIGH, .mode = GPIO_MODE_AF_PP, .alt = GPIO_AF9_QUADSPI }, // D3
|
||||
};
|
||||
#define OMV_BOOT_PINS_COUNT (sizeof(omv_boot_pins) / sizeof(omv_boot_pins[0]))
|
||||
|
||||
// Boot partitions.
|
||||
static const partition_t OMV_BOOT_PARTITIONS[] = {
|
||||
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08020000, .limit = 0x08040000, .attr = 0 }, // FFS
|
||||
{ .type = PTYPE_AXI_FLASH, .region = -1, .rdonly = 0, .start = 0x08040000, .limit = 0x08200000, .attr = 0 }, // FIRMWARE
|
||||
{ .type = PTYPE_SPI_FLASH, .region = -1, .rdonly = 0, .start = 0x00000000, .limit = 0x02000000, .attr = 0 }, // QSPI
|
||||
};
|
||||
#define OMV_BOOT_PARTITIONS_COUNT 3 // Must be a literal
|
||||
#define OMV_BOOT_PARTITIONS_STR "FILESYSTEM", "FIRMWARE", "SPI_FLASH"
|
||||
#endif //__OMV_BOOTCONFIG_H__
|
||||
|
||||
29
src/omv/boards/OPENMV_N6/omv_bootconfig.h
Normal file
29
src/omv/boards/OPENMV_N6/omv_bootconfig.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* This file is part of the OpenMV project.
|
||||
*
|
||||
* Copyright (c) 2013-2022 Ibrahim Abdelkader <iabdalkader@openmv.io>
|
||||
* Copyright (c) 2013-2022 Kwabena W. Agyeman <kwagyeman@openmv.io>
|
||||
*
|
||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
*
|
||||
* Board configuration and pin definitions.
|
||||
*/
|
||||
#ifndef __OMV_BOOTCONFIG_H__
|
||||
#define __OMV_BOOTCONFIG_H__
|
||||
|
||||
// Bootloader version.
|
||||
#define OMV_BOOT_VERSION (0xABCD0003)
|
||||
|
||||
// Bootloader LED GPIO config.
|
||||
#define OMV_BOOT_LED_PIN (GPIO_PIN_7)
|
||||
#define OMV_BOOT_LED_PORT (GPIOA)
|
||||
|
||||
// Flash layout for the bootloader.
|
||||
// Flash FS sector, main FW sector, max sector.
|
||||
#define OMV_BOOT_FLASH_LAYOUT {1, 2, 15}
|
||||
|
||||
// Flash configuration.
|
||||
#define OMV_BOOT_FLASH_ORIGIN 0x34180400
|
||||
#define OMV_BOOT_FLASH_LENGTH 128K
|
||||
|
||||
#endif //__OMV_BOOTCONFIG_H__
|
||||
@ -62,7 +62,6 @@ export FROZEN_MANIFEST
|
||||
|
||||
# Export board config variables
|
||||
export PORT
|
||||
export HAL_DIR
|
||||
export MCU
|
||||
export MCU_SERIES
|
||||
export MCU_VARIANT
|
||||
@ -73,6 +72,8 @@ export TOP_DIR
|
||||
export BUILD
|
||||
export TOOLS
|
||||
export FW_DIR
|
||||
export HAL_DIR
|
||||
export BOOT_DIR
|
||||
export OMV_DIR
|
||||
export CMSIS_DIR
|
||||
export MICROPY_DIR
|
||||
|
||||
@ -1,29 +0,0 @@
|
||||
# This file is part of the OpenMV project.
|
||||
#
|
||||
# Copyright (c) 2013-2021 Ibrahim Abdelkader <iabdalkader@openmv.io>
|
||||
# Copyright (c) 2013-2021 Kwabena W. Agyeman <kwagyeman@openmv.io>
|
||||
#
|
||||
# This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
#
|
||||
# bootloader Makefile
|
||||
SRCS = $(wildcard src/*.c)
|
||||
OBJS = $(addprefix $(BUILD)/, $(SRCS:.c=.o))
|
||||
OBJ_DIRS = $(sort $(dir $(OBJS)))
|
||||
|
||||
all: | $(OBJ_DIRS) $(OBJS)
|
||||
$(OBJ_DIRS):
|
||||
$(MKDIR) -p $@
|
||||
|
||||
$(BUILD)/%.o : %.c
|
||||
$(ECHO) "CC $<"
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
$(BUILD)/src/string0.o : src/string0.c
|
||||
$(ECHO) "CC $<"
|
||||
$(CC) $(CFLAGS) -ffreestanding -fno-builtin -fno-lto -c -o $@ $<
|
||||
|
||||
$(BUILD)/%.o : %.s
|
||||
$(ECHO) "AS $<"
|
||||
$(AS) $(AFLAGS) $< -o $@
|
||||
|
||||
-include $(OBJS:%.o=%.d)
|
||||
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013, 2014 Damien P. George
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
void flash_erase(uint32_t sector);
|
||||
void flash_write(const uint32_t *src, uint32_t dst, uint32_t size);
|
||||
@ -1,21 +0,0 @@
|
||||
/*
|
||||
* This file is part of the OpenMV project.
|
||||
*
|
||||
* Copyright (c) 2013-2021 Ibrahim Abdelkader <iabdalkader@openmv.io>
|
||||
* Copyright (c) 2013-2021 Kwabena W. Agyeman <kwagyeman@openmv.io>
|
||||
*
|
||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
*
|
||||
* QSPI Flash driver.
|
||||
*/
|
||||
#ifndef __QSPIF_H__
|
||||
#define __QSPIF_H__
|
||||
int qspif_init();
|
||||
int qspif_deinit();
|
||||
int qspif_reset();
|
||||
int qspif_read(uint8_t *buf, uint32_t addr, uint32_t size);
|
||||
int qspif_write(uint8_t *buf, uint32_t addr, uint32_t size);
|
||||
int qspif_erase_block(uint32_t addr);
|
||||
int qspif_erase_chip();
|
||||
int qspif_memory_test();
|
||||
#endif //__QSPIF_H__
|
||||
@ -1,74 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file USB_Device/CDC_Standalone/Inc/stm32f4xx_it.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.2
|
||||
* @date 25-May-2015
|
||||
* @brief This file contains the headers of the interrupt handlers.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32F4xx_IT_H
|
||||
#define __STM32F4xx_IT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
void NMI_Handler(void);
|
||||
void HardFault_Handler(void);
|
||||
void MemManage_Handler(void);
|
||||
void BusFault_Handler(void);
|
||||
void UsageFault_Handler(void);
|
||||
void SVC_Handler(void);
|
||||
void DebugMon_Handler(void);
|
||||
void PendSV_Handler(void);
|
||||
void SysTick_Handler(void);
|
||||
#ifdef USE_USB_FS
|
||||
void OTG_FS_IRQHandler(void);
|
||||
#else
|
||||
void OTG_HS_IRQHandler(void);
|
||||
#endif
|
||||
void USARTx_DMA_TX_IRQHandler(void);
|
||||
void USARTx_IRQHandler(void);
|
||||
void TIMx_IRQHandler(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32F4xx_IT_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@ -1,191 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_cdc.h
|
||||
* @author MCD Application Team
|
||||
* @version V2.4.1
|
||||
* @date 19-June-2015
|
||||
* @brief header file for the usbd_cdc.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_CDC_H
|
||||
#define __USB_CDC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbdev/usbd_ioreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup usbd_cdc
|
||||
* @brief This file is the Header file for usbd_cdc.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup usbd_cdc_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#define CDC_IN_EP 0x81 /* EP1 for data IN */
|
||||
#define CDC_OUT_EP 0x01 /* EP1 for data OUT */
|
||||
#define CDC_CMD_EP 0x82 /* EP2 for CDC commands */
|
||||
|
||||
/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
|
||||
#define CDC_DATA_HS_MAX_PACKET_SIZE 512 /* Endpoint IN & OUT Packet size */
|
||||
#define CDC_DATA_FS_MAX_PACKET_SIZE 64 /* Endpoint IN & OUT Packet size */
|
||||
#define CDC_CMD_PACKET_SIZE 8 /* Control Endpoint Packet size */
|
||||
|
||||
#if defined(USE_USB_FS)
|
||||
#define CDC_DATA_MAX_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
|
||||
#elif defined(USE_USB_HS)
|
||||
#define CDC_DATA_MAX_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE
|
||||
#else
|
||||
#error "USB speed is not defined"
|
||||
#endif
|
||||
|
||||
#define USB_CDC_CONFIG_DESC_SIZ 75
|
||||
#define CDC_DATA_HS_IN_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE
|
||||
#define CDC_DATA_HS_OUT_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE
|
||||
|
||||
#define CDC_DATA_FS_IN_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
|
||||
#define CDC_DATA_FS_OUT_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* CDC definitions */
|
||||
/*---------------------------------------------------------------------*/
|
||||
#define CDC_SEND_ENCAPSULATED_COMMAND 0x00
|
||||
#define CDC_GET_ENCAPSULATED_RESPONSE 0x01
|
||||
#define CDC_SET_COMM_FEATURE 0x02
|
||||
#define CDC_GET_COMM_FEATURE 0x03
|
||||
#define CDC_CLEAR_COMM_FEATURE 0x04
|
||||
#define CDC_SET_LINE_CODING 0x20
|
||||
#define CDC_GET_LINE_CODING 0x21
|
||||
#define CDC_SET_CONTROL_LINE_STATE 0x22
|
||||
#define CDC_SEND_BREAK 0x23
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t bitrate;
|
||||
uint8_t format;
|
||||
uint8_t paritytype;
|
||||
uint8_t datatype;
|
||||
}USBD_CDC_LineCodingTypeDef;
|
||||
|
||||
typedef struct _USBD_CDC_Itf
|
||||
{
|
||||
int8_t (* Init) (void);
|
||||
int8_t (* DeInit) (void);
|
||||
int8_t (* Control) (uint8_t, uint8_t * , uint16_t);
|
||||
int8_t (* Receive) (uint8_t *, uint32_t *);
|
||||
|
||||
}USBD_CDC_ItfTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t data[CDC_DATA_HS_MAX_PACKET_SIZE/4]; /* Force 32bits alignment */
|
||||
uint8_t CmdOpCode;
|
||||
uint8_t CmdLength;
|
||||
uint8_t *RxBuffer;
|
||||
uint8_t *TxBuffer;
|
||||
uint32_t RxLength;
|
||||
uint32_t TxLength;
|
||||
|
||||
__IO uint32_t TxState;
|
||||
__IO uint32_t RxState;
|
||||
}
|
||||
USBD_CDC_HandleTypeDef;
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_CDC;
|
||||
#define USBD_CDC_CLASS &USBD_CDC
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev,
|
||||
USBD_CDC_ItfTypeDef *fops);
|
||||
|
||||
uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff,
|
||||
uint16_t length);
|
||||
|
||||
uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff);
|
||||
|
||||
uint8_t USBD_CDC_ReceivePacket (USBD_HandleTypeDef *pdev);
|
||||
|
||||
uint8_t USBD_CDC_TransmitPacket (USBD_HandleTypeDef *pdev);
|
||||
|
||||
uint8_t USBD_VCP_Connected (void);
|
||||
uint8_t USBD_IDE_Connected (void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_CDC_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@ -1,77 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file USB_Device/CDC_Standalone/Inc/usbd_conf.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.2
|
||||
* @date 25-May-2015
|
||||
* @brief General low level driver configuration
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_CONF_H
|
||||
#define __USBD_CONF_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include STM32_HAL_H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Common Config */
|
||||
#define USBD_MAX_NUM_INTERFACES 2
|
||||
#define USBD_MAX_NUM_CONFIGURATION 1
|
||||
#define USBD_MAX_STR_DESC_SIZ 0x100
|
||||
#define USBD_SUPPORT_USER_STRING 0
|
||||
#define USBD_SELF_POWERED 1
|
||||
#define USBD_DEBUG_LEVEL 0
|
||||
|
||||
/* DEBUG macros */
|
||||
#if (USBD_DEBUG_LEVEL > 0)
|
||||
#define USBD_UsrLog(...) printf(__VA_ARGS__);\
|
||||
printf("\n");
|
||||
#else
|
||||
#define USBD_UsrLog(...)
|
||||
#endif
|
||||
|
||||
#if (USBD_DEBUG_LEVEL > 1)
|
||||
|
||||
#define USBD_ErrLog(...) printf("ERROR: ") ;\
|
||||
printf(__VA_ARGS__);\
|
||||
printf("\n");
|
||||
#else
|
||||
#define USBD_ErrLog(...)
|
||||
#endif
|
||||
|
||||
#if (USBD_DEBUG_LEVEL > 2)
|
||||
#define USBD_DbgLog(...) printf("DEBUG : ") ;\
|
||||
printf(__VA_ARGS__);\
|
||||
printf("\n");
|
||||
#else
|
||||
#define USBD_DbgLog(...)
|
||||
#endif
|
||||
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
#endif /* __USBD_CONF_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@ -1,159 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_core.h
|
||||
* @author MCD Application Team
|
||||
* @version V2.0.0
|
||||
* @date 18-February-2014
|
||||
* @brief Header file for usbd_core.c
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_CORE_H
|
||||
#define __USBD_CORE_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbdev/usbd_conf.h"
|
||||
#include "usbdev/usbd_def.h"
|
||||
#include "usbdev/usbd_ioreq.h"
|
||||
#include "usbdev/usbd_ctlreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE
|
||||
* @brief This file is the Header file for usbd_core.c file
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
#define USBD_SOF USBD_LL_SOF
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id);
|
||||
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass);
|
||||
|
||||
USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup);
|
||||
USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata);
|
||||
USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed);
|
||||
USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev);
|
||||
|
||||
/* USBD Low Level Driver */
|
||||
USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_DeInit (USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_Stop (USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_OpenEP (USBD_HandleTypeDef *pdev,
|
||||
uint8_t ep_addr,
|
||||
uint8_t ep_type,
|
||||
uint16_t ep_mps);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_CloseEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
USBD_StatusTypeDef USBD_LL_FlushEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
USBD_StatusTypeDef USBD_LL_StallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
USBD_StatusTypeDef USBD_LL_ClearStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
uint8_t USBD_LL_IsStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
USBD_StatusTypeDef USBD_LL_SetUSBAddress (USBD_HandleTypeDef *pdev, uint8_t dev_addr);
|
||||
USBD_StatusTypeDef USBD_LL_Transmit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t ep_addr,
|
||||
uint8_t *pbuf,
|
||||
uint16_t size);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
|
||||
uint8_t ep_addr,
|
||||
uint8_t *pbuf,
|
||||
uint16_t size);
|
||||
|
||||
uint32_t USBD_LL_GetRxDataSize (USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
void USBD_LL_Delay (uint32_t Delay);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __USBD_CORE_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
|
||||
@ -1,106 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_req.h
|
||||
* @author MCD Application Team
|
||||
* @version V2.0.0
|
||||
* @date 18-February-2014
|
||||
* @brief header file for the usbd_req.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
|
||||
#ifndef __USB_REQUEST_H_
|
||||
#define __USB_REQUEST_H_
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbdev/usbd_def.h"
|
||||
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_REQ
|
||||
* @brief header file for the usbd_ioreq.c file
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_REQ_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_REQ_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_REQ_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
|
||||
|
||||
void USBD_CtlError (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
|
||||
void USBD_ParseSetupRequest (USBD_SetupReqTypedef *req, uint8_t *pdata);
|
||||
|
||||
void USBD_GetString (uint8_t *desc, uint8_t *unicode, uint16_t *len);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __USB_REQUEST_H_ */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@ -1,323 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_def.h
|
||||
* @author MCD Application Team
|
||||
* @version V2.0.0
|
||||
* @date 18-February-2014
|
||||
* @brief general defines for the usb device library
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
|
||||
#ifndef __USBD_DEF_H
|
||||
#define __USBD_DEF_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbdev/usbd_conf.h"
|
||||
|
||||
/** @addtogroup STM32_USBD_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_DEF
|
||||
* @brief general defines for the usb device library file
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_DEF_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
|
||||
|
||||
#define USB_LEN_DEV_QUALIFIER_DESC 0x0A
|
||||
#define USB_LEN_DEV_DESC 0x12
|
||||
#define USB_LEN_CFG_DESC 0x09
|
||||
#define USB_LEN_IF_DESC 0x09
|
||||
#define USB_LEN_EP_DESC 0x07
|
||||
#define USB_LEN_OTG_DESC 0x03
|
||||
#define USB_LEN_LANGID_STR_DESC 0x04
|
||||
#define USB_LEN_OTHER_SPEED_DESC_SIZ 0x09
|
||||
|
||||
#define USBD_IDX_LANGID_STR 0x00
|
||||
#define USBD_IDX_MFC_STR 0x01
|
||||
#define USBD_IDX_PRODUCT_STR 0x02
|
||||
#define USBD_IDX_SERIAL_STR 0x03
|
||||
#define USBD_IDX_CONFIG_STR 0x04
|
||||
#define USBD_IDX_INTERFACE_STR 0x05
|
||||
|
||||
#define USB_REQ_TYPE_STANDARD 0x00
|
||||
#define USB_REQ_TYPE_CLASS 0x20
|
||||
#define USB_REQ_TYPE_VENDOR 0x40
|
||||
#define USB_REQ_TYPE_MASK 0x60
|
||||
|
||||
#define USB_REQ_RECIPIENT_DEVICE 0x00
|
||||
#define USB_REQ_RECIPIENT_INTERFACE 0x01
|
||||
#define USB_REQ_RECIPIENT_ENDPOINT 0x02
|
||||
#define USB_REQ_RECIPIENT_MASK 0x03
|
||||
|
||||
#define USB_REQ_GET_STATUS 0x00
|
||||
#define USB_REQ_CLEAR_FEATURE 0x01
|
||||
#define USB_REQ_SET_FEATURE 0x03
|
||||
#define USB_REQ_SET_ADDRESS 0x05
|
||||
#define USB_REQ_GET_DESCRIPTOR 0x06
|
||||
#define USB_REQ_SET_DESCRIPTOR 0x07
|
||||
#define USB_REQ_GET_CONFIGURATION 0x08
|
||||
#define USB_REQ_SET_CONFIGURATION 0x09
|
||||
#define USB_REQ_GET_INTERFACE 0x0A
|
||||
#define USB_REQ_SET_INTERFACE 0x0B
|
||||
#define USB_REQ_SYNCH_FRAME 0x0C
|
||||
|
||||
#define USB_DESC_TYPE_DEVICE 1
|
||||
#define USB_DESC_TYPE_CONFIGURATION 2
|
||||
#define USB_DESC_TYPE_STRING 3
|
||||
#define USB_DESC_TYPE_INTERFACE 4
|
||||
#define USB_DESC_TYPE_ENDPOINT 5
|
||||
#define USB_DESC_TYPE_DEVICE_QUALIFIER 6
|
||||
#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 7
|
||||
|
||||
|
||||
#define USB_CONFIG_REMOTE_WAKEUP 2
|
||||
#define USB_CONFIG_SELF_POWERED 1
|
||||
|
||||
#define USB_FEATURE_EP_HALT 0
|
||||
#define USB_FEATURE_REMOTE_WAKEUP 1
|
||||
#define USB_FEATURE_TEST_MODE 2
|
||||
|
||||
|
||||
#define USB_HS_MAX_PACKET_SIZE 512
|
||||
#define USB_FS_MAX_PACKET_SIZE 64
|
||||
#define USB_MAX_EP0_SIZE 64
|
||||
|
||||
/* Device Status */
|
||||
#define USBD_STATE_DEFAULT 1
|
||||
#define USBD_STATE_ADDRESSED 2
|
||||
#define USBD_STATE_CONFIGURED 3
|
||||
#define USBD_STATE_SUSPENDED 4
|
||||
|
||||
|
||||
/* EP0 State */
|
||||
#define USBD_EP0_IDLE 0
|
||||
#define USBD_EP0_SETUP 1
|
||||
#define USBD_EP0_DATA_IN 2
|
||||
#define USBD_EP0_DATA_OUT 3
|
||||
#define USBD_EP0_STATUS_IN 4
|
||||
#define USBD_EP0_STATUS_OUT 5
|
||||
#define USBD_EP0_STALL 6
|
||||
|
||||
#define USBD_EP_TYPE_CTRL 0
|
||||
#define USBD_EP_TYPE_ISOC 1
|
||||
#define USBD_EP_TYPE_BULK 2
|
||||
#define USBD_EP_TYPE_INTR 3
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_DEF_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct usb_setup_req
|
||||
{
|
||||
|
||||
uint8_t bmRequest;
|
||||
uint8_t bRequest;
|
||||
uint16_t wValue;
|
||||
uint16_t wIndex;
|
||||
uint16_t wLength;
|
||||
}USBD_SetupReqTypedef;
|
||||
|
||||
struct _USBD_HandleTypeDef;
|
||||
|
||||
typedef struct _Device_cb
|
||||
{
|
||||
uint8_t (*Init) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx);
|
||||
uint8_t (*DeInit) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx);
|
||||
/* Control Endpoints*/
|
||||
uint8_t (*Setup) (struct _USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req);
|
||||
uint8_t (*EP0_TxSent) (struct _USBD_HandleTypeDef *pdev );
|
||||
uint8_t (*EP0_RxReady) (struct _USBD_HandleTypeDef *pdev );
|
||||
/* Class Specific Endpoints*/
|
||||
uint8_t (*DataIn) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
|
||||
uint8_t (*DataOut) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
|
||||
uint8_t (*SOF) (struct _USBD_HandleTypeDef *pdev);
|
||||
uint8_t (*IsoINIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
|
||||
uint8_t (*IsoOUTIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
|
||||
|
||||
uint8_t *(*GetHSConfigDescriptor)(uint16_t *length);
|
||||
uint8_t *(*GetFSConfigDescriptor)(uint16_t *length);
|
||||
uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length);
|
||||
uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length);
|
||||
#if (USBD_SUPPORT_USER_STRING == 1)
|
||||
uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev ,uint8_t index, uint16_t *length);
|
||||
#endif
|
||||
|
||||
} USBD_ClassTypeDef;
|
||||
|
||||
/* Following USB Device Speed */
|
||||
typedef enum
|
||||
{
|
||||
USBD_SPEED_HIGH = 0,
|
||||
USBD_SPEED_FULL = 1,
|
||||
USBD_SPEED_LOW = 2,
|
||||
}USBD_SpeedTypeDef;
|
||||
|
||||
/* Following USB Device status */
|
||||
typedef enum {
|
||||
USBD_OK = 0,
|
||||
USBD_BUSY,
|
||||
USBD_FAIL,
|
||||
}USBD_StatusTypeDef;
|
||||
|
||||
/* USB Device descriptors structure */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t *(*GetDeviceDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
|
||||
uint8_t *(*GetLangIDStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
|
||||
uint8_t *(*GetManufacturerStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
|
||||
uint8_t *(*GetProductStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
|
||||
uint8_t *(*GetSerialStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
|
||||
uint8_t *(*GetConfigurationStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
|
||||
uint8_t *(*GetInterfaceStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
|
||||
} USBD_DescriptorsTypeDef;
|
||||
|
||||
/* USB Device handle structure */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t status;
|
||||
uint32_t total_length;
|
||||
uint32_t rem_length;
|
||||
uint32_t maxpacket;
|
||||
} USBD_EndpointTypeDef;
|
||||
|
||||
/* USB Device handle structure */
|
||||
typedef struct _USBD_HandleTypeDef
|
||||
{
|
||||
uint8_t id;
|
||||
uint32_t dev_config;
|
||||
uint32_t dev_default_config;
|
||||
uint32_t dev_config_status;
|
||||
USBD_SpeedTypeDef dev_speed;
|
||||
USBD_EndpointTypeDef ep_in[15];
|
||||
USBD_EndpointTypeDef ep_out[15];
|
||||
uint32_t ep0_state;
|
||||
uint32_t ep0_data_len;
|
||||
uint8_t dev_state;
|
||||
uint8_t dev_old_state;
|
||||
uint8_t dev_address;
|
||||
uint8_t dev_connection_status;
|
||||
uint8_t dev_test_mode;
|
||||
uint32_t dev_remote_wakeup;
|
||||
|
||||
USBD_SetupReqTypedef request;
|
||||
USBD_DescriptorsTypeDef *pDesc;
|
||||
USBD_ClassTypeDef *pClass;
|
||||
void *pClassData;
|
||||
void *pUserData;
|
||||
void *pData;
|
||||
} USBD_HandleTypeDef;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_DEF_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
#define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \
|
||||
(((uint16_t)(*(((uint8_t *)(addr)) + 1))) << 8))
|
||||
|
||||
#define LOBYTE(x) ((uint8_t)(x & 0x00FF))
|
||||
#define HIBYTE(x) ((uint8_t)((x & 0xFF00) >>8))
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
#ifndef MAX
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
#ifndef __weak
|
||||
#define __weak __attribute__((weak))
|
||||
#endif /* __weak */
|
||||
#ifndef __packed
|
||||
#define __packed __attribute__((__packed__))
|
||||
#endif /* __packed */
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
|
||||
/* In HS mode and when the DMA is used, all variables and data structures dealing
|
||||
with the DMA during the transaction process should be 4-bytes aligned */
|
||||
|
||||
#if defined (__GNUC__) /* GNU Compiler */
|
||||
#define __ALIGN_END __attribute__ ((aligned (4)))
|
||||
#define __ALIGN_BEGIN
|
||||
#else
|
||||
#define __ALIGN_END
|
||||
#if defined (__CC_ARM) /* ARM Compiler */
|
||||
#define __ALIGN_BEGIN __align(4)
|
||||
#elif defined (__ICCARM__) /* IAR Compiler */
|
||||
#define __ALIGN_BEGIN
|
||||
#elif defined (__TASKING__) /* TASKING Compiler */
|
||||
#define __ALIGN_BEGIN __align(4)
|
||||
#endif /* __CC_ARM */
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DEF_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DEF_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __USBD_DEF_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@ -1,48 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file USB_Device/CDC_Standalone/Inc/usbd_desc.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.2
|
||||
* @date 25-May-2015
|
||||
* @brief Header for usbd_desc.c module
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_DESC_H
|
||||
#define __USBD_DESC_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbdev/usbd_def.h"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define DEVICE_ID1 (0x1FFF7A10)
|
||||
#define DEVICE_ID2 (0x1FFF7A14)
|
||||
#define DEVICE_ID3 (0x1FFF7A18)
|
||||
|
||||
#define USB_SIZ_STRING_SERIAL 0x1A
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
extern USBD_DescriptorsTypeDef VCP_Desc;
|
||||
|
||||
#endif /* __USBD_DESC_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@ -1,121 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_ioreq.h
|
||||
* @author MCD Application Team
|
||||
* @version V2.0.0
|
||||
* @date 18-February-2014
|
||||
* @brief header file for the usbd_ioreq.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
|
||||
#ifndef __USBD_IOREQ_H_
|
||||
#define __USBD_IOREQ_H_
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbdev/usbd_def.h"
|
||||
#include "usbdev/usbd_core.h"
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_IOREQ
|
||||
* @brief header file for the usbd_ioreq.c file
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_IOREQ_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_IOREQ_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_IOREQ_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *buf,
|
||||
uint16_t len);
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf,
|
||||
uint16_t len);
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf,
|
||||
uint16_t len);
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf,
|
||||
uint16_t len);
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev);
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev);
|
||||
|
||||
uint16_t USBD_GetRxCount (USBD_HandleTypeDef *pdev ,
|
||||
uint8_t epnum);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __USBD_IOREQ_H_ */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@ -1,103 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013, 2014 Damien P. George
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include STM32_HAL_H
|
||||
#include "flash.h"
|
||||
|
||||
#if defined(MCU_SERIES_F7)
|
||||
#define FLASH_FLAG_PGSERR (FLASH_FLAG_ERSERR)
|
||||
#endif
|
||||
|
||||
extern void __fatal_error();
|
||||
|
||||
void flash_erase(uint32_t sector) {
|
||||
// unlock
|
||||
HAL_FLASH_Unlock();
|
||||
|
||||
#if defined(MCU_SERIES_H7)
|
||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS_BANK1 | FLASH_FLAG_ALL_ERRORS_BANK2);
|
||||
#else
|
||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
|
||||
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
|
||||
#endif
|
||||
|
||||
// erase the sector(s)
|
||||
FLASH_EraseInitTypeDef EraseInitStruct;
|
||||
EraseInitStruct.TypeErase = TYPEERASE_SECTORS;
|
||||
EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3; // voltage range needs to be 2.7V to 3.6V
|
||||
#if defined(MCU_SERIES_H7)
|
||||
EraseInitStruct.Sector = (sector % 8);
|
||||
if (sector < 8) {
|
||||
EraseInitStruct.Banks = FLASH_BANK_1;
|
||||
} else {
|
||||
EraseInitStruct.Banks = FLASH_BANK_2;
|
||||
}
|
||||
#else
|
||||
EraseInitStruct.Sector = sector;
|
||||
#endif
|
||||
EraseInitStruct.NbSectors = 1;
|
||||
|
||||
uint32_t SectorError = 0;
|
||||
if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) {
|
||||
// error occurred during sector erase
|
||||
HAL_FLASH_Lock(); // lock the flash
|
||||
__fatal_error();
|
||||
}
|
||||
|
||||
HAL_FLASH_Lock(); // lock the flash
|
||||
}
|
||||
|
||||
void flash_write(const uint32_t *src, uint32_t dst, uint32_t size) {
|
||||
// Unlock flash
|
||||
HAL_FLASH_Unlock();
|
||||
|
||||
#if defined(MCU_SERIES_H7)
|
||||
// Program the flash 32 bytes at a time.
|
||||
for (int i = 0; i < size / 32; i++) {
|
||||
if (HAL_FLASH_Program(TYPEPROGRAM_WORD, dst, (uint64_t) (uint32_t) src) != HAL_OK) {
|
||||
// error occurred during flash write
|
||||
HAL_FLASH_Lock(); // lock the flash
|
||||
__fatal_error();
|
||||
}
|
||||
src += 8;
|
||||
dst += 32;
|
||||
}
|
||||
#else
|
||||
// Program the flash 4 bytes at a time.
|
||||
for (int i = 0; i < size / 4; i++) {
|
||||
if (HAL_FLASH_Program(TYPEPROGRAM_WORD, dst, *src) != HAL_OK) {
|
||||
// error occurred during flash write
|
||||
HAL_FLASH_Lock(); // lock the flash
|
||||
__fatal_error();
|
||||
}
|
||||
src += 1;
|
||||
dst += 4;
|
||||
}
|
||||
#endif
|
||||
|
||||
// lock the flash
|
||||
HAL_FLASH_Lock();
|
||||
}
|
||||
@ -1,112 +0,0 @@
|
||||
/*
|
||||
* This file is part of the OpenMV project.
|
||||
*
|
||||
* Copyright (c) 2013-2021 Ibrahim Abdelkader <iabdalkader@openmv.io>
|
||||
* Copyright (c) 2013-2021 Kwabena W. Agyeman <kwagyeman@openmv.io>
|
||||
*
|
||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
*
|
||||
* main function.
|
||||
*/
|
||||
#include STM32_HAL_H
|
||||
#include "usbdev/usbd_cdc.h"
|
||||
#include "usbdev/usbd_desc.h"
|
||||
#include "omv_boardconfig.h"
|
||||
#include "omv_bootconfig.h"
|
||||
#include "qspif.h"
|
||||
|
||||
#define IDE_TIMEOUT (1000)
|
||||
#define CONFIG_TIMEOUT (2000)
|
||||
USBD_HandleTypeDef USBD_Device;
|
||||
extern USBD_CDC_ItfTypeDef USBD_CDC_fops;
|
||||
|
||||
void __flash_led() {
|
||||
HAL_GPIO_TogglePin(OMV_BOOT_LED_PORT, OMV_BOOT_LED_PIN);
|
||||
HAL_Delay(100);
|
||||
HAL_GPIO_TogglePin(OMV_BOOT_LED_PORT, OMV_BOOT_LED_PIN);
|
||||
HAL_Delay(100);
|
||||
}
|
||||
|
||||
void __attribute__((noreturn)) __fatal_error() {
|
||||
while (1) {
|
||||
__flash_led();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef STACK_PROTECTOR
|
||||
uint32_t __stack_chk_guard = 0xDEADBEEF;
|
||||
|
||||
void __attribute__((noreturn)) __stack_chk_fail(void) {
|
||||
__asm__ volatile ("BKPT");
|
||||
while (1) {
|
||||
__flash_led();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
// Override main app interrupt vector offset (set in system_stm32fxxx.c)
|
||||
SCB->VTOR = FLASH_BASE | 0x0;
|
||||
|
||||
HAL_Init();
|
||||
|
||||
#if defined(OMV_BOOT_QSPIF_LAYOUT)
|
||||
if (qspif_init() != 0) {
|
||||
__fatal_error();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Init Device Library */
|
||||
USBD_Init(&USBD_Device, &VCP_Desc, 0);
|
||||
|
||||
/* Add Supported Class */
|
||||
USBD_RegisterClass(&USBD_Device, USBD_CDC_CLASS);
|
||||
|
||||
/* Add CDC Interface Class */
|
||||
USBD_CDC_RegisterInterface(&USBD_Device, &USBD_CDC_fops);
|
||||
|
||||
/* Start Device Process */
|
||||
USBD_Start(&USBD_Device);
|
||||
|
||||
// Note: The SRQINT interrupt is triggered when VBUS is in the valid range, I assume it's safe
|
||||
// to use it to detect if USB is connected or not. The dev_connection_status is set in usbd_conf.c
|
||||
// It wasn't used anywhere else, so again assuming it's safe to use it for connection status.
|
||||
if (USBD_Device.dev_connection_status) {
|
||||
uint32_t start = HAL_GetTick();
|
||||
// Wait for device to be configured
|
||||
while (USBD_Device.dev_state != USBD_STATE_CONFIGURED
|
||||
// We still have to timeout because the camera
|
||||
// might be connected to a power bank or charger
|
||||
&& (HAL_GetTick() - start) < CONFIG_TIMEOUT) {
|
||||
__flash_led();
|
||||
}
|
||||
|
||||
// If the device is configured, wait for IDE to connect or timeout
|
||||
if (USBD_Device.dev_state == USBD_STATE_CONFIGURED) {
|
||||
uint32_t start = HAL_GetTick();
|
||||
while (!USBD_IDE_Connected()
|
||||
&& (HAL_GetTick() - start) < IDE_TIMEOUT) {
|
||||
__flash_led();
|
||||
}
|
||||
|
||||
// Wait for new firmware image if the IDE is connected
|
||||
while (USBD_IDE_Connected()) {
|
||||
__flash_led();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Deinit USB
|
||||
USBD_DeInit(&USBD_Device);
|
||||
|
||||
#if defined(OMV_BOOT_QSPIF_LAYOUT)
|
||||
qspif_reset();
|
||||
qspif_deinit();
|
||||
#endif
|
||||
|
||||
// Disable IRQs
|
||||
__disable_irq(); __DSB(); __ISB();
|
||||
|
||||
// Jump to main app
|
||||
((void (*) (void)) (*((uint32_t *) (MAIN_APP_ADDR + 4)))) ();
|
||||
}
|
||||
@ -1,387 +0,0 @@
|
||||
/*
|
||||
* This file is part of the OpenMV project.
|
||||
*
|
||||
* Copyright (c) 2013-2021 Ibrahim Abdelkader <iabdalkader@openmv.io>
|
||||
* Copyright (c) 2013-2021 Kwabena W. Agyeman <kwagyeman@openmv.io>
|
||||
*
|
||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
*
|
||||
* QSPI Flash driver.
|
||||
*/
|
||||
#include STM32_HAL_H
|
||||
#include <string.h>
|
||||
#include "qspif.h"
|
||||
#include "omv_boardconfig.h"
|
||||
#include "omv_bootconfig.h"
|
||||
|
||||
#if defined(OMV_BOOT_QSPIF_LAYOUT)
|
||||
|
||||
#define HAL_QSPI_TIMEOUT (5000)
|
||||
#define SECTOR_ERASE_TIMEOUT (400)
|
||||
#define BLOCK_ERASE_TIMEOUT (2000)
|
||||
#define CHIP_ERASE_TIMEOUT (400000)
|
||||
|
||||
#define CMD_RESET_ENABLE (0x66)
|
||||
#define CMD_RESET_MEMORY (0x99)
|
||||
|
||||
#define CMD_READ_QUADIO (0xEC)
|
||||
#define CMD_PROG_QUADIO (0x34)
|
||||
|
||||
#define CMD_64K_BLOCK_ERASE (0xDC)
|
||||
#define CMD_CHIP_ERASE (0xC7)
|
||||
|
||||
#define CMD_4BYTE_ADDR_ENABLE (0xB7)
|
||||
#define CMD_4BYTE_ADDR_DISABLE (0xE9)
|
||||
|
||||
#define CMD_WRITE_ENABLE (0x06)
|
||||
#define CMD_WRITE_DISABLE (0x04)
|
||||
|
||||
#define CMD_READ_STATUS_REG (0x05)
|
||||
#define CMD_WRITE_STATUS_REG (0x01)
|
||||
|
||||
static QSPI_HandleTypeDef QSPIHandle = {0};
|
||||
static int qspif_write_enable();
|
||||
static int qspif_4byte_addr_mode_enable();
|
||||
static int qspif_poll_status_flag(uint32_t mask, uint32_t match, uint32_t timeout);
|
||||
|
||||
int qspif_init() {
|
||||
QSPIHandle.Instance = QUADSPI;
|
||||
QSPIHandle.Init.ClockPrescaler = 1; // clock = 200MHz / (1+1) = 100MHz
|
||||
QSPIHandle.Init.FifoThreshold = 3;
|
||||
QSPIHandle.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_HALFCYCLE;
|
||||
QSPIHandle.Init.FlashSize = OMV_BOOT_QSPIF_SIZE_BITS - 1;
|
||||
QSPIHandle.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_2_CYCLE;
|
||||
QSPIHandle.Init.ClockMode = QSPI_CLOCK_MODE_0;
|
||||
QSPIHandle.Init.FlashID = QSPI_FLASH_ID_1;
|
||||
QSPIHandle.Init.DualFlash = QSPI_DUALFLASH_DISABLE;
|
||||
|
||||
// Initialize the QSPI
|
||||
HAL_QSPI_DeInit(&QSPIHandle);
|
||||
if (HAL_QSPI_Init(&QSPIHandle) != HAL_OK) {
|
||||
// Initialization Error
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Reset the QSPI
|
||||
if (qspif_reset() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Enable 4-byte address mode.
|
||||
if (qspif_4byte_addr_mode_enable() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int qspif_deinit() {
|
||||
if (QSPIHandle.Instance != NULL &&
|
||||
HAL_QSPI_DeInit(&QSPIHandle) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
QSPIHandle.Instance = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int qspif_reset() {
|
||||
QSPI_CommandTypeDef command = {
|
||||
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
|
||||
.AddressMode = QSPI_ADDRESS_NONE,
|
||||
.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE,
|
||||
.DataMode = QSPI_DATA_NONE,
|
||||
.DummyCycles = 0,
|
||||
.DdrMode = QSPI_DDR_MODE_DISABLE,
|
||||
.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY,
|
||||
.SIOOMode = QSPI_SIOO_INST_EVERY_CMD,
|
||||
};
|
||||
|
||||
if (QSPIHandle.Instance == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
command.Instruction = CMD_RESET_ENABLE;
|
||||
if (HAL_QSPI_Command(&QSPIHandle, &command, HAL_QSPI_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
command.Instruction = CMD_RESET_MEMORY;
|
||||
if (HAL_QSPI_Command(&QSPIHandle, &command, HAL_QSPI_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qspif_poll_status_flag(OMV_BOOT_QSPIF_SR_WIP_MASK, 0, HAL_QSPI_TIMEOUT) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int qspif_read(uint8_t *buf, uint32_t addr, uint32_t size) {
|
||||
QSPI_CommandTypeDef command = {
|
||||
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
|
||||
.Instruction = CMD_READ_QUADIO,
|
||||
.AddressMode = QSPI_ADDRESS_4_LINES,
|
||||
.AddressSize = QSPI_ADDRESS_32_BITS,
|
||||
.Address = addr,
|
||||
.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE,
|
||||
.DataMode = QSPI_DATA_4_LINES,
|
||||
.DummyCycles = OMV_BOOT_QSPIF_READ_QUADIO_DCYC,
|
||||
.NbData = size,
|
||||
.DdrMode = QSPI_DDR_MODE_DISABLE,
|
||||
.DdrHoldHalfCycle = QSPI_DDR_HHC_HALF_CLK_DELAY,
|
||||
.SIOOMode = QSPI_SIOO_INST_EVERY_CMD
|
||||
};
|
||||
|
||||
if (QSPIHandle.Instance == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (HAL_QSPI_Command(&QSPIHandle, &command, HAL_QSPI_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (HAL_QSPI_Receive(&QSPIHandle, buf, HAL_QSPI_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int qspif_write(uint8_t *buf, uint32_t addr, uint32_t size) {
|
||||
QSPI_CommandTypeDef command = {
|
||||
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
|
||||
.Instruction = CMD_PROG_QUADIO,
|
||||
.Address = addr,
|
||||
.AddressMode = QSPI_ADDRESS_1_LINE,
|
||||
.AddressSize = QSPI_ADDRESS_32_BITS,
|
||||
.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE,
|
||||
.NbData = size,
|
||||
.DataMode = QSPI_DATA_4_LINES,
|
||||
.DummyCycles = 0,
|
||||
.DdrMode = QSPI_DDR_MODE_DISABLE,
|
||||
.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY,
|
||||
.SIOOMode = QSPI_SIOO_INST_EVERY_CMD
|
||||
};
|
||||
|
||||
if (QSPIHandle.Instance == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Address must be page-aligned and size between 0->OMV_BOOT_QSPIF_PAGE_SIZE bytes.
|
||||
if ((addr % OMV_BOOT_QSPIF_PAGE_SIZE) != 0 || size <= 0 || size > OMV_BOOT_QSPIF_PAGE_SIZE) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Enable write operations
|
||||
if (qspif_write_enable(&QSPIHandle) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Configure the command
|
||||
if (HAL_QSPI_Command(&QSPIHandle, &command, HAL_QSPI_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Transmit the data
|
||||
if (HAL_QSPI_Transmit(&QSPIHandle, buf, HAL_QSPI_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Poll the status register.
|
||||
if (qspif_poll_status_flag(OMV_BOOT_QSPIF_SR_WIP_MASK, 0, HAL_QSPI_TIMEOUT) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int qspif_erase_block(uint32_t addr) {
|
||||
QSPI_CommandTypeDef command = {
|
||||
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
|
||||
.Instruction = CMD_64K_BLOCK_ERASE,
|
||||
.AddressMode = QSPI_ADDRESS_1_LINE,
|
||||
.AddressSize = QSPI_ADDRESS_32_BITS,
|
||||
.Address = addr,
|
||||
.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE,
|
||||
.DataMode = QSPI_DATA_NONE,
|
||||
.DummyCycles = 0,
|
||||
.DdrMode = QSPI_DDR_MODE_DISABLE,
|
||||
.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY,
|
||||
.SIOOMode = QSPI_SIOO_INST_EVERY_CMD,
|
||||
};
|
||||
|
||||
if (QSPIHandle.Instance == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qspif_write_enable(&QSPIHandle) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (HAL_QSPI_Command(&QSPIHandle, &command, HAL_QSPI_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qspif_poll_status_flag(OMV_BOOT_QSPIF_SR_WIP_MASK, 0, BLOCK_ERASE_TIMEOUT) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int qspif_erase_chip() {
|
||||
QSPI_CommandTypeDef command = {
|
||||
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
|
||||
.Instruction = CMD_CHIP_ERASE,
|
||||
.AddressMode = QSPI_ADDRESS_NONE,
|
||||
.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE,
|
||||
.DataMode = QSPI_DATA_NONE,
|
||||
.DummyCycles = 0,
|
||||
.DdrMode = QSPI_DDR_MODE_DISABLE,
|
||||
.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY,
|
||||
.SIOOMode = QSPI_SIOO_INST_EVERY_CMD,
|
||||
};
|
||||
|
||||
if (QSPIHandle.Instance == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qspif_write_enable(&QSPIHandle) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (HAL_QSPI_Command(&QSPIHandle, &command, HAL_QSPI_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qspif_poll_status_flag(OMV_BOOT_QSPIF_SR_WIP_MASK, 0, CHIP_ERASE_TIMEOUT) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qspif_write_enable() {
|
||||
QSPI_CommandTypeDef command = {
|
||||
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
|
||||
.Instruction = CMD_WRITE_ENABLE,
|
||||
.AddressMode = QSPI_ADDRESS_NONE,
|
||||
.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE,
|
||||
.DataMode = QSPI_DATA_NONE,
|
||||
.DummyCycles = 0,
|
||||
.DdrMode = QSPI_DDR_MODE_DISABLE,
|
||||
.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY,
|
||||
.SIOOMode = QSPI_SIOO_INST_EVERY_CMD,
|
||||
};
|
||||
|
||||
if (HAL_QSPI_Command(&QSPIHandle, &command, HAL_QSPI_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qspif_poll_status_flag(OMV_BOOT_QSPIF_SR_WEL_MASK, OMV_BOOT_QSPIF_SR_WEL_MASK, HAL_QSPI_TIMEOUT) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qspif_4byte_addr_mode_enable() {
|
||||
QSPI_CommandTypeDef command = {
|
||||
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
|
||||
.Instruction = CMD_4BYTE_ADDR_ENABLE,
|
||||
.AddressMode = QSPI_ADDRESS_NONE,
|
||||
.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE,
|
||||
.DataMode = QSPI_DATA_NONE,
|
||||
.DummyCycles = 0,
|
||||
.DdrMode = QSPI_DDR_MODE_DISABLE,
|
||||
.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY,
|
||||
.SIOOMode = QSPI_SIOO_INST_EVERY_CMD,
|
||||
};
|
||||
|
||||
if (qspif_write_enable() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (HAL_QSPI_Command(&QSPIHandle, &command, HAL_QSPI_TIMEOUT) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qspif_poll_status_flag(OMV_BOOT_QSPIF_SR_WIP_MASK, 0, HAL_QSPI_TIMEOUT) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qspif_poll_status_flag(uint32_t mask, uint32_t match, uint32_t timeout) {
|
||||
QSPI_AutoPollingTypeDef config = {
|
||||
.Mask = mask,
|
||||
.Match = match,
|
||||
.MatchMode = QSPI_MATCH_MODE_AND,
|
||||
.Interval = 0x10,
|
||||
.AutomaticStop = QSPI_AUTOMATIC_STOP_ENABLE,
|
||||
.StatusBytesSize = 1
|
||||
};
|
||||
|
||||
QSPI_CommandTypeDef command = {
|
||||
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
|
||||
.Instruction = CMD_READ_STATUS_REG,
|
||||
.AddressMode = QSPI_ADDRESS_NONE,
|
||||
.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE,
|
||||
.DataMode = QSPI_DATA_1_LINE,
|
||||
.DummyCycles = 0,
|
||||
.DdrMode = QSPI_DDR_MODE_DISABLE,
|
||||
.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY,
|
||||
.SIOOMode = QSPI_SIOO_INST_EVERY_CMD
|
||||
};
|
||||
|
||||
if (HAL_QSPI_AutoPolling(&QSPIHandle, &command, &config, timeout) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __attribute__((optimize("O0"))) qspif_memory_test() {
|
||||
uint8_t buf[OMV_BOOT_QSPIF_PAGE_SIZE];
|
||||
uint8_t pat[OMV_BOOT_QSPIF_PAGE_SIZE];
|
||||
|
||||
if (qspif_init() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < OMV_BOOT_QSPIF_PAGE_SIZE; i++) {
|
||||
pat[i] = ((i % 2) == 0) ? 0xaa : 0x55;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0, addr = 0; i < OMV_BOOT_QSPIF_NUM_BLOCKS; i++, addr += OMV_BOOT_QSPIF_BLOCK_SIZE) {
|
||||
if (qspif_erase_block(addr) != 0) {
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t i = 0, addr = 0; i < OMV_BOOT_QSPIF_NUM_PAGES; i++, addr += OMV_BOOT_QSPIF_PAGE_SIZE) {
|
||||
if (qspif_write(pat, addr, OMV_BOOT_QSPIF_PAGE_SIZE) != 0) {
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t i = 0, addr = 0; i < OMV_BOOT_QSPIF_NUM_PAGES; i++, addr += OMV_BOOT_QSPIF_PAGE_SIZE) {
|
||||
memset(buf, 0, OMV_BOOT_QSPIF_PAGE_SIZE);
|
||||
if (qspif_read(buf, addr, OMV_BOOT_QSPIF_PAGE_SIZE) != 0) {
|
||||
return -4;
|
||||
}
|
||||
if (memcmp(buf, pat, OMV_BOOT_QSPIF_PAGE_SIZE) != 0) {
|
||||
return -5;
|
||||
}
|
||||
}
|
||||
|
||||
if (qspif_erase_chip() != 0) {
|
||||
return -6;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif //defined(OMV_BOOT_QSPIF_LAYOUT)
|
||||
@ -1,140 +0,0 @@
|
||||
/*
|
||||
* This file is part of the OpenMV project.
|
||||
*
|
||||
* Copyright (c) 2013-2021 Ibrahim Abdelkader <iabdalkader@openmv.io>
|
||||
* Copyright (c) 2013-2021 Kwabena W. Agyeman <kwagyeman@openmv.io>
|
||||
*
|
||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
*
|
||||
* HAL MSP.
|
||||
*/
|
||||
#include STM32_HAL_H
|
||||
#include "omv_boardconfig.h"
|
||||
#include "omv_bootconfig.h"
|
||||
|
||||
extern void SystemClock_Config();
|
||||
|
||||
void HAL_MspInit() {
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
|
||||
#if defined(OMV_BOOT_OSCEN_PIN)
|
||||
OMV_BOOT_OSCEN_CLK_ENABLE();
|
||||
GPIO_InitStructure.Pin = OMV_BOOT_OSCEN_PIN;
|
||||
HAL_GPIO_Init(OMV_BOOT_OSCEN_PORT, &GPIO_InitStructure);
|
||||
HAL_GPIO_WritePin(OMV_BOOT_OSCEN_PORT, OMV_BOOT_OSCEN_PIN, GPIO_PIN_SET);
|
||||
#endif
|
||||
|
||||
// Set the system clock
|
||||
SystemClock_Config();
|
||||
|
||||
// Config Systick
|
||||
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
|
||||
|
||||
/* Enable GPIO clocks */
|
||||
__GPIOA_CLK_ENABLE();
|
||||
__GPIOB_CLK_ENABLE();
|
||||
__GPIOC_CLK_ENABLE();
|
||||
__GPIOD_CLK_ENABLE();
|
||||
__GPIOE_CLK_ENABLE();
|
||||
#ifdef OMV_GPIO_PORT_F_ENABLE
|
||||
__GPIOF_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef OMV_GPIO_PORT_G_ENABLE
|
||||
__GPIOG_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef OMV_GPIO_PORT_H_ENABLE
|
||||
__GPIOH_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef OMV_GPIO_PORT_I_ENABLE
|
||||
__GPIOI_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef OMV_GPIO_PORT_J_ENABLE
|
||||
__GPIOJ_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef OMV_GPIO_PORT_K_ENABLE
|
||||
__GPIOK_CLK_ENABLE();
|
||||
#endif
|
||||
|
||||
GPIO_InitStructure.Pin = OMV_BOOT_LED_PIN;
|
||||
HAL_GPIO_Init(OMV_BOOT_LED_PORT, &GPIO_InitStructure);
|
||||
HAL_GPIO_WritePin(OMV_BOOT_LED_PORT, OMV_BOOT_LED_PIN, GPIO_PIN_SET);
|
||||
|
||||
#if defined(OMV_BOOT_USBEN_PIN)
|
||||
OMV_BOOT_USBEN_CLK_ENABLE();
|
||||
GPIO_InitStructure.Pin = OMV_BOOT_USBEN_PIN;
|
||||
HAL_GPIO_Init(OMV_BOOT_USBEN_PORT, &GPIO_InitStructure);
|
||||
HAL_GPIO_WritePin(OMV_BOOT_USBEN_PORT, OMV_BOOT_USBEN_PIN, GPIO_PIN_SET);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(OMV_BOOT_QSPIF_LAYOUT)
|
||||
void HAL_QSPI_MspInit(QSPI_HandleTypeDef *hqspi) {
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
|
||||
/*##-1- Enable peripherals and GPIO Clocks #################################*/
|
||||
/* Enable the QuadSPI memory interface clock */
|
||||
OMV_BOOT_QSPIF_CLK_ENABLE();
|
||||
|
||||
/* Reset the QuadSPI memory interface */
|
||||
OMV_BOOT_QSPIF_FORCE_RESET();
|
||||
OMV_BOOT_QSPIF_RELEASE_RESET();
|
||||
|
||||
/*##-2- Configure peripheral GPIO ##########################################*/
|
||||
/* QSPI CLK GPIO pin configuration */
|
||||
gpio_init_structure.Pin = OMV_BOOT_QSPIF_CLK_PIN;
|
||||
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
|
||||
gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
gpio_init_structure.Pull = GPIO_NOPULL;
|
||||
gpio_init_structure.Alternate = OMV_BOOT_QSPIF_CLK_ALT;
|
||||
HAL_GPIO_Init(OMV_BOOT_QSPIF_CLK_PORT, &gpio_init_structure);
|
||||
|
||||
/* QSPI CS GPIO pin configuration */
|
||||
gpio_init_structure.Pin = OMV_BOOT_QSPIF_CS_PIN;
|
||||
gpio_init_structure.Pull = GPIO_PULLUP;
|
||||
gpio_init_structure.Alternate = OMV_BOOT_QSPIF_CS_ALT;
|
||||
HAL_GPIO_Init(OMV_BOOT_QSPIF_CS_PORT, &gpio_init_structure);
|
||||
|
||||
/* QSPI D0 GPIO pin configuration */
|
||||
gpio_init_structure.Pin = OMV_BOOT_QSPIF_D0_PIN;
|
||||
gpio_init_structure.Pull = GPIO_NOPULL;
|
||||
gpio_init_structure.Alternate = OMV_BOOT_QSPIF_D0_ALT;
|
||||
HAL_GPIO_Init(OMV_BOOT_QSPIF_D0_PORT, &gpio_init_structure);
|
||||
|
||||
/* QSPI D1 GPIO pin configuration */
|
||||
gpio_init_structure.Pin = OMV_BOOT_QSPIF_D1_PIN;
|
||||
gpio_init_structure.Alternate = OMV_BOOT_QSPIF_D1_ALT;
|
||||
HAL_GPIO_Init(OMV_BOOT_QSPIF_D1_PORT, &gpio_init_structure);
|
||||
|
||||
/* QSPI D2 GPIO pin configuration */
|
||||
gpio_init_structure.Pin = OMV_BOOT_QSPIF_D2_PIN;
|
||||
gpio_init_structure.Alternate = OMV_BOOT_QSPIF_D2_ALT;
|
||||
HAL_GPIO_Init(OMV_BOOT_QSPIF_D2_PORT, &gpio_init_structure);
|
||||
|
||||
/* QSPI D3 GPIO pin configuration */
|
||||
gpio_init_structure.Pin = OMV_BOOT_QSPIF_D3_PIN;
|
||||
gpio_init_structure.Alternate = OMV_BOOT_QSPIF_D3_ALT;
|
||||
HAL_GPIO_Init(OMV_BOOT_QSPIF_D3_PORT, &gpio_init_structure);
|
||||
}
|
||||
|
||||
void HAL_QSPI_MspDeInit(QSPI_HandleTypeDef *hqspi) {
|
||||
/*##-1- Disable peripherals and GPIO Clocks ################################*/
|
||||
/* De-Configure QSPI pins */
|
||||
HAL_GPIO_DeInit(OMV_BOOT_QSPIF_CLK_PORT, OMV_BOOT_QSPIF_CLK_PIN);
|
||||
HAL_GPIO_DeInit(OMV_BOOT_QSPIF_CS_PORT, OMV_BOOT_QSPIF_CS_PIN);
|
||||
HAL_GPIO_DeInit(OMV_BOOT_QSPIF_D0_PORT, OMV_BOOT_QSPIF_D0_PIN);
|
||||
HAL_GPIO_DeInit(OMV_BOOT_QSPIF_D1_PORT, OMV_BOOT_QSPIF_D1_PIN);
|
||||
HAL_GPIO_DeInit(OMV_BOOT_QSPIF_D2_PORT, OMV_BOOT_QSPIF_D2_PIN);
|
||||
HAL_GPIO_DeInit(OMV_BOOT_QSPIF_D3_PORT, OMV_BOOT_QSPIF_D3_PIN);
|
||||
|
||||
/*##-2- Reset peripherals ##################################################*/
|
||||
/* Reset the QuadSPI memory interface */
|
||||
OMV_BOOT_QSPIF_FORCE_RESET();
|
||||
OMV_BOOT_QSPIF_RELEASE_RESET();
|
||||
|
||||
/* Disable the QuadSPI memory interface clock */
|
||||
OMV_BOOT_QSPIF_CLK_DISABLE();
|
||||
}
|
||||
#endif // OMV_BOOT_QSPIF_LAYOUT
|
||||
@ -1,142 +0,0 @@
|
||||
/*
|
||||
* This file is part of the OpenMV project.
|
||||
*
|
||||
* Copyright (c) 2013-2021 Ibrahim Abdelkader <iabdalkader@openmv.io>
|
||||
* Copyright (c) 2013-2021 Kwabena W. Agyeman <kwagyeman@openmv.io>
|
||||
*
|
||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
||||
*
|
||||
* Interrupt handlers.
|
||||
*/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file USB_Device/CDC_Standalone/Src/stm32f4xx_it.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.2
|
||||
* @date 25-May-2015
|
||||
* @brief Main Interrupt Service Routines.
|
||||
* This file provides template for all exceptions handler and
|
||||
* peripherals interrupt service routine.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include STM32_HAL_H
|
||||
#include <stm32fxxx_it.h>
|
||||
|
||||
extern PCD_HandleTypeDef hpcd;
|
||||
/**
|
||||
* @brief This function handles NMI exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void NMI_Handler(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Hard Fault exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HardFault_Handler(void) {
|
||||
/* Go to infinite loop when Hard Fault exception occurs */
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Memory Manage exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void MemManage_Handler(void) {
|
||||
/* Go to infinite loop when Memory Manage exception occurs */
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Bus Fault exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void BusFault_Handler(void) {
|
||||
/* Go to infinite loop when Bus Fault exception occurs */
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Usage Fault exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void UsageFault_Handler(void) {
|
||||
/* Go to infinite loop when Usage Fault exception occurs */
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles SVCall exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SVC_Handler(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Debug Monitor exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void DebugMon_Handler(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles PendSVC exception.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void PendSV_Handler(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles SysTick Handler.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SysTick_Handler(void) {
|
||||
HAL_IncTick();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles USB-On-The-Go FS global interrupt request.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
#ifdef USE_USB_FS
|
||||
void OTG_FS_IRQHandler(void)
|
||||
#else
|
||||
void OTG_HS_IRQHandler(void)
|
||||
#endif
|
||||
{
|
||||
HAL_PCD_IRQHandler(&hpcd);
|
||||
}
|
||||
@ -1,240 +0,0 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013, 2014 Damien P. George
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#define likely(x) __builtin_expect((x), 1)
|
||||
|
||||
void *memcpy(void *dst, const void *src, size_t n) {
|
||||
if (likely(!(((uintptr_t) dst) & 3) && !(((uintptr_t) src) & 3))) {
|
||||
// pointers aligned
|
||||
uint32_t *d = dst;
|
||||
const uint32_t *s = src;
|
||||
|
||||
// copy words first
|
||||
for (size_t i = (n >> 2); i; i--) {
|
||||
*d++ = *s++;
|
||||
}
|
||||
|
||||
if (n & 2) {
|
||||
// copy half-word
|
||||
*(uint16_t *) d = *(const uint16_t *) s;
|
||||
d = (uint32_t *) ((uint16_t *) d + 1);
|
||||
s = (const uint32_t *) ((const uint16_t *) s + 1);
|
||||
}
|
||||
|
||||
if (n & 1) {
|
||||
// copy byte
|
||||
*((uint8_t *) d) = *((const uint8_t *) s);
|
||||
}
|
||||
} else {
|
||||
// unaligned access, copy bytes
|
||||
uint8_t *d = dst;
|
||||
const uint8_t *s = src;
|
||||
|
||||
for (; n; n--) {
|
||||
*d++ = *s++;
|
||||
}
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
void *memmove(void *dest, const void *src, size_t n) {
|
||||
if (src < dest && (uint8_t *) dest < (const uint8_t *) src + n) {
|
||||
// need to copy backwards
|
||||
uint8_t *d = (uint8_t *) dest + n - 1;
|
||||
const uint8_t *s = (const uint8_t *) src + n - 1;
|
||||
for (; n > 0; n--) {
|
||||
*d-- = *s--;
|
||||
}
|
||||
return dest;
|
||||
} else {
|
||||
// can use normal memcpy
|
||||
return memcpy(dest, src, n);
|
||||
}
|
||||
}
|
||||
|
||||
void *memset(void *s, int c, size_t n) {
|
||||
if (c == 0 && ((uintptr_t) s & 3) == 0) {
|
||||
// aligned store of 0
|
||||
uint32_t *s32 = s;
|
||||
for (size_t i = n >> 2; i > 0; i--) {
|
||||
*s32++ = 0;
|
||||
}
|
||||
if (n & 2) {
|
||||
*((uint16_t *) s32) = 0;
|
||||
s32 = (uint32_t *) ((uint16_t *) s32 + 1);
|
||||
}
|
||||
if (n & 1) {
|
||||
*((uint8_t *) s32) = 0;
|
||||
}
|
||||
} else {
|
||||
uint8_t *s2 = s;
|
||||
for (; n > 0; n--) {
|
||||
*s2++ = c;
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
int memcmp(const void *s1, const void *s2, size_t n) {
|
||||
const uint8_t *s1_8 = s1;
|
||||
const uint8_t *s2_8 = s2;
|
||||
while (n--) {
|
||||
char c1 = *s1_8++;
|
||||
char c2 = *s2_8++;
|
||||
if (c1 < c2) {
|
||||
return -1;
|
||||
} else if (c1 > c2) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *memchr(const void *s, int c, size_t n) {
|
||||
if (n != 0) {
|
||||
const unsigned char *p = s;
|
||||
|
||||
do {
|
||||
if (*p++ == c) {
|
||||
return ((void *) (p - 1));
|
||||
}
|
||||
} while (--n != 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t strlen(const char *str) {
|
||||
int len = 0;
|
||||
for (const char *s = str; *s; s++) {
|
||||
len += 1;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int strcmp(const char *s1, const char *s2) {
|
||||
while (*s1 && *s2) {
|
||||
char c1 = *s1++; // XXX UTF8 get char, next char
|
||||
char c2 = *s2++; // XXX UTF8 get char, next char
|
||||
if (c1 < c2) {
|
||||
return -1;
|
||||
} else if (c1 > c2) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (*s2) {
|
||||
return -1;
|
||||
} else if (*s1) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int strncmp(const char *s1, const char *s2, size_t n) {
|
||||
while (*s1 && *s2 && n > 0) {
|
||||
char c1 = *s1++; // XXX UTF8 get char, next char
|
||||
char c2 = *s2++; // XXX UTF8 get char, next char
|
||||
n--;
|
||||
if (c1 < c2) {
|
||||
return -1;
|
||||
} else if (c1 > c2) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (n == 0) {
|
||||
return 0;
|
||||
} else if (*s2) {
|
||||
return -1;
|
||||
} else if (*s1) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
char *strcpy(char *dest, const char *src) {
|
||||
char *d = dest;
|
||||
while (*src) {
|
||||
*d++ = *src++;
|
||||
}
|
||||
*d = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
// needed because gcc optimises strcpy + strcat to this
|
||||
char *stpcpy(char *dest, const char *src) {
|
||||
while (*src) {
|
||||
*dest++ = *src++;
|
||||
}
|
||||
*dest = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
char *strcat(char *dest, const char *src) {
|
||||
char *d = dest;
|
||||
while (*d) {
|
||||
d++;
|
||||
}
|
||||
while (*src) {
|
||||
*d++ = *src++;
|
||||
}
|
||||
*d = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
// Public Domain implementation of strchr from:
|
||||
// http://en.wikibooks.org/wiki/C_Programming/Strings#The_strchr_function
|
||||
char *strchr(const char *s, int c) {
|
||||
/* Scan s for the character. When this loop is finished,
|
||||
s will either point to the end of the string or the
|
||||
character we were looking for. */
|
||||
while (*s != '\0' && *s != (char) c) {
|
||||
s++;
|
||||
}
|
||||
return ((*s == c) ? (char *) s : 0);
|
||||
}
|
||||
|
||||
|
||||
// Public Domain implementation of strstr from:
|
||||
// http://en.wikibooks.org/wiki/C_Programming/Strings#The_strstr_function
|
||||
char *strstr(const char *haystack, const char *needle) {
|
||||
size_t needlelen;
|
||||
/* Check for the null needle case. */
|
||||
if (*needle == '\0') {
|
||||
return (char *) haystack;
|
||||
}
|
||||
needlelen = strlen(needle);
|
||||
for (; (haystack = strchr(haystack, *needle)) != 0; haystack++) {
|
||||
if (strncmp(haystack, needle, needlelen) == 0) {
|
||||
return (char *) haystack;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1,631 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_cdc.c
|
||||
* @author MCD Application Team
|
||||
* @version V2.4.1
|
||||
* @date 19-June-2015
|
||||
* @brief This file provides the high layer firmware functions to manage the
|
||||
* following functionalities of the USB CDC Class:
|
||||
* - Initialization and Configuration of high and low layer
|
||||
* - Enumeration as CDC Device (and enumeration for each implemented memory interface)
|
||||
* - OUT/IN data transfer
|
||||
* - Command IN transfer (class requests management)
|
||||
* - Error management
|
||||
*
|
||||
* @verbatim
|
||||
*
|
||||
* ===================================================================
|
||||
* CDC Class Driver Description
|
||||
* ===================================================================
|
||||
* This driver manages the "Universal Serial Bus Class Definitions for Communications Devices
|
||||
* Revision 1.2 November 16, 2007" and the sub-protocol specification of "Universal Serial Bus
|
||||
* Communications Class Subclass Specification for PSTN Devices Revision 1.2 February 9, 2007"
|
||||
* This driver implements the following aspects of the specification:
|
||||
* - Device descriptor management
|
||||
* - Configuration descriptor management
|
||||
* - Enumeration as CDC device with 2 data endpoints (IN and OUT) and 1 command endpoint (IN)
|
||||
* - Requests management (as described in section 6.2 in specification)
|
||||
* - Abstract Control Model compliant
|
||||
* - Union Functional collection (using 1 IN endpoint for control)
|
||||
* - Data interface class
|
||||
*
|
||||
* These aspects may be enriched or modified for a specific user application.
|
||||
*
|
||||
* This driver doesn't implement the following aspects of the specification
|
||||
* (but it is possible to manage these features with some modifications on this driver):
|
||||
* - Any class-specific aspect relative to communication classes should be managed by user application.
|
||||
* - All communication classes other than PSTN are not managed
|
||||
*
|
||||
* @endverbatim
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbdev/usbd_cdc.h"
|
||||
#include "usbdev/usbd_desc.h"
|
||||
#include "usbdev/usbd_ctlreq.h"
|
||||
|
||||
#define CDC_IFACE_NUM (0)
|
||||
static USBD_CDC_HandleTypeDef CDC_ClassData;
|
||||
static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev);
|
||||
static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length);
|
||||
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length);
|
||||
|
||||
/* CDC interface class callbacks structure */
|
||||
USBD_ClassTypeDef USBD_CDC =
|
||||
{
|
||||
USBD_CDC_Init,
|
||||
USBD_CDC_DeInit,
|
||||
USBD_CDC_Setup,
|
||||
NULL, /* EP0_TxSent, */
|
||||
USBD_CDC_EP0_RxReady,
|
||||
USBD_CDC_DataIn,
|
||||
USBD_CDC_DataOut,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
USBD_CDC_GetFSCfgDesc,
|
||||
USBD_CDC_GetFSCfgDesc,
|
||||
USBD_CDC_GetFSCfgDesc,
|
||||
USBD_CDC_GetDeviceQualifierDescriptor,
|
||||
};
|
||||
|
||||
/* USB CDC device Configuration Descriptor */
|
||||
__ALIGN_BEGIN uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
/*Configuration Descriptor*/
|
||||
0x09, /* bLength: Configuration Descriptor size */
|
||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||
USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */
|
||||
0x00,
|
||||
0x02, /* bNumInterfaces: 2 interface */
|
||||
0x01, /* bConfigurationValue: Configuration value */
|
||||
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
||||
0xC0, /* bmAttributes: self powered */
|
||||
0XFA, // bMaxPower: in units of 2mA
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
// Interface Association for CDC VCP
|
||||
0x08, // bLength: 8 bytes
|
||||
0x0b, // bDescriptorType: IAD
|
||||
CDC_IFACE_NUM, // bFirstInterface: first interface for this association
|
||||
0x02, // bInterfaceCount: nummber of interfaces for this association
|
||||
0x02, // bFunctionClass: Communication Interface Class
|
||||
0x02, // bFunctionSubClass: Abstract Control Model
|
||||
0x01, // bFunctionProtocol: Common AT commands
|
||||
0x00, // iFunction: index of string for this function
|
||||
|
||||
/*Interface Descriptor */
|
||||
0x09, /* bLength: Interface Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
|
||||
/* Interface descriptor type */
|
||||
CDC_IFACE_NUM, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x01, /* bNumEndpoints: One endpoints used */
|
||||
0x02, /* bInterfaceClass: Communication Interface Class */
|
||||
0x02, /* bInterfaceSubClass: Abstract Control Model */
|
||||
0x01, /* bInterfaceProtocol: Common AT commands */
|
||||
0x00, /* iInterface: */
|
||||
|
||||
/*Header Functional Descriptor*/
|
||||
0x05, /* bLength: Endpoint Descriptor size */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x00, /* bDescriptorSubtype: Header Func Desc */
|
||||
0x10, /* bcdCDC: spec release number */
|
||||
0x01,
|
||||
|
||||
/*Call Management Functional Descriptor*/
|
||||
0x05, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x01, /* bDescriptorSubtype: Call Management Func Desc */
|
||||
0x00, /* bmCapabilities: D0+D1 */
|
||||
CDC_IFACE_NUM + 1, /* bDataInterface: 1 */
|
||||
|
||||
/*ACM Functional Descriptor*/
|
||||
0x04, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
|
||||
0x02, /* bmCapabilities */
|
||||
|
||||
/*Union Functional Descriptor*/
|
||||
0x05, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x06, /* bDescriptorSubtype: Union func desc */
|
||||
CDC_IFACE_NUM + 0, /* bMasterInterface: Communication class interface */
|
||||
CDC_IFACE_NUM + 1, /* bSlaveInterface0: Data Class Interface */
|
||||
|
||||
/*Endpoint 2 Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_CMD_EP, /* bEndpointAddress */
|
||||
0x03, /* bmAttributes: Interrupt */
|
||||
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_CMD_PACKET_SIZE),
|
||||
0x10, /* bInterval: */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*Data class interface descriptor*/
|
||||
0x09, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
||||
CDC_IFACE_NUM + 1, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x02, /* bNumEndpoints: Two endpoints used */
|
||||
0x0A, /* bInterfaceClass: CDC */
|
||||
0x00, /* bInterfaceSubClass: */
|
||||
0x00, /* bInterfaceProtocol: */
|
||||
0x00, /* iInterface: */
|
||||
|
||||
/*Endpoint OUT Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_OUT_EP, /* bEndpointAddress */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
LOBYTE(CDC_DATA_MAX_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_DATA_MAX_PACKET_SIZE),
|
||||
0x00, /* bInterval: ignore for Bulk transfer */
|
||||
|
||||
/*Endpoint IN Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_IN_EP, /* bEndpointAddress */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
LOBYTE(CDC_DATA_MAX_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_DATA_MAX_PACKET_SIZE),
|
||||
0x00 /* bInterval: ignore for Bulk transfer */
|
||||
} ;
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_Init
|
||||
* Initialize the CDC interface
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
USBD_CDC_HandleTypeDef *hcdc;
|
||||
|
||||
if(pdev->dev_speed == USBD_SPEED_HIGH )
|
||||
{
|
||||
/* Open EP IN */
|
||||
USBD_LL_OpenEP(pdev,
|
||||
CDC_IN_EP,
|
||||
USBD_EP_TYPE_BULK,
|
||||
CDC_DATA_HS_IN_PACKET_SIZE);
|
||||
|
||||
/* Open EP OUT */
|
||||
USBD_LL_OpenEP(pdev,
|
||||
CDC_OUT_EP,
|
||||
USBD_EP_TYPE_BULK,
|
||||
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Open EP IN */
|
||||
USBD_LL_OpenEP(pdev,
|
||||
CDC_IN_EP,
|
||||
USBD_EP_TYPE_BULK,
|
||||
CDC_DATA_FS_IN_PACKET_SIZE);
|
||||
|
||||
/* Open EP OUT */
|
||||
USBD_LL_OpenEP(pdev,
|
||||
CDC_OUT_EP,
|
||||
USBD_EP_TYPE_BULK,
|
||||
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||
}
|
||||
/* Open Command IN EP */
|
||||
USBD_LL_OpenEP(pdev,
|
||||
CDC_CMD_EP,
|
||||
USBD_EP_TYPE_INTR,
|
||||
CDC_CMD_PACKET_SIZE);
|
||||
|
||||
|
||||
pdev->pClassData = &CDC_ClassData;
|
||||
|
||||
hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
|
||||
/* Init physical Interface components */
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Init();
|
||||
|
||||
/* Init Xfer states */
|
||||
hcdc->TxState =0;
|
||||
hcdc->RxState =0;
|
||||
|
||||
if(pdev->dev_speed == USBD_SPEED_HIGH )
|
||||
{
|
||||
/* Prepare Out endpoint to receive next packet */
|
||||
USBD_LL_PrepareReceive(pdev,
|
||||
CDC_OUT_EP,
|
||||
hcdc->RxBuffer,
|
||||
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Prepare Out endpoint to receive next packet */
|
||||
USBD_LL_PrepareReceive(pdev,
|
||||
CDC_OUT_EP,
|
||||
hcdc->RxBuffer,
|
||||
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_Init
|
||||
* DeInitialize the CDC layer
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
|
||||
/* Open EP IN */
|
||||
USBD_LL_CloseEP(pdev,
|
||||
CDC_IN_EP);
|
||||
|
||||
/* Open EP OUT */
|
||||
USBD_LL_CloseEP(pdev,
|
||||
CDC_OUT_EP);
|
||||
|
||||
/* Open Command IN EP */
|
||||
USBD_LL_CloseEP(pdev,
|
||||
CDC_CMD_EP);
|
||||
|
||||
|
||||
/* DeInit physical Interface components */
|
||||
if(pdev->pClassData != NULL)
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->DeInit();
|
||||
pdev->pClassData = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_Setup
|
||||
* Handle the CDC specific requests
|
||||
* @param pdev: instance
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
static uint8_t ifalt = 0;
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
if (req->wLength)
|
||||
{
|
||||
if (req->bmRequest & 0x80)
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
||||
(uint8_t *)hcdc->data,
|
||||
req->wLength);
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)hcdc->data,
|
||||
req->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
hcdc->CmdOpCode = req->bRequest;
|
||||
hcdc->CmdLength = req->wLength;
|
||||
|
||||
USBD_CtlPrepareRx (pdev,
|
||||
(uint8_t *)hcdc->data,
|
||||
req->wLength);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
||||
(uint8_t*)req,
|
||||
req->wValue);
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
USBD_CtlSendData (pdev,
|
||||
&ifalt,
|
||||
1);
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_DataIn
|
||||
* Data sent on non-control IN endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
|
||||
if(pdev->pClassData != NULL)
|
||||
{
|
||||
|
||||
hcdc->TxState = 0;
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_DataOut
|
||||
* Data received on non-control Out endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
|
||||
/* Get the received data length */
|
||||
hcdc->RxLength = USBD_LL_GetRxDataSize (pdev, epnum);
|
||||
|
||||
/* USB data will be immediately processed, this allow next USB traffic being
|
||||
NAKed till the end of the application Xfer */
|
||||
if(pdev->pClassData != NULL)
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Receive(hcdc->RxBuffer, &hcdc->RxLength);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_DataOut
|
||||
* Data received on non-control Out endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
|
||||
if((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFF))
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(hcdc->CmdOpCode,
|
||||
(uint8_t *)hcdc->data,
|
||||
hcdc->CmdLength);
|
||||
hcdc->CmdOpCode = 0xFF;
|
||||
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_GetFSCfgDesc
|
||||
* Return configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_CDC_CfgFSDesc);
|
||||
return USBD_CDC_CfgFSDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length)
|
||||
{
|
||||
*length = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_RegisterInterface
|
||||
* @param pdev: device instance
|
||||
* @param fops: CD Interface callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev,
|
||||
USBD_CDC_ItfTypeDef *fops)
|
||||
{
|
||||
uint8_t ret = USBD_FAIL;
|
||||
|
||||
if(fops != NULL)
|
||||
{
|
||||
pdev->pUserData= fops;
|
||||
ret = USBD_OK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_SetTxBuffer
|
||||
* @param pdev: device instance
|
||||
* @param pbuff: Tx Buffer
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff,
|
||||
uint16_t length)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
|
||||
hcdc->TxBuffer = pbuff;
|
||||
hcdc->TxLength = length;
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_SetRxBuffer
|
||||
* @param pdev: device instance
|
||||
* @param pbuff: Rx Buffer
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
|
||||
hcdc->RxBuffer = pbuff;
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_DataOut
|
||||
* Data received on non-control Out endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
|
||||
if(pdev->pClassData != NULL)
|
||||
{
|
||||
if(hcdc->TxState == 0)
|
||||
{
|
||||
/* Tx Transfer in progress */
|
||||
hcdc->TxState = 1;
|
||||
|
||||
/* Transmit next packet */
|
||||
USBD_LL_Transmit(pdev,
|
||||
CDC_IN_EP,
|
||||
hcdc->TxBuffer,
|
||||
hcdc->TxLength);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return USBD_BUSY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_ReceivePacket
|
||||
* prepare OUT Endpoint for reception
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
|
||||
/* Suspend or Resume USB Out process */
|
||||
if(pdev->pClassData != NULL)
|
||||
{
|
||||
if(pdev->dev_speed == USBD_SPEED_HIGH )
|
||||
{
|
||||
/* Prepare Out endpoint to receive next packet */
|
||||
USBD_LL_PrepareReceive(pdev,
|
||||
CDC_OUT_EP,
|
||||
hcdc->RxBuffer,
|
||||
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Prepare Out endpoint to receive next packet */
|
||||
USBD_LL_PrepareReceive(pdev,
|
||||
CDC_OUT_EP,
|
||||
hcdc->RxBuffer,
|
||||
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@ -1,330 +0,0 @@
|
||||
#include <stdint.h>
|
||||
#include "flash.h"
|
||||
#include "usbdev/usbd_cdc.h"
|
||||
#include "omv_boardconfig.h"
|
||||
#include "omv_bootconfig.h"
|
||||
#include "qspif.h"
|
||||
|
||||
#define APP_RX_DATA_SIZE (2048)
|
||||
#define APP_TX_DATA_SIZE (2048)
|
||||
|
||||
USBD_CDC_LineCodingTypeDef LineCoding =
|
||||
{
|
||||
115200, /* baud rate*/
|
||||
0x00, /* stop bits-1*/
|
||||
0x00, /* parity - none*/
|
||||
0x08 /* nb. of bits 8*/
|
||||
};
|
||||
|
||||
uint32_t BuffLength;
|
||||
uint32_t UserTxBufPtrIn = 0; /* Increment this pointer or roll it back to
|
||||
start address when data are received over USART */
|
||||
uint32_t UserTxBufPtrOut = 0; /* Increment this pointer or roll it back to
|
||||
start address when data are sent over USB */
|
||||
uint8_t UserRxBuffer[APP_RX_DATA_SIZE];/* Received Data over USB are stored in this buffer */
|
||||
uint8_t UserTxBuffer[APP_TX_DATA_SIZE];/* Received Data over UART (CDC interface) are stored in this buffer */
|
||||
|
||||
static volatile uint8_t ide_connected = 0;
|
||||
static volatile uint8_t vcp_connected = 0;
|
||||
|
||||
#define FLASH_BUF_SIZE (CDC_DATA_MAX_PACKET_SIZE)
|
||||
static volatile uint32_t flash_buf_idx=0;
|
||||
static volatile uint8_t flash_buf[FLASH_BUF_SIZE];
|
||||
static const uint32_t flash_layout[3] = OMV_BOOT_FLASH_LAYOUT;
|
||||
#if defined(OMV_BOOT_QSPIF_LAYOUT)
|
||||
#define QSPIF_BUF_SIZE OMV_BOOT_QSPIF_PAGE_SIZE
|
||||
static volatile uint32_t qspif_buf_idx=0;
|
||||
static volatile uint8_t qspif_buf[QSPIF_BUF_SIZE];
|
||||
static const uint32_t qspif_layout[3] = OMV_BOOT_QSPIF_LAYOUT;
|
||||
#else
|
||||
static const uint32_t qspif_layout[3] = {0, 0, 0};
|
||||
#endif
|
||||
static const uint32_t bootloader_version = OMV_BOOT_VERSION;
|
||||
|
||||
/* USB handler declaration */
|
||||
extern USBD_HandleTypeDef USBD_Device;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static int8_t CDC_Itf_Init(void);
|
||||
static int8_t CDC_Itf_DeInit(void);
|
||||
static int8_t CDC_Itf_Control(uint8_t cmd, uint8_t* pbuf, uint16_t length);
|
||||
static int8_t CDC_Itf_Receive(uint8_t* pbuf, uint32_t *Len);
|
||||
|
||||
enum bootldr_cmd {
|
||||
BOOTLDR_START = 0xABCD0001,
|
||||
BOOTLDR_RESET = 0xABCD0002,
|
||||
BOOTLDR_FLASH_ERASE = 0xABCD0004,
|
||||
BOOTLDR_FLASH_WRITE = 0xABCD0008,
|
||||
BOOTLDR_FLASH_LAYOUT = 0xABCD0010,
|
||||
BOOTLDR_QSPIF_ERASE = 0xABCD1004,
|
||||
BOOTLDR_QSPIF_WRITE = 0xABCD1008,
|
||||
BOOTLDR_QSPIF_LAYOUT = 0xABCD1010,
|
||||
BOOTLDR_QSPIF_MEMTEST = 0xABCD1020,
|
||||
};
|
||||
|
||||
USBD_CDC_ItfTypeDef USBD_CDC_fops =
|
||||
{
|
||||
CDC_Itf_Init,
|
||||
CDC_Itf_DeInit,
|
||||
CDC_Itf_Control,
|
||||
CDC_Itf_Receive
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief CDC_Itf_Init
|
||||
* Initializes the CDC media low layer
|
||||
* @param None
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_Itf_Init(void)
|
||||
{
|
||||
// Set Application Buffers
|
||||
USBD_CDC_SetTxBuffer(&USBD_Device, UserTxBuffer, 0);
|
||||
USBD_CDC_SetRxBuffer(&USBD_Device, UserRxBuffer);
|
||||
|
||||
return (USBD_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CDC_Itf_DeInit
|
||||
* DeInitializes the CDC media low layer
|
||||
* @param None
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_Itf_DeInit(void)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CDC_Itf_Control
|
||||
* Manage the CDC class requests
|
||||
* @param Cmd: Command code
|
||||
* @param Buf: Buffer containing command data (request parameters)
|
||||
* @param Len: Number of data to be sent (in bytes)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_Itf_Control(uint8_t cmd, uint8_t* pbuf, uint16_t length)
|
||||
{
|
||||
switch (cmd) {
|
||||
case CDC_SEND_ENCAPSULATED_COMMAND:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_GET_ENCAPSULATED_RESPONSE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_SET_COMM_FEATURE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_GET_COMM_FEATURE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_CLEAR_COMM_FEATURE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_SET_LINE_CODING:
|
||||
LineCoding.bitrate = (uint32_t) (pbuf[0] | (pbuf[1] << 8) |
|
||||
(pbuf[2] << 16) | (pbuf[3] << 24));
|
||||
LineCoding.format = pbuf[4];
|
||||
LineCoding.paritytype = pbuf[5];
|
||||
LineCoding.datatype = pbuf[6];
|
||||
break;
|
||||
|
||||
case CDC_GET_LINE_CODING:
|
||||
pbuf[0] = (uint8_t)(LineCoding.bitrate);
|
||||
pbuf[1] = (uint8_t)(LineCoding.bitrate >> 8);
|
||||
pbuf[2] = (uint8_t)(LineCoding.bitrate >> 16);
|
||||
pbuf[3] = (uint8_t)(LineCoding.bitrate >> 24);
|
||||
pbuf[4] = LineCoding.format;
|
||||
pbuf[5] = LineCoding.paritytype;
|
||||
pbuf[6] = LineCoding.datatype;
|
||||
break;
|
||||
|
||||
case CDC_SET_CONTROL_LINE_STATE:
|
||||
vcp_connected = length & 1; // wValue is passed in Len (bit of a hack)
|
||||
break;
|
||||
|
||||
case CDC_SEND_BREAK:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (USBD_OK);
|
||||
}
|
||||
|
||||
// This function is called to process outgoing data. We hook directly into the
|
||||
// SOF (start of frame) callback so that it is called exactly at the time it is
|
||||
// needed (reducing latency), and often enough (increasing bandwidth).
|
||||
void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
uint32_t buffptr;
|
||||
uint32_t buffsize;
|
||||
|
||||
if(UserTxBufPtrOut != UserTxBufPtrIn) {
|
||||
if (UserTxBufPtrOut > UserTxBufPtrIn) /* Rollback */ {
|
||||
buffsize = APP_RX_DATA_SIZE - UserTxBufPtrOut;
|
||||
} else {
|
||||
buffsize = UserTxBufPtrIn - UserTxBufPtrOut;
|
||||
}
|
||||
|
||||
buffptr = UserTxBufPtrOut;
|
||||
USBD_CDC_SetTxBuffer(&USBD_Device, (uint8_t*)&UserTxBuffer[buffptr], buffsize);
|
||||
|
||||
if (USBD_CDC_TransmitPacket(&USBD_Device) == USBD_OK) {
|
||||
UserTxBufPtrOut += buffsize;
|
||||
if (UserTxBufPtrOut == APP_RX_DATA_SIZE) {
|
||||
UserTxBufPtrOut = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDC_Tx(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
for (int i=0; i<len; i++) {
|
||||
UserTxBuffer[UserTxBufPtrIn++] = buf[i];
|
||||
|
||||
/* To avoid buffer overflow */
|
||||
if(UserTxBufPtrIn == APP_RX_DATA_SIZE) {
|
||||
UserTxBufPtrIn = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CDC_Itf_DataRx
|
||||
* Data received over USB OUT endpoint are sent over CDC interface
|
||||
* through this function.
|
||||
* @param Buf: Buffer of data to be transmitted
|
||||
* @param Len: Number of data received (in bytes)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_Itf_Receive(uint8_t *Buf, uint32_t *Len)
|
||||
{
|
||||
static volatile uint32_t flash_offset;
|
||||
#if defined(OMV_BOOT_QSPIF_LAYOUT)
|
||||
static volatile uint32_t qspif_offset=0;
|
||||
#endif
|
||||
|
||||
uint32_t *cmd_buf = (uint32_t*) Buf;
|
||||
uint32_t cmd = *cmd_buf++;
|
||||
|
||||
switch (cmd) {
|
||||
case BOOTLDR_START:
|
||||
flash_buf_idx = 0;
|
||||
#if defined(OMV_BOOT_QSPIF_LAYOUT)
|
||||
qspif_buf_idx = 0;
|
||||
#endif
|
||||
ide_connected = 1;
|
||||
flash_offset = MAIN_APP_ADDR;
|
||||
// Send back the bootloader version.
|
||||
CDC_Tx((uint8_t *) &bootloader_version, 4);
|
||||
break;
|
||||
|
||||
case BOOTLDR_FLASH_LAYOUT:
|
||||
// Return flash layout (bootloader v2)
|
||||
CDC_Tx((uint8_t*) flash_layout, 12);
|
||||
break;
|
||||
|
||||
case BOOTLDR_FLASH_ERASE: {
|
||||
uint32_t sector = *cmd_buf;
|
||||
flash_erase(sector);
|
||||
break;
|
||||
}
|
||||
|
||||
case BOOTLDR_FLASH_WRITE: {
|
||||
uint8_t *buf = Buf + 4;
|
||||
uint32_t len = *Len - 4;
|
||||
for (int i=0; i<len; i++) {
|
||||
flash_buf[flash_buf_idx++] = buf[i];
|
||||
if (flash_buf_idx == FLASH_BUF_SIZE) {
|
||||
flash_buf_idx = 0;
|
||||
flash_write((uint32_t*)flash_buf, flash_offset, FLASH_BUF_SIZE);
|
||||
flash_offset += FLASH_BUF_SIZE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case BOOTLDR_QSPIF_LAYOUT:
|
||||
CDC_Tx((uint8_t*) qspif_layout, 12);
|
||||
break;
|
||||
|
||||
case BOOTLDR_QSPIF_ERASE: {
|
||||
#if defined(OMV_BOOT_QSPIF_LAYOUT)
|
||||
uint32_t block = *cmd_buf;
|
||||
qspif_erase_block(block * OMV_BOOT_QSPIF_BLOCK_SIZE);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
case BOOTLDR_QSPIF_WRITE: {
|
||||
#if defined(OMV_BOOT_QSPIF_LAYOUT)
|
||||
uint8_t *buf = Buf + 4;
|
||||
uint32_t len = *Len - 4;
|
||||
for (int i=0; i<len; i++) {
|
||||
qspif_buf[qspif_buf_idx++] = buf[i];
|
||||
if (qspif_buf_idx == QSPIF_BUF_SIZE) {
|
||||
qspif_buf_idx = 0;
|
||||
qspif_write((uint8_t*) qspif_buf, qspif_offset, QSPIF_BUF_SIZE);
|
||||
qspif_offset += QSPIF_BUF_SIZE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
case BOOTLDR_QSPIF_MEMTEST: {
|
||||
uint32_t qspif_test = 0;
|
||||
#if defined(OMV_BOOT_QSPIF_LAYOUT)
|
||||
qspif_test = (qspif_memory_test() == 0);
|
||||
#endif
|
||||
CDC_Tx((uint8_t*) &qspif_test, 4);
|
||||
break;
|
||||
}
|
||||
|
||||
case BOOTLDR_RESET: {
|
||||
ide_connected = 0;
|
||||
if (flash_buf_idx) {
|
||||
// Pad and flush the last packet
|
||||
for (int i=flash_buf_idx; i<FLASH_BUF_SIZE; i++) {
|
||||
flash_buf[i] = 0xFF;
|
||||
}
|
||||
flash_write((uint32_t*)flash_buf, flash_offset, FLASH_BUF_SIZE);
|
||||
}
|
||||
#if defined(OMV_BOOT_QSPIF_LAYOUT)
|
||||
if (qspif_buf_idx) {
|
||||
// Pad and flush the last packet
|
||||
for (int i=qspif_buf_idx; i<QSPIF_BUF_SIZE; i++) {
|
||||
qspif_buf[i] = 0xFF;
|
||||
}
|
||||
qspif_write((uint8_t*) qspif_buf, qspif_offset, QSPIF_BUF_SIZE);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Initiate next USB packet transfer
|
||||
USBD_CDC_ReceivePacket(&USBD_Device);
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
uint8_t USBD_VCP_Connected(void)
|
||||
{
|
||||
return vcp_connected;
|
||||
}
|
||||
|
||||
uint8_t USBD_IDE_Connected(void)
|
||||
{
|
||||
return ide_connected;
|
||||
}
|
||||
@ -1,569 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file USB_Device/CDC_Standalone/Src/usbd_conf.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.2
|
||||
* @date 25-May-2015
|
||||
* @brief This file implements the USB Device library callbacks and MSP
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include STM32_HAL_H
|
||||
#include "stm32_hal_legacy.h"
|
||||
#include "usbdev/usbd_core.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
PCD_HandleTypeDef hpcd;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/*******************************************************************************
|
||||
PCD BSP Routines
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief Initializes the PCD MSP.
|
||||
* @param hpcd: PCD handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
if(hpcd->Instance == USB_OTG_FS)
|
||||
{
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
|
||||
/* Configure DM DP Pins */
|
||||
GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* Configure VBUS Pin */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_9;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
#if defined(USE_USB_OTG_ID)
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_10;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
#endif
|
||||
|
||||
#if defined(MCU_SERIES_H7)
|
||||
// Keep USB clock running during sleep or else __WFI() will disable the USB
|
||||
__HAL_RCC_USB2_OTG_FS_CLK_SLEEP_ENABLE();
|
||||
__HAL_RCC_USB2_OTG_FS_ULPI_CLK_SLEEP_ENABLE();
|
||||
#endif
|
||||
|
||||
/* Enable USB FS Clocks */
|
||||
__USB_OTG_FS_CLK_ENABLE();
|
||||
|
||||
/* Set USBFS Interrupt priority */
|
||||
HAL_NVIC_SetPriority(OTG_FS_IRQn, 6, 0);
|
||||
|
||||
/* Enable USBFS Interrupt */
|
||||
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
|
||||
|
||||
}
|
||||
#if defined(USE_USB_HS)
|
||||
else if (hpcd->Instance == USB1_OTG_HS)
|
||||
{
|
||||
/* Configure USB FS GPIOs */
|
||||
__GPIOA_CLK_ENABLE();
|
||||
__GPIOB_CLK_ENABLE();
|
||||
__GPIOC_CLK_ENABLE();
|
||||
__GPIOH_CLK_ENABLE();
|
||||
__GPIOI_CLK_ENABLE();
|
||||
|
||||
/* CLK */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_5;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF10_OTG1_HS;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* D0 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_3;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF10_OTG1_HS;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* D1 D2 D3 D4 D5 D6 D7 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_5 |
|
||||
GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF10_OTG1_HS;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/* STP */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF10_OTG1_HS;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/* NXT */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_3;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF10_OTG1_HS;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/* DIR */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_11;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF10_OTG1_HS;
|
||||
HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
|
||||
|
||||
/* Enable USB HS Clocks */
|
||||
__HAL_RCC_USB1_OTG_HS_CLK_ENABLE();
|
||||
__HAL_RCC_USB1_OTG_HS_CLK_SLEEP_ENABLE();
|
||||
__HAL_RCC_USB1_OTG_HS_ULPI_CLK_ENABLE();
|
||||
__HAL_RCC_USB1_OTG_HS_ULPI_CLK_SLEEP_ENABLE();
|
||||
|
||||
/* Set USBHS Interrupt priority */
|
||||
HAL_NVIC_SetPriority(OTG_HS_IRQn, 6, 0);
|
||||
|
||||
/* Enable USBHS Interrupt */
|
||||
HAL_NVIC_EnableIRQ(OTG_HS_IRQn);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes the PCD MSP.
|
||||
* @param hpcd: PCD handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
if(hpcd->Instance == USB_OTG_FS)
|
||||
{
|
||||
/* Disable USB FS Clocks */
|
||||
__USB_OTG_FS_CLK_DISABLE();
|
||||
__SYSCFG_CLK_DISABLE();
|
||||
}
|
||||
#if defined(USE_USB_HS)
|
||||
else if(hpcd->Instance == USB_OTG_HS)
|
||||
{
|
||||
/* Disable USB FS Clocks */
|
||||
__USB_OTG_HS_CLK_DISABLE();
|
||||
__SYSCFG_CLK_DISABLE();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
LL Driver Callbacks (PCD -> USB Device Library)
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Setup stage callback.
|
||||
* @param hpcd: PCD handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
USBD_LL_SetupStage(hpcd->pData, (uint8_t *)hpcd->Setup);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Data Out stage callback.
|
||||
* @param hpcd: PCD handle
|
||||
* @param epnum: Endpoint Number
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||
{
|
||||
USBD_LL_DataOutStage(hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Data In stage callback.
|
||||
* @param hpcd: PCD handle
|
||||
* @param epnum: Endpoint Number
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||
{
|
||||
USBD_LL_DataInStage(hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset callback.
|
||||
* @param hpcd: PCD handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
USBD_SpeedTypeDef speed = USBD_SPEED_FULL;
|
||||
|
||||
/* Set USB Current Speed */
|
||||
switch (hpcd->Init.speed)
|
||||
{
|
||||
case PCD_SPEED_HIGH:
|
||||
speed = USBD_SPEED_HIGH;
|
||||
break;
|
||||
|
||||
case PCD_SPEED_FULL:
|
||||
speed = USBD_SPEED_FULL;
|
||||
break;
|
||||
|
||||
default:
|
||||
speed = USBD_SPEED_FULL;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Reset Device */
|
||||
USBD_LL_Reset(hpcd->pData);
|
||||
|
||||
USBD_LL_SetSpeed(hpcd->pData, speed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Suspend callback.
|
||||
* @param hpcd: PCD handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
USBD_LL_Suspend(hpcd->pData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resume callback.
|
||||
* @param hpcd: PCD handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
USBD_LL_Resume(hpcd->pData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ISOC Out Incomplete callback.
|
||||
* @param hpcd: PCD handle
|
||||
* @param epnum: Endpoint Number
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||
{
|
||||
USBD_LL_IsoOUTIncomplete(hpcd->pData, epnum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ISOC In Incomplete callback.
|
||||
* @param hpcd: PCD handle
|
||||
* @param epnum: Endpoint Number
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
||||
{
|
||||
USBD_LL_IsoINIncomplete(hpcd->pData, epnum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Connect callback.
|
||||
* @param hpcd: PCD handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
USBD_HandleTypeDef *pdev = hpcd->pData;
|
||||
pdev->dev_connection_status = 1;
|
||||
USBD_LL_DevConnected(hpcd->pData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disconnect callback.
|
||||
* @param hpcd: PCD handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
|
||||
{
|
||||
USBD_HandleTypeDef *pdev = hpcd->pData;
|
||||
pdev->dev_connection_status = 0;
|
||||
USBD_LL_DevDisconnected(hpcd->pData);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
LL Driver Interface (USB Device Library --> PCD)
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief Initializes the Low Level portion of the Device driver.
|
||||
* @param pdev: Device handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
#if defined(USE_USB_FS)
|
||||
/*Set LL Driver parameters */
|
||||
hpcd.Instance = USB_OTG_FS;
|
||||
hpcd.Init.dev_endpoints = 4;
|
||||
hpcd.Init.use_dedicated_ep1 = 0;
|
||||
hpcd.Init.ep0_mps = 0x40;
|
||||
hpcd.Init.dma_enable = 0;
|
||||
hpcd.Init.low_power_enable = 0;
|
||||
hpcd.Init.phy_itface = PCD_PHY_EMBEDDED;
|
||||
hpcd.Init.Sof_enable = 1;
|
||||
hpcd.Init.speed = PCD_SPEED_FULL;
|
||||
hpcd.Init.vbus_sensing_enable = 1;
|
||||
/* Link The driver to the stack */
|
||||
hpcd.pData = pdev;
|
||||
pdev->pData = &hpcd;
|
||||
|
||||
/* Initialize LL Driver */
|
||||
HAL_PCD_Init(&hpcd);
|
||||
|
||||
HAL_PCDEx_SetRxFiFo(&hpcd, 0x80);
|
||||
HAL_PCDEx_SetTxFiFo(&hpcd, 0, 0x40);
|
||||
HAL_PCDEx_SetTxFiFo(&hpcd, 1, 0x80);
|
||||
|
||||
#elif defined(USE_USB_HS)
|
||||
/*Set LL Driver parameters */
|
||||
hpcd.Instance = USB_OTG_HS;
|
||||
hpcd.Init.dev_endpoints = 6;
|
||||
hpcd.Init.use_dedicated_ep1 = 0;
|
||||
hpcd.Init.ep0_mps = 0x40;
|
||||
|
||||
/* Be aware that enabling DMA mode will result in data being sent only by
|
||||
* multiple of 4 packet sizes. This is due to the fact that USB DMA does not
|
||||
* allow sending data from non word-aligned addresses. For this specific
|
||||
* application, it is advised to not enable this option unless required. */
|
||||
hpcd.Init.dma_enable = 0;
|
||||
hpcd.Init.low_power_enable = 0;
|
||||
hpcd.Init.lpm_enable = 0;
|
||||
hpcd.Init.speed = PCD_SPEED_HIGH;
|
||||
hpcd.Init.phy_itface = PCD_PHY_ULPI;
|
||||
hpcd.Init.Sof_enable = 1;
|
||||
hpcd.Init.use_external_vbus = 0;
|
||||
hpcd.Init.vbus_sensing_enable = 1;
|
||||
hpcd.Init.battery_charging_enable = 0;
|
||||
|
||||
/* Link The driver to the stack */
|
||||
hpcd.pData = pdev;
|
||||
pdev->pData = &hpcd;
|
||||
|
||||
/*Initialize LL Driver */
|
||||
HAL_PCD_Init(&hpcd);
|
||||
|
||||
HAL_PCDEx_SetRxFiFo(&hpcd, 0x200);
|
||||
HAL_PCDEx_SetTxFiFo(&hpcd, 0, 0x80);
|
||||
HAL_PCDEx_SetTxFiFo(&hpcd, 1, 0x174);
|
||||
#endif
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief De-Initializes the Low Level portion of the Device driver.
|
||||
* @param pdev: Device handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
HAL_PCD_DeInit(pdev->pData);
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Starts the Low Level portion of the Device driver.
|
||||
* @param pdev: Device handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
HAL_PCD_Start(pdev->pData);
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stops the Low Level portion of the Device driver.
|
||||
* @param pdev: Device handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
HAL_PCD_Stop(pdev->pData);
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Opens an endpoint of the Low Level Driver.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @param ep_type: Endpoint Type
|
||||
* @param ep_mps: Endpoint Max Packet Size
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps)
|
||||
{
|
||||
HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type);
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Closes an endpoint of the Low Level Driver.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
HAL_PCD_EP_Close(pdev->pData, ep_addr);
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Flushes an endpoint of the Low Level Driver.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
HAL_PCD_EP_Flush(pdev->pData, ep_addr);
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets a Stall condition on an endpoint of the Low Level Driver.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
HAL_PCD_EP_SetStall(pdev->pData, ep_addr);
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clears a Stall condition on an endpoint of the Low Level Driver.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
HAL_PCD_EP_ClrStall(pdev->pData, ep_addr);
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns Stall condition.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval Stall (1: yes, 0: No)
|
||||
*/
|
||||
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
PCD_HandleTypeDef *hpcd = pdev->pData;
|
||||
|
||||
if ((ep_addr & 0x80) == 0x80)
|
||||
{
|
||||
return hpcd->IN_ep[ep_addr & 0x7F].is_stall;
|
||||
}
|
||||
else
|
||||
{
|
||||
return hpcd->OUT_ep[ep_addr & 0x7F].is_stall;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Assigns an USB address to the device
|
||||
* @param pdev: Device handle
|
||||
* @param dev_addr: USB address
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr)
|
||||
{
|
||||
HAL_PCD_SetAddress(pdev->pData, dev_addr);
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Transmits data over an endpoint
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @param pbuf: Pointer to data to be sent
|
||||
* @param size: Data size
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size)
|
||||
{
|
||||
HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size);
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Prepares an endpoint for reception
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @param pbuf:pointer to data to be received
|
||||
* @param size: data size
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size)
|
||||
{
|
||||
HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size);
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the last transfered packet size.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval Recived Data Size
|
||||
*/
|
||||
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
return HAL_PCD_EP_GetRxCount(pdev->pData, ep_addr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delay routine for the USB Device Library.
|
||||
* @param Delay: Delay in ms
|
||||
* @retval None
|
||||
*/
|
||||
void USBD_LL_Delay(uint32_t Delay)
|
||||
{
|
||||
HAL_Delay(Delay);
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@ -1,554 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_core.c
|
||||
* @author MCD Application Team
|
||||
* @version V2.0.0
|
||||
* @date 18-February-2014
|
||||
* @brief This file provides all the USBD core functions.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbdev/usbd_core.h"
|
||||
|
||||
/** @addtogroup STM32_USBD_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_Init
|
||||
* Initailizes the device stack and load the class driver
|
||||
* @param pdev: device instance
|
||||
* @param core_address: USB OTG core ID
|
||||
* @param pdesc: Descriptor structure address
|
||||
* @param id: Low level core index
|
||||
* @retval None
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id)
|
||||
{
|
||||
/* Check whether the USB Host handle is valid */
|
||||
if(pdev == NULL)
|
||||
{
|
||||
USBD_ErrLog("Invalid Device handle");
|
||||
return USBD_FAIL;
|
||||
}
|
||||
|
||||
/* Unlink previous class*/
|
||||
if(pdev->pClass != NULL)
|
||||
{
|
||||
pdev->pClass = NULL;
|
||||
}
|
||||
|
||||
/* Assign USBD Descriptors */
|
||||
if(pdesc != NULL)
|
||||
{
|
||||
pdev->pDesc = pdesc;
|
||||
}
|
||||
|
||||
/* Set Device initial State */
|
||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||
pdev->id = id;
|
||||
/* Initialize low level driver */
|
||||
USBD_LL_Init(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DeInit
|
||||
* Re-Initialize th device library
|
||||
* @param pdev: device instance
|
||||
* @retval status: status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Set Default State */
|
||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||
|
||||
/* Free Class Resources */
|
||||
pdev->pClass->DeInit(pdev, pdev->dev_config);
|
||||
|
||||
/* Stop the low level driver */
|
||||
USBD_LL_Stop(pdev);
|
||||
|
||||
/* Initialize low level driver */
|
||||
USBD_LL_DeInit(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_RegisterClass
|
||||
* Link class driver to Device Core.
|
||||
* @param pDevice : Device Handle
|
||||
* @param pclass: Class handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass)
|
||||
{
|
||||
USBD_StatusTypeDef status = USBD_OK;
|
||||
if(pclass != 0)
|
||||
{
|
||||
/* link the class tgo the USB Device handle */
|
||||
pdev->pClass = pclass;
|
||||
status = USBD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_ErrLog("Invalid Class handle");
|
||||
status = USBD_FAIL;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_Start
|
||||
* Start the USB Device Core.
|
||||
* @param pdev: Device Handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
|
||||
/* Start the low level driver */
|
||||
USBD_LL_Start(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_Stop
|
||||
* Stop the USB Device Core.
|
||||
* @param pdev: Device Handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Free Class Resources */
|
||||
pdev->pClass->DeInit(pdev, pdev->dev_config);
|
||||
|
||||
/* Stop the low level driver */
|
||||
USBD_LL_Stop(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_RunTestMode
|
||||
* Launch test mode process
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_SetClassConfig
|
||||
* Configure device and start the interface
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: configuration index
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
USBD_StatusTypeDef ret = USBD_FAIL;
|
||||
|
||||
if(pdev->pClass != NULL)
|
||||
{
|
||||
/* Set configuration and Start the Class*/
|
||||
if(pdev->pClass->Init(pdev, cfgidx) == 0)
|
||||
{
|
||||
ret = USBD_OK;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_ClrClassConfig
|
||||
* Clear current configuration
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: configuration index
|
||||
* @retval status: USBD_StatusTypeDef
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
/* Clear configuration and Deinitialize the Class process*/
|
||||
pdev->pClass->DeInit(pdev, cfgidx);
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_SetupStage
|
||||
* Handle the setup stage
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup)
|
||||
{
|
||||
|
||||
USBD_ParseSetupRequest(&pdev->request, psetup);
|
||||
|
||||
pdev->ep0_state = USBD_EP0_SETUP;
|
||||
pdev->ep0_data_len = pdev->request.wLength;
|
||||
|
||||
switch (pdev->request.bmRequest & 0x1F)
|
||||
{
|
||||
case USB_REQ_RECIPIENT_DEVICE:
|
||||
USBD_StdDevReq (pdev, &pdev->request);
|
||||
break;
|
||||
|
||||
case USB_REQ_RECIPIENT_INTERFACE:
|
||||
USBD_StdItfReq(pdev, &pdev->request);
|
||||
break;
|
||||
|
||||
case USB_REQ_RECIPIENT_ENDPOINT:
|
||||
USBD_StdEPReq(pdev, &pdev->request);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_LL_StallEP(pdev , pdev->request.bmRequest & 0x80);
|
||||
break;
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DataOutStage
|
||||
* Handle data OUT stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata)
|
||||
{
|
||||
USBD_EndpointTypeDef *pep;
|
||||
|
||||
if(epnum == 0)
|
||||
{
|
||||
pep = &pdev->ep_out[0];
|
||||
|
||||
if ( pdev->ep0_state == USBD_EP0_DATA_OUT)
|
||||
{
|
||||
if(pep->rem_length > pep->maxpacket)
|
||||
{
|
||||
pep->rem_length -= pep->maxpacket;
|
||||
|
||||
USBD_CtlContinueRx (pdev,
|
||||
pdata,
|
||||
MIN(pep->rem_length ,pep->maxpacket));
|
||||
}
|
||||
else
|
||||
{
|
||||
if((pdev->pClass->EP0_RxReady != NULL)&&
|
||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
||||
{
|
||||
pdev->pClass->EP0_RxReady(pdev);
|
||||
}
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if((pdev->pClass->DataOut != NULL)&&
|
||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
||||
{
|
||||
pdev->pClass->DataOut(pdev, epnum);
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DataInStage
|
||||
* Handle data in stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev ,uint8_t epnum, uint8_t *pdata)
|
||||
{
|
||||
USBD_EndpointTypeDef *pep;
|
||||
|
||||
if(epnum == 0)
|
||||
{
|
||||
pep = &pdev->ep_in[0];
|
||||
|
||||
if ( pdev->ep0_state == USBD_EP0_DATA_IN)
|
||||
{
|
||||
if(pep->rem_length > pep->maxpacket)
|
||||
{
|
||||
pep->rem_length -= pep->maxpacket;
|
||||
|
||||
USBD_CtlContinueSendData (pdev,
|
||||
pdata,
|
||||
pep->rem_length);
|
||||
}
|
||||
else
|
||||
{ /* last packet is MPS multiple, so send ZLP packet */
|
||||
if((pep->total_length % pep->maxpacket == 0) &&
|
||||
(pep->total_length >= pep->maxpacket) &&
|
||||
(pep->total_length < pdev->ep0_data_len ))
|
||||
{
|
||||
|
||||
USBD_CtlContinueSendData(pdev , NULL, 0);
|
||||
pdev->ep0_data_len = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if((pdev->pClass->EP0_TxSent != NULL)&&
|
||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
||||
{
|
||||
pdev->pClass->EP0_TxSent(pdev);
|
||||
}
|
||||
USBD_CtlReceiveStatus(pdev);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pdev->dev_test_mode == 1)
|
||||
{
|
||||
USBD_RunTestMode(pdev);
|
||||
pdev->dev_test_mode = 0;
|
||||
}
|
||||
}
|
||||
else if((pdev->pClass->DataIn != NULL)&&
|
||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
||||
{
|
||||
pdev->pClass->DataIn(pdev, epnum);
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_LL_Reset
|
||||
* Handle Reset event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Open EP0 OUT */
|
||||
USBD_LL_OpenEP(pdev,
|
||||
0x00,
|
||||
USBD_EP_TYPE_CTRL,
|
||||
USB_MAX_EP0_SIZE);
|
||||
|
||||
pdev->ep_out[0].maxpacket = USB_MAX_EP0_SIZE;
|
||||
|
||||
/* Open EP0 IN */
|
||||
USBD_LL_OpenEP(pdev,
|
||||
0x80,
|
||||
USBD_EP_TYPE_CTRL,
|
||||
USB_MAX_EP0_SIZE);
|
||||
|
||||
pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE;
|
||||
/* Upon Reset call usr call back */
|
||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||
|
||||
if (pdev->pClassData)
|
||||
pdev->pClass->DeInit(pdev, pdev->dev_config);
|
||||
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_LL_Reset
|
||||
* Handle Reset event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed)
|
||||
{
|
||||
pdev->dev_speed = speed;
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_Suspend
|
||||
* Handle Suspend event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
pdev->dev_old_state = pdev->dev_state;
|
||||
pdev->dev_state = USBD_STATE_SUSPENDED;
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_Resume
|
||||
* Handle Resume event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
pdev->dev_state = pdev->dev_old_state;
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_SOF
|
||||
* Handle SOF event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
if(pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if(pdev->pClass->SOF != NULL)
|
||||
{
|
||||
pdev->pClass->SOF(pdev);
|
||||
}
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_IsoINIncomplete
|
||||
* Handle iso in incomplete event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_IsoOUTIncomplete
|
||||
* Handle iso out incomplete event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DevConnected
|
||||
* Handle device connection event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DevDisconnected
|
||||
* Handle device disconnection event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Free Class Resources */
|
||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||
pdev->pClass->DeInit(pdev, pdev->dev_config);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@ -1,769 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_req.c
|
||||
* @author MCD Application Team
|
||||
* @version V2.0.0
|
||||
* @date 18-February-2014
|
||||
* @brief This file provides the standard USB requests following chapter 9.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbdev/usbd_ctlreq.h"
|
||||
#include "usbdev/usbd_ioreq.h"
|
||||
|
||||
|
||||
/** @addtogroup STM32_USBD_STATE_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ
|
||||
* @brief USB standard requests module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_REQ_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_SetAddress(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_SetConfig(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_GetConfig(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_GetStatus(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_SetFeature(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_ClrFeature(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static uint8_t USBD_GetLen(uint8_t *buf);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_StdDevReq
|
||||
* Handle standard usb device requests
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
|
||||
USBD_GetDescriptor (pdev, req) ;
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_ADDRESS:
|
||||
USBD_SetAddress(pdev, req);
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_CONFIGURATION:
|
||||
USBD_SetConfig (pdev , req);
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_CONFIGURATION:
|
||||
USBD_GetConfig (pdev , req);
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_STATUS:
|
||||
USBD_GetStatus (pdev , req);
|
||||
break;
|
||||
|
||||
|
||||
case USB_REQ_SET_FEATURE:
|
||||
USBD_SetFeature (pdev , req);
|
||||
break;
|
||||
|
||||
case USB_REQ_CLEAR_FEATURE:
|
||||
USBD_ClrFeature (pdev , req);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev , req);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_StdItfReq
|
||||
* Handle standard usb interface requests
|
||||
* @param pdev: USB OTG device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_CONFIGURED:
|
||||
|
||||
if (LOBYTE(req->wIndex) <= USBD_MAX_NUM_INTERFACES)
|
||||
{
|
||||
pdev->pClass->Setup (pdev, req);
|
||||
|
||||
if((req->wLength == 0)&& (ret == USBD_OK))
|
||||
{
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev , req);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev , req);
|
||||
break;
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_StdEPReq
|
||||
* Handle standard usb endpoint requests
|
||||
* @param pdev: USB OTG device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req)
|
||||
{
|
||||
|
||||
uint8_t ep_addr;
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
USBD_EndpointTypeDef *pep;
|
||||
ep_addr = LOBYTE(req->wIndex);
|
||||
|
||||
switch (req->bRequest)
|
||||
{
|
||||
|
||||
case USB_REQ_SET_FEATURE :
|
||||
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_ADDRESSED:
|
||||
if ((ep_addr != 0x00) && (ep_addr != 0x80))
|
||||
{
|
||||
USBD_LL_StallEP(pdev , ep_addr);
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_STATE_CONFIGURED:
|
||||
if (req->wValue == USB_FEATURE_EP_HALT)
|
||||
{
|
||||
if ((ep_addr != 0x00) && (ep_addr != 0x80))
|
||||
{
|
||||
USBD_LL_StallEP(pdev , ep_addr);
|
||||
|
||||
}
|
||||
}
|
||||
pdev->pClass->Setup (pdev, req);
|
||||
USBD_CtlSendStatus(pdev);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev , req);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_CLEAR_FEATURE :
|
||||
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_ADDRESSED:
|
||||
if ((ep_addr != 0x00) && (ep_addr != 0x80))
|
||||
{
|
||||
USBD_LL_StallEP(pdev , ep_addr);
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_STATE_CONFIGURED:
|
||||
if (req->wValue == USB_FEATURE_EP_HALT)
|
||||
{
|
||||
if ((ep_addr & 0x7F) != 0x00)
|
||||
{
|
||||
USBD_LL_ClearStallEP(pdev , ep_addr);
|
||||
pdev->pClass->Setup (pdev, req);
|
||||
}
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev , req);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_STATUS:
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_ADDRESSED:
|
||||
if ((ep_addr & 0x7F) != 0x00)
|
||||
{
|
||||
USBD_LL_StallEP(pdev , ep_addr);
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_STATE_CONFIGURED:
|
||||
pep = ((ep_addr & 0x80) == 0x80) ? &pdev->ep_in[ep_addr & 0x7F]:\
|
||||
&pdev->ep_out[ep_addr & 0x7F];
|
||||
if(USBD_LL_IsStallEP(pdev, ep_addr))
|
||||
{
|
||||
pep->status = 0x0001;
|
||||
}
|
||||
else
|
||||
{
|
||||
pep->status = 0x0000;
|
||||
}
|
||||
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)&pep->status,
|
||||
2);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev , req);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_GetDescriptor
|
||||
* Handle Get Descriptor requests
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
uint16_t len;
|
||||
uint8_t *pbuf;
|
||||
|
||||
|
||||
switch (req->wValue >> 8)
|
||||
{
|
||||
case USB_DESC_TYPE_DEVICE:
|
||||
pbuf = pdev->pDesc->GetDeviceDescriptor(pdev->dev_speed, &len);
|
||||
break;
|
||||
|
||||
case USB_DESC_TYPE_CONFIGURATION:
|
||||
if(pdev->dev_speed == USBD_SPEED_HIGH )
|
||||
{
|
||||
pbuf = (uint8_t *)pdev->pClass->GetHSConfigDescriptor(&len);
|
||||
pbuf[1] = USB_DESC_TYPE_CONFIGURATION;
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuf = (uint8_t *)pdev->pClass->GetFSConfigDescriptor(&len);
|
||||
pbuf[1] = USB_DESC_TYPE_CONFIGURATION;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_DESC_TYPE_STRING:
|
||||
switch ((uint8_t)(req->wValue))
|
||||
{
|
||||
case USBD_IDX_LANGID_STR:
|
||||
pbuf = pdev->pDesc->GetLangIDStrDescriptor(pdev->dev_speed, &len);
|
||||
break;
|
||||
|
||||
case USBD_IDX_MFC_STR:
|
||||
pbuf = pdev->pDesc->GetManufacturerStrDescriptor(pdev->dev_speed, &len);
|
||||
break;
|
||||
|
||||
case USBD_IDX_PRODUCT_STR:
|
||||
pbuf = pdev->pDesc->GetProductStrDescriptor(pdev->dev_speed, &len);
|
||||
break;
|
||||
|
||||
case USBD_IDX_SERIAL_STR:
|
||||
pbuf = pdev->pDesc->GetSerialStrDescriptor(pdev->dev_speed, &len);
|
||||
break;
|
||||
|
||||
case USBD_IDX_CONFIG_STR:
|
||||
pbuf = pdev->pDesc->GetConfigurationStrDescriptor(pdev->dev_speed, &len);
|
||||
break;
|
||||
|
||||
case USBD_IDX_INTERFACE_STR:
|
||||
pbuf = pdev->pDesc->GetInterfaceStrDescriptor(pdev->dev_speed, &len);
|
||||
break;
|
||||
|
||||
default:
|
||||
#if (USBD_SUPPORT_USER_STRING == 1)
|
||||
pbuf = pdev->pClass->GetUsrStrDescriptor(pdev, (req->wValue) , &len);
|
||||
break;
|
||||
#else
|
||||
USBD_CtlError(pdev , req);
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case USB_DESC_TYPE_DEVICE_QUALIFIER:
|
||||
|
||||
if(pdev->dev_speed == USBD_SPEED_HIGH )
|
||||
{
|
||||
pbuf = (uint8_t *)pdev->pClass->GetDeviceQualifierDescriptor(&len);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev , req);
|
||||
return;
|
||||
}
|
||||
|
||||
case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION:
|
||||
if(pdev->dev_speed == USBD_SPEED_HIGH )
|
||||
{
|
||||
pbuf = (uint8_t *)pdev->pClass->GetOtherSpeedConfigDescriptor(&len);
|
||||
pbuf[1] = USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev , req);
|
||||
return;
|
||||
}
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev , req);
|
||||
return;
|
||||
}
|
||||
|
||||
if((len != 0)&& (req->wLength != 0))
|
||||
{
|
||||
|
||||
len = MIN(len , req->wLength);
|
||||
|
||||
USBD_CtlSendData (pdev,
|
||||
pbuf,
|
||||
len);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_SetAddress
|
||||
* Set device address
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_SetAddress(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
uint8_t dev_addr;
|
||||
|
||||
if ((req->wIndex == 0) && (req->wLength == 0))
|
||||
{
|
||||
dev_addr = (uint8_t)(req->wValue) & 0x7F;
|
||||
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlError(pdev , req);
|
||||
}
|
||||
else
|
||||
{
|
||||
pdev->dev_address = dev_addr;
|
||||
USBD_LL_SetUSBAddress(pdev, dev_addr);
|
||||
USBD_CtlSendStatus(pdev);
|
||||
|
||||
if (dev_addr != 0)
|
||||
{
|
||||
pdev->dev_state = USBD_STATE_ADDRESSED;
|
||||
}
|
||||
else
|
||||
{
|
||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev , req);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_SetConfig
|
||||
* Handle Set device configuration request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_SetConfig(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
|
||||
static uint8_t cfgidx;
|
||||
|
||||
cfgidx = (uint8_t)(req->wValue);
|
||||
|
||||
if (cfgidx > USBD_MAX_NUM_CONFIGURATION )
|
||||
{
|
||||
USBD_CtlError(pdev , req);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_ADDRESSED:
|
||||
if (cfgidx)
|
||||
{
|
||||
pdev->dev_config = cfgidx;
|
||||
pdev->dev_state = USBD_STATE_CONFIGURED;
|
||||
if(USBD_SetClassConfig(pdev , cfgidx) == USBD_FAIL)
|
||||
{
|
||||
USBD_CtlError(pdev , req);
|
||||
return;
|
||||
}
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_STATE_CONFIGURED:
|
||||
if (cfgidx == 0)
|
||||
{
|
||||
pdev->dev_state = USBD_STATE_ADDRESSED;
|
||||
pdev->dev_config = cfgidx;
|
||||
USBD_ClrClassConfig(pdev , cfgidx);
|
||||
USBD_CtlSendStatus(pdev);
|
||||
|
||||
}
|
||||
else if (cfgidx != pdev->dev_config)
|
||||
{
|
||||
/* Clear old configuration */
|
||||
USBD_ClrClassConfig(pdev , pdev->dev_config);
|
||||
|
||||
/* set new configuration */
|
||||
pdev->dev_config = cfgidx;
|
||||
if(USBD_SetClassConfig(pdev , cfgidx) == USBD_FAIL)
|
||||
{
|
||||
USBD_CtlError(pdev , req);
|
||||
return;
|
||||
}
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev , req);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_GetConfig
|
||||
* Handle Get device configuration request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_GetConfig(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
|
||||
if (req->wLength != 1)
|
||||
{
|
||||
USBD_CtlError(pdev , req);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (pdev->dev_state )
|
||||
{
|
||||
case USBD_STATE_ADDRESSED:
|
||||
pdev->dev_default_config = 0;
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)&pdev->dev_default_config,
|
||||
1);
|
||||
break;
|
||||
|
||||
case USBD_STATE_CONFIGURED:
|
||||
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)&pdev->dev_config,
|
||||
1);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev , req);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_GetStatus
|
||||
* Handle Get Status request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_GetStatus(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
|
||||
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_ADDRESSED:
|
||||
case USBD_STATE_CONFIGURED:
|
||||
|
||||
#if ( USBD_SELF_POWERED == 1)
|
||||
pdev->dev_config_status = USB_CONFIG_SELF_POWERED;
|
||||
#else
|
||||
pdev->dev_config_status = 0;
|
||||
#endif
|
||||
|
||||
if (pdev->dev_remote_wakeup)
|
||||
{
|
||||
pdev->dev_config_status |= USB_CONFIG_REMOTE_WAKEUP;
|
||||
}
|
||||
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)& pdev->dev_config_status,
|
||||
2);
|
||||
break;
|
||||
|
||||
default :
|
||||
USBD_CtlError(pdev , req);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_SetFeature
|
||||
* Handle Set device feature request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_SetFeature(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
|
||||
if (req->wValue == USB_FEATURE_REMOTE_WAKEUP)
|
||||
{
|
||||
pdev->dev_remote_wakeup = 1;
|
||||
pdev->pClass->Setup (pdev, req);
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_ClrFeature
|
||||
* Handle clear device feature request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_ClrFeature(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_ADDRESSED:
|
||||
case USBD_STATE_CONFIGURED:
|
||||
if (req->wValue == USB_FEATURE_REMOTE_WAKEUP)
|
||||
{
|
||||
pdev->dev_remote_wakeup = 0;
|
||||
pdev->pClass->Setup (pdev, req);
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
break;
|
||||
|
||||
default :
|
||||
USBD_CtlError(pdev , req);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_ParseSetupRequest
|
||||
* Copy buffer into setup structure
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata)
|
||||
{
|
||||
req->bmRequest = *(uint8_t *) (pdata);
|
||||
req->bRequest = *(uint8_t *) (pdata + 1);
|
||||
req->wValue = SWAPBYTE (pdata + 2);
|
||||
req->wIndex = SWAPBYTE (pdata + 4);
|
||||
req->wLength = SWAPBYTE (pdata + 6);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlError
|
||||
* Handle USB low level Error
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void USBD_CtlError( USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_LL_StallEP(pdev , 0x80);
|
||||
USBD_LL_StallEP(pdev , 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_GetString
|
||||
* Convert Ascii string into unicode one
|
||||
* @param desc : descriptor buffer
|
||||
* @param unicode : Formatted string buffer (unicode)
|
||||
* @param len : descriptor length
|
||||
* @retval None
|
||||
*/
|
||||
void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len)
|
||||
{
|
||||
uint8_t idx = 0;
|
||||
|
||||
if (desc != NULL)
|
||||
{
|
||||
*len = USBD_GetLen(desc) * 2 + 2;
|
||||
unicode[idx++] = *len;
|
||||
unicode[idx++] = USB_DESC_TYPE_STRING;
|
||||
|
||||
while (*desc != '\0')
|
||||
{
|
||||
unicode[idx++] = *desc++;
|
||||
unicode[idx++] = 0x00;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_GetLen
|
||||
* return the string length
|
||||
* @param buf : pointer to the ascii string buffer
|
||||
* @retval string length
|
||||
*/
|
||||
static uint8_t USBD_GetLen(uint8_t *buf)
|
||||
{
|
||||
uint8_t len = 0;
|
||||
|
||||
while (*buf != '\0')
|
||||
{
|
||||
len++;
|
||||
buf++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@ -1,220 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file USB_Device/CDC_Standalone/Src/usbd_desc.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.2
|
||||
* @date 25-May-2015
|
||||
* @brief This file provides the USBD descriptors and string formating method.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbdev/usbd_core.h"
|
||||
#include "usbdev/usbd_desc.h"
|
||||
#include "usbdev/usbd_conf.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
#define USBD_VID 0x1209
|
||||
#define USBD_PID 0xabd1
|
||||
#define USBD_LANGID_STRING 0x409
|
||||
#define USBD_MANUFACTURER_STRING "OpenMV"
|
||||
#define USBD_PRODUCT_HS_STRING "OpenMV Virtual Comm Port in HS Mode"
|
||||
#define USBD_SERIALNUMBER_HS_STRING "000000000010"
|
||||
#define USBD_PRODUCT_FS_STRING "OpenMV Virtual Comm Port in FS Mode"
|
||||
#define USBD_SERIALNUMBER_FS_STRING "000000000011"
|
||||
#define USBD_CONFIGURATION_HS_STRING "VCP Config"
|
||||
#define USBD_INTERFACE_HS_STRING "VCP Interface"
|
||||
#define USBD_CONFIGURATION_FS_STRING "VCP Config"
|
||||
#define USBD_INTERFACE_FS_STRING "VCP Interface"
|
||||
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
uint8_t *USBD_VCP_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *USBD_VCP_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *USBD_VCP_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *USBD_VCP_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *USBD_VCP_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *USBD_VCP_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *USBD_VCP_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
#ifdef USB_SUPPORT_USER_STRING_DESC
|
||||
uint8_t *USBD_VCP_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
|
||||
#endif /* USB_SUPPORT_USER_STRING_DESC */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
USBD_DescriptorsTypeDef VCP_Desc = {
|
||||
USBD_VCP_DeviceDescriptor,
|
||||
USBD_VCP_LangIDStrDescriptor,
|
||||
USBD_VCP_ManufacturerStrDescriptor,
|
||||
USBD_VCP_ProductStrDescriptor,
|
||||
USBD_VCP_SerialStrDescriptor,
|
||||
USBD_VCP_ConfigStrDescriptor,
|
||||
USBD_VCP_InterfaceStrDescriptor,
|
||||
};
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
|
||||
0x12, /* bLength */
|
||||
USB_DESC_TYPE_DEVICE, /* bDescriptorType */
|
||||
0x00, /* bcdUSB */
|
||||
0x02,
|
||||
0xef, /* bDeviceClass */
|
||||
0x02, /* bDeviceSubClass */
|
||||
0x01, /* bDeviceProtocol */
|
||||
USB_MAX_EP0_SIZE, /* bMaxPacketSize */
|
||||
LOBYTE(USBD_VID), /* idVendor */
|
||||
HIBYTE(USBD_VID), /* idVendor */
|
||||
LOBYTE(USBD_PID), /* idVendor */
|
||||
HIBYTE(USBD_PID), /* idVendor */
|
||||
0x00, /* bcdDevice rel. 2.00 */
|
||||
0x02,
|
||||
USBD_IDX_MFC_STR, /* Index of manufacturer string */
|
||||
USBD_IDX_PRODUCT_STR, /* Index of product string */
|
||||
USBD_IDX_SERIAL_STR, /* Index of serial number string */
|
||||
USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */
|
||||
}; /* USB_DeviceDescriptor */
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = {
|
||||
USB_LEN_LANGID_STR_DESC,
|
||||
USB_DESC_TYPE_STRING,
|
||||
LOBYTE(USBD_LANGID_STRING),
|
||||
HIBYTE(USBD_LANGID_STRING),
|
||||
};
|
||||
|
||||
uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] =
|
||||
{
|
||||
USB_SIZ_STRING_SERIAL,
|
||||
USB_DESC_TYPE_STRING,
|
||||
};
|
||||
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
|
||||
|
||||
/**
|
||||
* @brief Returns the device descriptor.
|
||||
* @param speed: Current device speed
|
||||
* @param length: Pointer to data length variable
|
||||
* @retval Pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_VCP_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_DeviceDesc);
|
||||
return (uint8_t*)USBD_DeviceDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the LangID string descriptor.
|
||||
* @param speed: Current device speed
|
||||
* @param length: Pointer to data length variable
|
||||
* @retval Pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_VCP_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_LangIDDesc);
|
||||
return (uint8_t*)USBD_LangIDDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the product string descriptor.
|
||||
* @param speed: Current device speed
|
||||
* @param length: Pointer to data length variable
|
||||
* @retval Pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_VCP_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
if(speed == 0) {
|
||||
USBD_GetString((uint8_t *)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
|
||||
} else {
|
||||
USBD_GetString((uint8_t *)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
|
||||
}
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the manufacturer string descriptor.
|
||||
* @param speed: Current device speed
|
||||
* @param length: Pointer to data length variable
|
||||
* @retval Pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_VCP_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the serial number string descriptor.
|
||||
* @param speed: Current device speed
|
||||
* @param length: Pointer to data length variable
|
||||
* @retval Pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_VCP_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
if(speed == USBD_SPEED_HIGH) {
|
||||
USBD_GetString((uint8_t *)USBD_SERIALNUMBER_HS_STRING, USBD_StrDesc, length);
|
||||
} else {
|
||||
USBD_GetString((uint8_t *)USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length);
|
||||
}
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the configuration string descriptor.
|
||||
* @param speed: Current device speed
|
||||
* @param length: Pointer to data length variable
|
||||
* @retval Pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_VCP_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
if(speed == USBD_SPEED_HIGH) {
|
||||
USBD_GetString((uint8_t *)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
|
||||
} else {
|
||||
USBD_GetString((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
|
||||
}
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the interface string descriptor.
|
||||
* @param speed: Current device speed
|
||||
* @param length: Pointer to data length variable
|
||||
* @retval Pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_VCP_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
if(speed == 0) {
|
||||
USBD_GetString((uint8_t *)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length);
|
||||
} else {
|
||||
USBD_GetString((uint8_t *)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
|
||||
}
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@ -1,236 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_ioreq.c
|
||||
* @author MCD Application Team
|
||||
* @version V2.0.0
|
||||
* @date 18-February-2014
|
||||
* @brief This file provides the IO requests APIs for control endpoints.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbdev/usbd_ioreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ
|
||||
* @brief control I/O requests module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_IOREQ_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlSendData
|
||||
* send data on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be sent
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf,
|
||||
uint16_t len)
|
||||
{
|
||||
/* Set EP0 State */
|
||||
pdev->ep0_state = USBD_EP0_DATA_IN;
|
||||
pdev->ep_in[0].total_length = len;
|
||||
pdev->ep_in[0].rem_length = len;
|
||||
/* Start the transfer */
|
||||
USBD_LL_Transmit (pdev, 0x00, pbuf, len);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlContinueSendData
|
||||
* continue sending data on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be sent
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf,
|
||||
uint16_t len)
|
||||
{
|
||||
/* Start the next transfer */
|
||||
USBD_LL_Transmit (pdev, 0x00, pbuf, len);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlPrepareRx
|
||||
* receive data on the ctl pipe
|
||||
* @param pdev: USB OTG device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be received
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf,
|
||||
uint16_t len)
|
||||
{
|
||||
/* Set EP0 State */
|
||||
pdev->ep0_state = USBD_EP0_DATA_OUT;
|
||||
pdev->ep_out[0].total_length = len;
|
||||
pdev->ep_out[0].rem_length = len;
|
||||
/* Start the transfer */
|
||||
USBD_LL_PrepareReceive (pdev,
|
||||
0,
|
||||
pbuf,
|
||||
len);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlContinueRx
|
||||
* continue receive data on the ctl pipe
|
||||
* @param pdev: USB OTG device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be received
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf,
|
||||
uint16_t len)
|
||||
{
|
||||
|
||||
USBD_LL_PrepareReceive (pdev,
|
||||
0,
|
||||
pbuf,
|
||||
len);
|
||||
return USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_CtlSendStatus
|
||||
* send zero lzngth packet on the ctl pipe
|
||||
* @param pdev: USB OTG device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
|
||||
/* Set EP0 State */
|
||||
pdev->ep0_state = USBD_EP0_STATUS_IN;
|
||||
|
||||
/* Start the transfer */
|
||||
USBD_LL_Transmit (pdev, 0x00, NULL, 0);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlReceiveStatus
|
||||
* receive zero lzngth packet on the ctl pipe
|
||||
* @param pdev: USB OTG device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Set EP0 State */
|
||||
pdev->ep0_state = USBD_EP0_STATUS_OUT;
|
||||
|
||||
/* Start the transfer */
|
||||
USBD_LL_PrepareReceive ( pdev,
|
||||
0,
|
||||
NULL,
|
||||
0);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_GetRxCount
|
||||
* returns the received data length
|
||||
* @param pdev: USB OTG device instance
|
||||
* epnum: endpoint index
|
||||
* @retval Rx Data blength
|
||||
*/
|
||||
uint16_t USBD_GetRxCount (USBD_HandleTypeDef *pdev , uint8_t ep_addr)
|
||||
{
|
||||
return USBD_LL_GetRxDataSize(pdev, ep_addr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@ -24,7 +24,7 @@
|
||||
SYSTEM ?= st/system_stm32fxxx
|
||||
STARTUP ?= st/startup_$(shell echo $(MCU) | tr '[:upper:]' '[:lower:]')
|
||||
UVC_DIR := $(OMV_DIR)/ports/$(PORT)/uvc
|
||||
BOOT_DIR := $(OMV_DIR)/ports/$(PORT)/boot
|
||||
BOOT_DIR := boot
|
||||
|
||||
LDSCRIPT ?= stm32fxxx
|
||||
|
||||
@ -126,21 +126,6 @@ OMV_CFLAGS += -I$(TOP_DIR)/$(DISPLAY_DIR)/include/
|
||||
OMV_CFLAGS += -I$(TOP_DIR)/$(LIBPDM_DIR)/
|
||||
OMV_CFLAGS += -I$(BUILD)/$(TENSORFLOW_DIR)/
|
||||
|
||||
ifeq ($(OMV_ENABLE_BL), 1)
|
||||
CFLAGS += -DOMV_ENABLE_BOOTLOADER
|
||||
BL_CFLAGS := $(CFLAGS) $(HAL_CFLAGS)
|
||||
BL_CFLAGS += -I$(OMV_BOARD_CONFIG_DIR)
|
||||
BL_CFLAGS += -I$(TOP_DIR)/$(BOOT_DIR)/include/
|
||||
# Linker Flags
|
||||
BL_LDFLAGS = -mcpu=$(CPU) \
|
||||
-mabi=aapcs-linux \
|
||||
-mthumb \
|
||||
-mfpu=$(FPU) \
|
||||
-mfloat-abi=hard \
|
||||
-Wl,--gc-sections \
|
||||
-Wl,-T$(BUILD)/$(BOOT_DIR)/stm32fxxx.lds
|
||||
endif
|
||||
|
||||
ifeq ($(OMV_ENABLE_UVC), 1)
|
||||
UVC_CFLAGS := $(CFLAGS) $(HAL_CFLAGS)
|
||||
UVC_CFLAGS += -I$(OMV_BOARD_CONFIG_DIR)
|
||||
@ -583,17 +568,6 @@ ifeq ($(CUBEAI), 1)
|
||||
include $(TOP_DIR)/stm32cubeai/cube.mk
|
||||
endif
|
||||
|
||||
ifeq ($(OMV_ENABLE_BL), 1)
|
||||
BOOTLOADER = bootloader
|
||||
# Bootloader object files
|
||||
BOOT_OBJ += $(wildcard $(BUILD)/$(BOOT_DIR)/src/*.o)
|
||||
BOOT_OBJ += $(wildcard $(BUILD)/$(HAL_DIR)/src/*.o)
|
||||
BOOT_OBJ += $(addprefix $(BUILD)/$(CMSIS_DIR)/src/,\
|
||||
$(STARTUP).o \
|
||||
$(SYSTEM).o \
|
||||
)
|
||||
endif
|
||||
|
||||
ifeq ($(OMV_ENABLE_UVC), 1)
|
||||
UVC = uvc
|
||||
# UVC object files
|
||||
@ -710,13 +684,29 @@ endif
|
||||
ifeq ($(CUBEAI), 1)
|
||||
$(MAKE) -C $(CUBEAI_DIR) BUILD=$(BUILD)/$(CUBEAI_DIR) CFLAGS="$(CFLAGS) -fno-strict-aliasing -MMD"
|
||||
endif
|
||||
|
||||
ifeq ($(OMV_ENABLE_UVC), 1)
|
||||
UVC_OBJS: FIRMWARE_OBJS
|
||||
$(MAKE) -C $(UVC_DIR) BUILD=$(BUILD)/$(UVC_DIR) CFLAGS="$(UVC_CFLAGS) -MMD"
|
||||
endif
|
||||
|
||||
# This target generates the bootloader.
|
||||
ifeq ($(OMV_ENABLE_BL), 1)
|
||||
BOOTLOADER_OBJS: FIRMWARE_OBJS
|
||||
$(MAKE) -C $(BOOT_DIR) BUILD=$(BUILD)/$(BOOT_DIR) CFLAGS="$(BL_CFLAGS) -MMD"
|
||||
BOOTLOADER = bootloader
|
||||
$(BOOTLOADER): | $(BUILD) $(FW_DIR)
|
||||
$(MAKE) -C $(TOP_DIR)/$(BOOT_DIR) BUILD=$(BUILD)/$(BOOT_DIR)
|
||||
$(OBJCOPY) -Obinary $(FW_DIR)/$(BOOTLOADER).elf $(FW_DIR)/$(BOOTLOADER).bin
|
||||
$(PYTHON) $(MKDFU) -D $(DFU_DEVICE) -b 0x08000000:$(FW_DIR)/$(BOOTLOADER).bin $(FW_DIR)/$(BOOTLOADER).dfu
|
||||
endif
|
||||
|
||||
# This target generates the UVC firmware.
|
||||
ifeq ($(OMV_ENABLE_UVC), 1)
|
||||
$(UVC): FIRMWARE_OBJS UVC_OBJS
|
||||
$(CPP) -P -E -I$(OMV_COMMON_DIR) -I$(OMV_BOARD_CONFIG_DIR) \
|
||||
$(UVC_DIR)/stm32fxxx.ld.S > $(BUILD)/$(UVC_DIR)/stm32fxxx.lds
|
||||
$(CC) $(UVC_LDFLAGS) $(UVC_OBJ) -o $(FW_DIR)/$(UVC).elf -lgcc
|
||||
$(OBJCOPY) -Obinary $(FW_DIR)/$(UVC).elf $(FW_DIR)/$(UVC).bin
|
||||
$(PYTHON) $(MKDFU) -D $(DFU_DEVICE) -b $(MAIN_APP_ADDR):$(FW_DIR)/$(UVC).bin $(FW_DIR)/$(UVC).dfu
|
||||
endif
|
||||
|
||||
# This target generates the main/app firmware image located at 0x08010000
|
||||
@ -727,26 +717,6 @@ $(FIRMWARE): FIRMWARE_OBJS
|
||||
$(OBJCOPY) -Obinary $(FW_DIR)/$(FIRMWARE).elf $(FW_DIR)/$(FIRMWARE).bin
|
||||
$(PYTHON) $(MKDFU) -D $(DFU_DEVICE) -b $(MAIN_APP_ADDR):$(FW_DIR)/$(FIRMWARE).bin $(FW_DIR)/$(FIRMWARE).dfu
|
||||
|
||||
ifeq ($(OMV_ENABLE_BL), 1)
|
||||
# This target generates the bootloader.
|
||||
$(BOOTLOADER): FIRMWARE_OBJS BOOTLOADER_OBJS
|
||||
$(CPP) -P -E -I$(OMV_COMMON_DIR) -I$(OMV_BOARD_CONFIG_DIR) \
|
||||
$(BOOT_DIR)/stm32fxxx.ld.S > $(BUILD)/$(BOOT_DIR)/stm32fxxx.lds
|
||||
$(CC) $(BL_LDFLAGS) $(BOOT_OBJ) -o $(FW_DIR)/$(BOOTLOADER).elf
|
||||
$(OBJCOPY) -Obinary $(FW_DIR)/$(BOOTLOADER).elf $(FW_DIR)/$(BOOTLOADER).bin
|
||||
$(PYTHON) $(MKDFU) -D $(DFU_DEVICE) -b 0x08000000:$(FW_DIR)/$(BOOTLOADER).bin $(FW_DIR)/$(BOOTLOADER).dfu
|
||||
endif
|
||||
|
||||
ifeq ($(OMV_ENABLE_UVC), 1)
|
||||
# This target generates the UVC firmware.
|
||||
$(UVC): FIRMWARE_OBJS UVC_OBJS
|
||||
$(CPP) -P -E -I$(OMV_COMMON_DIR) -I$(OMV_BOARD_CONFIG_DIR) \
|
||||
$(UVC_DIR)/stm32fxxx.ld.S > $(BUILD)/$(UVC_DIR)/stm32fxxx.lds
|
||||
$(CC) $(UVC_LDFLAGS) $(UVC_OBJ) -o $(FW_DIR)/$(UVC).elf -lgcc
|
||||
$(OBJCOPY) -Obinary $(FW_DIR)/$(UVC).elf $(FW_DIR)/$(UVC).bin
|
||||
$(PYTHON) $(MKDFU) -D $(DFU_DEVICE) -b $(MAIN_APP_ADDR):$(FW_DIR)/$(UVC).bin $(FW_DIR)/$(UVC).dfu
|
||||
endif
|
||||
|
||||
# This target generates the uvc, bootloader and firmware images.
|
||||
$(OPENMV): $(BOOTLOADER) $(UVC) $(FIRMWARE)
|
||||
ifeq ($(OMV_ENABLE_BL), 1)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user