cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 read from flash breaks freertos.

WilliamVR
Associate III

Hi, 

 

This is a weird one. When my controller starts up, it is supposed to read the flash and use this data to check if my lwip should start up in DHCP mode or with a static IP adres.

When I don't read from flash, this code works fine, when I do read from flash It breaks after a while.

Anyone any ideas?

 

I have tried debugging en have found that he kinda gets stuck in queue.c on line 1794. But I don't understand how these are related.

WilliamVR_2-1718106796722.png

 

This is my code: 

void StartDefaultTask(void const * argument)
{
	/* init code for LWIP */
	MX_LWIP_Init();
	/* USER CODE BEGIN 5 */

	readFromFlash(&configIRIS);
	osPrintf("debug", "read form flash");

	//restart with static
	if(configIRIS.ETHuseDHCP == 0){
		customInitLwip();
	}

	//init netconn
	http_server_netconn_init();

	//debug message
	osPrintf("INIT", "LWIP_TASK");

	//init flag
	lwipInitFlag = 1;

	//clear busy led
	HAL_GPIO_WritePin(MCL_GREEN_GPIO_Port, MCL_GREEN_Pin, 0);

	/* Infinite loop */
	for(;;)
	{
		//debug print ip adres
		snprintf(debugMain, sizeof(debugMain), "IP address: %s", ip4addr_ntoa(&gnetif.ip_addr));
		osPrintf("LWIP",debugMain);

		//chk for reset button
		if(HAL_GPIO_ReadPin(M_RESET_GPIO_Port, M_RESET_Pin) == GPIO_PIN_RESET){
			customInitLwipWithDHCP();
		}

		//	Heartbeat
		heartbeat();

		//delay
		osDelay(1);
	}

read from flash function:

void readFromFlash(IRISConfigstr* IRISstruct) {
	uint32_t flashAddress = 0x080E0000; // Ensure flashAddress is initialized correctly

	// Ensure that the pointer is valid before waiting for the mutex
	if (IRISstruct == NULL) {
		return;
	}

	// Wait indefinitely to acquire the mutex
	if (osMutexWait(FLASH_MUETXHandle, osWaitForever) == osOK) {

		// Make pointer to the structure
		uint32_t* ptr = (uint32_t*)IRISstruct;

		// Calculate the number of uint32_t members in the struct
		size_t numMembers = sizeof(IRISConfigstr) / sizeof(uint32_t);

		// Loop through each member of the struct and read from flash
		for (size_t i = 0; i < numMembers; i++) {
			// Read data from flash
			*ptr = *(__IO uint32_t*)flashAddress;

			// Move to the next flash address
			flashAddress += sizeof(uint32_t);

			// Move to the next uint32_t member
			ptr++;
		}

		//memcpy(IRISstruct, (void*)flashAddress, sizeof(IRISConfigstr));

		// Release the mutex after the operation
		osMutexRelease(FLASH_MUETXHandle);
	} else {
		// Handle error if the mutex cannot be acquired
		osPrintf("ERROR","Failed to acquire the flash mutex");
	}
}

I have modified my linker so I can write to sector 11 (I use a the STM32F407 controller).

WilliamVR_1-1718106658676.pngtest print:

(it stops printing after this)

WilliamVR_0-1718106598884.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
WilliamVR
Associate III

 

Oké I fixed it haha,

A bit embarrassing, but when you read from the flash memory you read 0xFF... everywhere.
Another one of my interfaces was using this to try to initialize and failing drastically.

But its fixed now!

 

View solution in original post

1 REPLY 1
WilliamVR
Associate III

 

Oké I fixed it haha,

A bit embarrassing, but when you read from the flash memory you read 0xFF... everywhere.
Another one of my interfaces was using this to try to initialize and failing drastically.

But its fixed now!