Skip to main content
Associate
August 25, 2026
Question

FX_DRIVER_BOOT_WRITE bug in fx_stm32_sd_driver.c

  • August 25, 2026
  • 5 replies
  • 78 views

Hello,

I ran into a bug in fx_stm32_sd_driver function.

Our firmware was calling fx_media_volume_set on a partitioned card and we found it was corrupting the disk. The issue is  that the FX_DRIVER_BOOT_WRITE case statement hardcodes the boot sector to be at sector number 0. This works for unpartitioned (superfloppy) layouts, but does not work on partitioned SD cards with a master boot record. Calling fx_media_volume_set on a partitioned drive overwrites the MBR instead of the boot sector and corrupts the disk.

Note that the FX_DRIVER_BOOT_READ, which also has to manage this problem correctly calculates the offset using the _fx_partition_offset_calculate function.

Regards,

Mike

5 replies

ST Technical Moderator
August 26, 2026

Hello ​@mike5 

Could you please specify the middleware version you are using, as well as the MCU series?

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om
mike5Author
Associate
August 26, 2026

Hello ​@Saket_Om 

The MCU is the STM32U585.

The STM32CubeU5 SDK version is Release v1.8.0. This version incorporates FileX version 6.4.0.

I checked STM32CubeU5 version 1.9.0 in GitHub. This appears to be the latest release tag and the FileX code I referred to above is unchanged in that version.

 

Regards,

Mike

ST Technical Moderator
August 27, 2026

Hello ​@mike5 

Thank you for bringing this issue to our attention.

I reported this internally.

Internal ticket number: CDM0065364 (This is an internal tracking number and is not accessible or usable by customers).

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om
ST Technical Moderator
September 1, 2026

Hello ​@mike5 

Could you please share your project so that we can reproduce the issue on our side?

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om
mike5Author
Associate
September 7, 2026

Hello,

I can’t provide the project source code because I’m a consultant and the code belongs to one of my customers, but I can provide the steps you would need to reproduce it.

First you need an SD card that is partitioned. If the you take a blank SD card or one that is unpartitioned and just reformat it with Windows quick format you will end up with a single volume (superfloppy) format and no partition table and the code described below will not corrupt it, so you need to ensure that your SD card has a Master Boot Record with a partition table. On Windows you can use the diskpart tool in an admin level Powershell to create this.

Inside diskpart run these commands (NOTE! clean will wipe any file system away so make sure you have selected SD card disk before running the clean command)

list disk
select disk <N> # replace <N> with your SD card's disk number
clean
create partition primary align=4096
format fs=fat32 quick
assign letter=E
list partition # confirm Offset is 4096 KB (= LBA 8192), not 0 B
exit
The output from list partition should show something like:
 
Partition ###  Type     Size      Offset
------------- ------- -------- -------
* Partition 1 Primary 7576 MB 4096 KB

The key is that the offset of the partition is non-zero, so that the partitions boot sector is not the same as sector 0 on the disk.

The above commands will create a partitioned disk with a single volume. FileX has no trouble reading and working with partitioned volumes because STM SD driver that provides the FX_DRIVER_BOOT_READ function does extra work to determine where the volumes root sector is before reading it instead of assuming it’s at sector 0. This is the code that is missing from the  FX_DRIVER_BOOT_WRITE case which assumes it’s always at sector 0, and so overwrites the Master Boot Record.
 
Once you have the partitioned disk, you just need a minimal FileX project that calls fx_media_volume_set on the disk (after opening the media and any other required initialization). Then the media can be flushed and removed from the device. After that, if you put that SD card back into a Windows machine and run chkdsk on it, it will show the corruption.

Kind regards,

Mike