diff --git a/stk500v2/main.cpp b/stk500v2/main.cpp index 499b4ab..a5fa85a 100644 --- a/stk500v2/main.cpp +++ b/stk500v2/main.cpp @@ -450,10 +450,8 @@ constexpr ChipEraseState &operator|=(ChipEraseState &self, const ChipEraseState return self; } -static inline void handleMessage(Message &msg, ChipEraseState &chipEraseFlag) +static inline void handleMessage(Message &msg, uint32_t &addr, ChipEraseState &chipEraseFlag) { - static uint32_t s_address; - if (isSignOn(msg)) formatSignOnAnswer(msg); else if (isGetParameter(msg)) @@ -469,20 +467,20 @@ static inline void handleMessage(Message &msg, ChipEraseState &chipEraseFlag) else if (isReadLockIsp(msg)) formatReadLockIspAnswer(msg); else if (isLoadAddress(msg)) { - s_address = msg.body[1]; - s_address = (s_address << 8) | msg.body[2]; - s_address = (s_address << 8) | msg.body[3]; - s_address = (s_address << 8) | msg.body[4]; + addr = msg.body[1]; + addr = (addr << 8) | msg.body[2]; + addr = (addr << 8) | msg.body[3]; + addr = (addr << 8) | msg.body[4]; formatLoadAddressAnswer(msg); } else if (isReadFlashIsp(msg)) - formatReadFlashIspAnswer(msg, s_address); + formatReadFlashIspAnswer(msg, addr); else if (isReadEepromIsp(msg)) - formatReadEepromIspAnswer(msg, s_address); + formatReadEepromIspAnswer(msg, addr); else if (isChipEraseIsp(msg)) { chipEraseFlag = ChipEraseState::REQUEST; formatChipEraseIspAnswer(msg); } else if (isProgramEepromIsp(msg)) - formatProgramEepromIspAnswer(msg, s_address); + formatProgramEepromIspAnswer(msg, addr); else if (isLeaveProgmodeIsp(msg)) { chipEraseFlag |= ChipEraseState::RESPONSE; formatLeaveProgmodeIspAnswer(msg); @@ -502,11 +500,12 @@ int main() serial.init(); Message msg; + uint32_t addr = 0x0000; ChipEraseState chipEraseFlag = ChipEraseState::NONE; while (true) { if (receiveMessage(msg)) { - handleMessage(msg, chipEraseFlag); + handleMessage(msg, addr, chipEraseFlag); } }