stm: Fix USART3 init. Small edits to Makefile and other things.
diff --git a/stm/usb.c b/stm/usb.c
index ed2b035..89cc1df 100644
--- a/stm/usb.c
+++ b/stm/usb.c
@@ -8,9 +8,14 @@
#include "usbd_desc.h"
#include "misc.h"
+#include "mpconfig.h"
+#include "qstr.h"
+#include "obj.h"
#include "usb.h"
+#ifdef USE_DEVICE_MODE
extern CDC_IF_Prop_TypeDef VCP_fops;
+#endif
USB_OTG_CORE_HANDLE USB_OTG_dev;
@@ -22,8 +27,10 @@
void usb_init(void) {
if (!is_enabled) {
// only init USB once in the device's power-lifetime
+#ifdef USE_DEVICE_MODE
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_PYB_cb, &USR_cb);
//USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_PYB_HID_cb, &USR_cb);
+#endif
}
rx_buf_in = 0;
rx_buf_out = 0;
@@ -76,7 +83,9 @@
void usb_vcp_send_strn(const char *str, int len) {
if (is_enabled) {
+#ifdef USE_DEVICE_MODE
VCP_fops.pIf_DataTx((const uint8_t*)str, len);
+#endif
}
}
@@ -84,14 +93,17 @@
/* These are external variables imported from CDC core to be used for IN
transfer management. */
+#ifdef USE_DEVICE_MODE
extern uint8_t APP_Rx_Buffer []; /* Write CDC received data in this buffer.
These data will be sent over USB IN endpoint
in the CDC core functions. */
extern uint32_t APP_Rx_ptr_in; /* Increment this pointer or roll it back to
start address when writing received data
in the buffer APP_Rx_Buffer. */
+#endif
void usb_vcp_send_strn_cooked(const char *str, int len) {
+#ifdef USE_DEVICE_MODE
for (const char *top = str + len; str < top; str++) {
if (*str == '\n') {
APP_Rx_Buffer[APP_Rx_ptr_in] = '\r';
@@ -100,10 +112,13 @@
APP_Rx_Buffer[APP_Rx_ptr_in] = *str;
APP_Rx_ptr_in = (APP_Rx_ptr_in + 1) & (APP_RX_DATA_SIZE - 1);
}
+#endif
}
void usb_hid_send_report(uint8_t *buf) {
+#ifdef USE_DEVICE_MODE
USBD_HID_SendReport(&USB_OTG_dev, buf, 4);
+#endif
}
/******************************************************************************/
@@ -114,6 +129,7 @@
#include "lib-otg/usbh_core.h"
#include "lib-otg/usbh_usr.h"
#include "lib-otg/usbh_hid_core.h"
+#include "lib-otg/usb_hcd_int.h"
__ALIGN_BEGIN USBH_HOST USB_Host __ALIGN_END ;
@@ -127,8 +143,14 @@
host_is_enabled = 1;
}
-void pyb_usbh_process(void) {
+mp_obj_t pyb_usbh_process(void) {
USBH_Process(&USB_OTG_dev, &USB_Host);
+ return mp_const_none;
+}
+
+mp_obj_t pyb_usbh_connect(void) {
+ USBH_HCD_INT_fops->DevConnected(&USB_OTG_dev);
+ return mp_const_none;
}
#endif // USE_HOST_MODE