diff --git a/boards/holybro/durandal-v1/nuttx-config/bootloader/defconfig b/boards/holybro/durandal-v1/nuttx-config/bootloader/defconfig index 614571a89a..e947baa195 100644 --- a/boards/holybro/durandal-v1/nuttx-config/bootloader/defconfig +++ b/boards/holybro/durandal-v1/nuttx-config/bootloader/defconfig @@ -29,7 +29,7 @@ CONFIG_BOARD_LOOPSPERMSEC=22114 CONFIG_BOARD_RESET_ON_ASSERT=2 CONFIG_C99_BOOL8=y CONFIG_CDCACM=y -CONFIG_CDCACM_PRODUCTID=0x008b +CONFIG_CDCACM_PRODUCTID=0x004b CONFIG_CDCACM_PRODUCTSTR="PX4 BL Holybro Durandal Vx" CONFIG_CDCACM_RXBUFSIZE=600 CONFIG_CDCACM_TXBUFSIZE=12000 diff --git a/boards/holybro/durandal-v1/nuttx-config/nsh/defconfig b/boards/holybro/durandal-v1/nuttx-config/nsh/defconfig index cf21b91f31..b133c05268 100644 --- a/boards/holybro/durandal-v1/nuttx-config/nsh/defconfig +++ b/boards/holybro/durandal-v1/nuttx-config/nsh/defconfig @@ -44,7 +44,7 @@ CONFIG_BOARD_RESET_ON_ASSERT=2 CONFIG_BUILTIN=y CONFIG_C99_BOOL8=y CONFIG_CDCACM=y -CONFIG_CDCACM_PRODUCTID=0x008b +CONFIG_CDCACM_PRODUCTID=0x004b CONFIG_CDCACM_PRODUCTSTR="PX4 DurandalV1" CONFIG_CDCACM_RXBUFSIZE=600 CONFIG_CDCACM_TXBUFSIZE=12000 diff --git a/platforms/nuttx/src/bootloader/bl.c b/platforms/nuttx/src/bootloader/bl.c index d48df0d1fb..617f99790b 100644 --- a/platforms/nuttx/src/bootloader/bl.c +++ b/platforms/nuttx/src/bootloader/bl.c @@ -39,6 +39,7 @@ * Aside from the header includes below, this file should have no board-specific logic. */ #include "hw_config.h" + #include #include #include @@ -141,7 +142,7 @@ #define STATE_ALLOWS_REBOOT (STATE_PROTO_GET_SYNC) # define SET_BL_STATE(s) #else -#define STATE_ALLOWS_ERASE (STATE_PROTO_GET_SYNC|STATE_PROTO_GET_DEVICE|STATE_PROTO_GET_CHIP) +#define STATE_ALLOWS_ERASE (STATE_PROTO_GET_SYNC|STATE_PROTO_GET_DEVICE) #define STATE_ALLOWS_REBOOT (STATE_ALLOWS_ERASE|STATE_PROTO_PROG_MULTI|STATE_PROTO_GET_CRC) # define SET_BL_STATE(s) bl_state |= (s) #endif diff --git a/platforms/nuttx/src/bootloader/lib/cdcacm.c b/platforms/nuttx/src/bootloader/lib/cdcacm.c index 3e1ded7717..601fa9a97e 100644 --- a/platforms/nuttx/src/bootloader/lib/cdcacm.c +++ b/platforms/nuttx/src/bootloader/lib/cdcacm.c @@ -53,8 +53,11 @@ char *g_init = 0; #if defined(SERIAL_TRACE) int in = 0; int out = 0; -char in_trace[254]; -char out_trace[254]; +// must be powere of 2 length +#define TRACE_SIZE 256 +#define TRACE_WRAP(f) (f) &=(TRACE_SIZE-1) +char in_trace[TRACE_SIZE]; +char out_trace[TRACE_SIZE]; #endif void usb_cinit(void *config) @@ -72,6 +75,7 @@ void usb_cinit(void *config) g_device = pt; } + g_usb_df = -1; int fd = open(g_device, O_RDWR | O_NONBLOCK); if (fd >= 0) { @@ -105,9 +109,8 @@ int usb_cin(void) if (read(g_usb_df, &b, 1) == 1) { c = b; #if defined(SERIAL_TRACE) - in_trace[in] = b; - in++; - in &= 255; + in_trace[in++] = b; + TRACE_WRAP(in); #endif } @@ -115,24 +118,18 @@ int usb_cin(void) } void usb_cout(uint8_t *buf, unsigned len) { - uint32_t timeout = 1000; - - for (unsigned i = 0; i < len; i++) { - while (timeout) { - if (write(g_usb_df, &buf[i], 1) == 1) { + write(g_usb_df, buf, len); #if defined(SERIAL_TRACE) - out_trace[out] = buf[i]; - out++; - out &= 255; -#endif - timeout = 1000; - break; - } else { - if (timeout-- == 0) { - return; - } - } - } + if (len > TRACE_SIZE) { + len = TRACE_SIZE; + out = 0; } + + for (unsigned i = 0; i < len; i++) { + out_trace[out++] = buf[i]; + TRACE_WRAP(out); + } + +#endif }