Unable to run SRAM/QSPI software on bootloader from PlatformIO

hello everyone! i’ve been hard at work trying to get the STM32Cube framework to compile in PlatformIO with libDaisy and DaisySP, which has been requiring me to rewrite the Makefiles into PIO config files, and i’ve run into a little hurdle.

recently i’ve successfully uploaded a working 1kHz sine tone program to the internal flash memory (yay!) after a lot of trouble trying to figure out how to use the libDaisy HAL drivers instead of those PIO installs for you (since they aren’t the same, and compiling with the latter will run you into weird errors), and decided to add some more functionalities in order to be able to upload to the SRAM or QSPI memory through the bootloader. to do so, i’ve written a little Python script that sets the linker script and adds the -DBOOT_APP flag according to a custom option set in the main .ini file. however, i’m noticing that, first of all, the program size seems to be considerably heavier than when using the usual Makefile process (110kb through PIO, 70kb through Makefile); weirdly enough, this isn’t the case when uploading to flash. also, the program doesn’t run, as the bootloader sends an SOS signal to the onboard LED.

would anyone be able to take a look at my code and see where i’m going wrong? i feel like something’s missing in my build chain, but at this point i’m not really sure what that could be and some help would be appreciated.
here’s the repository i’m working from: GitHub - netherwaves/daisyseed_template
it adds libDaisy and DaisySP as submodules; i’ve linked both to forks where i was able to add JSON files for proper compilation in PlatformIO.
here is the Python code where i decide which linker script to use:

BOOT_TYPE = env.GetProjectOption("boot_type")
LD_PATH = os.path.join(env.get('PROJECT_DIR'), 'lib/libDaisy/core/STM32H750IB_%s.lds' % BOOT_TYPE)
board_config.update("build.ldscript", LD_PATH)

if BOOT_TYPE == 'flash':
    board_config.update("upload.offset_address", '0x08000000')

elif BOOT_TYPE == 'sram':
    board_config.update("upload.offset_address", '0x90040000')
    env.Append(CFLAGS=['-DBOOT_APP'])

elif BOOT_TYPE == 'qspi':
    board_config.update("upload.offset_address", '0x90040000')
    env.Append(CFLAGS=['-DBOOT_APP'])

i figured it out! for some reason changing the board configuration from Python didn’t change anything; however, i was able to apply the correct linker script by adding it as a link flag like so:

env.Append(
    LINKFLAGS=[
        ...

        '-Wl,--gc-sections',
        '-Wl,--print-memory-usage',
        '-Wl,-Tlib/libDaisy/core/STM32H750IB_%s.lds' % BOOT_TYPE
    ]
)

although i’m getting a warning message from PlatformIO saying that '-Wl,-T' option for specifying linker scripts is deprecated, but it seems to work regardless! i’m guessing the dynamic ldscript assignment in Python is related to a bug and might have to do with PIO…

in any case i’m now getting the correct memory distribution for QSPI:

Memory region         Used Size  Region Size  %age Used
           FLASH:          0 GB       128 KB      0.00%
         DTCMRAM:          0 GB       128 KB      0.00%
            SRAM:       16316 B       512 KB      3.11%
      RAM_D2_DMA:         16 KB        32 KB     50.00%
          RAM_D2:          0 GB       256 KB      0.00%
          RAM_D3:          0 GB        64 KB      0.00%
         ITCMRAM:          0 GB        64 KB      0.00%
           SDRAM:          0 GB        64 MB      0.00%
       QSPIFLASH:       60280 B      7936 KB      0.74%

and the .bin file is appropriately sized as well! and it runs on the Seed :3
next step is figuring out how to include the FatFS sources in the compilation with a custom option …

2 Likes

I’m glad to hear that you figured it out!
And thank you for sharing the solution :slight_smile: