gin66 / FastAccelStepper

A high speed stepper library for Atmega 168/328p (nano), Atmega32u4, Atmega 2560, ESP32, ESP32S2, ESP32S3, ESP32C3, ESP32C6 and Atmel SAM Due
MIT License
301 stars 70 forks source link

Increase task stack size #145

Closed JustinOng closed 1 year ago

JustinOng commented 1 year ago

This increases the size of the stack allocated for StepperTask because it has been observed to overflow its stack when setExternalCallForPin is used.

Tracing the free stack space indicates that the approximate stack space used:

I've just arbitrarily doubled the stack size since the ESP32 has a significant amount of RAM available, though it might be good to consider if we can set this more intelligently.

gin66 commented 1 year ago

Even though I am wondering, what the content of the external callback function is

JustinOng commented 1 year ago

I have 8 outputs on a shift register, and 8 on a I2C IO expander.

void set_dir(uint8_t index, uint8_t index_state) {
  // Current state of the shift register output
  static uint8_t state = 0;

  state = (state & ~(1 << index)) | ((index_state & 1) << index);

  spi_transaction_t t;
  memset(&t, 0, sizeof(t));
  t.length = 8;
  t.flags = SPI_TRANS_USE_TXDATA;
  t.tx_data[0] = state;

  ESP_ERROR_CHECK(spi_device_polling_transmit(_spi_sr, &t));
}

void set_en(uint8_t index, uint8_t index_state) {
  static uint8_t state = 0;

  state = (state & ~(1 << index)) | ((index_state & 1) << index);

  uint8_t data[] = {
      2, state};

  ESP_ERROR_CHECK(i2c_master_write_to_device(I2C_PORT, I2C_IO_EXP_ADDR, data, sizeof(data), portMAX_DELAY));
}
gin66 commented 1 year ago

Hope those functions - despite stack usage - do not cause trouble with the 4ms task for updating the stepper queues