From 7b5d679c66636d4f6768a4e0dfa1ddea3884c12f Mon Sep 17 00:00:00 2001 From: vintagepc <53943260+vintagepc@users.noreply.github.com> Date: Tue, 20 Apr 2021 13:42:55 -0400 Subject: [PATCH] Add "debugcore" option for more flash space on 2560 (#304) * Add debugchip option for more flash space on 2560 --- MK404.cpp | 16 +++++++++++++++- parts/Board.cpp | 9 +++++---- parts/PinSpec.h | 4 ++-- parts/pinspecs/PinSpec_2560.h | 3 +++ utility/Config.h | 5 +++++ 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/MK404.cpp b/MK404.cpp index 8bf79d5a..5ce0a1e3 100644 --- a/MK404.cpp +++ b/MK404.cpp @@ -338,8 +338,10 @@ int main(int argc, char *argv[]) std::vector vstrExts = PrintVisualType::GetOpts(); ValuesConstraint vcPrintOpts(vstrExts); ValueArg argExtrusion("","extrusion","Set Print visual type. HR options create a LOT of triangles, do not use for large prints!",false, "Line", &vcPrintOpts, cmd); + SwitchArg argDebugCore("","debugcore","Uses a debug version of the chip with more flash space. Board-dependent.", cmd); MultiSwitchArg argDebug("d","debug","Increases debugging output, where supported.", cmd); SwitchArg argColourE("", "colour-extrusion", "Colours extrusion by width (for advanced step/extrusion debugging.", cmd, false); + ValueArg argStrBoot("","bootloader-file", "Specifies a .hex file to load as the bootloader. If empty, ("") no bootloader is loaded, if unspecified the default is used.",false,"stk500boot_v2_mega2560.hex","string",cmd); SwitchArg argBootloader("b","bootloader","Run bootloader on first start instead of going straight to the firmware.",cmd); SwitchArg argMD("","markdown","Used to auto-generate the items in refs/ as markdown",cmd); @@ -364,6 +366,8 @@ int main(int argc, char *argv[]) bool bArgHacks = argNoHacks.isSet() || argKlipper.isSet() || argMarlin.isSet(); bool bArgSkew = argSkew.isSet() || argKlipper.isSet(); Config::Get().SetSkewCorrect(bArgSkew); + + Config::Get().SetDebugCore(argDebugCore.isSet()); // Make new image. if (argImgSize.isSet()) { @@ -402,8 +406,18 @@ int main(int argc, char *argv[]) strFW = argFW.getValue(); } + if (!argStrBoot.isSet()) + { + std::cout << "No bootloader specified, using default: " << argStrBoot.getValue() << '\n'; + } else if (argStrBoot.getValue().empty()) + { + std::cout << "Empty bootloader filename provided. NOT loading a bootloader.\n"; + } else { + std::cout << "Using Bootloader: " << argStrBoot.getValue() << '\n'; + } + void *pRawPrinter = PrinterFactory::CreatePrinter(argModel.getValue(),pBoard,printer,argBootloader.isSet(),bArgHacks,argSerial.isSet(), argSD.getValue() , - strFW,argSpam.getValue(), argGDB.isSet(), argVCDRate.getValue(),"stk500boot_v2_mega2560.hex"); // this line is the CreateBoard() args. + strFW,argSpam.getValue(), argGDB.isSet(), argVCDRate.getValue(),argStrBoot.getValue()); // this line is the CreateBoard() args. pBoard->SetPrimary(true); // This is the primary board, responsible for scripting/dispatch. Blocks contention from sub-boards, e.g. MMU. diff --git a/parts/Board.cpp b/parts/Board.cpp index 9b80a393..16b5ae09 100644 --- a/parts/Board.cpp +++ b/parts/Board.cpp @@ -338,12 +338,13 @@ namespace Boards { } gsl::span chunk0 {pChunks[0].data, pChunks[0].size}; uint32_t uiFWStart = pChunks[0].baseaddr; - if (iCount > 1) { - pChunks[1].baseaddr = 0; // Want to start at 0 in the flash chip, but after hex read this is end-of-firmware. + if (iCount > 1) + { gsl::span spanChunks {pChunks, gsl::narrow(iCount)}; - for (int i=1; i 2) { - OnExtraHexChunk({spanChunks.at(i).data,spanChunks.at(i).size},spanChunks.at(i).baseaddr); + std::cout << "Note: Hex file contains extra chunks, only 2 of " << std::to_string(iCount) << " were used.\n"; } } std::cout << "Loaded " << chunk0.size_bytes() << " bytes from HEX file: " << strFW << '\n'; diff --git a/parts/PinSpec.h b/parts/PinSpec.h index 44ef201c..d2427f07 100644 --- a/parts/PinSpec.h +++ b/parts/PinSpec.h @@ -29,7 +29,7 @@ class PinSpec { PinSpec(gsl::spanpin2port, gsl::spanpin2Mask, gsl::spanpin2Timer,const std::string &strMCU): m_pDPin2Port(pin2port),m_pDPin2Mask(pin2Mask),m_pDPin2Timer(pin2Timer),m_strMCU(strMCU) { - std::cout << "Creating pinspec for" << strMCU << '\n'; + std::cout << "Creating pinspec for " << strMCU << '\n'; }; // Returns a char representation of the port, e.g. 'A' @@ -46,7 +46,7 @@ class PinSpec { // Returns the MCU this spec is for. Used to designate the // CPU in a board using this pinspec. - inline std::string GetMCUName() const { return m_strMCU; } + virtual inline std::string GetMCUName() const { return m_strMCU; } protected: // Set these in your derived class constructor args to pointer diff --git a/parts/pinspecs/PinSpec_2560.h b/parts/pinspecs/PinSpec_2560.h index fa8f7162..67071a1d 100755 --- a/parts/pinspecs/PinSpec_2560.h +++ b/parts/pinspecs/PinSpec_2560.h @@ -24,6 +24,7 @@ #pragma once #include "PinSpec.h" +#include "Config.h" #include "PinSpec_Helper.h" class PinSpec_2560 : public PinSpec @@ -33,6 +34,8 @@ class PinSpec_2560 : public PinSpec public: PinSpec_2560():PinSpec(DPin2Port,DPin2Mask,DPin2Timer,"atmega2560"){}; + std::string GetMCUName() const { return Config::Get().GetDebugCore()?"atmega404":m_strMCU; }; + private: const unsigned char DPin2Timer[86] = { diff --git a/utility/Config.h b/utility/Config.h index e26b8781..47176d12 100644 --- a/utility/Config.h +++ b/utility/Config.h @@ -48,10 +48,15 @@ class Config inline void SetLCDScheme(uint8_t iVal){ m_iScheme = iVal;} inline uint8_t GetLCDScheme(){ return m_iScheme;} + // Use a "debug" core? (board-specific) + inline void SetDebugCore(bool bVal){ m_bDebugCore = bVal;} + inline bool GetDebugCore(){ return m_bDebugCore;} + private: unsigned int m_iExtrusion = false; bool m_bColorExtrusion = false; bool m_bSkew = false; uint8_t m_iScheme = 0; + bool m_bDebugCore = false; };