mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Merge pull request #1057 from openmv/usbdbg_common
Make USB debug configurable to work with different ports.
This commit is contained in:
commit
81e0eb99fa
@ -20,6 +20,7 @@ SRCS += $(addprefix common/, \
|
|||||||
ringbuf.c \
|
ringbuf.c \
|
||||||
trace.c \
|
trace.c \
|
||||||
mutex.c \
|
mutex.c \
|
||||||
|
usbdbg.c \
|
||||||
)
|
)
|
||||||
|
|
||||||
SRCS += $(addprefix sensors/, \
|
SRCS += $(addprefix sensors/, \
|
||||||
|
|||||||
@ -30,6 +30,9 @@
|
|||||||
// Core VBAT for selftests
|
// Core VBAT for selftests
|
||||||
#define OMV_CORE_VBAT "3.3"
|
#define OMV_CORE_VBAT "3.3"
|
||||||
|
|
||||||
|
// USB IRQn.
|
||||||
|
#define OMV_USB_IRQN (OTG_FS_IRQn)
|
||||||
|
|
||||||
//PLL1 168MHz/48MHz
|
//PLL1 168MHz/48MHz
|
||||||
#define OMV_OSC_PLL1M (12)
|
#define OMV_OSC_PLL1M (12)
|
||||||
#define OMV_OSC_PLL1N (336)
|
#define OMV_OSC_PLL1N (336)
|
||||||
|
|||||||
@ -75,6 +75,9 @@
|
|||||||
// Core VBAT for selftests
|
// Core VBAT for selftests
|
||||||
#define OMV_CORE_VBAT "3.3"
|
#define OMV_CORE_VBAT "3.3"
|
||||||
|
|
||||||
|
// USB IRQn.
|
||||||
|
#define OMV_USB_IRQN (OTG_FS_IRQn)
|
||||||
|
|
||||||
//PLL1 192MHz/48MHz
|
//PLL1 192MHz/48MHz
|
||||||
#define OMV_OSC_PLL1M (12)
|
#define OMV_OSC_PLL1M (12)
|
||||||
#define OMV_OSC_PLL1N (384)
|
#define OMV_OSC_PLL1N (384)
|
||||||
|
|||||||
@ -75,6 +75,9 @@
|
|||||||
// Core VBAT for selftests
|
// Core VBAT for selftests
|
||||||
#define OMV_CORE_VBAT "3.3"
|
#define OMV_CORE_VBAT "3.3"
|
||||||
|
|
||||||
|
// USB IRQn.
|
||||||
|
#define OMV_USB_IRQN (OTG_FS_IRQn)
|
||||||
|
|
||||||
//PLL1 216MHz/48MHz
|
//PLL1 216MHz/48MHz
|
||||||
#define OMV_OSC_PLL1M (12)
|
#define OMV_OSC_PLL1M (12)
|
||||||
#define OMV_OSC_PLL1N (432)
|
#define OMV_OSC_PLL1N (432)
|
||||||
|
|||||||
@ -81,6 +81,9 @@
|
|||||||
// Core VBAT for selftests
|
// Core VBAT for selftests
|
||||||
#define OMV_CORE_VBAT "3.3"
|
#define OMV_CORE_VBAT "3.3"
|
||||||
|
|
||||||
|
// USB IRQn.
|
||||||
|
#define OMV_USB_IRQN (OTG_FS_IRQn)
|
||||||
|
|
||||||
//PLL1 480MHz/48MHz for USB, SDMMC and FDCAN
|
//PLL1 480MHz/48MHz for USB, SDMMC and FDCAN
|
||||||
#define OMV_OSC_PLL1M (3)
|
#define OMV_OSC_PLL1M (3)
|
||||||
#define OMV_OSC_PLL1N (240)
|
#define OMV_OSC_PLL1N (240)
|
||||||
|
|||||||
@ -85,6 +85,9 @@
|
|||||||
// Core VBAT for selftests
|
// Core VBAT for selftests
|
||||||
#define OMV_CORE_VBAT "3.3"
|
#define OMV_CORE_VBAT "3.3"
|
||||||
|
|
||||||
|
// USB IRQn.
|
||||||
|
#define OMV_USB_IRQN (OTG_FS_IRQn)
|
||||||
|
|
||||||
//PLL1 48MHz for USB, SDMMC and FDCAN
|
//PLL1 48MHz for USB, SDMMC and FDCAN
|
||||||
#define OMV_OSC_PLL1M (3)
|
#define OMV_OSC_PLL1M (3)
|
||||||
#define OMV_OSC_PLL1N (240)
|
#define OMV_OSC_PLL1N (240)
|
||||||
|
|||||||
@ -82,6 +82,9 @@
|
|||||||
// Core VBAT for selftests
|
// Core VBAT for selftests
|
||||||
#define OMV_CORE_VBAT "3.3"
|
#define OMV_CORE_VBAT "3.3"
|
||||||
|
|
||||||
|
// USB IRQn.
|
||||||
|
#define OMV_USB_IRQN (OTG_FS_IRQn)
|
||||||
|
|
||||||
// Clock Sources
|
// Clock Sources
|
||||||
#define OMV_OSC_USB_CLKSOURCE RCC_USBCLKSOURCE_PLL
|
#define OMV_OSC_USB_CLKSOURCE RCC_USBCLKSOURCE_PLL
|
||||||
#define OMV_OSC_RNG_CLKSOURCE RCC_RNGCLKSOURCE_HSI48
|
#define OMV_OSC_RNG_CLKSOURCE RCC_RNGCLKSOURCE_HSI48
|
||||||
|
|||||||
@ -79,6 +79,9 @@
|
|||||||
// Core VBAT for selftests
|
// Core VBAT for selftests
|
||||||
#define OMV_CORE_VBAT "3.0"
|
#define OMV_CORE_VBAT "3.0"
|
||||||
|
|
||||||
|
// USB IRQn.
|
||||||
|
#define OMV_USB_IRQN (OTG_HS_IRQn)
|
||||||
|
|
||||||
// Defined for cpu frequency scaling to override the revid.
|
// Defined for cpu frequency scaling to override the revid.
|
||||||
#define OMV_MAX_CPU_FREQ (400)
|
#define OMV_MAX_CPU_FREQ (400)
|
||||||
|
|
||||||
|
|||||||
@ -21,20 +21,15 @@
|
|||||||
#include "pendsv.h"
|
#include "pendsv.h"
|
||||||
|
|
||||||
#include "imlib.h"
|
#include "imlib.h"
|
||||||
|
#if MICROPY_PY_SENSOR
|
||||||
#include "sensor.h"
|
#include "sensor.h"
|
||||||
|
#endif
|
||||||
#include "framebuffer.h"
|
#include "framebuffer.h"
|
||||||
#include "ff.h"
|
#include "ff.h"
|
||||||
#include "usb.h"
|
|
||||||
#include "usbdbg.h"
|
#include "usbdbg.h"
|
||||||
#include "omv_boardconfig.h"
|
#include "omv_boardconfig.h"
|
||||||
#include "py_image.h"
|
#include "py_image.h"
|
||||||
|
|
||||||
#if MICROPY_HW_USB_HS
|
|
||||||
#define OTG_IRQn (OTG_HS_IRQn)
|
|
||||||
#else
|
|
||||||
#define OTG_IRQn (OTG_FS_IRQn)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int xfer_bytes;
|
static int xfer_bytes;
|
||||||
static int xfer_length;
|
static int xfer_length;
|
||||||
static enum usbdbg_cmd cmd;
|
static enum usbdbg_cmd cmd;
|
||||||
@ -43,10 +38,14 @@ static volatile bool script_ready;
|
|||||||
static volatile bool script_running;
|
static volatile bool script_running;
|
||||||
static vstr_t script_buf;
|
static vstr_t script_buf;
|
||||||
static mp_obj_t mp_const_ide_interrupt = MP_OBJ_NULL;
|
static mp_obj_t mp_const_ide_interrupt = MP_OBJ_NULL;
|
||||||
extern const char *ffs_strerror(FRESULT res);
|
|
||||||
|
// These functions must be implemented in MicroPython CDC driver.
|
||||||
|
extern uint32_t usb_cdc_buf_len();
|
||||||
|
extern uint32_t usb_cdc_get_buf(uint8_t *buf, uint32_t len);
|
||||||
|
|
||||||
void usbdbg_init()
|
void usbdbg_init()
|
||||||
{
|
{
|
||||||
|
cmd = USBDBG_NONE;
|
||||||
script_ready=false;
|
script_ready=false;
|
||||||
script_running=false;
|
script_running=false;
|
||||||
vstr_init(&script_buf, 32);
|
vstr_init(&script_buf, 32);
|
||||||
@ -71,9 +70,9 @@ void usbdbg_set_script_running(bool running)
|
|||||||
inline void usbdbg_set_irq_enabled(bool enabled)
|
inline void usbdbg_set_irq_enabled(bool enabled)
|
||||||
{
|
{
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
HAL_NVIC_EnableIRQ(OTG_IRQn);
|
NVIC_EnableIRQ(OMV_USB_IRQN);
|
||||||
} else {
|
} else {
|
||||||
HAL_NVIC_DisableIRQ(OTG_IRQn);
|
NVIC_DisableIRQ(OMV_USB_IRQN);
|
||||||
}
|
}
|
||||||
__DSB(); __ISB();
|
__DSB(); __ISB();
|
||||||
}
|
}
|
||||||
@ -99,9 +98,11 @@ void usbdbg_data_in(void *buffer, int length)
|
|||||||
|
|
||||||
case USBDBG_SENSOR_ID: {
|
case USBDBG_SENSOR_ID: {
|
||||||
int sensor_id = 0xFF;
|
int sensor_id = 0xFF;
|
||||||
|
#if MICROPY_PY_SENSOR
|
||||||
if (sensor_is_detected() == true) {
|
if (sensor_is_detected() == true) {
|
||||||
sensor_id = sensor_get_id();
|
sensor_id = sensor_get_id();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
memcpy(buffer, &sensor_id, 4);
|
memcpy(buffer, &sensor_id, 4);
|
||||||
cmd = USBDBG_NONE;
|
cmd = USBDBG_NONE;
|
||||||
break;
|
break;
|
||||||
@ -244,10 +245,12 @@ void usbdbg_data_out(void *buffer, int length)
|
|||||||
|
|
||||||
py_image_descriptor_from_roi(&image, path, roi);
|
py_image_descriptor_from_roi(&image, path, roi);
|
||||||
#endif //IMLIB_ENABLE_IMAGE_IO && IMLIB_ENABLE_KEYPOINTS
|
#endif //IMLIB_ENABLE_IMAGE_IO && IMLIB_ENABLE_KEYPOINTS
|
||||||
|
cmd = USBDBG_NONE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case USBDBG_ATTR_WRITE: {
|
case USBDBG_ATTR_WRITE: {
|
||||||
|
#if MICROPY_PY_SENSOR
|
||||||
/* write sensor attribute */
|
/* write sensor attribute */
|
||||||
int32_t attr= *((int32_t*)buffer);
|
int32_t attr= *((int32_t*)buffer);
|
||||||
int32_t val = *((int32_t*)buffer+1);
|
int32_t val = *((int32_t*)buffer+1);
|
||||||
@ -267,6 +270,7 @@ void usbdbg_data_out(void *buffer, int length)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
cmd = USBDBG_NONE;
|
cmd = USBDBG_NONE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -322,8 +326,8 @@ void usbdbg_control(void *buffer, uint8_t request, uint32_t length)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case USBDBG_SCRIPT_SAVE:
|
case USBDBG_SCRIPT_SAVE:
|
||||||
/* save running script */
|
// TODO: save running script
|
||||||
// TODO
|
cmd = USBDBG_NONE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USBDBG_SCRIPT_RUNNING:
|
case USBDBG_SCRIPT_RUNNING:
|
||||||
@ -348,9 +352,11 @@ void usbdbg_control(void *buffer, uint8_t request, uint32_t length)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case USBDBG_SYS_RESET_TO_BL:{
|
case USBDBG_SYS_RESET_TO_BL:{
|
||||||
|
#if defined(RTC_BASE)
|
||||||
RTC_HandleTypeDef RTCHandle;
|
RTC_HandleTypeDef RTCHandle;
|
||||||
RTCHandle.Instance = RTC;
|
RTCHandle.Instance = RTC;
|
||||||
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR0, 0xDF59);
|
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR0, 0xDF59);
|
||||||
|
#endif
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -119,6 +119,7 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/common/, \
|
|||||||
ringbuf.o \
|
ringbuf.o \
|
||||||
trace.o \
|
trace.o \
|
||||||
mutex.o \
|
mutex.o \
|
||||||
|
usbdbg.o \
|
||||||
)
|
)
|
||||||
|
|
||||||
FIRM_OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/sensors/, \
|
FIRM_OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/sensors/, \
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user