Local variable overwrite global variable
Hi,
I'm facing a problem in the managing of local variables on STM32WB50CG with the STM32CubeIDE version 1.14.1.
Specifically, the code must perform a write via the sprintf function on a local variable (allocated at address 0x20009bd8).
ALL the writings are performed correctly but during the execution of the same sprintf, a memory area in which a global variable is allocated (address 0x20009708) is also overwritten with the same data without generating any interrupt in MemManage_Handler.
At the end of the execution of DiagnosticPktCreator I obtained the correct string inside the datafifo but the same string is also present at address 0x20009708.
Any ideas on why this occurs?
void DiagnosticPacketGenerator(void){
char datafifo[MAX_PACKET_SIZE];
uint16_t fifosize;
static uint32_t PTimeOld_Diagnostic;
uint8_t i = 0;
memset(datafifo,0,MAX_PACKET_SIZE);
PTimeOld_Diagnostic=(HAL_GetTick()/1000)-PTimeOld_Diagnostic;
while(i < GetSystemVariable().ValvesNumber)
{
/*Diagnostic packet after update (8) or direct reply (0)*/
if(GetDiagnosticEnable()==3)
DiagnosticPktCreator(&datafifo[0], &fifosize, 8, PTimeOld_Diagnostic, &i);
else
DiagnosticPktCreator(&datafifo[0], &fifosize, 0, PTimeOld_Diagnostic, &i);
FIFO_Packet_handler_opt(FIFO_PUSH, (uint8_t*)&datafifo[0], &fifosize);
i++;
}
PTimeOld_Diagnostic=(HAL_GetTick())/1000;
}
void DiagnosticPktCreator(char* data, uint16_t* data_size, uint8_t PacketType, uint32_t PTime, uint8_t* idx){
strcpy(data,"{pkt_9:");
uint16_t packet_len;
/*function that adds informations to the packet*/
Key_DB(&data[strlen(data)],PacketType, PTime);
Identifying_DB(&data[strlen(data)]);
Diagnostic_DB(&data[strlen(data)]);
strcpy(&data[strlen(data)],"}}");
*data_size=strlen(data);
}
void Key_DB(char* data, uint8_t PacketType, uint32_t Time ){ sprintf(data,"{\"key\":\"%u,%s,%lu,%s,%u,%u\"",GetSystemVariable().PacketCounter,GetSystemVariable().Datetime,Time,GetConnection_info().IMEI,GetSystemVariable().Bootcode,PacketType);
}
void Identifying_DB(char* data){
sprintf(data,",\"id\":\"%s,%s\"",GetConnection_info().ICCID,GetConnection_info().Cell_info);
}
void Diagnostic_DB(char* data){
sprintf(data,",\"diagnostic\":\"%u,%s,%.f,%u,%s\"",GetSystemVariable().EDStatus,GetConnection_info().Cell_pwr,GetSystem_Acquisition().Voltage,GetSystem_Acquisition().Frequency,FW_VERSION);
}
Thank you in advance.
Davide Graziani