I am trying to continue with freeRTOS examples from the STM32 Beginners book. I am trying to make the CDCserial example work compiled from platformio. Currently if I compile with the authors make file, the file easily fits in the 20k bluePill RAM, but when compiled in platformio, the ram is 21kb - 688 bytes too much. It appears the solution for this is the use of newlib.
It seems like maybe I need a separate target.json file, or some way to specify more linker config? As usual, any help is greatly appreciated!
Archiving .pio\build\genericSTM32F103CB\libFrameworkLibOpenCM3.a
Indexing .pio\build\genericSTM32F103CB\libFrameworkLibOpenCM3.a
Linking .pio\build\genericSTM32F103CB\firmware.elf
.pio\build\genericSTM32F103CB\lib2e3\newlib\newlib\libc\string\strcasecmp.o: In function `strcasecmp':
strcasecmp.c:(.text.strcasecmp+0xa): undefined reference to `__locale_ctype_ptr'
strcasecmp.c:(.text.strcasecmp+0x20): undefined reference to `__locale_ctype_ptr'
.pio\build\genericSTM32F103CB\lib898\rtos\tasks.o: In function `vTaskSwitchContext':
tasks.c:(.text.vTaskSwitchContext+0x26): undefined reference to `vApplicationStackOverflowHook'
.pio\build\genericSTM32F103CB\libef7\getline\getline.o: In function `getline':
getline.c:(.text.getline+0x28): undefined reference to `getc'
getline.c:(.text.getline+0x44): undefined reference to `__assert_func'
getline.c:(.text.getline+0x4c): undefined reference to `malloc'
getline.c:(.text.getline+0x6a): undefined reference to `realloc'
.pio\build\genericSTM32F103CB\src\adventure.o: In function `adventure':
adventure.c:(.text.adventure+0xee): undefined reference to `__locale_ctype_ptr'
adventure.c:(.text.adventure+0x116): undefined reference to `__locale_ctype_ptr'
adventure.c:(.text.adventure+0x178): undefined reference to `__locale_ctype_ptr'
adventure.c:(.text.adventure+0x21e): undefined reference to `__locale_ctype_ptr'
adventure.c:(.text.adventure+0x37a): undefined reference to `__locale_ctype_ptr'
.pio\build\genericSTM32F103CB\src\adventure.o:adventure.c:(.text.adventure+0x416): more undefined references to `__locale_ctype_ptr' follow
.pio\build\genericSTM32F103CB\src\main.o: In function `main':
main.c:(.text.startup.main+0x48): undefined reference to `xQueueCreateMutex'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\genericSTM32F103CB\firmware.elf] Error 1
This article and the linked project code seem to solve the issue I am facing, but I am not sure how the target.json file is composed in relation to platformio.ini.
The following link also deals with this specific question, but I am not experienced enough with the toolchain to really make actionable decisions yet.
Thanks. I have actually discovered there is a bunch of variables that effect final file size. However my main confusion was that FreeRTOS pre-requisitions all of the RAM you make available to it’s stack - so I was seeing 99.7% RAM usage and that was a normal thing. Interesting to learn ARM-NONE-EABI 9.x has a different compiled file size from 7.x, but not surprising given what compilers do.
I will dig through your links and see if they help.
Thanks a lot for your continued help Max, people like you make DIY fun instead of a rabbit hole. Happy New Years!
Unfortunately changing the number of tasks stacks/size in freeRTOSconfig did not make my out of RAM problem go away. I have not yet figured out how to reduce RAM usage, but also have not dug too deep.
All I have done is copy it into platformio and used the platformio.ini I have pasted in the initial comment.
I have bigger problems than this at the moment though, which I will mention briefly now in case anyone reading has any advice:
When I try to use libopencm3 USART alongside libopencm3 USB HID or use USB HID in FreeRTOS, I get errorless crashes. Neither works. I am assuming it is interrupt priorities or something similar. I am not skilled enough to write USB HID software without a debug output console, and that means without USART being viable along side USB HID, I simply am stuck. If there is a way to use the PIO universal debugger to actually debug these things, it is failing for me. The debugger simply runs forever when my software crashes. I do not know how to figure out where it has crashed. I need print statements and to see if they are spit out or not.
About to give up on libopencm3 because it has no dedicated forum and everywhere I’ve asked for help with it, people just get mad that you are asking for help with someone elses software. There is zero community for libopencm3.
I am going to start another, more general thread here asking for advice I think, maybe some experienced devs will find it in their heart to comment and advise! I am struggling to understand how to use USB HID while I have interrupts going off from buttons and encoders. I can move everything to polling\loops, but I really am reluctant to continue changing my working ‘main program code’ until I have a platform figured out that will let me have a Composite HID device of Joystick\Keyboard, alongside a standard USART output for debugging! It really is sad the libopencm3 HID library does not seem to play alongside USART!
If it will help I can put up my whole platformio project attempting to compile the CDC example here. I really dont want to abandon platformio, it is a very nice user experience and I’ve now spent a month learning some of it’s basic-intermediate ins and outs! Moving to attolic in particular is not appealing. Same with spending a ton of $ on IAR or Keil.
Thanks again for your ongoing help. If I seem exasperated it isn’t with you! I know this is all my own shortcomings.
Import("env", "projenv")
for e in [ env, projenv ]:
#
# Fix options after "_bare.py"
#
e.Replace(LINKFLAGS = [i for i in e['LINKFLAGS'] if i not in [ '-nostartfiles', '-nostdlib' ]])
e.Append(LINKFLAGS = [ "--specs=nano.specs", "--specs=nosys.specs" ])
e.Replace(AS = '$CC', ASCOM = '$ASPPCOM')
#
# .ld script should be passed to linker directly as "-T<path>"
# instead of "-Wl,-T<path>", to avoid 1K RAM loss for ".data.impure_data"
#
e.Replace(BUILD_FLAGS = [i for i in e['BUILD_FLAGS'] if not i.startswith('-Wl,-T')])
e.Replace(LINKFLAGS = [(i[4:] if i.startswith('-Wl,-T') else i) for i in e['LINKFLAGS']])
Nothing hardcoded, everything configurable from .ini