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

Post here all questions related to STM32 core if you can't find a relevant section!
User avatar
fpiSTM
Posts: 1754
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: SerialUSB doesn't work on Maple Mini

Post by fpiSTM »

In your log, after the reset it switches to bootloader.
Ralf9
Posts: 33
Joined: Sat Jan 11, 2020 7:21 pm
Answers: 1
Location: Germany, BaWü

Re: SerialUSB doesn't work on Maple Mini

Post 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
Ralf9
Posts: 33
Joined: Sat Jan 11, 2020 7:21 pm
Answers: 1
Location: Germany, BaWü

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

Post 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
User avatar
fpiSTM
Posts: 1754
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

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

Post 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
Ralf9
Posts: 33
Joined: Sat Jan 11, 2020 7:21 pm
Answers: 1
Location: Germany, BaWü

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

Post 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 ?
stas2z
Posts: 131
Joined: Mon Feb 24, 2020 8:17 pm
Answers: 8

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

Post 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
User avatar
fpiSTM
Posts: 1754
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

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

Post 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
Ralf9
Posts: 33
Joined: Sat Jan 11, 2020 7:21 pm
Answers: 1
Location: Germany, BaWü

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

Post 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
User avatar
fpiSTM
Posts: 1754
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

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

Post by fpiSTM »

Souns really strange.... :shock:
I have no idea why...seems like the weak function is not called.
Ralf9
Posts: 33
Joined: Sat Jan 11, 2020 7:21 pm
Answers: 1
Location: Germany, BaWü

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

Post 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
Post Reply

Return to “General discussion”