找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4684|回复: 3
收起左侧

grbl stm32f4移植

[复制链接]
ID:344556 发表于 2018-9-7 07:29 | 显示全部楼层 |阅读模式
grbl stm32f4 移植工程包:
0.png

单片机源程序如下:
  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虚拟串口,不再需要外接转换芯片,但其他功能都没有调试,存在严重问题。此次移植了
  20. grbl1.1f-20170801,同时进行了少许调试,目前通讯正常,步进电机接口、冷却和主轴正常,同时
  21. 加入了四相五线步进接口(x和y),这些在cpu_map.h中有相应定义。但手头没有机器,尚未实机测
  22. 试,慎用!
  23.   如有重大问题,请联系 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, 下载次数: 70)
回复

使用道具 举报

ID:548018 发表于 2019-6-9 22:30 | 显示全部楼层
被骗了,明明是F103的。Grbl网站本来就有的。
回复

使用道具 举报

ID:612008 发表于 2019-9-16 12:05 | 显示全部楼层
测试过没有啊
回复

使用道具 举报

ID:1619 发表于 2021-3-12 08:19 | 显示全部楼层
货不对版啊。这是stm32f103的移植,并不是stm32f407
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表