2025-04-18 1:39 AM - last edited on 2025-04-18 1:43 AM by mƎALLEm
I am using STMF103CBT6 the problem is nothing gets written to the specified address
void SIM800C_HTTP_GetAndWrite(char *url, uint32_t flashAddress) {
SIM800C_SendCommand("AT+HTTPINIT\r\n");
HAL_Delay(500);
SIM800C_SendCommand("AT+HTTPPARA=\"CID\",1\r\n");
HAL_Delay(500);
char httpParaUrl[100];
sprintf(httpParaUrl, "AT+HTTPPARA=\"URL\",\"%s\"\r\n", url);
SIM800C_SendCommand(httpParaUrl);
HAL_Delay(500);
SIM800C_SendCommand("AT+HTTPACTION=0\r\n"); // Start GET
HAL_Delay(5000);
// Read the +HTTPACTION result
char actionResponse[64] = {0};
HAL_UART_Receive(&huart1, (uint8_t *)actionResponse, sizeof(actionResponse), 2000);
// Extract data length
int dataLen = 0;
sscanf(actionResponse, "+HTTPACTION: 0,200,%d", &dataLen);
if (dataLen <= 0 || dataLen > MAX_FILE_SIZE) {
Error_Handler(); // Invalid size
}
HAL_FLASH_Unlock();
for (uint32_t offset = 0; offset < dataLen; offset += CHUNK_SIZE) {
int thisChunkSize = (dataLen - offset > CHUNK_SIZE) ? CHUNK_SIZE : (dataLen - offset);
char readCmd[32];
sprintf(readCmd, "AT+HTTPREAD=%lu,%d\r\n", offset, thisChunkSize);
SIM800C_SendCommand(readCmd);
HAL_Delay(1000);
memset(chunkBuffer, 0xFF, sizeof(chunkBuffer));
HAL_UART_Receive(&huart1, chunkBuffer, thisChunkSize, HAL_MAX_DELAY);
// Write chunk to flash
for (int i = 0; i < thisChunkSize; i += 4) {
uint32_t word = 0xFFFFFFFF;
memcpy(&word, chunkBuffer + i, (thisChunkSize - i >= 4) ? 4 : (thisChunkSize - i));
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, flashAddress + offset + i, word) != HAL_OK) {
Error_Handler();
}
}
}
HAL_FLASH_Lock();
SIM800C_SendCommand("AT+HTTPTERM\r\n");
}
2025-04-18 1:42 AM
Hello @ortegar23 and welcome to the ST community,
Please review how to post a thread in this community.
Thank you.
2025-04-18 2:04 AM
uint32_t word = 0xFFFFFFFF;
memcpy(&word, chunkBuffer + i, (thisChunkSize - i >= 4) ? 4 : (thisChunkSize - i));
this maybe dont work. word in compiler is placed into reg no mem , then memcpy ... and try ask better we dont see error result or question ...
2025-04-18 2:12 AM
For this type of unique set up, expect to have to instrument and debug your own work.
Understand what's happening.
Don't expect single stepping to work helpfully.
Memory must be erased, you get one chance to write. Address must be within Flash and at word aligned address.
Test by writing into RAM or dumping to console. Test Flash writing code independently.
2025-04-18 8:05 AM
There's a lot in that code about SIM800, HTTP, etc.
Get rid of such extra complications - just focus on getting the Flash writes working.
Once that's thoroughly tested - and only then - move on adding the comms stuff.