You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.4 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #include <stddef.h>
  2. #include <stdio.h>
  3. #include "sdk/os/zos.hpp"
  4. #include "sdk\components\tmc\ic\ztmc4361A.hpp"
  5. #define TAG "main"
  6. using namespace iflytop;
  7. using namespace std;
  8. extern void umain();
  9. extern "C" {
  10. void StartDefaultTask(void const* argument) { umain(); }
  11. }
  12. #define TMC_MOTOR_SPI hspi1
  13. void umain() {
  14. /*******************************************************************************
  15. * *
  16. *******************************************************************************/
  17. chip_cfg_t chipcfg;
  18. chipcfg.us_dleay_tim = &DELAY_US_TIMER;
  19. chipcfg.tim_irq_scheduler_tim = &TIM_IRQ_SCHEDULER_TIMER;
  20. chipcfg.huart = &DEBUG_UART;
  21. chipcfg.debuglight = DEBUG_LIGHT_GPIO;
  22. chip_init(&chipcfg);
  23. zos_cfg_t zoscfg;
  24. zos_init(&zoscfg);
  25. osDelay(1000);
  26. static TMC4361A motora;
  27. static TMC4361A motorb;
  28. {
  29. TMC4361A::cfg_t cfg = {
  30. .spi = &TMC_MOTOR_SPI, //
  31. .csgpio = TMC_MOTOR1_SPI_SELECT1_IO, //
  32. .resetPin = TMC_MOTOR1_nRESET_IO, //
  33. .fREEZEPin = TMC_MOTOR1_nFREEZE_IO, //
  34. .ennPin = PinNull, //
  35. .driverIC_ennPin = TMC_MOTOR1_SUB_IC_ENN_IO, //
  36. .driverIC_resetPin = PinNull, //
  37. };
  38. motora.initialize(&cfg);
  39. ZLOGI(TAG, "motora initialize TMC4361A:%x DriverIC:%x", motora.readICVersion(), motora.readSubICVersion());
  40. }
  41. {
  42. TMC4361A::cfg_t cfg = {
  43. .spi = &TMC_MOTOR_SPI, //
  44. .csgpio = TMC_MOTOR2_SPI_SELECT1_IO, //
  45. .resetPin = TMC_MOTOR2_nRESET_IO, //
  46. .fREEZEPin = TMC_MOTOR2_nFREEZE_IO, //
  47. .ennPin = PinNull, //
  48. .driverIC_ennPin = TMC_MOTOR2_SUB_IC_ENN_IO, //
  49. .driverIC_resetPin = PinNull, //
  50. };
  51. motorb.initialize(&cfg);
  52. ZLOGI(TAG, "motorb initialize TMC4361A:%x DriverIC:%x", motorb.readICVersion(), motorb.readSubICVersion());
  53. }
  54. motora.setAcceleration(300000);
  55. motora.setDeceleration(300000);
  56. motora.setIHOLD_IRUN(0, 2, 10);
  57. motorb.setAcceleration(300000);
  58. motorb.setDeceleration(300000);
  59. motorb.setIHOLD_IRUN(0, 2, 10);
  60. motora.rotate(0);
  61. motorb.rotate(0);
  62. // motorb.rotate(100000);
  63. while (true) {
  64. OSDefaultSchduler::getInstance()->loop();
  65. osDelay(1);
  66. }
  67. }