cancel
Showing results for 
Search instead for 
Did you mean: 

STL flash test failing

heveskar
Senior

I do not know if this is appropriate place to ask but I will try. We are integrating the STM STL library and we cannot get the flash test to be successful.

This, this, this nor this helped. I believe we are generating the checksums correctly, we tried either post-build step as recommended in the user manual or running the script separately in the CMD. We can see that the CRCs are written in the memory the same way they are written in the .elf. StlFlashStatus is being set to STL_FAILED every time.

Our MCU is STM32H723ZG with 1 MB of flash. Therefore in the configuration, ROM start address is set to 0x08000000UL and ROM end address is set to 0x080FFFFFUL. We are trying flow similar to the default examples, either single test or multiple tests. ROM start address is set to 0x08000000U, even when trying to check 1 flash section, StlFlashStatus is set to STL_FAILED.

Unfortunately we do not have Nucleo H743ZI to test the example project, however we tried the 'G4 variant using Nucleo-G474RE and it worked, so I believe that software settings from our side are correct.

Any ideas what could be wrong?

I have one additional question/clarification, does SW CRC differ from HW CRC calculation-wise? In the utilities there is a CRC function that seems to be doing just a XOR of the input data, which is not the same as the CRC peripheral does, no?

 @Petr Sladecek @Amel NASRI 

EDIT: I forgot that we are using the X-CUBE-STL library

1 ACCEPTED SOLUTION

Accepted Solutions
Petr Sladecek
ST Employee

Hello,

I confirm the problem comes from code alignment applied by GCC compiler and linker making unexpectedly gaps between the code sections due to different alignment control what results at default filling of these gaps. This default filling is done differently by GCC compiler and STM32CubeProgrammer used to calculate and make content (CRC results) of the Flash CRC descriptor field as a consequence. Different alignment usually happen when STL is combined with another code or FW (e.g. it was observed after implementation of floating point arithmetic). We strongly suggest to inspect the compiled binary file by IDE build analyzer and verify and detect if any discontinuity appears at the code binary. If the binary file is not continuous, STL works (and all CRC check sums match) only if it is downloaded by the STM32CubeProgrammer but not by e.g. STM32CubeIDE debugger applying the GCC ELF output file and so different default filling of the gaps between the not aligned code sections. Solution is to modify the linker scatter file and force unique alignment of all the sections eliminating these gaps. We met cases when even forcing alignment 8 was not enough to protect this issue.

We haven't observe such a problem at IAR or KEIL compilers so far and its occurrence is still under our investigation.

Best regards,

Petr

View solution in original post

9 REPLIES 9
heveskar
Senior

Update, so now it seems that only the first section (1024 B starting at 0x8000000) fails, but other sections work (STL_PASSED). Still have no idea what can be causing this.

heveskar
Senior

It was caused by the fact that .isr_vector size was not divisible by 8 so that before the next aligned section, there was an empty word that was throwing off the CRC calculation.

awiernie
Senior II

It seems that I have the same problem. How did you solve the problem that the .isr_vector size was not divisible by 8? 

heveskar
Senior

Sorry I did not mention the full solution in the original comment. I fixed it in the linker by changing the alignment to 8:

  .isr_vector :
  {
    . = ALIGN(8);
    KEEP(*(.isr_vector)) /* Startup code */
    . = ALIGN(8);
  } >FLASH

 

We had already tried this and it worked for the first blocks of flash. But later it fails again. We had set all align to 8.

I wonder why one should change align to 8.

The self-test library user guide says only that the binary has to be aligned to 4 bytes.

If the problem comes from uninitialised fill bytes in the gaps between alignment, setting it to 8 bytes would make it even worse as more fill bytes are introduced. 

Do you know why the alignment has to be 8?

I thought that alignment helps because fill bytes now become part of the section and it no longer throws the CRC calculation off. Why it has to be 8 I do not know. Integration tips application note seems to suggest that the calculation tool changes the binary in such a way that problems with the end address alignment are not present, but obviously it doen't work correctly.

I thought that changing <pattern> value for the safety lib command to 0xFF would maybe help, but when I did that the resulting elf was not even valid.

Furthermore, I seem to recall that I had to keep the .init_array and .fini_array sections at alignment 4, else the CRC check did not work (or maybe the whole app did not work, I am not sure now).

heveskar
Senior

Actually, I looked at this again and I forgotten that I had knew where the original problem was. For me the culprit is, that when there is that 4-byte "gap" between .isr_vector and .text sections (on my device at address 0x80202cc), even though in the .elf this is filled with 0x00000000 (or it seems so from the STM32CubeProgrammer):

heveskar_0-1708681054377.png

When loaded to the device, there is actually uninitialized memory 0xffffffff:

heveskar_1-1708681108199.png

This is why the CRCs do not match as the safety lib command probably uses 0x00000000 for the calculation. It seems to me that .text section is somehow forced to be aligned to 8 bytes, (even though it is not specified in the linker) and that's where this gap is created when .isr_vector section is not long enough. Maybe you have this similar problem between other sections? I forced all the flash sections' start and end address to alignment 8 (except .init_array and .fini_array as I mentioned before) and all is working correctly for me.

 

PS: IDE memory details for clarity: heveskar_2-1708681258698.png

and working configuration: heveskar_5-1708682491550.png

 

 

 

Now it works for me. My CPU was not in stl_user_templacte.c and I had written the wrong STL_ROM_END_ADDR.

Therefore the flash test expected the crc table on a different flash address.

It works with both, alignment of 4 and also of 8. With alignment 8 there are additional fill bytes, but in both versions all are zero in .elf file and also in flash memory after upload.

 

The other project first only worked with alignment 8 but after switching back to 4 it works also. Don't know why, maybe there was another

Petr Sladecek
ST Employee

Hello,

I confirm the problem comes from code alignment applied by GCC compiler and linker making unexpectedly gaps between the code sections due to different alignment control what results at default filling of these gaps. This default filling is done differently by GCC compiler and STM32CubeProgrammer used to calculate and make content (CRC results) of the Flash CRC descriptor field as a consequence. Different alignment usually happen when STL is combined with another code or FW (e.g. it was observed after implementation of floating point arithmetic). We strongly suggest to inspect the compiled binary file by IDE build analyzer and verify and detect if any discontinuity appears at the code binary. If the binary file is not continuous, STL works (and all CRC check sums match) only if it is downloaded by the STM32CubeProgrammer but not by e.g. STM32CubeIDE debugger applying the GCC ELF output file and so different default filling of the gaps between the not aligned code sections. Solution is to modify the linker scatter file and force unique alignment of all the sections eliminating these gaps. We met cases when even forcing alignment 8 was not enough to protect this issue.

We haven't observe such a problem at IAR or KEIL compilers so far and its occurrence is still under our investigation.

Best regards,

Petr