2024-06-11 04:53 AM
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.
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).
test print:
(it stops printing after this)
Solved! Go to Solution.
2024-06-12 03:01 AM
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!
2024-06-12 03:01 AM
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!