找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 15272|回復: 21
打印 上一主題 下一主題
收起左側

基于STM32平臺GRBL V1.1F源代碼IAR工程文件

  [復制鏈接]
跳轉到指定樓層
樓主
ID:96552 發(fā)表于 2018-7-26 20:02 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
基于STM32平臺GRBL V1.1F源代碼IAR工程文件,效果非常棒,比AVR328和2560效果好多了,用機器實際測試過,可以直接使用。


單片機源程序如下:
  1. /*
  2.   main.c - An embedded CNC Controller with rs274/ngc (g-code) support
  3.   Part of Grbl

  4.   Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC
  5.   Copyright (c) 2009-2011 Simen Svale Skogsrud

  6.   Grbl is free software: you can redistribute it and/or modify
  7.   it under the terms of the GNU General Public License as published by
  8.   the Free Software Foundation, either version 3 of the License, or
  9.   (at your option) any later version.

  10.   Grbl is distributed in the hope that it will be useful,
  11.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.   GNU General Public License for more details.

  14.   You should have received a copy of the GNU General Public License
  15.   along with Grbl.  If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /*
  18.   之前在github上看到了grbl-0.9j在stm32上的移植,于是照貓畫老虎,移植了grbl1.1f-20170131,
  19. 增加了USB虛擬串口,不再需要外接轉換芯片,但其他功能都沒有調(diào)試,存在嚴重問題。此次移植了
  20. grbl1.1f-20170801,同時進行了少許調(diào)試,目前通訊正常,步進電機接口、冷卻和主軸正常,同時
  21. 加入了四相五線步進接口(x和y),這些在cpu_map.h中有相應定義。但手頭沒有機器,尚未實機測
  22. 試,慎用!
  23.   如有重大問題,請聯(lián)系 tuoqiang@outlook.com
  24. */

  25. #include "grbl.h"

  26. // Declare system global variable structure
  27. system_t sys;
  28. int32_t sys_position[N_AXIS];      // Real-time machine (aka home) position vector in steps.
  29. int32_t sys_probe_position[N_AXIS]; // Last probe position in machine coordinates and steps.
  30. volatile uint8_t sys_probe_state;   // Probing state value.  Used to coordinate the probing cycle with stepper ISR.
  31. volatile uint8_t sys_rt_exec_state;   // Global realtime executor bitflag variable for state management. See EXEC bitmasks.
  32. volatile uint8_t sys_rt_exec_alarm;   // Global realtime executor bitflag variable for setting various alarms.
  33. volatile uint8_t sys_rt_exec_motion_override; // Global realtime executor bitflag variable for motion-based overrides.
  34. volatile uint8_t sys_rt_exec_accessory_override; // Global realtime executor bitflag variable for spindle/coolant overrides.
  35. #ifdef DEBUG
  36.   volatile uint8_t sys_rt_exec_debug;
  37. #endif


  38. int main(void)
  39. {
  40.   //USB init
  41.   //Delay Init
  42.   //GPIO CLK init
  43.   Hardware_Init();
  44.   
  45.   // Initialize system upon power-up.
  46.   serial_init();   // Setup serial baud rate and interrupts
  47.   settings_init(); // Load Grbl settings from EEPROM
  48.   stepper_init();  // Configure stepper pins and interrupt timers
  49.   system_init();   // Configure pinout pins and pin-change interrupt

  50.   memset(sys_position,0,sizeof(sys_position)); // Clear machine position.
  51.   asm("cpsie i"); // Enable interrupts

  52.   // Initialize system state.
  53.   #ifdef FORCE_INITIALIZATION_ALARM
  54.     // Force Grbl into an ALARM state upon a power-cycle or hard reset.
  55.     sys.state = STATE_ALARM;
  56.   #endif
  57.   
  58.   // Check for power-up and set system alarm if homing is enabled to force homing cycle
  59.   // by setting Grbl's alarm state. Alarm locks out all g-code commands, including the
  60.   // startup scripts, but allows access to settings and internal commands. Only a homing
  61.   // cycle '$H' or kill alarm locks '$X' will disable the alarm.
  62.   // NOTE: The startup script will run after successful completion of the homing cycle, but
  63.   // not after disabling the alarm locks. Prevents motion startup blocks from crashing into
  64.   // things uncontrollably. Very bad.
  65.   #ifdef HOMING_INIT_LOCK
  66.     if (bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) { sys.state = STATE_ALARM; }
  67.   #endif

  68.   // Grbl initialization loop upon power-up or a system abort. For the latter, all processes
  69.   // will return to this loop to be cleanly re-initialized.
  70.   for(;;) {

  71.     // Reset system variables.
  72.     uint8_t prior_state = sys.state;
  73.     memset(&sys, 0, sizeof(system_t)); // Clear system struct variable.
  74.     sys.state = prior_state;
  75.     sys.f_override = DEFAULT_FEED_OVERRIDE;  // Set to 100%
  76.     sys.r_override = DEFAULT_RAPID_OVERRIDE; // Set to 100%
  77.     sys.spindle_speed_ovr = DEFAULT_SPINDLE_SPEED_OVERRIDE; // Set to 100%
  78.                 memset(sys_probe_position,0,sizeof(sys_probe_position)); // Clear probe position.
  79.     sys_probe_state = 0;
  80.     sys_rt_exec_state = 0;
  81.     sys_rt_exec_alarm = 0;
  82.     sys_rt_exec_motion_override = 0;
  83.     sys_rt_exec_accessory_override = 0;

  84.     // Reset Grbl primary systems.
  85.     serial_reset_read_buffer(); // Clear serial read buffer
  86.     gc_init(); // Set g-code parser to default state
  87.     spindle_init();
  88.     coolant_init();
  89.     limits_init();
  90.     probe_init();
  91.     plan_reset(); // Clear block buffer and planner variables
  92.     st_reset(); // Clear stepper subsystem variables.

  93.     // Sync cleared gcode and planner positions to current system position.
  94.     plan_sync_position();
  95.     gc_sync_position();

  96.     // Print welcome message. Indicates an initialization has occured at power-up or with a reset.
  97.     report_init_message();

  98.     // Start Grbl main loop. Processes program inputs and executes them.
  99.     protocol_main_loop();

  100.   }
  101.   //return 0;   /* Never reached */
  102. }
