Skip to main content
FShah.1
Associate III
October 22, 2024
Question

STM32F446RE CRC mismatch

  • October 22, 2024
  • 3 replies
  • 2331 views

Hi, I am following a video to write a bootloader that transfers the application code serially into the STM32F446 controller. The video originally presents the STM32F7xx series controller, but I am applying it to the F4xxx series. I have modified the code as needed, such as assigning the proper flash areas for the bootloader and application code. See the GitHub link for this tutorial.

https://github.com/Embetronicx/STM32-Bootloader/tree/ETX_Bootloader_3.0/Bootloader_Example

This link also provides a PC tool that transfers the code from the host to the controller once the handshaking is complete.

What are the recommendations if I want to calculate the CRC32 on a PC that matches the CRC32 calculated on the STM32F446 using HAL_CRC_Calculate()?

My code gives 0x08b329c8 and host calculated CRC is 0x4e08bfb4?

3 replies

Tesla DeLorean
Guru
October 22, 2024

So posted three times on this topic.

STM32's standard algo operates on whole 32-bit words, in a right shifting word sense, which is not normative for little-endian platforms. See my code here

https://github.com/cturvey/RandomNinjaChef/blob/main/stm32crc.c

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
FShah.1
FShah.1Author
Associate III
October 22, 2024

@Tesla DeLorean 

Thank you for your response. I appreciate all the work done by community members, when I see a useful and understandable post, I add my question.

Should I use the code you linked on the host to calculate the CRC? Sorry if I'm asking a simple question!

Tesla DeLorean
Guru
October 22, 2024

Well, I'd start with your test pattern to affirm the calculation on PC vs the one you've got on the STM32

Most on-line calculators use more normative byte-wise computations.

On the F4 the CRC peripheral has a fixed form, which is 32-bit words. You can use the code to compute the equivalent for word aligned / word length multiples.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
FShah.1
FShah.1Author
Associate III
December 2, 2024

I checked the memory regions where the code is being written and identified an issue with how the data was being written to the flash memory—specifically, little-endian / big-endian issue. After addressing this, the application is now successfully loading and working.

Thanks for being responsive. I will reach out to you for assistance with other parts of the bootloader process during my development.

Thanks again,
FS

FShah.1
FShah.1Author
Associate III
December 2, 2024

Noted. I made these changes, and the code is still working. Please have a look and let me know if this is what you meant.

static void goto_application(void)
{

	
	printf("Gonna Jump to Application\r\n");

	// Set the Vector Table Offset Register (VTOR) to the address of the application
	SCB->VTOR = ETX_APP_FLASH_ADDR;
	// Get the application reset handler address
	void (*app_reset_handler)(void) = (void*)(*((volatile uint32_t*) (ETX_APP_FLASH_ADDR + 4U)));//Application starting address
	// Optionally turn off the LED
	HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
	__set_MSP(*(volatile uint32_t*) ETX_APP_FLASH_ADDR);
	/* Jump to application */
	app_reset_handler(); //call the app reset handler
}