Skip to content

Commit

Permalink
Release v5.0.0-alpha4
Browse files Browse the repository at this point in the history
  • Loading branch information
Prusa Research authored and dragomirecky committed Jul 18, 2023
1 parent 35e2ec1 commit 82deea9
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 72 deletions.
7 changes: 4 additions & 3 deletions include/marlin/Configuration_MK4.h
Original file line number Diff line number Diff line change
Expand Up @@ -1444,13 +1444,14 @@

// Homing speeds (mm/m)
#ifdef HAS_LDO_400_STEP
#define HOMING_FEEDRATE_XY (62 * 60)
#include "hw_configuration.hpp"
#define HOMING_FEEDRATE_XY buddy::hw::Configuration::Instance().has_trinamic_oscillators() ? (80 * 60) : (62 * 60)
#else
#define HOMING_FEEDRATE_XY (62 * 60)//(150 * 60)
#define HOMING_FEEDRATE_XY (80 * 60)//(150 * 60)
#endif

#define HOMING_FEEDRATE_Z (8 * 60)
#define HOMING_FEEDRATE_INVERTED_Z (30 * 60)
#define HOMING_FEEDRATE_INVERTED_Z buddy::hw::Configuration::Instance().has_trinamic_oscillators() ? (60 * 60) : (30 * 60)

// Validate that endstops are triggered on homing moves
//#define VALIDATE_HOMING_ENDSTOPS
Expand Down
9 changes: 6 additions & 3 deletions include/marlin/Configuration_MK4_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,8 @@
#if EITHER(SENSORLESS_HOMING, SENSORLESS_PROBING)
#if X_DRIVER_TYPE == TMC2130
#if defined(HAS_LDO_400_STEP)
#define X_STALL_SENSITIVITY -2
#include "hw_configuration.hpp"
#define X_STALL_SENSITIVITY buddy::hw::Configuration::Instance().has_trinamic_oscillators() ? (int16_t) -4 : (int16_t) -2
#else
#define X_STALL_SENSITIVITY 3
#endif
Expand All @@ -1817,7 +1818,8 @@

#if Y_DRIVER_TYPE == TMC2130
#if defined(HAS_LDO_400_STEP)
#define Y_STALL_SENSITIVITY -2
#include "hw_configuration.hpp"
#define Y_STALL_SENSITIVITY buddy::hw::Configuration::Instance().has_trinamic_oscillators() ? (int16_t) -4 : (int16_t) -2
#else
#define Y_STALL_SENSITIVITY 3
#endif
Expand All @@ -1826,7 +1828,8 @@
#endif

