usb_pump thread does not restore after chSysDisable/Enable

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
tsichevski
Posts: 35
Joined: Fri Feb 09, 2018 12:44 am
Has thanked: 2 times
Been thanked: 5 times

usb_pump thread does not restore after chSysDisable/Enable

Postby tsichevski » Fri Oct 26, 2018 1:51 pm

Hi all,

I use ChibiOS_17.6.3
I use power STOP mode to save power on my battery-powered device.
I shut my system down and restart it according to the recommendations here: http://www.chibios.org/dokuwiki/doku.ph ... s:kb:power
Everything goes well, but I noticed that the thread named "usb_pump" does not reappear after system has restarted.

The driver sources say that this thread can only be started once:

Code: Select all

#if defined(_CHIBIOS_RT_)
    /* Creates the data pump thread. Note, it is created only once.*/
    if (usbp->tr == NULL) {
      thread_descriptor_t usbpump_descriptor = {
        "usb_pump",
        THD_WORKING_AREA_BASE(usbp->wa_pump),
        THD_WORKING_AREA_END(usbp->wa_pump),
        STM32_USB_OTG_THREAD_PRIO,
        usb_lld_pump,
        (void *)usbp
      };

      usbp->tr = chThdCreateI(&usbpump_descriptor);
      chSchRescheduleS();
  }
#endif


The sources also say "This function must be executed by a system thread in order to make the USB driver work."

My question is: how can I restart this thread after returning from STOP mode?

Regards,
Vladimir

PS: I notices this system thread disappeared in ChibiOS 18.2.1 code.

User avatar
Giovanni
Site Admin
Posts: 13115
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 765 times
Been thanked: 647 times
Contact:

Re: usb_pump thread does not restore after chSysDisable/Enable

Postby Giovanni » Fri Oct 26, 2018 3:25 pm

Hi,

It depends on what you do before entering STOP and after leaving it. Try stopping/starting the USB driver.

Anyway, it would be better to migrate to 18.x.

Giovanni

tsichevski
Posts: 35
Joined: Fri Feb 09, 2018 12:44 am
Has thanked: 2 times
Been thanked: 5 times

Re: usb_pump thread does not restore after chSysDisable/Enable

Postby tsichevski » Fri Oct 26, 2018 5:47 pm

> Try stopping/starting the USB driver.
I do this. This does not affect the usb_pump thread. There is no means to stop it nicely either.
As a workaround, I zero the USBD1.tr field after the RT is stopped by chSysDisable().

Regards,
Vladimir

User avatar
Giovanni
Site Admin
Posts: 13115
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 765 times
Been thanked: 647 times
Contact:

Re: usb_pump thread does not restore after chSysDisable/Enable

Postby Giovanni » Fri Oct 26, 2018 7:11 pm

The thread does not stop by itself, do you restart the OS using chSysInit()?

Giovanni

tsichevski
Posts: 35
Joined: Fri Feb 09, 2018 12:44 am
Has thanked: 2 times
Been thanked: 5 times

Re: usb_pump thread does not restore after chSysDisable/Enable

Postby tsichevski » Fri Oct 26, 2018 10:01 pm

Yes, my main() looks like this:

Code: Select all

  for(;;) {
    chSysInit();
    ...initialize app threads and periphery
    chThdWait(... the main control loop thread);
    ...stop app threads and shutdown periphery
   
    chSysDisable();
    // stop the system timer
    STM32_ST_TIM->CR1 &= ~(TIM_CR1_CEN);
    nvicDisableVector(STM32_TIM2_NUMBER);
    chSysEnable();

    ...go power stop mode

    chSysDisable();
  }

User avatar
Giovanni
Site Admin
Posts: 13115
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 765 times
Been thanked: 647 times
Contact:

Re: usb_pump thread does not restore after chSysDisable/Enable

Postby Giovanni » Sat Oct 27, 2018 2:49 am

If RAM content is preserved then you should not re-initialize the RTOS, just enable the systick timer again, Probably you could also not terminate other threads.

Giovanni

tsichevski
Posts: 35
Joined: Fri Feb 09, 2018 12:44 am
Has thanked: 2 times
Been thanked: 5 times

Re: usb_pump thread does not restore after chSysDisable/Enable

Postby tsichevski » Sat Oct 27, 2018 11:20 am

Thanks, Giovanni, I will give it a try.


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 1 guest