Skip to content

Commit 7480a15

Browse files
committed
leven: reenable usb on demand
user needs to call __USBStart(); SerialUSB.begin(115200); in the sketch. To perform another uplaod, double click the reset button Former-commit-id: 2ba1796
1 parent 3ca73f0 commit 7480a15

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

cores/arduino/Arduino.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,6 @@ float analogReference();
117117
#endif
118118

119119
#include "pins_arduino.h"
120+
#include "usb/USB.h"
120121

121122
#endif //__ARDUINO__H__

cores/arduino/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "Arduino.h"
2-
#include "usb/USB.h"
32
#include "cm_backtrace/cm_backtrace.h"
43

54
/* TODO: make me configurable by the variant */

cores/arduino/usb/USB.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1616
*/
1717

18-
#if !defined(USE_TINYUSB) && !defined(NO_USB)
19-
2018
#include <Arduino.h>
2119
#include "IRQManager.h"
2220
#include "USB.h"
@@ -296,6 +294,8 @@ extern "C" {
296294
void tud_set_irq_usbhs(IRQn_Type q);
297295
}
298296

297+
__attribute__((weak)) void configure_usb_mux() {}
298+
299299
void __USBStart() {
300300
USBIrqCfg_t usb_irq_cfg;
301301

@@ -304,6 +304,8 @@ void __USBStart() {
304304
return;
305305
}
306306

307+
configure_usb_mux();
308+
307309
/*
308310
* ENABLE USB
309311
*/
@@ -419,8 +421,4 @@ extern "C" __attribute((weak)) void tud_msc_capacity_cb(uint8_t lun, uint32_t*
419421
extern "C" __attribute((weak)) int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize) {
420422

421423
return -1;
422-
}
423-
424-
425-
426-
#endif
424+
}

variants/SANTIAGO_COMPOSTA/variant.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ extern "C" const PinMuxCfg_t g_pin_cfg[] = {
124124
{ BSP_IO_PORT_02_PIN_13, P213 }, /* (38) D38 */
125125

126126
{ BSP_IO_PORT_05_PIN_00, P500 }, /* (39) Analog voltage measure pin */
127+
{ BSP_IO_PORT_04_PIN_08, P408 }, /* (40) USB switch, drive high for RA4 */
127128
};
128129

129130
extern "C" const size_t g_pin_cfg_size = sizeof(g_pin_cfg);
@@ -140,6 +141,19 @@ int32_t getPinIndex(bsp_io_port_pin_t p) {
140141
return rv;
141142
}
142143

144+
#define BSP_PRV_PRCR_KEY (0xA500U)
145+
#define BSP_PRV_PRCR_PRC1_UNLOCK ((BSP_PRV_PRCR_KEY) | 0x2U)
146+
#define BSP_PRV_PRCR_LOCK ((BSP_PRV_PRCR_KEY) | 0x0U)
147+
// if _USBStart is called, this will swap the USB port over the ESP one
148+
void configure_usb_mux() {
149+
R_SYSTEM->PRCR = (uint16_t) BSP_PRV_PRCR_PRC1_UNLOCK;
150+
(*((volatile uint32_t *) &R_SYSTEM->VBTBKR[1])) = 12;
151+
R_SYSTEM->PRCR = (uint16_t) BSP_PRV_PRCR_LOCK;
152+
153+
pinMode(40, OUTPUT);
154+
digitalWrite(40, HIGH);
155+
}
156+
143157
#include "FspTimer.h"
144158

145159
void initVariant() {

0 commit comments

Comments
 (0)