diff --git a/stk500v2/command.hpp b/stk500v2/command.hpp new file mode 100644 index 0000000..68742a1 --- /dev/null +++ b/stk500v2/command.hpp @@ -0,0 +1,113 @@ +#pragma once + +#include + +////////////////////////////////////////////////////////////////////////// +// STK message constants + +static constexpr uint8_t MESSAGE_START = 0x1B; // ASCII ESC +static constexpr uint8_t TOKEN = 0x0E; + +////////////////////////////////////////////////////////////////////////// +// STK general command constants + +static constexpr uint8_t CMD_SIGN_ON = 0x01; +static constexpr uint8_t CMD_SET_PARAMETER = 0x02; +static constexpr uint8_t CMD_GET_PARAMETER = 0x03; +static constexpr uint8_t CMD_SET_DEVICE_PARAMETERS = 0x04; +static constexpr uint8_t CMD_OSCCAL = 0x05; +static constexpr uint8_t CMD_LOAD_ADDRESS = 0x06; +static constexpr uint8_t CMD_FIRMWARE_UPGRADE = 0x07; + +////////////////////////////////////////////////////////////////////////// +// STK ISP command constants + +static constexpr uint8_t CMD_ENTER_PROGMODE_ISP = 0x10; +static constexpr uint8_t CMD_LEAVE_PROGMODE_ISP = 0x11; +static constexpr uint8_t CMD_CHIP_ERASE_ISP = 0x12; +static constexpr uint8_t CMD_PROGRAM_FLASH_ISP = 0x13; +static constexpr uint8_t CMD_READ_FLASH_ISP = 0x14; +static constexpr uint8_t CMD_PROGRAM_EEPROM_ISP = 0x15; +static constexpr uint8_t CMD_READ_EEPROM_ISP = 0x16; +static constexpr uint8_t CMD_PROGRAM_FUSE_ISP = 0x17; +static constexpr uint8_t CMD_READ_FUSE_ISP = 0x18; +static constexpr uint8_t CMD_PROGRAM_LOCK_ISP = 0x19; +static constexpr uint8_t CMD_READ_LOCK_ISP = 0x1A; +static constexpr uint8_t CMD_READ_SIGNATURE_ISP = 0x1B; +static constexpr uint8_t CMD_READ_OSCCAL_ISP = 0x1C; +static constexpr uint8_t CMD_SPI_MULTI = 0x1D; + +////////////////////////////////////////////////////////////////////////// +// STK PP command constants + +static constexpr uint8_t CMD_ENTER_PROGMODE_PP = 0x20; +static constexpr uint8_t CMD_LEAVE_PROGMODE_PP = 0x21; +static constexpr uint8_t CMD_CHIP_ERASE_PP = 0x22; +static constexpr uint8_t CMD_PROGRAM_FLASH_PP = 0x23; +static constexpr uint8_t CMD_READ_FLASH_PP = 0x24; +static constexpr uint8_t CMD_PROGRAM_EEPROM_PP = 0x25; +static constexpr uint8_t CMD_READ_EEPROM_PP = 0x26; +static constexpr uint8_t CMD_PROGRAM_FUSE_PP = 0x27; +static constexpr uint8_t CMD_READ_FUSE_PP = 0x28; +static constexpr uint8_t CMD_PROGRAM_LOCK_PP = 0x29; +static constexpr uint8_t CMD_READ_LOCK_PP = 0x2A; +static constexpr uint8_t CMD_READ_SIGNATURE_PP = 0x2B; +static constexpr uint8_t CMD_READ_OSCCAL_PP = 0x2C; + +static constexpr uint8_t CMD_SET_CONTROL_STACK = 0x2D; + +////////////////////////////////////////////////////////////////////////// +// STK HVSP command constants + +static constexpr uint8_t CMD_ENTER_PROGMODE_HVSP = 0x30; +static constexpr uint8_t CMD_LEAVE_PROGMODE_HVSP = 0x31; +static constexpr uint8_t CMD_CHIP_ERASE_HVSP = 0x32; +static constexpr uint8_t CMD_PROGRAM_FLASH_HVSP = 0x33; +static constexpr uint8_t CMD_READ_FLASH_HVSP = 0x34; +static constexpr uint8_t CMD_PROGRAM_EEPROM_HVSP = 0x35; +static constexpr uint8_t CMD_READ_EEPROM_HVSP = 0x36; +static constexpr uint8_t CMD_PROGRAM_FUSE_HVSP = 0x37; +static constexpr uint8_t CMD_READ_FUSE_HVSP = 0x38; +static constexpr uint8_t CMD_PROGRAM_LOCK_HVSP = 0x39; +static constexpr uint8_t CMD_READ_LOCK_HVSP = 0x3A; +static constexpr uint8_t CMD_READ_SIGNATURE_HVSP = 0x3B; +static constexpr uint8_t CMD_READ_OSCCAL_HVSP = 0x3C; + +////////////////////////////////////////////////////////////////////////// +// STK status constants + +// Success +static constexpr uint8_t STATUS_CMD_OK = 0x00; + +// Warnings +static constexpr uint8_t STATUS_CMD_TOUT = 0x80; +static constexpr uint8_t STATUS_RDY_BSY_TOUT = 0x81; +static constexpr uint8_t STATUS_SET_PARAM_MISSING = 0x82; + +// Errors +static constexpr uint8_t STATUS_CMD_FAILED = 0xC0; +static constexpr uint8_t STATUS_CKSUM_ERROR = 0xC1; +static constexpr uint8_t STATUS_CMD_UNKNOWN = 0xC9; + +////////////////////////////////////////////////////////////////////////// +// STK parameter constants +static constexpr uint8_t PARAM_BUILD_NUMBER_LOW = 0x80; +static constexpr uint8_t PARAM_BUILD_NUMBER_HIGH = 0x81; +static constexpr uint8_t PARAM_HW_VER = 0x90; +static constexpr uint8_t PARAM_SW_MAJOR = 0x91; +static constexpr uint8_t PARAM_SW_MINOR = 0x92; +static constexpr uint8_t PARAM_VTARGET = 0x94; +static constexpr uint8_t PARAM_VADJUST = 0x95; +static constexpr uint8_t PARAM_OSC_PSCALE = 0x96; +static constexpr uint8_t PARAM_OSC_CMATCH = 0x97; +static constexpr uint8_t PARAM_SCK_DURATION = 0x98; +static constexpr uint8_t PARAM_TOPCARD_DETECT = 0x9A; +static constexpr uint8_t PARAM_STATUS = 0x9C; +static constexpr uint8_t PARAM_DATA = 0x9D; +static constexpr uint8_t PARAM_RESET_POLARITY = 0x9E; +static constexpr uint8_t PARAM_CONTROLLER_INIT = 0x9F; + +////////////////////////////////////////////////////////////////////////// +// STK answer constants + +static constexpr uint8_t ANSWER_CKSUM_ERROR = 0xB0; diff --git a/stk500v2/main.cpp b/stk500v2/main.cpp index f0552a4..65eebe2 100644 --- a/stk500v2/main.cpp +++ b/stk500v2/main.cpp @@ -2,6 +2,8 @@ #include "uart/uart.hpp" +#include "command.hpp" + using uart_interface = uart::Hardware0, uart::Driven::BLOCKING>; int main() diff --git a/stk500v2/stk500v2.cppproj b/stk500v2/stk500v2.cppproj index 6c553f9..f1fc821 100644 --- a/stk500v2/stk500v2.cppproj +++ b/stk500v2/stk500v2.cppproj @@ -215,6 +215,9 @@ compile + + compile + compile