Browse Source

Move extended_axis_codes to PROGMEM

pull/1/head
Scott Lahteine 7 years ago
parent
commit
e28e3bb532
  1. 87
      Marlin/src/feature/tmc_util.cpp
  2. 49
      Marlin/src/feature/tmc_util.h
  3. 4
      Marlin/src/gcode/feature/trinamic/M906.cpp
  4. 26
      Marlin/src/gcode/feature/trinamic/M911-M915.cpp

87
Marlin/src/feature/tmc_util.cpp

@ -37,7 +37,6 @@
#endif
bool report_tmc_status = false;
char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1", "E2", "E3", "E4" };
/**
* Check for over temperature or short to ground error flags.
@ -96,18 +95,17 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
#endif
template<typename TMC>
void monitor_tmc_driver(TMC &st, const char * const axisName, uint8_t &otpw_cnt) {
void monitor_tmc_driver(TMC &st, const TMC_AxisEnum axis, uint8_t &otpw_cnt) {
TMC_driver_data data = get_driver_data(st);
#if ENABLED(STOP_ON_ERROR)
if (data.is_error) {
SERIAL_EOL();
SERIAL_ECHO(axisName);
SERIAL_ECHOPGM(" driver error detected:");
if (data.is_ot) SERIAL_ECHOPGM("\novertemperature");
if (st.s2ga()) SERIAL_ECHOPGM("\nshort to ground (coil A)");
if (st.s2gb()) SERIAL_ECHOPGM("\nshort to ground (coil B)");
SERIAL_EOL();
_tmc_say_axis(axis);
SERIAL_ECHOLNPGM(" driver error detected:");
if (data.is_ot) SERIAL_ECHOLNPGM("overtemperature");
if (st.s2ga()) SERIAL_ECHOLNPGM("short to ground (coil A)");
if (st.s2gb()) SERIAL_ECHOLNPGM("short to ground (coil B)");
#if ENABLED(TMC_DEBUG)
tmc_report_all();
#endif
@ -124,7 +122,7 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
SERIAL_EOL();
SERIAL_ECHO(timestamp);
SERIAL_ECHOPGM(": ");
SERIAL_ECHO(axisName);
_tmc_say_axis(axis);
SERIAL_ECHOPGM(" driver overtemperature warning! (");
SERIAL_ECHO(st.getCurrent());
SERIAL_ECHOLNPGM("mA)");
@ -134,7 +132,7 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
if (data.is_otpw && !st.isEnabled() && otpw_cnt > 4) {
st.setCurrent(st.getCurrent() - CURRENT_STEP_DOWN, R_SENSE, HOLD_MULTIPLIER);
#if ENABLED(REPORT_CURRENT_CHANGE)
SERIAL_ECHO(axisName);
_tmc_say_axis(axis);
SERIAL_ECHOLNPAIR(" current decreased to ", st.getCurrent());
#endif
}
@ -148,7 +146,7 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
if (report_tmc_status) {
const uint32_t pwm_scale = get_pwm_scale(st);
SERIAL_ECHO(axisName);
_tmc_say_axis(axis);
SERIAL_ECHOPAIR(":", pwm_scale);
SERIAL_ECHOPGM(" |0b"); SERIAL_PRINT(get_status_response(st), BIN);
SERIAL_ECHOPGM("| ");
@ -169,47 +167,47 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
next_cOT = millis() + 500;
#if HAS_HW_COMMS(X) || ENABLED(IS_TRAMS)
static uint8_t x_otpw_cnt = 0;
monitor_tmc_driver(stepperX, extended_axis_codes[TMC_X], x_otpw_cnt);
monitor_tmc_driver(stepperX, TMC_X, x_otpw_cnt);
#endif
#if HAS_HW_COMMS(Y) || ENABLED(IS_TRAMS)
static uint8_t y_otpw_cnt = 0;
monitor_tmc_driver(stepperY, extended_axis_codes[TMC_Y], y_otpw_cnt);
monitor_tmc_driver(stepperY, TMC_Y, y_otpw_cnt);
#endif
#if HAS_HW_COMMS(Z) || ENABLED(IS_TRAMS)
static uint8_t z_otpw_cnt = 0;
monitor_tmc_driver(stepperZ, extended_axis_codes[TMC_Z], z_otpw_cnt);
monitor_tmc_driver(stepperZ, TMC_Z, z_otpw_cnt);
#endif
#if HAS_HW_COMMS(X2)
static uint8_t x2_otpw_cnt = 0;
monitor_tmc_driver(stepperX2, extended_axis_codes[TMC_X], x2_otpw_cnt);
monitor_tmc_driver(stepperX2, TMC_X, x2_otpw_cnt);
#endif
#if HAS_HW_COMMS(Y2)
static uint8_t y2_otpw_cnt = 0;
monitor_tmc_driver(stepperY2, extended_axis_codes[TMC_Y], y2_otpw_cnt);
monitor_tmc_driver(stepperY2, TMC_Y, y2_otpw_cnt);
#endif
#if HAS_HW_COMMS(Z2)
static uint8_t z2_otpw_cnt = 0;
monitor_tmc_driver(stepperZ2, extended_axis_codes[TMC_Z], z2_otpw_cnt);
monitor_tmc_driver(stepperZ2, TMC_Z, z2_otpw_cnt);
#endif
#if HAS_HW_COMMS(E0) || ENABLED(IS_TRAMS)
static uint8_t e0_otpw_cnt = 0;
monitor_tmc_driver(stepperE0, extended_axis_codes[TMC_E0], e0_otpw_cnt);
monitor_tmc_driver(stepperE0, TMC_E0, e0_otpw_cnt);
#endif
#if HAS_HW_COMMS(E1)
static uint8_t e1_otpw_cnt = 0;
monitor_tmc_driver(stepperE1, extended_axis_codes[TMC_E1], e1_otpw_cnt);
monitor_tmc_driver(stepperE1, TMC_E1, e1_otpw_cnt);
#endif
#if HAS_HW_COMMS(E2)
static uint8_t e2_otpw_cnt = 0;
monitor_tmc_driver(stepperE2, extended_axis_codes[TMC_E2], e2_otpw_cnt);
monitor_tmc_driver(stepperE2, TMC_E2, e2_otpw_cnt);
#endif
#if HAS_HW_COMMS(E3)
static uint8_t e3_otpw_cnt = 0;
monitor_tmc_driver(stepperE3, extended_axis_codes[TMC_E3], e3_otpw_cnt);
monitor_tmc_driver(stepperE3, TMC_E3, e3_otpw_cnt);
#endif
#if HAS_HW_COMMS(E4)
static uint8_t e4_otpw_cnt = 0;
monitor_tmc_driver(stepperE4, extended_axis_codes[TMC_E4], e4_otpw_cnt);
monitor_tmc_driver(stepperE4, TMC_E4, e4_otpw_cnt);
#endif
if (report_tmc_status) SERIAL_EOL();
@ -218,26 +216,37 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
#endif // MONITOR_DRIVER_STATUS
void _tmc_say_current(const char name[], const uint16_t curr) {
SERIAL_ECHO(name);
void _tmc_say_axis(const TMC_AxisEnum axis) {
const static char ext_X[] PROGMEM = "X", ext_X2[] PROGMEM = "X2",
ext_Y[] PROGMEM = "Y", ext_Y2[] PROGMEM = "Y2",
ext_Z[] PROGMEM = "Z", ext_Z2[] PROGMEM = "Z2",
ext_E0[] PROGMEM = "E0", ext_E1[] PROGMEM = "E1",
ext_E2[] PROGMEM = "E2", ext_E3[] PROGMEM = "E3",
ext_E4[] PROGMEM = "E4";
const static char* const tmc_axes[] PROGMEM = { ext_X, ext_X2, ext_Y, ext_Y2, ext_Z, ext_Z2, ext_E0, ext_E1, ext_E2, ext_E3, ext_E4 };
serialprintPGM(tmc_axes[axis]);
}
void _tmc_say_current(const TMC_AxisEnum axis, const uint16_t curr) {
_tmc_say_axis(axis);
SERIAL_ECHOLNPAIR(" axis driver current: ", curr);
}
void _tmc_say_otpw(const char name[], const bool otpw) {
SERIAL_ECHO(name);
void _tmc_say_otpw(const TMC_AxisEnum axis, const bool otpw) {
_tmc_say_axis(axis);
SERIAL_ECHOPGM(" axis temperature prewarn triggered: ");
serialprintPGM(otpw ? PSTR("true") : PSTR("false"));
SERIAL_EOL();
}
void _tmc_say_otpw_cleared(const char name[]) {
SERIAL_ECHO(name);
void _tmc_say_otpw_cleared(const TMC_AxisEnum axis) {
_tmc_say_axis(axis);
SERIAL_ECHOLNPGM(" prewarn flag cleared");
}
void _tmc_say_pwmthrs(const char name[], const uint32_t thrs) {
SERIAL_ECHO(name);
void _tmc_say_pwmthrs(const TMC_AxisEnum axis, const uint32_t thrs) {
_tmc_say_axis(axis);
SERIAL_ECHOLNPAIR(" stealthChop max speed set to ", thrs);
}
void _tmc_say_sgt(const char name[], const int8_t sgt) {
SERIAL_ECHO(name);
void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) {
_tmc_say_axis(axis);
SERIAL_ECHOPGM(" driver homing sensitivity set to ");
SERIAL_PRINTLN(sgt, DEC);
}
@ -290,8 +299,8 @@ void _tmc_say_sgt(const char name[], const int8_t sgt) {
TMC_S2VSB,
TMC_S2VSA
};
static void drv_status_print_hex(const char name[], const uint32_t drv_status) {
SERIAL_ECHO(name);
static void drv_status_print_hex(const TMC_AxisEnum axis, const uint32_t drv_status) {
_tmc_say_axis(axis);
SERIAL_ECHOPGM(" = 0x");
for (int B = 24; B >= 8; B -= 8){
SERIAL_PRINT((drv_status >> (B + 4)) & 0xF, HEX);
@ -345,10 +354,10 @@ void _tmc_say_sgt(const char name[], const int8_t sgt) {
#endif
template <typename TMC>
static void tmc_status(TMC &st, TMC_AxisEnum axis, const TMC_debug_enum i, const float spmm) {
static void tmc_status(TMC &st, const TMC_AxisEnum axis, const TMC_debug_enum i, const float spmm) {
SERIAL_ECHO('\t');
switch(i) {
case TMC_CODES: SERIAL_ECHO(extended_axis_codes[axis]); break;
case TMC_CODES: _tmc_say_axis(axis); break;
case TMC_ENABLED: serialprintPGM(st.isEnabled() ? PSTR("true") : PSTR("false")); break;
case TMC_CURRENT: SERIAL_ECHO(st.getCurrent()); break;
case TMC_RMS_CURRENT: SERIAL_PROTOCOL(st.rms_current()); break;
@ -390,10 +399,10 @@ void _tmc_say_sgt(const char name[], const int8_t sgt) {
}
template <typename TMC>
static void tmc_parse_drv_status(TMC &st, TMC_AxisEnum axis, const TMC_drv_status_enum i) {
static void tmc_parse_drv_status(TMC &st, const TMC_AxisEnum axis, const TMC_drv_status_enum i) {
SERIAL_CHAR('\t');
switch(i) {
case TMC_DRV_CODES: SERIAL_ECHO(extended_axis_codes[axis]); break;
case TMC_DRV_CODES: _tmc_say_axis(axis); break;
case TMC_STST: if (st.stst()) SERIAL_CHAR('X'); break;
case TMC_OLB: if (st.olb()) SERIAL_CHAR('X'); break;
case TMC_OLA: if (st.ola()) SERIAL_CHAR('X'); break;
@ -402,7 +411,7 @@ void _tmc_say_sgt(const char name[], const int8_t sgt) {
case TMC_DRV_OTPW: if (st.otpw()) SERIAL_CHAR('X'); break;
case TMC_OT: if (st.ot()) SERIAL_CHAR('X'); break;
case TMC_DRV_CS_ACTUAL: SERIAL_PRINT(st.cs_actual(), DEC); break;
case TMC_DRV_STATUS_HEX:drv_status_print_hex(extended_axis_codes[axis], st.DRV_STATUS()); break;
case TMC_DRV_STATUS_HEX:drv_status_print_hex(axis, st.DRV_STATUS()); break;
default: tmc_parse_drv_status(st, i); break;
}
}

49
Marlin/src/feature/tmc_util.h

@ -28,58 +28,55 @@
#include "../inc/MarlinConfig.h"
extern bool report_tmc_status;
extern char extended_axis_codes[11][3];
enum TMC_AxisEnum {
TMC_X, TMC_X2, TMC_Y, TMC_Y2, TMC_Z, TMC_Z2,
TMC_E0, TMC_E1, TMC_E2, TMC_E3, TMC_E4
};
enum TMC_AxisEnum { TMC_X, TMC_X2, TMC_Y, TMC_Y2, TMC_Z, TMC_Z2, TMC_E0, TMC_E1, TMC_E2, TMC_E3, TMC_E4 };
constexpr uint32_t _tmc_thrs(const uint16_t msteps, const int32_t thrs, const uint32_t spmm) {
return 12650000UL * msteps / (256 * thrs * spmm);
}
void _tmc_say_current(const char name[], const uint16_t curr);
void _tmc_say_otpw(const char name[], const bool otpw);
void _tmc_say_otpw_cleared(const char name[]);
void _tmc_say_pwmthrs(const char name[], const uint32_t thrs);
void _tmc_say_sgt(const char name[], const int8_t sgt);
void _tmc_say_axis(const TMC_AxisEnum axis);
void _tmc_say_current(const TMC_AxisEnum axis, const uint16_t curr);
void _tmc_say_otpw(const TMC_AxisEnum axis, const bool otpw);
void _tmc_say_otpw_cleared(const TMC_AxisEnum axis);
void _tmc_say_pwmthrs(const TMC_AxisEnum axis, const uint32_t thrs);
void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt);
template<typename TMC>
void tmc_get_current(TMC &st, const char name[]) {
_tmc_say_current(name, st.getCurrent());
void tmc_get_current(TMC &st, const TMC_AxisEnum axis) {
_tmc_say_current(axis, st.getCurrent());
}
template<typename TMC>
void tmc_set_current(TMC &st, const char name[], const int mA) {
void tmc_set_current(TMC &st, const TMC_AxisEnum axis, const int mA) {
st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
tmc_get_current(st, name);
tmc_get_current(st, axis);
}
template<typename TMC>
void tmc_report_otpw(TMC &st, const char name[]) {
_tmc_say_otpw(name, st.getOTPW());
void tmc_report_otpw(TMC &st, const TMC_AxisEnum axis) {
_tmc_say_otpw(axis, st.getOTPW());
}
template<typename TMC>
void tmc_clear_otpw(TMC &st, const char name[]) {
void tmc_clear_otpw(TMC &st, const TMC_AxisEnum axis) {
st.clear_otpw();
_tmc_say_otpw_cleared(name);
_tmc_say_otpw_cleared(axis);
}
template<typename TMC>
void tmc_get_pwmthrs(TMC &st, const char name[], const uint16_t spmm) {
_tmc_say_pwmthrs(name, _tmc_thrs(st.microsteps(), st.TPWMTHRS(), spmm));
void tmc_get_pwmthrs(TMC &st, const TMC_AxisEnum axis, const uint16_t spmm) {
_tmc_say_pwmthrs(axis, _tmc_thrs(st.microsteps(), st.TPWMTHRS(), spmm));
}
template<typename TMC>
void tmc_set_pwmthrs(TMC &st, const char name[], const int32_t thrs, const uint32_t spmm) {
void tmc_set_pwmthrs(TMC &st, const TMC_AxisEnum axis, const int32_t thrs, const uint32_t spmm) {
st.TPWMTHRS(_tmc_thrs(st.microsteps(), thrs, spmm));
tmc_get_pwmthrs(st, name, spmm);
tmc_get_pwmthrs(st, axis, spmm);
}
template<typename TMC>
void tmc_get_sgt(TMC &st, const char name[]) {
_tmc_say_sgt(name, st.sgt());
void tmc_get_sgt(TMC &st, const TMC_AxisEnum axis) {
_tmc_say_sgt(axis, st.sgt());
}
template<typename TMC>
void tmc_set_sgt(TMC &st, const char name[], const int8_t sgt_val) {
void tmc_set_sgt(TMC &st, const TMC_AxisEnum axis, const int8_t sgt_val) {
st.sgt(sgt_val);
tmc_get_sgt(st, name);
tmc_get_sgt(st, axis);
}
void monitor_tmc_driver();

4
Marlin/src/gcode/feature/trinamic/M906.cpp

@ -37,8 +37,8 @@ void GcodeSuite::M906() {
LOOP_XYZE(i) values[i] = parser.intval(axis_codes[i]);
#define TMC_SET_GET_CURRENT(P,Q) do { \
if (values[P##_AXIS]) tmc_set_current(stepper##Q, extended_axis_codes[TMC_##Q], values[P##_AXIS]); \
else tmc_get_current(stepper##Q, extended_axis_codes[TMC_##Q]); } while(0)
if (values[P##_AXIS]) tmc_set_current(stepper##Q, TMC_##Q, values[P##_AXIS]); \
else tmc_get_current(stepper##Q, TMC_##Q); } while(0)
#if X_IS_TRINAMIC
TMC_SET_GET_CURRENT(X,X);

26
Marlin/src/gcode/feature/trinamic/M911-M915.cpp

@ -36,16 +36,16 @@
*/
void GcodeSuite::M911() {
#if ENABLED(X_IS_TMC2130) || (ENABLED(X_IS_TMC2208) && PIN_EXISTS(X_SERIAL_RX)) || ENABLED(IS_TRAMS)
tmc_report_otpw(stepperX, extended_axis_codes[TMC_X]);
tmc_report_otpw(stepperX, TMC_X);
#endif
#if ENABLED(Y_IS_TMC2130) || (ENABLED(Y_IS_TMC2208) && PIN_EXISTS(Y_SERIAL_RX)) || ENABLED(IS_TRAMS)
tmc_report_otpw(stepperY, extended_axis_codes[TMC_Y]);
tmc_report_otpw(stepperY, TMC_Y);
#endif
#if ENABLED(Z_IS_TMC2130) || (ENABLED(Z_IS_TMC2208) && PIN_EXISTS(Z_SERIAL_RX)) || ENABLED(IS_TRAMS)
tmc_report_otpw(stepperZ, extended_axis_codes[TMC_Z]);
tmc_report_otpw(stepperZ, TMC_Z);
#endif
#if ENABLED(E0_IS_TMC2130) || (ENABLED(E0_IS_TMC2208) && PIN_EXISTS(E0_SERIAL_RX)) || ENABLED(IS_TRAMS)
tmc_report_otpw(stepperE0, extended_axis_codes[TMC_E0]);
tmc_report_otpw(stepperE0, TMC_E0);
#endif
}
@ -56,22 +56,22 @@ void GcodeSuite::M912() {
const bool clearX = parser.seen(axis_codes[X_AXIS]), clearY = parser.seen(axis_codes[Y_AXIS]), clearZ = parser.seen(axis_codes[Z_AXIS]), clearE = parser.seen(axis_codes[E_AXIS]),
clearAll = (!clearX && !clearY && !clearZ && !clearE) || (clearX && clearY && clearZ && clearE);
#if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS) || (ENABLED(X_IS_TMC2208) && PIN_EXISTS(X_SERIAL_RX))
if (clearX || clearAll) tmc_clear_otpw(stepperX, extended_axis_codes[TMC_X]);
if (clearX || clearAll) tmc_clear_otpw(stepperX, TMC_X);
#endif
#if ENABLED(X2_IS_TMC2130) || (ENABLED(X2_IS_TMC2208) && PIN_EXISTS(X_SERIAL_RX))
if (clearX || clearAll) tmc_clear_otpw(stepperX, extended_axis_codes[TMC_X]);
if (clearX || clearAll) tmc_clear_otpw(stepperX, TMC_X);
#endif
#if ENABLED(Y_IS_TMC2130) || (ENABLED(Y_IS_TMC2208) && PIN_EXISTS(Y_SERIAL_RX))
if (clearY || clearAll) tmc_clear_otpw(stepperY, extended_axis_codes[TMC_Y]);
if (clearY || clearAll) tmc_clear_otpw(stepperY, TMC_Y);
#endif
#if ENABLED(Z_IS_TMC2130) || (ENABLED(Z_IS_TMC2208) && PIN_EXISTS(Z_SERIAL_RX))
if (clearZ || clearAll) tmc_clear_otpw(stepperZ, extended_axis_codes[TMC_Z]);
if (clearZ || clearAll) tmc_clear_otpw(stepperZ, TMC_Z);
#endif
#if ENABLED(E0_IS_TMC2130) || (ENABLED(E0_IS_TMC2208) && PIN_EXISTS(E0_SERIAL_RX))
if (clearE || clearAll) tmc_clear_otpw(stepperE0, extended_axis_codes[TMC_E0]);
if (clearE || clearAll) tmc_clear_otpw(stepperE0, TMC_E0);
#endif
}
@ -84,8 +84,8 @@ void GcodeSuite::M912() {
LOOP_XYZE(i) values[i] = parser.intval(axis_codes[i]);
#define TMC_SET_GET_PWMTHRS(P,Q) do { \
if (values[P##_AXIS]) tmc_set_pwmthrs(stepper##Q, extended_axis_codes[TMC_##Q], values[P##_AXIS], planner.axis_steps_per_mm[P##_AXIS]); \
else tmc_get_pwmthrs(stepper##Q, extended_axis_codes[TMC_##Q], planner.axis_steps_per_mm[P##_AXIS]); } while(0)
if (values[P##_AXIS]) tmc_set_pwmthrs(stepper##Q, TMC_##Q, values[P##_AXIS], planner.axis_steps_per_mm[P##_AXIS]); \
else tmc_get_pwmthrs(stepper##Q, TMC_##Q, planner.axis_steps_per_mm[P##_AXIS]); } while(0)
#if X_IS_TRINAMIC
TMC_SET_GET_PWMTHRS(X,X);
@ -129,8 +129,8 @@ void GcodeSuite::M912() {
#if ENABLED(SENSORLESS_HOMING)
void GcodeSuite::M914() {
#define TMC_SET_GET_SGT(P,Q) do { \
if (parser.seen(axis_codes[P##_AXIS])) tmc_set_sgt(stepper##Q, extended_axis_codes[TMC_##Q], parser.value_int()); \
else tmc_get_sgt(stepper##Q, extended_axis_codes[TMC_##Q]); } while(0)
if (parser.seen(axis_codes[P##_AXIS])) tmc_set_sgt(stepper##Q, TMC_##Q, parser.value_int()); \
else tmc_get_sgt(stepper##Q, TMC_##Q); } while(0)
#ifdef X_HOMING_SENSITIVITY
#if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS)

Loading…
Cancel
Save