Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for programming over USB #208

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bricks/_common/arm_none_eabi.mk
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ endif
SRC_STM32_USB_DEV += $(addprefix lib/pbio/drv/usb/stm32_usbd/,\
usbd_conf.c \
usbd_desc.c \
usbd_pybricks.c \
)

NXOS_SRC_C = $(addprefix lib/pbio/platform/nxt/nxos/,\
Expand Down
42 changes: 38 additions & 4 deletions bricks/_common_stm32/mphalport.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <contiki.h>

#include <pbdrv/config.h>
#include <pbdrv/usb.h>
#include <pbio/main.h>
#include <pbsys/bluetooth.h>

Expand Down Expand Up @@ -128,9 +129,40 @@ int mp_hal_stdin_rx_chr(void) {

// Send string of given length
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
uint32_t size;
pbio_error_t err;

#if PBDRV_CONFIG_USB

const char *usb_ptr = str;
nkarstens marked this conversation as resolved.
Show resolved Hide resolved
mp_uint_t usb_len = len;

while (usb_len) {
size = usb_len;
err = pbdrv_usb_stdout_tx((const uint8_t *)usb_ptr, &size);

if (err == PBIO_SUCCESS) {
usb_ptr += size;
usb_len -= size;
continue;
}

if (err != PBIO_ERROR_AGAIN) {
// Ignoring error for now. This means
// stdout lost if USB is disconnected.
break;
nkarstens marked this conversation as resolved.
Show resolved Hide resolved
}

if (usb_len) {
MICROPY_EVENT_POLL_HOOK
}
}

#endif // PBDRV_CONFIG_USB

while (len) {
uint32_t size = len;
pbio_error_t err = pbsys_bluetooth_tx((const uint8_t *)str, &size);
size = len;
err = pbsys_bluetooth_tx((const uint8_t *)str, &size);

if (err == PBIO_SUCCESS) {
str += size;
Expand All @@ -144,12 +176,14 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
return;
}

MICROPY_EVENT_POLL_HOOK
if (len) {
MICROPY_EVENT_POLL_HOOK
}
}
}

void mp_hal_stdout_tx_flush(void) {
while (!pbsys_bluetooth_tx_is_idle()) {
while (!pbsys_bluetooth_tx_is_idle() && !pbdrv_usb_stdout_tx_is_idle()) {
MICROPY_EVENT_POLL_HOOK
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/pbio/drv/usb/stm32_usbd/usbd_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define USBD_MAX_NUM_INTERFACES 1
#define USBD_MAX_NUM_CONFIGURATION 1
#define USBD_MAX_STR_DESC_SIZ 0x100
#define USBD_SELF_POWERED 1
#define USBD_SELF_POWERED 0
#define USBD_CLASS_BOS_ENABLED 1

#endif /* _USBD_CONF_H_ */
Loading
Loading