復制代碼

所有資料51hei提供下載:
grbl1.1f-stm32f103c8-master.zip (471.01 KB, 下載次數(shù): 399)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏9 分享淘帖 頂1 踩
回復

使用道具 舉報

沙發(fā)
ID:197515 發(fā)表于 2018-9-2 11:37 | 只看該作者
非常感謝分享,可以移植提速了。
回復

使用道具 舉報

板凳
ID:401723 發(fā)表于 2018-9-24 08:44 | 只看該作者
學習下
回復

使用道具 舉報

地板
ID:185057 發(fā)表于 2018-10-23 11:04 | 只看該作者
正好需要
回復

使用道具 舉報

5#
ID:244434 發(fā)表于 2018-11-8 19:05 | 只看該作者
也在學習感謝樓主,正好要做個機器一起來交流下可好.
回復

使用道具 舉報

6#
ID:451498 發(fā)表于 2018-12-21 15:13 | 只看該作者
1 、沒有工程文件   2 、 編譯不通過
回復

使用道具 舉報

7#
ID:403087 發(fā)表于 2018-12-30 21:49 | 只看該作者
學習一下這個東西。
回復

使用道具 舉報

8#
ID:472523 發(fā)表于 2019-1-24 15:37 | 只看該作者
感謝分享
回復

使用道具 舉報

9#
ID:418685 發(fā)表于 2019-6-6 16:38 | 只看該作者
正在學習中,感謝分享
回復

使用道具 舉報

10#
ID:582289 發(fā)表于 2019-7-11 14:11 | 只看該作者
學習下
回復

使用道具 舉報

11#
ID:591790 發(fā)表于 2019-7-28 22:44 | 只看該作者
謝謝分享
回復

使用道具 舉報

12#
ID:138247 發(fā)表于 2019-7-30 09:52 | 只看該作者

感謝樓主分享。。。
回復

使用道具 舉報

13#
ID:435052 發(fā)表于 2019-7-30 15:18 | 只看該作者
非常感謝分享,可以移植提速了。
回復

使用道具 舉報

14#
ID:634342 發(fā)表于 2019-11-2 14:16 | 只看該作者
學習下
回復

使用道具 舉報

15#
ID:96926 發(fā)表于 2019-11-7 13:51 | 只看該作者

學習下
回復

使用道具 舉報

16#
ID:568567 發(fā)表于 2019-11-8 16:54 | 只看該作者
下載來度度,不知道能不能用,謝謝了
回復

使用道具 舉報

17#
ID:605127 發(fā)表于 2019-11-21 16:36 | 只看該作者
0.9j版本正在調(diào)試中,搞好了再來玩玩這個
回復

使用道具 舉報

18#
ID:692686 發(fā)表于 2020-2-13 10:19 | 只看該作者
有硬件接線圖嗎
回復

使用道具 舉報

19#
ID:91165 發(fā)表于 2020-2-13 10:48 | 只看該作者
謝謝樓主分享   
回復

使用道具 舉報

20#
ID:852609 發(fā)表于 2024-8-2 22:49 | 只看該作者
探針,限位都有問題
回復

使用道具 舉報

21#
ID:852609 發(fā)表于 2024-8-2 22:51 | 只看該作者
探針,限位都不能用
回復

使用道具 舉報

22#
ID:517951 發(fā)表于 2024-8-29 07:30 | 只看該作者
下載學習一下.
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表