#if Z_DRIVER_TYPE == TMC2130
#define Z_STALL_SENSITIVITY 3
#include "hw_configuration.hpp"
#define Z_STALL_SENSITIVITY buddy::hw::Configuration::Instance().has_trinamic_oscillators() ? (int16_t) 1 : (int16_t) 3
#elif Z_DRIVER_TYPE == TMC2209
#define Z_STALL_SENSITIVITY 100
#endif
Expand Down
12 changes: 6 additions & 6 deletions src/buddy/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ extern "C" void main_cpp(void) {
hw_gpio_init();
hw_dma_init();

// must do this before timer 1
// timer 1 interrupt calls Configuration
#if BOARD_IS_XBUDDY
buddy::hw::Configuration::Instance();
#endif

#if BOARD_IS_BUDDY || BOARD_IS_XBUDDY
hw_tim1_init();
#endif
Expand Down Expand Up @@ -587,6 +581,12 @@ extern "C" void startup_task(void const *) {
init_stores();
taskEXIT_CRITICAL();

// must do this before timer 1, timer 1 interrupt calls Configuration
// also must be before initializing global variables
#if BOARD_IS_XBUDDY
buddy::hw::Configuration::Instance();
#endif

// init global variables and call constructors
extern void __libc_init_array(void);
__libc_init_array();
Expand Down
13 changes: 11 additions & 2 deletions src/common/app_metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,18 @@ void buddy::metrics::RecordRuntimeStats() {
if (metric_record_is_due(&buddy_revision)) {
board_revision_t board_revision;
if (otp_get_board_revision(&board_revision) == false) {
board_revision.br = 0;
board_revision = 0;
}
metric_record_string(&buddy_revision, "%u.%u", board_revision.bytes[0], board_revision.bytes[1]);
metric_record_string(&buddy_revision, "%u", board_revision);
}

static metric_t buddy_bom = METRIC("buddy_bom", METRIC_VALUE_STRING, 10 * 10003, METRIC_HANDLER_ENABLE_ALL);
if (metric_record_is_due(&buddy_bom)) {
uint8_t bom;
if (otp_get_bom_id(&bom) == false) {
bom = 0;
}
metric_record_string(&buddy_bom, "%u", bom);
}

static metric_t current_filamnet = METRIC("filament", METRIC_VALUE_STRING, 10 * 1007, METRIC_HANDLER_ENABLE_ALL);
Expand Down
23 changes: 14 additions & 9 deletions src/common/hwio_XLBuddy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <option/has_loadcell.h>
#include <option/has_gui.h>
#include <option/debug_with_beeps.h>
#include <option/is_knoblet.h>
#include "device/board.h"
#include "Marlin/src/module/motion.h" // for active_extruder
#include "puppies/modular_bed.hpp"
Expand Down Expand Up @@ -112,8 +113,8 @@ static int *const _pwm_period_us[] = {
&_tim1_period_us, //_PWM_FAN
};

// stores board revision from OTP for faster access
board_revision_t board_revision;
// stores board bom ID from OTP for faster access
uint8_t board_bom_id;

// buddy pwm output maximum values
static constexpr int _pwm_max[] = { TIM1_default_Period };
Expand Down Expand Up @@ -632,13 +633,17 @@ void pinMode([[maybe_unused]] uint32_t ulPin, [[maybe_unused]] uint32_t ulMode)
}

void buddy::hw::hwio_configure_board_revision_changed_pins() {
if (!otp_get_board_revision(&board_revision) || board_revision.bytes[0] <= 4) {
bsod("Unable to determine board revision");
if (!otp_get_bom_id(&board_bom_id) || board_bom_id < 4) {
if constexpr (option::is_knoblet) {
board_bom_id = BOARD_VERSION_MINOR; // Knoblets can be without OTP (buzzer might not work)
} else {
bsod("Unable to determine board revision");
}
}
log_info(Buddy, "Detected board %d.%d", board_revision.bytes[0], board_revision.bytes[1]);
log_info(Buddy, "Detected bom ID %d", board_bom_id);

// Different HW revisions have different pins connections, figure it out here
if (board_revision.bytes[0] >= 9 || board_revision.bytes[0] == 4) {
if (board_bom_id >= 9 || board_bom_id == 4) {
Buzzer = &pin_a0;
XStep = &pin_d7;
YStep = &pin_d5;
Expand All @@ -648,19 +653,19 @@ void buddy::hw::hwio_configure_board_revision_changed_pins() {
YStep = &pin_a3;
}

if (board_revision.bytes[0] >= 9) {
if (board_bom_id >= 9) {
SideLed_LcdSelector = &pin_e9;
}
}

void hw_init_spi_side_leds() {
// Side leds was connectet to dedicated SPI untill revision 8, in revision 9 SPI is shared with LCD. So init SPI only if needed.
if (board_revision.bytes[0] <= 8) {
if (board_bom_id <= 8) {
hw_spi4_init();
}
}
SPI_HandleTypeDef *hw_get_spi_side_strip() {
if (board_revision.bytes[0] >= 9 || board_revision.bytes[0] == 4) {
if (board_bom_id >= 9 || board_bom_id == 4) {
return &SPI_HANDLE_FOR(lcd);
} else {
return &hspi4;
Expand Down
7 changes: 3 additions & 4 deletions src/common/otp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ bool otp_parse_board_revision(board_revision_t *revision, const uint8_t *memory,
if (!otp_parse_datamatrix(&datamatrix, memory, len))
return false;

revision->br = datamatrix.revision;
*revision = datamatrix.revision;
return true;
} else if (structure_version <= 2) {
if (len < 2) {
Expand All @@ -143,10 +143,9 @@ bool otp_parse_board_revision(board_revision_t *revision, const uint8_t *memory,
// older OTP layout
const uint8_t *board_revision = memory;
if (board_revision[0] == 0xFF || board_revision[0] == 1) {
return false; // TODO: really? (I don't think so)
return false; // TODO: really? (I don't think so)
} else {
revision->bytes[0] = board_revision[1];
revision->bytes[1] = board_revision[2];
*revision = board_revision[0] * 100 + board_revision[1] * 10 + board_revision[2]; // TODO test MINI
return true;
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/common/otp.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ typedef struct {
uint8_t mac[6];
} MAC_addr;

typedef union {
uint16_t br;
uint8_t bytes[2];
} board_revision_t;
typedef uint16_t board_revision_t;

typedef struct {
char txt[25];
Expand Down Expand Up @@ -69,6 +66,9 @@ uint8_t otp_get_serial_nr(serial_nr_t *sn);

/**
* @brief Get BOM ID from OTP.
* BOM == bill of material - list of electronic parts
* some parts might need different fw
* so in case of different hw support it is better to check this than board version
* @param bom_id output BOM ID
* @return true if parsed correctly, false otherwise
*/
Expand Down
2 changes: 1 addition & 1 deletion src/common/selftest/selftest_MK4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static constexpr const char *_suffix[] = { "_fan", "_xyz", "_heaters" };
/// These speeds create major chord
/// https://en.wikipedia.org/wiki/Just_intonation

static constexpr float XYfr_table[] = { HOMING_FEEDRATE_XY / 60 };
static const float XYfr_table[] = { HOMING_FEEDRATE_XY / 60 };
static constexpr size_t xy_fr_table_size = sizeof(XYfr_table) / sizeof(XYfr_table[0]);
static constexpr float Zfr_table_fw[] = { maxFeedrates[Z_AXIS] }; // up
static constexpr float Zfr_table_bw[] = { HOMING_FEEDRATE_Z / 60 };
Expand Down
4 changes: 2 additions & 2 deletions src/gui/version_info_ILI9488.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ ScreenMenuVersionInfo::ScreenMenuVersionInfo()

board_revision_t board_revision;
if (otp_get_board_revision(&board_revision) == false) {
board_revision.br = 0;
board_revision = 0;
}
snprintf(help_str, GuiDefaults::infoDefaultLen, "%d.%d", board_revision.bytes[0], board_revision.bytes[1]);
snprintf(help_str, GuiDefaults::infoDefaultLen, "%d", board_revision);
;
Item<MI_INFO_BOARD>().ChangeInformation(help_str);

Expand Down
6 changes: 3 additions & 3 deletions src/gui/version_info_ST7789V.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ScreenMenuVersionInfo::ScreenMenuVersionInfo()
//=============ACCESS IN ADDR=================
board_revision_t board_revision;
if (otp_get_board_revision(&board_revision) == false) {
board_revision.br = 0;
board_revision = 0;
}

serial_nr_t serial_nr;
Expand Down Expand Up @@ -66,13 +66,13 @@ ScreenMenuVersionInfo::ScreenMenuVersionInfo()

if (end > begin) {
// c=20 r=4
static const char fmt2Translate[] = N_("\nBootloader Version\n%d.%d.%d\n\nBuddy Board\n%d.%d\n%s");
static const char fmt2Translate[] = N_("\nBootloader Version\n%d.%d.%d\n\nBuddy Board\n%d\n%s");
char fmt[20 * 4];
_(fmt2Translate).copyToRAM(fmt, sizeof(fmt)); // note the underscore at the beginning of this line
begin += snprintf(begin, end - begin,
fmt,
bootloader->major, bootloader->minor, bootloader->patch,
board_revision.bytes[0], board_revision.bytes[1],
board_revision,
serial_nr.txt);
}

Expand Down
6 changes: 3 additions & 3 deletions src/hw/mk3.5/hw_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Configuration &Configuration::Instance() {
}

Configuration::Configuration() {
board_revision_t rev;
otp_get_board_revision(&rev);
uint8_t bom_id;
otp_get_bom_id(&bom_id);

if (rev.bytes[0] == 27) {
if (bom_id == 27) {
bsod("Wrong board version");
}
}
Expand Down
1 change: 1 addition & 0 deletions src/hw/mk4_ix/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target_include_directories(firmware PRIVATE . include)
target_include_directories(BuddyHeaders INTERFACE .)

target_sources(firmware PRIVATE calibrated_loveboard.cpp hw_configuration.cpp)
22 changes: 2 additions & 20 deletions src/hw/mk4_ix/hw_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,15 @@ Configuration &Configuration::Instance() {
Configuration::Configuration(const LoveBoardEeprom &eeprom) {
loveboard_eeprom = eeprom;

if (get_board_version() == 27) {
inverted_fans = true;
} else {
inverted_fans = false;
}
}

uint8_t Configuration::get_board_version() const {
board_revision_t rev;
otp_get_board_revision(&rev);
return rev.bytes[0];
otp_get_bom_id(&bom_id);
}

float Configuration::curr_measurement_voltage_to_current(float voltage) const {
constexpr float allegro_curr_from_voltage = 1 / 0.09F;

const float allegro_zero_curr_voltage = (get_board_version() == 27) ? 5.F / 2.F : 3.35F / 2.F; // choose half of 3V3 or 5V range
const float allegro_zero_curr_voltage = (bom_id == 27) ? 5.F / 2.F : 3.35F / 2.F; // choose half of 3V3 or 5V range

return (voltage - allegro_zero_curr_voltage) * allegro_curr_from_voltage;
}

bool Configuration::has_inverted_mmu_reset() const {
return (get_board_version() == 27) ? false : true;
}

bool Configuration::can_power_up_mmu_without_pulses() const {
return (get_board_version() == 27) ? false : true;
}

}
18 changes: 10 additions & 8 deletions src/hw/mk4_ix/hw_configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Configuration {

LoveBoardEeprom loveboard_eeprom;

bool inverted_fans;
uint8_t bom_id { 0 };

public:
/**
Expand All @@ -66,7 +66,15 @@ class Configuration {

const LoveBoardEeprom &get_love_board() const { return loveboard_eeprom; }

bool has_inverted_fans() const { return inverted_fans; }
uint8_t get_board_bom_id() const { return bom_id; }

bool has_inverted_fans() const { return bom_id < 37; }

bool has_inverted_mmu_reset() const { return bom_id >= 37; }

bool can_power_up_mmu_without_pulses() const { return bom_id >= 37; }

bool has_trinamic_oscillators() const { return bom_id >= 37; }

/**
* @brief voltage reference of current measurement
Expand All @@ -78,12 +86,6 @@ class Configuration {
* @return float current [mA]
*/
float curr_measurement_voltage_to_current(float voltage) const;

bool has_inverted_mmu_reset() const;

bool can_power_up_mmu_without_pulses() const;

uint8_t get_board_version() const;
};

}
8 changes: 4 additions & 4 deletions tests/unit/common/otp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ TEST_CASE("OTP test v4, DataMatrixID v5, date with offset", "[otp_v4]") {

board_revision_t br;
REQUIRE(otp_parse_board_revision(&br, otp, OTP_SIZE));
REQUIRE(br.br == 2);
REQUIRE(br == 2);

datamatrix_t datamatrix;
REQUIRE(otp_parse_datamatrix(&datamatrix, otp, OTP_SIZE));
Expand Down Expand Up @@ -83,7 +83,7 @@ TEST_CASE("OTP test v4, DataMatrixID v5", "[otp_v4]") {

board_revision_t br;
REQUIRE(otp_parse_board_revision(&br, otp, OTP_SIZE));
REQUIRE(br.br == 2);
REQUIRE(br == 2);

datamatrix_t datamatrix;
REQUIRE(otp_parse_datamatrix(&datamatrix, otp, OTP_SIZE));
Expand Down Expand Up @@ -137,7 +137,7 @@ TEST_CASE("OTP test v4", "[otp_v4]") {

board_revision_t br;
REQUIRE(otp_parse_board_revision(&br, otp, OTP_SIZE));
REQUIRE(br.br == 2);
REQUIRE(br == 2);

datamatrix_t datamatrix;
REQUIRE(otp_parse_datamatrix(&datamatrix, otp, OTP_SIZE));
Expand Down Expand Up @@ -193,7 +193,7 @@ TEST_CASE("OTP test v3", "[otp_v3]") {

board_revision_t br;
REQUIRE(otp_parse_board_revision(&br, otp, OTP_SIZE));
REQUIRE(br.br == 27);
REQUIRE(br == 27);

datamatrix_t datamatrix;
REQUIRE(otp_parse_datamatrix(&datamatrix, otp, OTP_SIZE));
Expand Down

0 comments on commit 82deea9

Please sign in to comment.