Page 4 of 5

Re: SerialUSB doesn't work on Maple Mini

Posted: Mon Apr 13, 2020 10:58 am
by fpiSTM
In your log, after the reset it switches to bootloader.

Re: SerialUSB doesn't work on Maple Mini

Posted: Mon Apr 13, 2020 11:05 am
by Ralf9
In your log, after the reset it switches to bootloader.
With the bootloader2.0 the testsketch is after the reset running (the LED is blinking), only the USB will not be initialised

Re: SerialUSB doesn't work on Maple Mini and Bootloader2.0

Posted: Fri Apr 17, 2020 9:37 pm
by Ralf9
the way it looks is in the bootloader20 a error.

The error on Bootloader 2.0 is that USB is not disconnected when leaving the Bootloader.
This means that there is no renewed enumeration of the CDC device.

one possibility is to patch the bootloader20
https://github.com/rogerclarkmelbourne/ ... are.c#L208

Code: Select all

void jumpToUser(u32 usrAddr) {

    /* tear down all the dfu related setup */
    // disable usb interrupts, clear them, turn off usb, set the disc pin
    // todo pick exactly what we want to do here, now its just a conservative
    flashLock();
    usbDsbISR();
    nvicDisableInterrupts();

#ifndef HAS_MAPLE_HARDWARE
    usbDsbBus();
#else
    gpio_write_bit(USB_DISC_BANK,USB_DISC_PIN,1);
#endif

// Does nothing, as PC12 is not connected on teh Maple mini according to the schemmatic     setPin(GPIOC, 12); // disconnect usb from host. todo, macroize pin
    systemReset(); // resets clocks and periphs, not core regs

    setMspAndJump(usrAddr);
}

Or you can disconnect the connection short in the setup part from the sketch

Code: Select all

void setup() {
   pinMode(D34, OUTPUT);
   digitalWrite(D34,1);
   delay(100);
   digitalWrite(D34, 0);

see also here
https://github.com/rogerclarkmelbourne/ ... /issues/91

Re: SerialUSB doesn't work on Maple Mini and Bootloader2.0

Posted: Sun Apr 19, 2020 5:40 am
by fpiSTM
It seems stange as the core already handle the reenum:
https://github.com/stm32duino/Arduino_C ... d_if.c#L19
This will change in the 1.9.0 to be more compliant with USB specs
https://github.com/stm32duino/Arduino_C ... b57dc5b4b6
anyway still one issue to fix for hardware which does not follow the spec:
https://github.com/stm32duino/Arduino_C ... ssues/1029

Re: SerialUSB doesn't work on Maple Mini and Bootloader2.0

Posted: Sun Apr 19, 2020 6:43 am
by Ralf9
Have you for me until the core 1.9.0 a better workaround than add this to my sketch?

Code: Select all

void setup() {
   pinMode(D34, OUTPUT);
   digitalWrite(D34,1);
   delay(100);
   digitalWrite(D34, 0);
Can I fix it directly in the cores/arduino/stm32/usb/usbd_if.c ?

Re: SerialUSB doesn't work on Maple Mini and Bootloader2.0

Posted: Sun Apr 19, 2020 7:27 am
by stas2z
Ralf9 wrote: Sun Apr 19, 2020 6:43 am Have you for me until the core 1.9.0 a better workaround than add this to my sketch?

Code: Select all

void setup() {
   pinMode(D34, OUTPUT);
   digitalWrite(D34,1);
   delay(100);
   digitalWrite(D34, 0);
Can I fix it directly in the cores/arduino/stm32/usb/usbd_if.c ?
This piece of code is for different core

Re: SerialUSB doesn't work on Maple Mini and Bootloader2.0

Posted: Sun Apr 19, 2020 7:44 am
by fpiSTM
Rafl9
Main issue is why you get issue, sveral other user (including me) does not have this issue.
So, it seems in your case the reenum does not have the expected effect, call too earlier? Delay should be increased?

You can override the core reenum function as it is a weak one or increase the delay as th delay is a definition wchich can be rederfined

Re: SerialUSB doesn't work on Maple Mini and Bootloader2.0

Posted: Sun Apr 19, 2020 10:40 am
by Ralf9
I have it tested, when I put this file "USBD_reenumerate.c" in my sketch directory, than it works with the bootloader2.0 also after a reset

Code: Select all

#include "usbd_if.h"
#include "usbd_cdc_if.h"

#if ARDUINO < 10900

void USBD_reenumerate(void)
{
#ifndef USBD_REENUM_DISABLED
  /* Re-enumerate the USB */
#ifdef USB_DISC_PIN
  pinMode(USB_DISC_PIN, OUTPUT);
  digitalWrite(USB_DISC_PIN, HIGH);
  delay(10);
  digitalWrite(USB_DISC_PIN, LOW);
#else
#ifdef USE_USB_HS_IN_FS
  PinName pinDP = USB_OTG_HS_DP;
#elif defined(USB_OTG_FS)
  PinName pinDP = USB_OTG_FS_DP;
#else /* USB */
  PinName pinDP =  USB_DP;
#endif
  pin_function(pinDP, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0));
  digitalWriteFast(pinDP, LOW);
  delay(USBD_ENUM_DELAY);
  pin_function(pinDP, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
  /*delay(USBD_ENUM_DELAY);*/
#endif /* USB_DISC_PIN */
#endif /* USBD_REENUM_DISABLED */
}

#endif

Re: SerialUSB doesn't work on Maple Mini and Bootloader2.0

Posted: Sun Apr 19, 2020 11:23 am
by fpiSTM
Souns really strange.... :shock:
I have no idea why...seems like the weak function is not called.

Re: SerialUSB doesn't work on Maple Mini and Bootloader2.0

Posted: Sun Apr 19, 2020 7:11 pm
by Ralf9
so that the USBD_reenumerate with the bootloader2.0 works,
the USB_DISC_PIN must be set to high once and then to low again

if I change the usbd_if.c in the core 1.8.0, the USBD_reenumerate works too

I have this as a test
stm32/1.8.0/cores/arduino/stm32/usb/usbd_if.c

Code: Select all

#ifdef USB_DISC_PIN
  pinMode(USB_DISC_PIN, OUTPUT);
  digitalWrite(USB_DISC_PIN, LOW);
#else
changed in

Code: Select all

#ifdef USB_DISC_PIN
  pinMode(USB_DISC_PIN, OUTPUT);
  digitalWrite(USB_DISC_PIN, HIGH);
  delay(10);
  digitalWrite(USB_DISC_PIN, LOW);
#else