From c46ba6bbb30ff2172b14fa5728a7863b3199581f Mon Sep 17 00:00:00 2001 From: BlackMark Date: Sat, 11 Apr 2020 16:51:09 +0200 Subject: [PATCH] Move code to bootloader section and provide custom init code --- stk500v2/main.cpp | 20 +++- stk500v2/stk500v2.cppproj | 230 ++++++++++++++++++++------------------ 2 files changed, 138 insertions(+), 112 deletions(-) diff --git a/stk500v2/main.cpp b/stk500v2/main.cpp index 375dc62..67af69b 100644 --- a/stk500v2/main.cpp +++ b/stk500v2/main.cpp @@ -3,6 +3,7 @@ #include "uart/uart.hpp" #include +#include #include #include "command.hpp" @@ -282,7 +283,7 @@ static inline void formatErrorAnswer(Message &msg) static inline void handleMessage(Message &msg) { - static uint32_t s_address = 0; + static uint32_t s_address; if (isSignOn(msg)) formatSignOnAnswer(msg); @@ -328,14 +329,23 @@ int main() { serial.init(); - Message msg; + static Message s_msg; while (true) { - if (receiveMessage(msg)) { - handleMessage(msg); - transmitMessage(msg); + if (receiveMessage(s_msg)) { + handleMessage(s_msg); + transmitMessage(s_msg); } } return 0; } + +void startup() __attribute__((naked, section(".vectors"))); +void startup() +{ + asm volatile("clr __zero_reg__"); + // SP = RAMEND; + SREG = 0; + asm volatile("jmp main"); +} diff --git a/stk500v2/stk500v2.cppproj b/stk500v2/stk500v2.cppproj index f1fc821..38008b3 100644 --- a/stk500v2/stk500v2.cppproj +++ b/stk500v2/stk500v2.cppproj @@ -93,122 +93,138 @@ Simulator + + + + - -mmcu=atmega328p - True - True - True - True - False - True - True - - - NDEBUG - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include - - - Optimize for size (-Os) - True - True - True - True - -fno-threadsafe-statics -std=c11 - True - True - - - NDEBUG - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include - - - Optimize for size (-Os) - True - True - True - -fno-threadsafe-statics -Wextra -std=c++17 - - - libm - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include - - - + -mmcu=atmega328p + True + True + True + True + False + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include + + + Optimize for size (-Os) + True + True + True + True + -fno-threadsafe-statics -std=c11 + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include + + + Optimize for size (-Os) + True + True + True + -fno-threadsafe-statics -Wextra -std=c++17 + True + + + libm + + + + + .text=0x3800 + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include + + + - -mmcu=atmega328p - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include - - - Optimize (-O1) - True - Maximum (-g3) - True - True - True - -fno-threadsafe-statics -std=c11 - True - True - - - DEBUG - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include - - - Optimize (-O1) - True - Maximum (-g3) - True - True - -fno-threadsafe-statics -Wextra -std=c++17 - - - libm - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include - - - Default (-Wa,-g) - + -mmcu=atmega328p + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include + + + Optimize (-O1) + True + Maximum (-g3) + True + True + True + -fno-threadsafe-statics -std=c11 + True + True + + + DEBUG + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include + + + Optimize debugging experience (-Og) + True + Maximum (-g3) + True + True + -fno-threadsafe-statics -Wextra -std=c++17 + True + + + libm + + + + + .text=0x3800 + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.4.346\include + + + Default (-Wa,-g) +