Skip to content

Including STM32FreeRTOS Crashes Board #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cversek opened this issue Mar 23, 2023 · 2 comments
Closed

Including STM32FreeRTOS Crashes Board #58

cversek opened this issue Mar 23, 2023 · 2 comments

Comments

@cversek
Copy link

cversek commented Mar 23, 2023

I am very new to stm32duino ecosystem and also new to FreeRTOS, but am an experienced Arduino user. I'm using an Adafruit Feather STM32F405 on Arduino 1.8.13 and used the library manager to download STM32FreeRTOS v10.3.1. I was unable to use any of the simple examples for this library without the USB CDC driver crashing and the device locking up. I modified the basic Arduino blink sketch to include just the following line and a similar problem is happening:

#include <STM32FreeRTOS.h>

I'm using Ubuntu 22.04.2 LTS (kernel 5.19.0-35-generic) and here is some of the typical dmesg output:

[ 9166.881885] usb 1-6: USB disconnect, device number 40
[ 9167.431336] usb 1-6: new full-speed USB device number 41 using xhci_hcd
[ 9167.581006] usb 1-6: New USB device found, idVendor=0483, idProduct=5740, bcdDevice= 0.00
[ 9167.581022] usb 1-6: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 9167.581029] usb 1-6: Product: FEATHER_F405 CDC in FS Mode
[ 9167.581035] usb 1-6: Manufacturer: STMicroelectronics
[ 9167.581040] usb 1-6: SerialNumber: 2078326B4D31
[ 9169.435126] usb 1-6: can't set config #1, error -71

and trying again

[ 9169.435328] usb 1-6: USB disconnect, device number 41
[ 9169.955274] usb 1-6: new full-speed USB device number 42 using xhci_hcd
[ 9170.105547] usb 1-6: New USB device found, idVendor=0483, idProduct=5740, bcdDevice= 0.00
[ 9170.105561] usb 1-6: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 9170.105567] usb 1-6: Product: FEATHER_F405 CDC in FS Mode
[ 9170.105572] usb 1-6: Manufacturer: STMicroelectronics
[ 9170.105577] usb 1-6: SerialNumber: 2078326B4D31
[ 9175.232019] usb 1-6: can't set config #1, error -110
[ 9177.519498] usb 1-6: USB disconnect, device number 42
[ 9177.983322] usb 1-6: new full-speed USB device number 43 using xhci_hcd
[ 9178.133660] usb 1-6: New USB device found, idVendor=0483, idProduct=5740, bcdDevice= 0.00
[ 9178.133675] usb 1-6: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 9178.133683] usb 1-6: Product: FEATHER_F405 CDC in FS Mode
[ 9178.133688] usb 1-6: Manufacturer: STMicroelectronics
[ 9178.133693] usb 1-6: SerialNumber: 2078326B4D31

With the frBlink sketch the LED flashes twice and then stays on. Here is the Arduino 1.8.13 debugging output:

Sketch uses 32472 bytes (3%) of program storage space. Maximum is 1048576 bytes.
Global variables use 4644 bytes (3%) of dynamic memory, leaving 126428 bytes for local variables. Maximum is 131072 bytes.
      -------------------------------------------------------------------
                        STM32CubeProgrammer v2.13.0                  
      -------------------------------------------------------------------



USB speed   : Full Speed (12MBit/s)
Manuf. ID   : STMicroelectronics
Product ID  : STM32  BOOTLOADER
SN          : 2078326B4D31
DFU protocol: 1.1
Board       : --
Device ID   : 0x0413
Device name : STM32F405xx/F407xx/F415xx/F417xx
Flash size  : 1 MBytes (default)
Device type : MCU
Revision ID : --  
Device CPU  : Cortex-M4


Memory Programming ...
Opening and parsing file: frBlink.ino.bin
  File          : frBlink.ino.bin
  Size          : 32.14 KB 
  Address       : 0x08000000 


Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 2]
erasing sector 0000 @: 0x08000000 done
erasing sector 0001 @: 0x08004000 done
erasing sector 0002 @: 0x08008000 done
Download in Progress:


File download complete
Time elapsed during download operation: 00:00:01.735

RUNNING Program ... 
  Address:      : 0x8000000
Start operation achieved successfully
Board at /dev/ttyACM0 is not available
Board at /dev/ttyACM0 is not available
Board at /dev/ttyACM0 is not available

Thanks.

@fpistm
Copy link
Member

fpistm commented Mar 24, 2023

Hi @cversek
when you include STM32FreeRTOS, it changes some core behavior mainly around the systick handler that's why it crashes as you do not launch the scheduler:

/*
* IMPORTANT:
* SysTick_Handler() from stm32duino core is calling weak osSystickHandler().
* Both CMSIS-RTOSv2 and CMSIS-RTOS override osSystickHandler()
* which is calling xPortSysTickHandler(), defined in respective CortexM-x port
*/

About USB you probably need to change the default MEMMANG, see
#29

This library is provided "as is", it is a port as Arduino library from official ST FreeRTOS and could required several configurations from user.

@cversek
Copy link
Author

cversek commented Mar 24, 2023

@fpistm
I can confirm that uncommenting this line fixes both the USB CDC driver issue and the frBlink example:
https://github.com/stm32duino/STM32FreeRTOS/blob/10.3.1/src/FreeRTOSConfig_Default.h#L49
Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants