├── .gitignore ├── .gitmodules ├── COPYING ├── DOCKER_LICENSE ├── DOCKER_README.md ├── Dockerfile ├── Makefile ├── README.md ├── VCOM_lib ├── intenable.c ├── lpcusb_type.h ├── serial_fifo.c ├── serial_fifo.h ├── usbSerial.c ├── usbSerial.h ├── usbapi.h ├── usbcontrol.c ├── usbdebug.h ├── usbhw_lpc.c ├── usbhw_lpc.h ├── usbinit.c ├── usbser.inf ├── usbstdreq.c └── usbstruct.h ├── doc ├── csv │ ├── alarm_codes_en_US.csv │ ├── build_option_codes_en_US.csv │ ├── error_codes_en_US.csv │ └── setting_codes_en_US.csv ├── log │ ├── commit_log_v0.7.txt │ ├── commit_log_v0.8c.txt │ ├── commit_log_v0.9g.txt │ ├── commit_log_v0.9i.txt │ ├── commit_log_v0.9j.txt │ ├── commit_log_v1.0b.txt │ ├── commit_log_v1.0c.txt │ └── commit_log_v1.1.txt ├── markdown │ ├── change_summary.md │ ├── commands.md │ ├── interface.md │ ├── jogging.md │ ├── laser_mode.md │ └── settings.md ├── media │ ├── COPYING │ ├── Grbl Logo 150px.png │ ├── Grbl Logo 250px.png │ ├── Grbl Logo 320px.png │ ├── Grbl Logo 640px.png │ ├── Grbl Logo.pdf │ ├── Grbl Logo.svg │ └── Thumbs.db └── script │ ├── simple_stream.py │ └── stream.py ├── grbl-lpc ├── avr │ ├── interrupt.h │ ├── io.h │ ├── pgmspace.h │ └── wdt.h ├── current_control.cpp ├── current_control.h ├── debug.h ├── delay.cpp ├── delay.h ├── flash.cpp ├── isr_init.cpp ├── pwm_driver.cpp ├── pwm_driver.h └── util │ └── delay.h ├── grbl ├── config.h ├── coolant_control.c ├── coolant_control.h ├── cpu_map.h ├── defaults.h ├── eeprom.c ├── eeprom.h ├── examples │ ├── grblUpload │ │ ├── grblUpload.ino │ │ └── license.txt │ └── grblWrite_BuildInfo │ │ ├── grblWrite_BuildInfo.ino │ │ └── license.txt ├── gcode.c ├── gcode.h ├── grbl.h ├── jog.c ├── jog.h ├── limits.c ├── limits.h ├── main.c ├── motion_control.c ├── motion_control.h ├── nuts_bolts.c ├── nuts_bolts.h ├── planner.c ├── planner.h ├── print.c ├── print.h ├── probe.c ├── probe.h ├── protocol.c ├── protocol.h ├── report.c ├── report.h ├── serial.c ├── serial.h ├── settings.c ├── settings.h ├── spindle_control.c ├── spindle_control.h ├── stepper.c ├── stepper.h ├── system.c └── system.h └── lpc17xx ├── LPC17xx.h ├── RTE_Components.h ├── RTE_Device.h ├── _exit.c ├── firmware.ld ├── grbl.ld ├── startup_LPC17xx.c ├── system_LPC17xx.c └── system_LPC17xx.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.hex 2 | *.o 3 | *.elf 4 | *.DS_Store 5 | *.d 6 | 7 | build 8 | README.md 9 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "CMSIS_5"] 2 | path = CMSIS_5 3 | url = https://github.com/ARM-software/CMSIS_5.git 4 | [submodule "NXP_LPC"] 5 | path = NXP_LPC 6 | url = https://github.com/ARM-software/NXP_LPC.git 7 | -------------------------------------------------------------------------------- /DOCKER_LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Ryan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /DOCKER_README.md: -------------------------------------------------------------------------------- 1 | # Arm Embedded Docker Environment 2 | Minimal docker environment for building arm-embedded projects 3 | 4 | ## Usage 5 | Run interactively with ```docker run -it --rm -v `pwd`:/root ryankurte/docker-arm-embedded /bin/bash```. 6 | This will create a temporal instance (changes will be dropped on exit) with a binding from the current directory to the root user home directory. 7 | 8 | If you are using selinux you may need to add a ```:z``` to the end of the -v parameter to indicate the mount is shared. 9 | 10 | ```docker run -it --rm -v `pwd`:/root:z ryankurte/docker-arm-embedded /bin/bash``` 11 | 12 | https://docs.docker.com/storage/bind-mounts/ 13 | 14 | ### Building grbl-LPC 15 | Update the grbl/config.h and uncomment the CPU_MAP define statement for the board you are compiling for 16 | 17 | ``` 18 | git submodule init 19 | git submodule update 20 | make 21 | ``` 22 | 23 | The resulting firmware file is build/firmware.bin 24 | 25 | ## Includes: 26 | - build-essential (native) 27 | - make, cmake 28 | - gawk, genromfs, ccache 29 | - arm-none-eabi from [launchpad.net](https://launchpad.net/~terry.guo/+archive/ubuntu/gcc-arm-embedded) 30 | - [Yotta](http://yotta.mbed.com/) 31 | 32 | 33 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:latest 2 | MAINTAINER Ryan Kurte 3 | LABEL Description="Docker image for building arm-embedded projects" 4 | 5 | # General dependencies 6 | RUN apt-get update && apt-get install -y \ 7 | git \ 8 | subversion \ 9 | curl \ 10 | cmake \ 11 | make \ 12 | automake \ 13 | autoconf \ 14 | python-setuptools \ 15 | ninja-build \ 16 | python-dev \ 17 | libtool \ 18 | unzip \ 19 | libffi-dev \ 20 | libssl-dev \ 21 | libusb-1.0.0 \ 22 | libusb-1.0.0-dev \ 23 | software-properties-common \ 24 | python-software-properties \ 25 | gawk \ 26 | genromfs \ 27 | ccache \ 28 | clang \ 29 | build-essential \ 30 | python3 \ 31 | python3-dev \ 32 | python3-pip \ 33 | libprotobuf-dev \ 34 | protobuf-compiler \ 35 | libprotobuf-c-dev \ 36 | protobuf-c-compiler \ 37 | python-protobuf 38 | 39 | # arm-none-eabi custom ppa 40 | RUN add-apt-repository ppa:team-gcc-arm-embedded/ppa && \ 41 | apt-get update && \ 42 | apt-get install -y gcc-arm-embedded 43 | 44 | # Yotta 45 | RUN easy_install pip && \ 46 | pip install yotta && \ 47 | mkdir -p /usr/local/lib/yotta_modules \ 48 | chown $USER /usr/local/lib/yotta_modules \ 49 | chmod 755 /usr/local/lib/yotta_modules 50 | 51 | # Pyserial for serial programming 52 | RUN pip install pyserial 53 | 54 | # STLink util 55 | RUN git clone https://github.com/texane/stlink.git && \ 56 | cd stlink && mkdir build && cd build && \ 57 | cmake .. && make && make install 58 | 59 | # Cleanup 60 | RUN apt-get clean && \ 61 | rm -rf /var/lib/apt 62 | 63 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for GRBL port to LPC17xx 2 | # 3 | # Copyright 2017 Todd Fleming 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | # IN THE SOFTWARE. 22 | 23 | INCLUDES = \ 24 | -I CMSIS_5/CMSIS/Core/Include \ 25 | -I CMSIS_5/CMSIS/Driver/Include \ 26 | -I CMSIS_5/Device/ARM/ARMCM3/Include \ 27 | -I grbl \ 28 | -I grbl-lpc \ 29 | -I lpc17xx \ 30 | -I VCOM_lib \ 31 | 32 | # Compile all .c and .cpp files in these directories 33 | # Hack: .c files are compiled as if they were c++. 34 | SRC_DIRS = \ 35 | grbl \ 36 | grbl-lpc \ 37 | VCOM_lib \ 38 | 39 | # Compile all .c files in these directories, except ones on the exclude list. 40 | # These files get extra -Wno-* flags to reduce spam. 41 | CMSIS_SRC_DIRS = \ 42 | NXP_LPC/LPC1700/CMSIS/Driver \ 43 | lpc17xx \ 44 | 45 | # These error out because we haven't set up the #defines they need. 46 | # To include one, remove it from this list and add the appropriate 47 | # #defines to RTE_Components.h 48 | CMSIS_EXCLUDE_OBJECTS = \ 49 | build/cmsis/CAN_LPC17xx.o \ 50 | build/cmsis/EMAC_LPC17xx.o \ 51 | build/cmsis/I2S_LPC17xx.o \ 52 | build/cmsis/MCI_LPC177x_8x.o \ 53 | build/cmsis/OTG_LPC17xx.o \ 54 | build/cmsis/PIN_LPC177x_8x.o \ 55 | build/cmsis/SPI_LPC17xx.o \ 56 | build/cmsis/USBD_LPC17xx.o \ 57 | build/cmsis/USBH_LPC17xx.o \ 58 | 59 | AS = arm-none-eabi-as 60 | CC = arm-none-eabi-gcc 61 | CXX = arm-none-eabi-g++ 62 | LD = arm-none-eabi-gcc 63 | OBJCOPY = arm-none-eabi-objcopy 64 | OBJDUMP = arm-none-eabi-objdump 65 | SIZE = arm-none-eabi-size 66 | 67 | CFLAGS = \ 68 | -DCORE_M3 \ 69 | -DLPC175x_6x \ 70 | -c \ 71 | -fdata-sections \ 72 | -ffunction-sections \ 73 | -fmessage-length=0 \ 74 | -fno-builtin \ 75 | -fno-delete-null-pointer-checks \ 76 | -fno-exceptions \ 77 | -fomit-frame-pointer \ 78 | -funsigned-char \ 79 | -mcpu=cortex-m3 \ 80 | -MMD \ 81 | -MP \ 82 | -mthumb \ 83 | -Os \ 84 | -Wall \ 85 | -Wextra \ 86 | 87 | # Disable warnings in CMSIS 88 | CMSIS_CFLAGS = $(CFLAGS) \ 89 | -Wno-incompatible-pointer-types \ 90 | -Wno-maybe-uninitialized \ 91 | -Wno-sign-compare \ 92 | -Wno-strict-aliasing \ 93 | -Wno-switch \ 94 | -Wno-unused-but-set-variable \ 95 | -Wno-unused-variable \ 96 | -Wno-int-conversion \ 97 | -Wno-missing-field-initializers \ 98 | -Wno-unused-function \ 99 | -Wno-unused-parameter \ 100 | 101 | # Disable warnings in .c files compiled as C++ 102 | C_AS_CPP_CFLAGS = $(CFLAGS) \ 103 | -Wno-unused-parameter \ 104 | 105 | CXXFLAGS = $(CFLAGS) \ 106 | -fno-rtti \ 107 | -std=gnu++14 \ 108 | 109 | LIBS = -Wl,--start-group -lgcc -lc -lm -Wl,--end-group 110 | 111 | VPATH = $(SRC_DIRS) $(CMSIS_SRC_DIRS) 112 | 113 | GET_OBJECTS = $(addprefix $(1),$(addsuffix .o,$(basename $(notdir $(wildcard $(foreach dir,$(2),$(dir)/*.c) $(foreach dir,$(2),$(dir)/*.cpp)))))) 114 | 115 | SRC_OBJECTS = $(call GET_OBJECTS,build/src/,$(SRC_DIRS)) 116 | 117 | CMSIS_OBJECTS = $(filter-out $(CMSIS_EXCLUDE_OBJECTS),$(call GET_OBJECTS,build/cmsis/,$(CMSIS_SRC_DIRS))) 118 | 119 | ifeq ($(shell echo $$OS),$$OS) 120 | MAKEDIR = @if not exist "$(1)" mkdir "$(1)" 121 | RM = @if exist "$(1)" rmdir /S /Q "$(1)" 122 | else 123 | MAKEDIR = $(SHELL) -c "mkdir -p \"$(1)\"" 124 | RM = $(SHELL) -c "rm -rf \"$(1)\"" 125 | endif 126 | 127 | build/cmsis/%.o : %.c 128 | $(call MAKEDIR,build) 129 | $(call MAKEDIR,build/cmsis) 130 | $(CC) $(CMSIS_CFLAGS) $(INCLUDES) -o $@ $< 131 | 132 | # hack: compile .c as c++ 133 | build/src/%.o : %.c 134 | $(call MAKEDIR,build) 135 | $(call MAKEDIR,build/src) 136 | $(CXX) $(CXXFLAGS) $(C_AS_CPP_CFLAGS) $(INCLUDES) -o $@ $< 137 | 138 | build/src/%.o : %.cpp 139 | $(call MAKEDIR,build) 140 | $(call MAKEDIR,build/src) 141 | $(CXX) $(CXXFLAGS) $(INCLUDES) -o $@ $< 142 | 143 | .PHONY: default 144 | default: build/grbl.hex build/firmware.bin 145 | 146 | build/grbl.elf: $(SRC_OBJECTS) $(CMSIS_OBJECTS) lpc17xx/grbl.ld 147 | $(LD) -mcpu=cortex-m3 -mthumb -specs=nosys.specs -T$(filter %.ld, $^) -o $@ $(filter %.o, $^) $(LIBS) 148 | 149 | build/firmware.elf: $(SRC_OBJECTS) $(CMSIS_OBJECTS) lpc17xx/firmware.ld 150 | $(LD) -mcpu=cortex-m3 -mthumb -specs=nosys.specs -T$(filter %.ld, $^) -o $@ $(filter %.o, $^) $(LIBS) 151 | 152 | build/%.bin : build/%.elf 153 | $(OBJCOPY) -O binary $^ $@ 154 | 155 | build/%.hex : build/%.elf 156 | $(OBJCOPY) -O ihex $^ $@ 157 | 158 | .PHONY: flash 159 | flash: build/grbl.hex 160 | fm COM(15, 115200) DEVICE(LPC1769, 0.000000, 0) HARDWARE(BOOTEXEC, 50, 100) ERASEUSED(build\grbl.hex, PROTECTISP) HEXFILE(build\grbl.hex, NOCHECKSUMS, NOFILL, PROTECTISP) 161 | 162 | .PHONY: clean 163 | clean: 164 | $(call RM,build) 165 | 166 | -include $(wildcard build/src/*.d build/cmsis/*.d) 167 | -------------------------------------------------------------------------------- /VCOM_lib/intenable.c: -------------------------------------------------------------------------------- 1 | #include "LPC17xx.h" 2 | 3 | void enable_USB_interrupts(void) 4 | { 5 | NVIC_EnableIRQ(USB_IRQn); 6 | } 7 | -------------------------------------------------------------------------------- /VCOM_lib/lpcusb_type.h: -------------------------------------------------------------------------------- 1 | /* 2 | LPCUSB, an USB device driver for LPC microcontrollers 3 | Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl) 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. The name of the author may not be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | /** 28 | @file 29 | primitive types used in the USB stack 30 | */ 31 | 32 | // *********************************************** 33 | // Code Red Technologies - port to RDB1768 board 34 | // In order to avoid clashing with the NXP-produced type.h file, this 35 | // one has been renamed to lpcusb_type.h, the NXP-produced type.h has 36 | // been included, and the duplicate contents of this file commented out. 37 | // *********************************************** 38 | 39 | 40 | #ifndef _LPCUSB_TYPE_H_ 41 | #define _LPCUSB_TYPE_H_ 42 | 43 | typedef unsigned char U8; /**< unsigned 8-bit */ 44 | typedef unsigned short int U16; /**< unsigned 16-bit */ 45 | typedef unsigned int U32; /**< unsigned 32-bit */ 46 | 47 | 48 | // CodeRed - comment out defines duplicated in NXP type.h 49 | 50 | typedef int BOOL; /**< #TRUE or #FALSE */ 51 | 52 | #define TRUE 1 /**< TRUE */ 53 | #define FALSE 0 /**< FALSE */ 54 | 55 | //#ifndef NULL 56 | //#define NULL ((void*)0) /**< NULL pointer */ 57 | //#endif 58 | //#endif 59 | 60 | /* some other useful macros */ 61 | #define MIN(x,y) ((x)<(y)?(x):(y)) /**< MIN */ 62 | #define MAX(x,y) ((x)>(y)?(x):(y)) /**< MAX */ 63 | 64 | #endif /* _LPCUSB_TYPE_H_ */ 65 | 66 | -------------------------------------------------------------------------------- /VCOM_lib/serial_fifo.c: -------------------------------------------------------------------------------- 1 | /* 2 | LPCUSB, an USB device driver for LPC microcontrollers 3 | Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl) 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. The name of the author may not be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | // CodeRed - LPCUSB type.h renamed 29 | //#include "type.h" 30 | #include "lpcusb_type.h" 31 | #include "serial_fifo.h" 32 | 33 | void fifo_init(fifo_t *fifo, U8 *buf) 34 | { 35 | fifo->head = 0; 36 | fifo->tail = 0; 37 | fifo->buf = buf; 38 | } 39 | 40 | 41 | // TBF: only non-isr may call this 42 | BOOL fifo_put(fifo_t *fifo, U8 c) 43 | { 44 | int tail = fifo->tail; 45 | int head = fifo->head; 46 | 47 | // check if FIFO has room 48 | int next = (head + 1) % VCOM_FIFO_SIZE; 49 | if (next == tail) { 50 | // full 51 | return FALSE; 52 | } 53 | 54 | fifo->buf[head] = c; 55 | fifo->head = next; 56 | 57 | return TRUE; 58 | } 59 | 60 | 61 | // TBF: only USB isr may call this 62 | BOOL fifo_get(fifo_t *fifo, U8 *pc) 63 | { 64 | int next; 65 | 66 | // check if FIFO has data 67 | if (fifo->head == fifo->tail) { 68 | return FALSE; 69 | } 70 | 71 | next = (fifo->tail + 1) % VCOM_FIFO_SIZE; 72 | 73 | *pc = fifo->buf[fifo->tail]; 74 | fifo->tail = next; 75 | 76 | return TRUE; 77 | } 78 | 79 | 80 | // TBF: only USB isr may call this 81 | int fifo_avail(fifo_t *fifo) 82 | { 83 | return (VCOM_FIFO_SIZE + fifo->head - fifo->tail) % VCOM_FIFO_SIZE; 84 | } 85 | 86 | 87 | // TBF: only USB isr may call this 88 | int fifo_free(fifo_t *fifo) 89 | { 90 | return (VCOM_FIFO_SIZE - 1 - fifo_avail(fifo)); 91 | } 92 | 93 | -------------------------------------------------------------------------------- /VCOM_lib/serial_fifo.h: -------------------------------------------------------------------------------- 1 | /* 2 | LPCUSB, an USB device driver for LPC microcontrollers 3 | Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl) 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. The name of the author may not be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "lpcusb_type.h" 29 | #include 30 | 31 | #define VCOM_FIFO_SIZE 512 32 | 33 | typedef struct { 34 | std::atomic head; 35 | std::atomic tail; 36 | U8 *buf; 37 | } fifo_t; 38 | 39 | void fifo_init(fifo_t *fifo, U8 *buf); 40 | BOOL fifo_put(fifo_t *fifo, U8 c); 41 | BOOL fifo_get(fifo_t *fifo, U8 *pc); 42 | int fifo_avail(fifo_t *fifo); 43 | int fifo_free(fifo_t *fifo); 44 | -------------------------------------------------------------------------------- /VCOM_lib/usbSerial.h: -------------------------------------------------------------------------------- 1 | //#define POLLED_USBSERIAL TRUE 2 | 3 | 4 | /* 5 | LPCUSB, an USB device driver for LPC microcontrollers 6 | Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl) 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 3. The name of the author may not be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | /* 32 | Minimal implementation of a USB serial port, using the CDC class. 33 | This example application simply echoes everything it receives right back 34 | to the host. 35 | 36 | Windows: 37 | Extract the usbser.sys file from .cab file in C:\WINDOWS\Driver Cache\i386 38 | and store it somewhere (C:\temp is a good place) along with the usbser.inf 39 | file. Then plug in the LPC176x and direct windows to the usbser driver. 40 | Windows then creates an extra COMx port that you can open in a terminal 41 | program, like hyperterminal. 42 | 43 | Linux: 44 | The device should be recognised automatically by the cdc_acm driver, 45 | which creates a /dev/ttyACMx device file that acts just like a regular 46 | serial port. 47 | 48 | */ 49 | 50 | /* Modified by Sagar G V, Feb 2011 51 | Used the USB CDC example to create a library. Added the following functions 52 | 53 | void VCOM_puts(const char* str); //writes a null terminated string. 54 | void VCOM_putc(char c); // writes a character. 55 | void VCOM_putHex(uint8_t hex); // writes 0x.. hex value on the terminal. 56 | char VCOM_getc(); // returns character entered in the terminal. blocking function 57 | void VCOM_gets(char* str); // returns a string. '\r' or '\n' will terminate character collection. 58 | char VCOM_getc_echo(); // returns character entered and echoes the same back. 59 | void VCOM_gets_echo(char *str); // gets string terminated in '\r' or '\n' and echoes back the same. 60 | 61 | */ 62 | 63 | /* Modified by Todd Fleming (TBF), 2017 64 | Replaced read polling API with callback API 65 | */ 66 | 67 | #ifndef __USB_SERIAL_H__ 68 | #define __USB_SERIAL_H__ 69 | 70 | #ifdef __cplusplus 71 | //extern "C" { 72 | #endif 73 | 74 | #include 75 | #include "LPC17xx.h" 76 | 77 | #include "usbapi.h" 78 | #include "usbdebug.h" 79 | 80 | #define BAUD_RATE 115200 81 | 82 | #define INT_IN_EP 0x81 83 | #define BULK_OUT_EP 0x05 84 | #define BULK_IN_EP 0x82 85 | 86 | #define MAX_PACKET_SIZE 64 87 | 88 | #define LE_WORD(x) ((x)&0xFF),((x)>>8) 89 | 90 | // CDC definitions 91 | #define CS_INTERFACE 0x24 92 | #define CS_ENDPOINT 0x25 93 | 94 | #define SET_LINE_CODING 0x20 95 | #define GET_LINE_CODING 0x21 96 | #define SET_CONTROL_LINE_STATE 0x22 97 | 98 | 99 | #include "serial_fifo.h" 100 | 101 | // Receives line state. Called by an interrupt. 102 | typedef void UsbSerialLineStateCallback(bool dtr, bool rts); 103 | 104 | // Receives serial data. Called by an interrupt. 105 | typedef void UsbSerialReadCallback(const U8* data, unsigned len); 106 | 107 | int usbSerialInit(UsbSerialLineStateCallback* usbSerialLineStateCallback, UsbSerialReadCallback* usbSerialReadCallback); // run once in main b4 main loop starts. 108 | 109 | /* 110 | Writes one character to VCOM port 111 | 112 | @param [in] c character to write 113 | @returns character written, or EOF if character could not be written 114 | */ 115 | int VCOM_putchar(int c); 116 | 117 | /** 118 | Reads one character from VCOM port 119 | 120 | @returns character read, or EOF if character could not be read 121 | */ 122 | //int VCOM_getchar(void); 123 | 124 | void VCOM_puts(const char* str); //writes a null terminated string. 125 | void VCOM_putc(char c); // writes a character. 126 | void VCOM_putHex(uint8_t hex); // writes 0x.. hex value on the terminal. 127 | //char VCOM_getc(); // returns character entered in the terminal. blocking function 128 | //void VCOM_gets(char* str); // returns a string. '\r' or '\n' will terminate character collection. 129 | //char VCOM_getc_echo(); // returns character entered and echoes the same back. 130 | //void VCOM_gets_echo(char *str); // gets string terminated in '\r' or '\n' and echoes back the same. 131 | 132 | void VCOM_printf(const char* str, ...); // Original code by Elm_CHaN. Modified by Martin Thomas 133 | 134 | #ifdef __cplusplus 135 | //} 136 | #endif 137 | 138 | #endif -------------------------------------------------------------------------------- /VCOM_lib/usbapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | LPCUSB, an USB device driver for LPC microcontrollers 3 | Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl) 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. The name of the author may not be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | /** 29 | @file 30 | */ 31 | 32 | // CodeRed - include the LPCUSB type.h file rather than NXP one directly 33 | #include "lpcusb_type.h" 34 | 35 | #include "usbstruct.h" // for TSetupPacket 36 | 37 | /************************************************************************* 38 | USB configuration 39 | **************************************************************************/ 40 | 41 | #define MAX_PACKET_SIZE0 64 /**< maximum packet size for EP 0 */ 42 | 43 | /************************************************************************* 44 | USB hardware interface 45 | **************************************************************************/ 46 | 47 | // endpoint status sent through callback 48 | #define EP_STATUS_DATA (1<<0) /**< EP has data */ 49 | #define EP_STATUS_STALLED (1<<1) /**< EP is stalled */ 50 | #define EP_STATUS_SETUP (1<<2) /**< EP received setup packet */ 51 | #define EP_STATUS_ERROR (1<<3) /**< EP data was overwritten by setup packet */ 52 | #define EP_STATUS_NACKED (1<<4) /**< EP sent NAK */ 53 | 54 | // device status sent through callback 55 | #define DEV_STATUS_CONNECT (1<<0) /**< device just got connected */ 56 | #define DEV_STATUS_SUSPEND (1<<2) /**< device entered suspend state */ 57 | #define DEV_STATUS_RESET (1<<4) /**< device just got reset */ 58 | 59 | // interrupt bits for NACK events in USBHwNakIntEnable 60 | // (these bits conveniently coincide with the LPC176x USB controller bit) 61 | #define INACK_CI (1<<1) /**< interrupt on NACK for control in */ 62 | #define INACK_CO (1<<2) /**< interrupt on NACK for control out */ 63 | #define INACK_II (1<<3) /**< interrupt on NACK for interrupt in */ 64 | #define INACK_IO (1<<4) /**< interrupt on NACK for interrupt out */ 65 | #define INACK_BI (1<<5) /**< interrupt on NACK for bulk in */ 66 | #define INACK_BO (1<<6) /**< interrupt on NACK for bulk out */ 67 | 68 | BOOL USBHwInit (void); 69 | void USBHwISR (void); 70 | 71 | void USBHwNakIntEnable (U8 bIntBits); 72 | 73 | void USBHwConnect (BOOL fConnect); 74 | 75 | void USBHwSetAddress (U8 bAddr); 76 | void USBHwConfigDevice (BOOL fConfigured); 77 | 78 | // endpoint operations 79 | void USBHwEPConfig (U8 bEP, U16 wMaxPacketSize); 80 | int USBHwEPRead (U8 bEP, U8 *pbBuf, int iMaxLen); 81 | int USBHwEPWrite (U8 bEP, U8 *pbBuf, int iLen); 82 | void USBHwEPStall (U8 bEP, BOOL fStall); 83 | U8 USBHwEPGetStatus (U8 bEP); 84 | 85 | /** Endpoint interrupt handler callback */ 86 | typedef void (TFnEPIntHandler) (U8 bEP, U8 bEPStatus); 87 | void USBHwRegisterEPIntHandler (U8 bEP, TFnEPIntHandler *pfnHandler); 88 | 89 | /** Device status handler callback */ 90 | typedef void (TFnDevIntHandler) (U8 bDevStatus); 91 | void USBHwRegisterDevIntHandler (TFnDevIntHandler *pfnHandler); 92 | 93 | /** Frame event handler callback */ 94 | typedef void (TFnFrameHandler)(U16 wFrame); 95 | void USBHwRegisterFrameHandler(TFnFrameHandler *pfnHandler); 96 | 97 | 98 | /************************************************************************* 99 | USB application interface 100 | **************************************************************************/ 101 | 102 | // initialise the complete stack, including HW 103 | BOOL USBInit(void); 104 | 105 | /** Request handler callback (standard, vendor, class) */ 106 | typedef BOOL (TFnHandleRequest)(TSetupPacket *pSetup, int *piLen, U8 **ppbData); 107 | void USBRegisterRequestHandler(int iType, TFnHandleRequest *pfnHandler, U8 *pbDataStore); 108 | void USBRegisterCustomReqHandler(TFnHandleRequest *pfnHandler); 109 | 110 | /** Descriptor handler callback */ 111 | typedef BOOL (TFnGetDescriptor)(U16 wTypeIndex, U16 wLangID, int *piLen, U8 **ppbData); 112 | 113 | /** Default standard request handler */ 114 | BOOL USBHandleStandardRequest(TSetupPacket *pSetup, int *piLen, U8 **ppbData); 115 | 116 | /** Default EP0 handler */ 117 | void USBHandleControlTransfer(U8 bEP, U8 bEPStat); 118 | 119 | /** Descriptor handling */ 120 | void USBRegisterDescriptors(const U8 *pabDescriptors); 121 | BOOL USBGetDescriptor(U16 wTypeIndex, U16 wLangID, int *piLen, U8 **ppbData); 122 | -------------------------------------------------------------------------------- /VCOM_lib/usbcontrol.c: -------------------------------------------------------------------------------- 1 | /* 2 | LPCUSB, an USB device driver for LPC microcontrollers 3 | Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl) 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. The name of the author may not be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | 29 | /** @file 30 | Control transfer handler. 31 | 32 | This module handles control transfers and is normally installed on the 33 | endpoint 0 callback. 34 | 35 | Control transfers can be of the following type: 36 | 0 Standard; 37 | 1 Class; 38 | 2 Vendor; 39 | 3 Reserved. 40 | 41 | A callback can be installed for each of these control transfers using 42 | USBRegisterRequestHandler. 43 | When an OUT request arrives, data is collected in the data store provided 44 | with the USBRegisterRequestHandler call. When the transfer is done, the 45 | callback is called. 46 | When an IN request arrives, the callback is called immediately to either 47 | put the control transfer data in the data store, or to get a pointer to 48 | control transfer data. The data is then packetised and sent to the host. 49 | */ 50 | 51 | // CodeRed - include the LPCUSB type.h file rather than NXP one directly 52 | //#include "type.h" 53 | #include "lpcusb_type.h" 54 | 55 | #include "usbdebug.h" 56 | 57 | #include "usbstruct.h" 58 | #include "usbapi.h" 59 | 60 | 61 | 62 | #define MAX_CONTROL_SIZE 128 /**< maximum total size of control transfer data */ 63 | #define MAX_REQ_HANDLERS 4 /**< standard, class, vendor, reserved */ 64 | 65 | static TSetupPacket Setup; /**< setup packet */ 66 | 67 | static U8 *pbData; /**< pointer to data buffer */ 68 | static int iResidue; /**< remaining bytes in buffer */ 69 | static int iLen; /**< total length of control transfer */ 70 | 71 | /** Array of installed request handler callbacks */ 72 | static TFnHandleRequest *apfnReqHandlers[4] = {NULL, NULL, NULL, NULL}; 73 | /** Array of installed request data pointers */ 74 | static U8 *apbDataStore[4] = {NULL, NULL, NULL, NULL}; 75 | 76 | /** 77 | Local function to handle a request by calling one of the installed 78 | request handlers. 79 | 80 | In case of data going from host to device, the data is at *ppbData. 81 | In case of data going from device to host, the handler can either 82 | choose to write its data at *ppbData or update the data pointer. 83 | 84 | @param [in] pSetup The setup packet 85 | @param [in,out] *piLen Pointer to data length 86 | @param [in,out] ppbData Data buffer. 87 | 88 | @return TRUE if the request was handles successfully 89 | */ 90 | static BOOL _HandleRequest(TSetupPacket *pSetup, int *piLen, U8 **ppbData) 91 | { 92 | TFnHandleRequest *pfnHandler; 93 | int iType; 94 | 95 | iType = REQTYPE_GET_TYPE(pSetup->bmRequestType); 96 | pfnHandler = apfnReqHandlers[iType]; 97 | if (pfnHandler == NULL) { 98 | DBG("No handler for reqtype %d\n", iType); 99 | return FALSE; 100 | } 101 | 102 | return pfnHandler(pSetup, piLen, ppbData); 103 | } 104 | 105 | 106 | /** 107 | Local function to stall the control endpoint 108 | 109 | @param [in] bEPStat Endpoint status 110 | */ 111 | static void StallControlPipe(U8 bEPStat) 112 | { 113 | U8 *pb; 114 | int i; 115 | bEPStat = bEPStat; 116 | USBHwEPStall(0x80, TRUE); 117 | 118 | // dump setup packet 119 | DBG("STALL on ["); 120 | pb = (U8 *)&Setup; 121 | pb = pb; 122 | for (i = 0; i < 8; i++) { 123 | DBG(" %02x", *pb++); 124 | } 125 | DBG("] stat=%x\n", bEPStat); 126 | } 127 | 128 | 129 | /** 130 | Sends next chunk of data (possibly 0 bytes) to host 131 | */ 132 | static void DataIn(void) 133 | { 134 | int iChunk; 135 | 136 | iChunk = MIN(MAX_PACKET_SIZE0, iResidue); 137 | USBHwEPWrite(0x80, pbData, iChunk); 138 | pbData += iChunk; 139 | iResidue -= iChunk; 140 | } 141 | 142 | 143 | /** 144 | * Handles IN/OUT transfers on EP0 145 | * 146 | * @param [in] bEP Endpoint address 147 | * @param [in] bEPStat Endpoint status 148 | */ 149 | void USBHandleControlTransfer(U8 bEP, U8 bEPStat) 150 | { 151 | int iChunk, iType; 152 | 153 | if (bEP == 0x00) { 154 | // OUT transfer 155 | if (bEPStat & EP_STATUS_SETUP) { 156 | // setup packet, reset request message state machine 157 | USBHwEPRead(0x00, (U8 *)&Setup, sizeof(Setup)); 158 | DBG("S%x", Setup.bRequest); 159 | 160 | // defaults for data pointer and residue 161 | iType = REQTYPE_GET_TYPE(Setup.bmRequestType); 162 | pbData = apbDataStore[iType]; 163 | iResidue = Setup.wLength; 164 | iLen = Setup.wLength; 165 | 166 | if ((Setup.wLength == 0) || 167 | (REQTYPE_GET_DIR(Setup.bmRequestType) == REQTYPE_DIR_TO_HOST)) { 168 | // ask installed handler to process request 169 | if (!_HandleRequest(&Setup, &iLen, &pbData)) { 170 | DBG("_HandleRequest1 failed\n"); 171 | StallControlPipe(bEPStat); 172 | return; 173 | } 174 | // send smallest of requested and offered length 175 | iResidue = MIN(iLen, Setup.wLength); 176 | // send first part (possibly a zero-length status message) 177 | DataIn(); 178 | } 179 | } 180 | else { 181 | if (iResidue > 0) { 182 | // store data 183 | iChunk = USBHwEPRead(0x00, pbData, iResidue); 184 | if (iChunk < 0) { 185 | StallControlPipe(bEPStat); 186 | return; 187 | } 188 | pbData += iChunk; 189 | iResidue -= iChunk; 190 | if (iResidue == 0) { 191 | // received all, send data to handler 192 | iType = REQTYPE_GET_TYPE(Setup.bmRequestType); 193 | pbData = apbDataStore[iType]; 194 | if (!_HandleRequest(&Setup, &iLen, &pbData)) { 195 | DBG("_HandleRequest2 failed\n"); 196 | StallControlPipe(bEPStat); 197 | return; 198 | } 199 | // send status to host 200 | DataIn(); 201 | } 202 | } 203 | else { 204 | // absorb zero-length status message 205 | iChunk = USBHwEPRead(0x00, NULL, 0); 206 | DBG(iChunk > 0 ? "?" : ""); 207 | } 208 | } 209 | } 210 | else if (bEP == 0x80) { 211 | // IN transfer 212 | // send more data if available (possibly a 0-length packet) 213 | DataIn(); 214 | } 215 | else { 216 | ASSERT(FALSE); 217 | } 218 | } 219 | 220 | 221 | /** 222 | Registers a callback for handling requests 223 | 224 | @param [in] iType Type of request, e.g. REQTYPE_TYPE_STANDARD 225 | @param [in] *pfnHandler Callback function pointer 226 | @param [in] *pbDataStore Data storage area for this type of request 227 | */ 228 | void USBRegisterRequestHandler(int iType, TFnHandleRequest *pfnHandler, U8 *pbDataStore) 229 | { 230 | ASSERT(iType >= 0); 231 | ASSERT(iType < 4); 232 | apfnReqHandlers[iType] = pfnHandler; 233 | apbDataStore[iType] = pbDataStore; 234 | } 235 | 236 | -------------------------------------------------------------------------------- /VCOM_lib/usbdebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | LPCUSB, an USB device driver for LPC microcontrollers 3 | Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl) 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. The name of the author may not be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | // CodeRed - comment out this printf, as will use real one from stdio.h 29 | // to implement output via semihosting 30 | 31 | //int printf(const char *format, ...); 32 | # include 33 | 34 | // CodeRed - added DEBUG_MESSAGES, so still get output for Release builds 35 | //#define DEBUG_MESSAGES 1 36 | //#ifdef DEBUG 37 | #ifdef DEBUG_MESSAGES 38 | #define DBG printf 39 | #define ASSERT(x) if(!(x)){DBG("\nAssertion '%s' failed in %s:%s#%d!\n",#x,__FILE__,__FUNCTION__,__LINE__);while(1);} 40 | #else 41 | #define DBG(x ...) 42 | #define ASSERT(x) 43 | #endif 44 | 45 | -------------------------------------------------------------------------------- /VCOM_lib/usbhw_lpc.h: -------------------------------------------------------------------------------- 1 | /* 2 | LPCUSB, an USB device driver for LPC microcontrollers 3 | Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl) 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. The name of the author may not be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | 29 | /** 30 | Hardware definitions for the LPC176x USB controller 31 | 32 | These are private to the usbhw module 33 | */ 34 | 35 | // CodeRed - pull in defines from NXP header file 36 | #include "LPC17xx.h" 37 | 38 | 39 | // CodeRed - these registers have been renamed on LPC176x 40 | #define USBReEP USBReEp 41 | #define OTG_CLK_CTRL USBClkCtrl 42 | #define OTG_CLK_STAT USBClkSt 43 | 44 | /* USBIntSt bits */ 45 | #define USB_INT_REQ_LP (1<<0) 46 | #define USB_INT_REQ_HP (1<<1) 47 | #define USB_INT_REQ_DMA (1<<2) 48 | #define USB_need_clock (1<<8) 49 | #define EN_USB_BITS (1<<31) 50 | 51 | /* USBDevInt... bits */ 52 | #define FRAME (1<<0) 53 | #define EP_FAST (1<<1) 54 | #define EP_SLOW (1<<2) 55 | #define DEV_STAT (1<<3) 56 | #define CCEMTY (1<<4) 57 | #define CDFULL (1<<5) 58 | #define RxENDPKT (1<<6) 59 | #define TxENDPKT (1<<7) 60 | #define EP_RLZED (1<<8) 61 | #define ERR_INT (1<<9) 62 | 63 | /* USBRxPLen bits */ 64 | #define PKT_LNGTH (1<<0) 65 | #define PKT_LNGTH_MASK 0x3FF 66 | #define DV (1<<10) 67 | #define PKT_RDY (1<<11) 68 | 69 | /* USBCtrl bits */ 70 | #define RD_EN (1<<0) 71 | #define WR_EN (1<<1) 72 | #define LOG_ENDPOINT (1<<2) 73 | 74 | /* protocol engine command codes */ 75 | /* device commands */ 76 | #define CMD_DEV_SET_ADDRESS 0xD0 77 | #define CMD_DEV_CONFIG 0xD8 78 | #define CMD_DEV_SET_MODE 0xF3 79 | #define CMD_DEV_READ_CUR_FRAME_NR 0xF5 80 | #define CMD_DEV_READ_TEST_REG 0xFD 81 | #define CMD_DEV_STATUS 0xFE /* read/write */ 82 | #define CMD_DEV_GET_ERROR_CODE 0xFF 83 | #define CMD_DEV_READ_ERROR_STATUS 0xFB 84 | /* endpoint commands */ 85 | #define CMD_EP_SELECT 0x00 86 | #define CMD_EP_SELECT_CLEAR 0x40 87 | #define CMD_EP_SET_STATUS 0x40 88 | #define CMD_EP_CLEAR_BUFFER 0xF2 89 | #define CMD_EP_VALIDATE_BUFFER 0xFA 90 | 91 | /* set address command */ 92 | #define DEV_ADDR (1<<0) 93 | #define DEV_EN (1<<7) 94 | 95 | /* configure device command */ 96 | #define CONF_DEVICE (1<<0) 97 | 98 | /* set mode command */ 99 | #define AP_CLK (1<<0) 100 | #define INAK_CI (1<<1) 101 | #define INAK_CO (1<<2) 102 | #define INAK_II (1<<3) 103 | #define INAK_IO (1<<4) 104 | #define INAK_BI (1<<5) 105 | #define INAK_BO (1<<6) 106 | 107 | /* set get device status command */ 108 | #define CON (1<<0) 109 | #define CON_CH (1<<1) 110 | #define SUS (1<<2) 111 | #define SUS_CH (1<<3) 112 | #define RST (1<<4) 113 | 114 | /* get error code command */ 115 | // ... 116 | 117 | /* Select Endpoint command read bits */ 118 | #define EPSTAT_FE (1<<0) 119 | #define EPSTAT_ST (1<<1) 120 | #define EPSTAT_STP (1<<2) 121 | #define EPSTAT_PO (1<<3) 122 | #define EPSTAT_EPN (1<<4) 123 | #define EPSTAT_B1FULL (1<<5) 124 | #define EPSTAT_B2FULL (1<<6) 125 | 126 | /* CMD_EP_SET_STATUS command */ 127 | #define EP_ST (1<<0) 128 | #define EP_DA (1<<5) 129 | #define EP_RF_MO (1<<6) 130 | #define EP_CND_ST (1<<7) 131 | 132 | /* read error status command */ 133 | #define PID_ERR (1<<0) 134 | #define UEPKT (1<<1) 135 | #define DCRC (1<<2) 136 | #define TIMEOUT (1<<3) 137 | #define EOP (1<<4) 138 | #define B_OVRN (1<<5) 139 | #define BTSTF (1<<6) 140 | #define TGL_ERR (1<<7) 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /VCOM_lib/usbinit.c: -------------------------------------------------------------------------------- 1 | /* 2 | LPCUSB, an USB device driver for LPC microcontrollers 3 | Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl) 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. The name of the author may not be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | 29 | /** @file 30 | USB stack initialisation 31 | */ 32 | 33 | // CodeRed - include the LPCUSB type.h file rather than NXP one directly 34 | //#include "type.h" 35 | #include "lpcusb_type.h" 36 | 37 | #include "usbdebug.h" 38 | #include "usbapi.h" 39 | 40 | 41 | /** data storage area for standard requests */ 42 | static U8 abStdReqData[8]; 43 | 44 | 45 | /** 46 | USB reset handler 47 | 48 | @param [in] bDevStatus Device status 49 | */ 50 | static void HandleUsbReset(U8 bDevStatus) 51 | { 52 | if (bDevStatus & DEV_STATUS_RESET) { 53 | DBG("\n!"); 54 | } 55 | } 56 | 57 | 58 | /** 59 | Initialises the USB hardware and sets up the USB stack by 60 | installing default callbacks. 61 | 62 | @return TRUE if initialisation was successful 63 | */ 64 | BOOL USBInit(void) 65 | { 66 | // init hardware 67 | USBHwInit(); 68 | 69 | // register bus reset handler 70 | USBHwRegisterDevIntHandler(HandleUsbReset); 71 | 72 | // register control transfer handler on EP0 73 | USBHwRegisterEPIntHandler(0x00, USBHandleControlTransfer); 74 | USBHwRegisterEPIntHandler(0x80, USBHandleControlTransfer); 75 | 76 | // setup control endpoints 77 | USBHwEPConfig(0x00, MAX_PACKET_SIZE0); 78 | USBHwEPConfig(0x80, MAX_PACKET_SIZE0); 79 | 80 | // register standard request handler 81 | USBRegisterRequestHandler(REQTYPE_TYPE_STANDARD, USBHandleStandardRequest, abStdReqData); 82 | 83 | return TRUE; 84 | } 85 | 86 | -------------------------------------------------------------------------------- /VCOM_lib/usbser.inf: -------------------------------------------------------------------------------- 1 | [Version] 2 | Signature="$Windows NT$" 3 | Class=Ports 4 | ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} 5 | Provider=%CodeRed% 6 | DriverVer=05/20/2010,1.0.0.0 7 | 8 | [MANUFACTURER] 9 | %ProviderName%=DeviceList, NTx86, NTamd64 10 | 11 | [DeviceList.NTx86] 12 | %RDB1768CDC%=DriverInstall,USB\VID_FFFF&PID_0005 13 | 14 | [DeviceList.NTamd64] 15 | %RDB1768CDC%=DriverInstall,USB\VID_FFFF&PID_0005 16 | 17 | [DriverInstall] 18 | include=mdmcpq.inf 19 | CopyFiles=FakeModemCopyFileSection 20 | AddReg=LowerFilterAddReg,SerialPropPageAddReg 21 | 22 | [DriverInstall.Services] 23 | include = mdmcpq.inf 24 | AddService = usbser, 0x00000002, LowerFilter_Service_Inst 25 | 26 | ; This adds the serial port property tab to the device properties dialog 27 | [SerialPropPageAddReg] 28 | HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 29 | 30 | [Strings] 31 | ProviderName = "CDC Driver" 32 | RDB1768CDC = "LPCUSB Virtual Com Port 33 | -------------------------------------------------------------------------------- /VCOM_lib/usbstruct.h: -------------------------------------------------------------------------------- 1 | /* 2 | LPCUSB, an USB device driver for LPC microcontrollers 3 | Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl) 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. The name of the author may not be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | 29 | /** 30 | Definitions of structures of standard USB packets 31 | */ 32 | 33 | #ifndef _USBSTRUCT_H_ 34 | #define _USBSTRUCT_H_ 35 | 36 | // CodeRed - include the LPCUSB type.h file rather than NXP one directly 37 | //#include "type.h" 38 | #include "lpcusb_type.h" 39 | 40 | 41 | /** setup packet definitions */ 42 | typedef struct { 43 | U8 bmRequestType; /**< characteristics of the specific request */ 44 | U8 bRequest; /**< specific request */ 45 | U16 wValue; /**< request specific parameter */ 46 | U16 wIndex; /**< request specific parameter */ 47 | U16 wLength; /**< length of data transfered in data phase */ 48 | } TSetupPacket; 49 | 50 | 51 | #define REQTYPE_GET_DIR(x) (((x)>>7)&0x01) 52 | #define REQTYPE_GET_TYPE(x) (((x)>>5)&0x03) 53 | #define REQTYPE_GET_RECIP(x) ((x)&0x1F) 54 | 55 | #define REQTYPE_DIR_TO_DEVICE 0 56 | #define REQTYPE_DIR_TO_HOST 1 57 | 58 | #define REQTYPE_TYPE_STANDARD 0 59 | #define REQTYPE_TYPE_CLASS 1 60 | #define REQTYPE_TYPE_VENDOR 2 61 | #define REQTYPE_TYPE_RESERVED 3 62 | 63 | #define REQTYPE_RECIP_DEVICE 0 64 | #define REQTYPE_RECIP_INTERFACE 1 65 | #define REQTYPE_RECIP_ENDPOINT 2 66 | #define REQTYPE_RECIP_OTHER 3 67 | 68 | /* standard requests */ 69 | #define REQ_GET_STATUS 0x00 70 | #define REQ_CLEAR_FEATURE 0x01 71 | #define REQ_SET_FEATURE 0x03 72 | #define REQ_SET_ADDRESS 0x05 73 | #define REQ_GET_DESCRIPTOR 0x06 74 | #define REQ_SET_DESCRIPTOR 0x07 75 | #define REQ_GET_CONFIGURATION 0x08 76 | #define REQ_SET_CONFIGURATION 0x09 77 | #define REQ_GET_INTERFACE 0x0A 78 | #define REQ_SET_INTERFACE 0x0B 79 | #define REQ_SYNCH_FRAME 0x0C 80 | 81 | /* class requests HID */ 82 | #define HID_GET_REPORT 0x01 83 | #define HID_GET_IDLE 0x02 84 | #define HID_GET_PROTOCOL 0x03 85 | #define HID_SET_REPORT 0x09 86 | #define HID_SET_IDLE 0x0A 87 | #define HID_SET_PROTOCOL 0x0B 88 | 89 | /* feature selectors */ 90 | #define FEA_ENDPOINT_HALT 0x00 91 | #define FEA_REMOTE_WAKEUP 0x01 92 | #define FEA_TEST_MODE 0x02 93 | 94 | /* 95 | USB descriptors 96 | */ 97 | 98 | /** USB descriptor header */ 99 | typedef struct { 100 | U8 bLength; /**< descriptor length */ 101 | U8 bDescriptorType; /**< descriptor type */ 102 | } TUSBDescHeader; 103 | 104 | #define DESC_DEVICE 1 105 | #define DESC_CONFIGURATION 2 106 | #define DESC_STRING 3 107 | #define DESC_INTERFACE 4 108 | #define DESC_ENDPOINT 5 109 | #define DESC_DEVICE_QUALIFIER 6 110 | #define DESC_OTHER_SPEED 7 111 | #define DESC_INTERFACE_POWER 8 112 | 113 | #define DESC_HID_HID 0x21 114 | #define DESC_HID_REPORT 0x22 115 | #define DESC_HID_PHYSICAL 0x23 116 | 117 | #define GET_DESC_TYPE(x) (((x)>>8)&0xFF) 118 | #define GET_DESC_INDEX(x) ((x)&0xFF) 119 | 120 | #endif /* _USBSTRUCT_H_ */ 121 | 122 | -------------------------------------------------------------------------------- /doc/csv/alarm_codes_en_US.csv: -------------------------------------------------------------------------------- 1 | "Alarm Code in v1.1+"," Alarm Message in v1.0-"," Alarm Description" 2 | "1","Hard limit","Hard limit has been triggered. Machine position is likely lost due to sudden halt. Re-homing is highly recommended." 3 | "2","Soft limit","Soft limit alarm. G-code motion target exceeds machine travel. Machine position retained. Alarm may be safely unlocked." 4 | "3","Abort during cycle","Reset while in motion. Machine position is likely lost due to sudden halt. Re-homing is highly recommended." 5 | "4","Probe fail","Probe fail. Probe is not in the expected initial state before starting probe cycle when G38.2 and G38.3 is not triggered and G38.4 and G38.5 is triggered." 6 | "5","Probe fail","Probe fail. Probe did not contact the workpiece within the programmed travel for G38.2 and G38.4." 7 | "6","Homing fail","Homing fail. The active homing cycle was reset." 8 | "7","Homing fail","Homing fail. Safety door was opened during homing cycle." 9 | "8","Homing fail","Homing fail. Pull off travel failed to clear limit switch. Try increasing pull-off setting or check wiring." 10 | "9","Homing fail","Homing fail. Could not find limit switch within search distances. Try increasing max travel, decreasing pull-off distance, or check wiring." 11 | -------------------------------------------------------------------------------- /doc/csv/build_option_codes_en_US.csv: -------------------------------------------------------------------------------- 1 | "OPT: Code"," Build-Option Description","State" 2 | "V","Variable spindle","Enabled" 3 | "N","Line numbers","Enabled" 4 | "M","Mist coolant M7","Enabled" 5 | "C","CoreXY","Enabled" 6 | "P","Parking motion","Enabled" 7 | "Z","Homing force origin","Enabled" 8 | "H","Homing single axis commands","Enabled" 9 | "L","Two limit switches on axis","Enabled" 10 | "A","Allow feed rate overrides in probe cycles","Enabled" 11 | "D","Use spindle direction as enable pin","Enabled" 12 | "0","Spindle enable off when speed is zero","Enabled" 13 | "S","Software limit pin debouncing","Enabled" 14 | "R","Parking override control","Enabled" 15 | "*","Restore all EEPROM command","Disabled" 16 | "$","Restore EEPROM `$` settings command","Disabled" 17 | "#","Restore EEPROM parameter data command","Disabled" 18 | "I","Build info write user string command","Disabled" 19 | "E","Force sync upon EEPROM write","Disabled" 20 | "W","Force sync upon work coordinate offset change","Disabled" 21 | "L","Homing initialization auto-lock","Disabled" -------------------------------------------------------------------------------- /doc/csv/error_codes_en_US.csv: -------------------------------------------------------------------------------- 1 | Error Code in v1.1+ ,Error Message in v1.0-, Error Description 2 | 1,Expected command letter,G-code words consist of a letter and a value. Letter was not found. 3 | 2,Bad number format,Missing the expected G-code word value or numeric value format is not valid. 4 | 3,Invalid statement,Grbl '$' system command was not recognized or supported. 5 | 4,Value < 0,Negative value received for an expected positive value. 6 | 5,Setting disabled,Homing cycle failure. Homing is not enabled via settings. 7 | 6,Value < 3 usec,Minimum step pulse time must be greater than 3usec. 8 | 7,EEPROM read fail. Using defaults,An EEPROM read failed. Auto-restoring affected EEPROM to default values. 9 | 8,Not idle,Grbl '$' command cannot be used unless Grbl is IDLE. Ensures smooth operation during a job. 10 | 9,G-code lock,G-code commands are locked out during alarm or jog state. 11 | 10,Homing not enabled,Soft limits cannot be enabled without homing also enabled. 12 | 11,Line overflow,Max characters per line exceeded. Received command line was not executed. 13 | 12,Step rate > 30kHz,Grbl '$' setting value cause the step rate to exceed the maximum supported. 14 | 13,Check Door,Safety door detected as opened and door state initiated. 15 | 14,Line length exceeded,Build info or startup line exceeded EEPROM line length limit. Line not stored. 16 | 15,Travel exceeded,Jog target exceeds machine travel. Jog command has been ignored. 17 | 16,Invalid jog command,Jog command has no '=' or contains prohibited g-code. 18 | 20,Unsupported command,Unsupported or invalid g-code command found in block. 19 | 21,Modal group violation,More than one g-code command from same modal group found in block. 20 | 22,Undefined feed rate,Feed rate has not yet been set or is undefined. 21 | 23,Invalid gcode ID:23,G-code command in block requires an integer value. 22 | 24,Invalid gcode ID:24,More than one g-code command that requires axis words found in block. 23 | 25,Invalid gcode ID:25,Repeated g-code word found in block. 24 | 26,Invalid gcode ID:26,No axis words found in block for g-code command or current modal state which requires them. 25 | 27,Invalid gcode ID:27,Line number value is invalid. 26 | 28,Invalid gcode ID:28,G-code command is missing a required value word. 27 | 29,Invalid gcode ID:29,G59.x work coordinate systems are not supported. 28 | 30,Invalid gcode ID:30,G53 only allowed with G0 and G1 motion modes. 29 | 31,Invalid gcode ID:31,Axis words found in block when no command or current modal state uses them. 30 | 32,Invalid gcode ID:32,G2 and G3 arcs require at least one in-plane axis word. 31 | 33,Invalid gcode ID:33,Motion command target is invalid. 32 | 34,Invalid gcode ID:34,Arc radius value is invalid. 33 | 35,Invalid gcode ID:35,G2 and G3 arcs require at least one in-plane offset word. 34 | 36,Invalid gcode ID:36,Unused value words found in block. 35 | 37,Invalid gcode ID:37,G43.1 dynamic tool length offset is not assigned to configured tool length axis. 36 | 38,Invalid gcode ID:38,Tool number greater than max supported value. -------------------------------------------------------------------------------- /doc/csv/setting_codes_en_US.csv: -------------------------------------------------------------------------------- 1 | "$-Code"," Setting"," Units"," Setting Description" 2 | "0","Step pulse time","microseconds","Sets time length per step. Minimum 3usec." 3 | "1","Step idle delay","milliseconds","Sets a short hold delay when stopping to let dynamics settle before disabling steppers. Value 255 keeps motors enabled with no delay." 4 | "2","Step pulse invert","mask","Inverts the step signal. Set axis bit to invert (00000ZYX)." 5 | "3","Step direction invert","mask","Inverts the direction signal. Set axis bit to invert (00000ZYX)." 6 | "4","Invert step enable pin","boolean","Inverts the stepper driver enable pin signal." 7 | "5","Invert limit pins","boolean","Inverts the all of the limit input pins." 8 | "6","Invert probe pin","boolean","Inverts the probe input pin signal." 9 | "10","Status report options","mask","Alters data included in status reports." 10 | "11","Junction deviation","millimeters","Sets how fast Grbl travels through consecutive motions. Lower value slows it down." 11 | "12","Arc tolerance","millimeters","Sets the G2 and G3 arc tracing accuracy based on radial error. Beware: A very small value may effect performance." 12 | "13","Report in inches","boolean","Enables inch units when returning any position and rate value that is not a settings value." 13 | "20","Soft limits enable","boolean","Enables soft limits checks within machine travel and sets alarm when exceeded. Requires homing." 14 | "21","Hard limits enable","boolean","Enables hard limits. Immediately halts motion and throws an alarm when switch is triggered." 15 | "22","Homing cycle enable","boolean","Enables homing cycle. Requires limit switches on all axes." 16 | "23","Homing direction invert","mask","Homing searches for a switch in the positive direction. Set axis bit (00000ZYX) to search in negative direction." 17 | "24","Homing locate feed rate","mm/min","Feed rate to slowly engage limit switch to determine its location accurately." 18 | "25","Homing search seek rate","mm/min","Seek rate to quickly find the limit switch before the slower locating phase." 19 | "26","Homing switch debounce delay","milliseconds","Sets a short delay between phases of homing cycle to let a switch debounce." 20 | "27","Homing switch pull-off distance","millimeters","Retract distance after triggering switch to disengage it. Homing will fail if switch isn't cleared." 21 | "30","Maximum spindle speed","RPM","Maximum spindle speed. Sets PWM to 100% duty cycle." 22 | "31","Minimum spindle speed","RPM","Minimum spindle speed. Sets PWM to 0.4% or lowest duty cycle." 23 | "32","Laser-mode enable","boolean","Enables laser mode. Consecutive G1/2/3 commands will not halt when spindle speed is changed." 24 | "100","X-axis travel resolution","step/mm","X-axis travel resolution in steps per millimeter." 25 | "101","Y-axis travel resolution","step/mm","Y-axis travel resolution in steps per millimeter." 26 | "102","Z-axis travel resolution","step/mm","Z-axis travel resolution in steps per millimeter." 27 | "110","X-axis maximum rate","mm/min","X-axis maximum rate. Used as G0 rapid rate." 28 | "111","Y-axis maximum rate","mm/min","Y-axis maximum rate. Used as G0 rapid rate." 29 | "112","Z-axis maximum rate","mm/min","Z-axis maximum rate. Used as G0 rapid rate." 30 | "120","X-axis acceleration","mm/sec^2","X-axis acceleration. Used for motion planning to not exceed motor torque and lose steps." 31 | "121","Y-axis acceleration","mm/sec^2","Y-axis acceleration. Used for motion planning to not exceed motor torque and lose steps." 32 | "122","Z-axis acceleration","mm/sec^2","Z-axis acceleration. Used for motion planning to not exceed motor torque and lose steps." 33 | "130","X-axis maximum travel","millimeters","Maximum X-axis travel distance from homing switch. Determines valid machine space for soft-limits and homing search distances." 34 | "131","Y-axis maximum travel","millimeters","Maximum Y-axis travel distance from homing switch. Determines valid machine space for soft-limits and homing search distances." 35 | "132","Z-axis maximum travel","millimeters","Maximum Z-axis travel distance from homing switch. Determines valid machine space for soft-limits and homing search distances." 36 | -------------------------------------------------------------------------------- /doc/log/commit_log_v0.9j.txt: -------------------------------------------------------------------------------- 1 | ---------------- 2 | Date: 2015-08-14 3 | Author: Sonny Jeon 4 | Subject: Individual control pin invert compile-option. 5 | 6 | - Control pins may be individually inverted through a 7 | CONTROL_INVERT_MASK macro. This mask is define in the cpu_map.h file. 8 | 9 | 10 | ---------------- 11 | Date: 2015-07-17 12 | Author: Sonny Jeon 13 | Subject: Version bump to v0.9j 14 | 15 | - Version bump requested by OEMs to easily determine whether the 16 | firmware supports the new EEPROM reset feature. Other than that, no 17 | significant changes. 18 | -------------------------------------------------------------------------------- /doc/log/commit_log_v1.0b.txt: -------------------------------------------------------------------------------- 1 | ---------------- 2 | Date: 2015-09-30 3 | Author: Sonny Jeon 4 | Subject: Bug fixes. 5 | 6 | - G38.x was not printing correctly in the $G g-code state reports. Now 7 | fixed. 8 | 9 | - When investigating the above issue, it was noticed that G38.x 10 | wouldn’t show at all, but instead a G0 would be printed. This was 11 | unlike the v0.9j master build. It turned out volatile variables do not 12 | like to be defined inside a C struct. These are undefined on how to be 13 | handled. Once pulled out, all weird issues went away. 14 | 15 | - Also changed two ‘sizeof()’ statements in the mc_probe() and 16 | probe_state_monitor() functions to be more robust later on. 17 | 18 | - Updated the commit logs to individual files for each minor release. 19 | Forgot to update the generating script to account for this. 20 | 21 | 22 | ---------------- 23 | Date: 2015-09-30 24 | Author: Sonny Jeon 25 | Subject: Minor bug fixes. 26 | 27 | - G38.x was not printing correctly in the $G g-code state reports. Now 28 | fixed. 29 | 30 | - Potential bug regarding volatile variables inside a struct. It has 31 | never been a problem in v0.9, but ran into this during v1.0 32 | development. Just to be safe, the fixes are applied here. 33 | 34 | - Updated pre-built firmwares with these two bug fixes. 35 | 36 | 37 | ---------------- 38 | Date: 2015-09-24 39 | Author: Sonny Jeon 40 | Subject: Updated G28/G30 intermediate motion behavior. 41 | 42 | - G28 and G30’s behavior has been updated from the old NIST g-code 43 | standard to LinuxCNC’s. Previously when an intermediate motion was 44 | programmed, the NIST standard would move all axes to the final G28/30 45 | stored coordinates. LinuxCNC states it only moves the axes specified in 46 | the command. 47 | 48 | For example, suppose G28’s stored position is (x,y,z) = (1,2,3) for 49 | simplicity, and we want to do an automated z-axis tool retraction and 50 | then park at the x,y location. `G28 G91 Z5` will first move the Z axis 51 | 5mm(or inches) up, then move Z to position 3 in machine coordinates. 52 | Next, the command `G28 G91 X0 Y0` would skip the intermediate move 53 | since distance is zero, but then move only the x and y axes to machine 54 | coordinates 1 and 2, respectively. The z-axis wouldn’t move in this 55 | case, since it wasn’t specified. 56 | 57 | This change is intended to make Grbl more LinuxCNC compatible while 58 | making commands, like the shown tool retraction, much easier to 59 | implement. 60 | 61 | 62 | ---------------- 63 | Date: 2015-09-05 64 | Author: Sonny Jeon 65 | Subject: Parking motion bug fix. 66 | 67 | - Parking motion would intermittently complete the queued tool path 68 | upon resuming in certain scenarios. Now fixed. 69 | 70 | 71 | ---------------- 72 | Date: 2015-08-29 73 | Author: Sonny Jeon 74 | Subject: Optional line number reporting bug fix. 75 | 76 | - Fixed a bug where it would not compile when USE_LINE_NUMBERS was 77 | enabled. 78 | 79 | 80 | ---------------- 81 | Date: 2015-08-27 82 | Author: Sonny Jeon 83 | Subject: Update README 84 | 85 | 86 | ---------------- 87 | Date: 2015-08-27 88 | Author: Sonny Jeon 89 | Subject: v1.0 Beta Release. 90 | 91 | - Tons of new stuff in this release, which is fairly stable and well 92 | tested. However, much more is coming soon! 93 | 94 | - Real-time parking motion with safety door. When this compile option 95 | is enabled, an opened safety door will cause Grbl to automatically feed 96 | hold, retract, de-energize the spindle/coolant, and parks near Z max. 97 | After the door is closed and resume is commanded, this reverses and the 98 | program continues as if nothing happened. This is also highly 99 | configurable. See config.h for details. 100 | 101 | - New spindle max and min rpm ‘$’ settings! This has been requested 102 | often. Grbl will output 5V when commanded to turn on the spindle at its 103 | max rpm, and 0.02V with min rpm. The voltage and the rpm range are 104 | linear to each other. This should help users tweak their settings to 105 | get close to true rpm’s. 106 | 107 | - If the new max rpm ‘$’ setting is set = 0 or less than min rpm, the 108 | spindle speed PWM pin will act like a regular on/off spindle enable 109 | pin. On pin D11. 110 | 111 | - BEWARE: Your old EEPROM settings will be wiped! The new spindle rpm 112 | settings require a new settings version, so Grbl will automatically 113 | wipe and restore the EEPROM with the new defaults. 114 | 115 | - Control pin can now be inverted individually with a 116 | CONTROL_INVERT_MASK in the cpu_map header file. Not typical for users 117 | to need this, but handy to have. 118 | 119 | - Fixed bug when Grbl receive too many characters in a line and 120 | overflows. Previously it would respond with an error per overflow 121 | character and another acknowledge upon an EOL character. This broke the 122 | streaming protocol. Now fixed to only respond with an error after an 123 | EOL character. 124 | 125 | - Fixed a bug with the safety door during an ALARM mode. You now can’t 126 | home or unlock the axes until the safety door has been closed. This is 127 | for safety reasons (obviously.) 128 | 129 | - Tweaked some the Mega2560 cpu_map settings . Increased segment buffer 130 | size and fixed the spindle PWM settings to output at a higher PWM 131 | frequency. 132 | 133 | - Generalized the delay function used by G4 delay for use by parking 134 | motion. Allows non-blocking status reports and real-time control during 135 | re-energizing of the spindle and coolant. 136 | 137 | - Added spindle rpm max and min defaults to default.h files. 138 | 139 | - Added a new print float for rpm values. 140 | 141 | -------------------------------------------------------------------------------- /doc/log/commit_log_v1.0c.txt: -------------------------------------------------------------------------------- 1 | ---------------- 2 | Date: 2016-03-19 3 | Author: Sonny Jeon 4 | Subject: No variable spindle and spindle speed fix. 5 | 6 | - Soft limit errors were stuck in a feed hold without notifying the 7 | user why it was in a hold. When resumed, the soft limit error would 8 | kick in. Issue should be fixed to behave as intended to automatically 9 | hold and issue a soft limit alarm once the machine has come to a stop. 10 | 11 | 12 | ---------------- 13 | Date: 2016-03-11 14 | Author: Sonny Jeon 15 | Subject: Soft limit error bug fix. 16 | 17 | - Soft limit errors were stuck in a feed hold without notifying the 18 | user why it was in a hold. When resumed, the soft limit error would 19 | kick in. Issue should be fixed to behave as intended. To automatically 20 | hold and issue a soft limit alarm once the machine has come to a stop. 21 | 22 | 23 | ---------------- 24 | Date: 2016-03-04 25 | Author: Sonny Jeon 26 | Subject: Applied master branch bug fixes. 27 | 28 | - Planner was under-estimating maximum speeds through straight 29 | junctions in certain cases. The calculations have been updated to be 30 | more accurate. 31 | 32 | - Strange sizeof() bug in the most recent releases. Manifested as an 33 | alarm upon a power up even when homing was disabled. Fixed by declaring 34 | sizeof() with struct types, rather than variable names, even though 35 | they were validated to give the same value. 36 | 37 | - Spindle speed zero should disable the spindle. Now fixed. 38 | 39 | - New configuration option for inverting certain limit pins. Handy for 40 | mixed NO and NC switch machines. See config.h for details. 41 | 42 | 43 | ---------------- 44 | Date: 2015-11-09 45 | Author: Sonny Jeon 46 | Subject: Pin state reporting of all pins. Flash optimization. 47 | 48 | - New pin state realtime reporting feature. Instead of `Lim:000` for 49 | limit state reports, the new feature shows `Pin:000|0|0000`, or 50 | something similar. The `|` delimited fields indicate xyz limits, probe, 51 | and control pin states, where 0 is always not triggered, and 1 is 52 | triggered. Invert masks ARE accounted for. 53 | Each field may be enabled or disabled via the `$10` status report 54 | setting. The probe and control pin flags are bits 5 and 6, respectively. 55 | 56 | - Remove the now deprecated `REPORT_CONTROL_PIN_STATE` option in 57 | config.h 58 | 59 | - The old limit pin reports `Lim:000` may be re-enabled by commenting 60 | out `REPORT_ALL_PIN_STATES` in config.h. 61 | 62 | - Incremented the version letter (v1.0c) to indicate the change in 63 | reporting style. 64 | 65 | - Replaced all bit_true_atomic and bit_false_atomic macros with 66 | function calls. This saved a couple hundred bytes of flash. 67 | 68 | -------------------------------------------------------------------------------- /doc/media/COPYING: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2015 Gnea Research LLC. All Rights Reserved. 3 | -------------------------------------------------------------------------------- /doc/media/Grbl Logo 150px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cprezzi/grbl-LPC/72d029ed2a9e020ae049fc6b92851f013a352ae7/doc/media/Grbl Logo 150px.png -------------------------------------------------------------------------------- /doc/media/Grbl Logo 250px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cprezzi/grbl-LPC/72d029ed2a9e020ae049fc6b92851f013a352ae7/doc/media/Grbl Logo 250px.png -------------------------------------------------------------------------------- /doc/media/Grbl Logo 320px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cprezzi/grbl-LPC/72d029ed2a9e020ae049fc6b92851f013a352ae7/doc/media/Grbl Logo 320px.png -------------------------------------------------------------------------------- /doc/media/Grbl Logo 640px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cprezzi/grbl-LPC/72d029ed2a9e020ae049fc6b92851f013a352ae7/doc/media/Grbl Logo 640px.png -------------------------------------------------------------------------------- /doc/media/Grbl Logo.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cprezzi/grbl-LPC/72d029ed2a9e020ae049fc6b92851f013a352ae7/doc/media/Grbl Logo.pdf -------------------------------------------------------------------------------- /doc/media/Grbl Logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 16 | 18 | 19 | 21 | image/svg+xml 22 | 24 | 25 | 26 | 27 | 28 | 48 | /Users/chamnit/Dropbox/documents/OHS/Logo/Grbl.DXF - scale = 58.043118, origin = (0.000000, 0.000000), auto = True 50 | 52 | 58 | 62 | 63 | 70 | 76 | 82 | 88 | 89 | 91 | 93 | 95 | 96 | 100 | 103 | 109 | 115 | 121 | 127 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /doc/media/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cprezzi/grbl-LPC/72d029ed2a9e020ae049fc6b92851f013a352ae7/doc/media/Thumbs.db -------------------------------------------------------------------------------- /doc/script/simple_stream.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """\ 3 | Simple g-code streaming script for grbl 4 | 5 | Provided as an illustration of the basic communication interface 6 | for grbl. When grbl has finished parsing the g-code block, it will 7 | return an 'ok' or 'error' response. When the planner buffer is full, 8 | grbl will not send a response until the planner buffer clears space. 9 | 10 | G02/03 arcs are special exceptions, where they inject short line 11 | segments directly into the planner. So there may not be a response 12 | from grbl for the duration of the arc. 13 | 14 | --------------------- 15 | The MIT License (MIT) 16 | 17 | Copyright (c) 2012 Sungeun K. Jeon 18 | 19 | Permission is hereby granted, free of charge, to any person obtaining a copy 20 | of this software and associated documentation files (the "Software"), to deal 21 | in the Software without restriction, including without limitation the rights 22 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 23 | copies of the Software, and to permit persons to whom the Software is 24 | furnished to do so, subject to the following conditions: 25 | 26 | The above copyright notice and this permission notice shall be included in 27 | all copies or substantial portions of the Software. 28 | 29 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 32 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 34 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 35 | THE SOFTWARE. 36 | --------------------- 37 | """ 38 | 39 | import serial 40 | import time 41 | 42 | # Open grbl serial port 43 | s = serial.Serial('/dev/tty.usbmodem1811',115200) 44 | 45 | # Open g-code file 46 | f = open('grbl.gcode','r'); 47 | 48 | # Wake up grbl 49 | s.write("\r\n\r\n") 50 | time.sleep(2) # Wait for grbl to initialize 51 | s.flushInput() # Flush startup text in serial input 52 | 53 | # Stream g-code to grbl 54 | for line in f: 55 | l = line.strip() # Strip all EOL characters for consistency 56 | print 'Sending: ' + l, 57 | s.write(l + '\n') # Send g-code block to grbl 58 | grbl_out = s.readline() # Wait for grbl response with carriage return 59 | print ' : ' + grbl_out.strip() 60 | 61 | # Wait here until grbl is finished to close serial port and file. 62 | raw_input(" Press to exit and disable grbl.") 63 | 64 | # Close file and serial port 65 | f.close() 66 | s.close() -------------------------------------------------------------------------------- /doc/script/stream.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """\ 3 | 4 | Stream g-code to grbl controller 5 | 6 | This script differs from the simple_stream.py script by 7 | tracking the number of characters in grbl's serial read 8 | buffer. This allows grbl to fetch the next line directly 9 | from the serial buffer and does not have to wait for a 10 | response from the computer. This effectively adds another 11 | buffer layer to prevent buffer starvation. 12 | 13 | CHANGELOG: 14 | - 20161212: Added push message feedback for simple streaming 15 | - 20140714: Updated baud rate to 115200. Added a settings 16 | write mode via simple streaming method. MIT-licensed. 17 | 18 | TODO: 19 | - Add runtime command capabilities 20 | 21 | --------------------- 22 | The MIT License (MIT) 23 | 24 | Copyright (c) 2012-2016 Sungeun K. Jeon 25 | 26 | Permission is hereby granted, free of charge, to any person obtaining a copy 27 | of this software and associated documentation files (the "Software"), to deal 28 | in the Software without restriction, including without limitation the rights 29 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 30 | copies of the Software, and to permit persons to whom the Software is 31 | furnished to do so, subject to the following conditions: 32 | 33 | The above copyright notice and this permission notice shall be included in 34 | all copies or substantial portions of the Software. 35 | 36 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 37 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 38 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 39 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 40 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 41 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 42 | THE SOFTWARE. 43 | --------------------- 44 | """ 45 | 46 | import serial 47 | import re 48 | import time 49 | import sys 50 | import argparse 51 | # import threading 52 | 53 | RX_BUFFER_SIZE = 128 54 | 55 | # Define command line argument interface 56 | parser = argparse.ArgumentParser(description='Stream g-code file to grbl. (pySerial and argparse libraries required)') 57 | parser.add_argument('gcode_file', type=argparse.FileType('r'), 58 | help='g-code filename to be streamed') 59 | parser.add_argument('device_file', 60 | help='serial device path') 61 | parser.add_argument('-q','--quiet',action='store_true', default=False, 62 | help='suppress output text') 63 | parser.add_argument('-s','--settings',action='store_true', default=False, 64 | help='settings write mode') 65 | args = parser.parse_args() 66 | 67 | # Periodic timer to query for status reports 68 | # TODO: Need to track down why this doesn't restart consistently before a release. 69 | # def periodic(): 70 | # s.write('?') 71 | # t = threading.Timer(0.1, periodic) # In seconds 72 | # t.start() 73 | 74 | # Initialize 75 | s = serial.Serial(args.device_file,115200) 76 | f = args.gcode_file 77 | verbose = True 78 | if args.quiet : verbose = False 79 | settings_mode = False 80 | if args.settings : settings_mode = True 81 | 82 | # Wake up grbl 83 | print "Initializing grbl..." 84 | s.write("\r\n\r\n") 85 | 86 | # Wait for grbl to initialize and flush startup text in serial input 87 | time.sleep(2) 88 | s.flushInput() 89 | 90 | # Stream g-code to grbl 91 | l_count = 0 92 | if settings_mode: 93 | # Send settings file via simple call-response streaming method. Settings must be streamed 94 | # in this manner since the EEPROM accessing cycles shut-off the serial interrupt. 95 | print "SETTINGS MODE: Streaming", args.gcode_file.name, " to ", args.device_file 96 | for line in f: 97 | l_count += 1 # Iterate line counter 98 | # l_block = re.sub('\s|\(.*?\)','',line).upper() # Strip comments/spaces/new line and capitalize 99 | l_block = line.strip() # Strip all EOL characters for consistency 100 | if verbose: print 'SND: ' + str(l_count) + ':' + l_block, 101 | s.write(l_block + '\n') # Send g-code block to grbl 102 | while 1: 103 | grbl_out = s.readline().strip() # Wait for grbl response with carriage return 104 | if grbl_out.find('ok') < 0 and grbl_out.find('error') < 0 : 105 | print "\n Debug: ",grbl_out, 106 | else : 107 | if verbose: print 'REC:',grbl_out 108 | break 109 | else: 110 | # Send g-code program via a more agressive streaming protocol that forces characters into 111 | # Grbl's serial read buffer to ensure Grbl has immediate access to the next g-code command 112 | # rather than wait for the call-response serial protocol to finish. This is done by careful 113 | # counting of the number of characters sent by the streamer to Grbl and tracking Grbl's 114 | # responses, such that we never overflow Grbl's serial read buffer. 115 | g_count = 0 116 | c_line = [] 117 | # periodic() # Start status report periodic timer 118 | for line in f: 119 | l_count += 1 # Iterate line counter 120 | # l_block = re.sub('\s|\(.*?\)','',line).upper() # Strip comments/spaces/new line and capitalize 121 | l_block = line.strip() 122 | c_line.append(len(l_block)+1) # Track number of characters in grbl serial read buffer 123 | grbl_out = '' 124 | while sum(c_line) >= RX_BUFFER_SIZE-1 | s.inWaiting() : 125 | out_temp = s.readline().strip() # Wait for grbl response 126 | if out_temp.find('ok') < 0 and out_temp.find('error') < 0 : 127 | print " Debug: ",out_temp # Debug response 128 | else : 129 | grbl_out += out_temp; 130 | g_count += 1 # Iterate g-code counter 131 | grbl_out += str(g_count); # Add line finished indicator 132 | del c_line[0] # Delete the block character count corresponding to the last 'ok' 133 | if verbose: print "SND: " + str(l_count) + " : " + l_block, 134 | s.write(l_block + '\n') # Send g-code block to grbl 135 | if verbose : print "BUF:",str(sum(c_line)),"REC:",grbl_out 136 | 137 | # Wait for user input after streaming is completed 138 | print "G-code streaming finished!\n" 139 | print "WARNING: Wait until grbl completes buffered g-code blocks before exiting." 140 | raw_input(" Press to exit and disable grbl.") 141 | 142 | # Close file and serial port 143 | f.close() 144 | s.close() 145 | -------------------------------------------------------------------------------- /grbl-lpc/avr/interrupt.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define ISR(f) void f() 6 | inline void cli() {__disable_irq();} 7 | inline void sei() {__enable_irq();} 8 | -------------------------------------------------------------------------------- /grbl-lpc/avr/io.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | struct DummyReg { 5 | operator uint8_t() {return 0;} 6 | uint8_t operator=(uint8_t x) {return x;} 7 | uint8_t operator&=(uint8_t x) {return *this = *this & x;} 8 | uint8_t operator|=(uint8_t x) {return *this = *this | x;} 9 | }; 10 | 11 | extern DummyReg NotUsed; 12 | extern DummyReg PCICR; 13 | extern DummyReg PCIE1; 14 | 15 | -------------------------------------------------------------------------------- /grbl-lpc/avr/pgmspace.h: -------------------------------------------------------------------------------- 1 | #define PSTR(s) s 2 | 3 | inline char pgm_read_byte_near(const char* p) {return *p;} 4 | -------------------------------------------------------------------------------- /grbl-lpc/avr/wdt.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cprezzi/grbl-LPC/72d029ed2a9e020ae049fc6b92851f013a352ae7/grbl-lpc/avr/wdt.h -------------------------------------------------------------------------------- /grbl-lpc/current_control.cpp: -------------------------------------------------------------------------------- 1 | // Current control 2 | // 3 | // Copyright 2017 Todd Fleming 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | // IN THE SOFTWARE. 22 | 23 | #include "current_control.h" 24 | #include "grbl.h" 25 | #include "Driver_I2C.h" 26 | 27 | #undef min 28 | #undef max 29 | #include 30 | 31 | #ifdef CURRENT_I2C 32 | extern ARM_DRIVER_I2C CURRENT_I2C; 33 | static const uint8_t wiperRegs[] = CURRENT_WIPERS; 34 | #endif 35 | 36 | void current_init() 37 | { 38 | #ifdef CURRENT_I2C 39 | CURRENT_I2C.Initialize(nullptr); 40 | CURRENT_I2C.PowerControl(ARM_POWER_FULL); 41 | CURRENT_I2C.Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_STANDARD); 42 | CURRENT_I2C.Control(ARM_I2C_BUS_CLEAR, 0); 43 | 44 | #ifdef CURRENT_MCP44XX_ADDR 45 | uint8_t init1[] = {0x40, 0xff}; 46 | uint8_t init2[] = {0xA0, 0xff}; 47 | CURRENT_I2C.MasterTransmit(CURRENT_MCP44XX_ADDR, init1, 2, false); 48 | while (CURRENT_I2C.GetStatus().busy) 49 | ; 50 | CURRENT_I2C.MasterTransmit(CURRENT_MCP44XX_ADDR, init2, 2, false); 51 | while (CURRENT_I2C.GetStatus().busy) 52 | ; 53 | #endif 54 | 55 | set_current(0, settings.current[0]); 56 | set_current(1, settings.current[1]); 57 | set_current(2, settings.current[2]); 58 | set_current(3, settings.current[3]); 59 | #endif 60 | } 61 | 62 | void set_current(uint8_t motor, float amps) 63 | { 64 | #if defined(CURRENT_I2C) && defined(CURRENT_MCP44XX_ADDR) 65 | uint8_t command[] = { 66 | uint8_t(wiperRegs[motor] << 4), 67 | uint8_t(std::min(255.0, std::max(0.0, std::round(amps * CURRENT_FACTOR)))), 68 | }; 69 | CURRENT_I2C.MasterTransmit(CURRENT_MCP44XX_ADDR, command, sizeof(command), false); 70 | while (CURRENT_I2C.GetStatus().busy) 71 | ; 72 | #endif 73 | } 74 | -------------------------------------------------------------------------------- /grbl-lpc/current_control.h: -------------------------------------------------------------------------------- 1 | // Current control 2 | // 3 | // Copyright 2017 Todd Fleming 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | // IN THE SOFTWARE. 22 | 23 | #include 24 | 25 | void current_init(); 26 | void set_current(uint8_t motor, float amps); 27 | -------------------------------------------------------------------------------- /grbl-lpc/debug.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Copyright 2017 Todd Fleming 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | // IN THE SOFTWARE. 22 | 23 | #include "LPC17xx.h" 24 | #include 25 | 26 | static const uint32_t leds = (1 << 21) | (1 << 20) | (1 << 19) | (1 << 18); 27 | 28 | inline void debug_init() 29 | { 30 | LPC_GPIO1->FIODIR = leds; 31 | LPC_GPIO1->FIOPIN = 0; 32 | } 33 | 34 | inline void debug_enter() 35 | { 36 | LPC_GPIO1->FIOPIN = (LPC_GPIO1->FIOPIN | (1 << 21)) ^ (1 << 20); 37 | } 38 | 39 | inline void debug_exit() 40 | { 41 | LPC_GPIO1->FIOPIN &= ~(1 << 21); 42 | } 43 | 44 | inline void xdebug_enter() {} 45 | inline void xdebug_exit() {} 46 | -------------------------------------------------------------------------------- /grbl-lpc/delay.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Todd Fleming 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #include "delay.h" 22 | 23 | void delay_init() 24 | { 25 | LPC_TIM3->CTCR = 0; // Count Control (0=TimerMode, 1-3=EdgeCounterMode) 26 | LPC_TIM3->PR = 0; // no Prescale (TC increments ever PR+1 clocks) 27 | LPC_TIM3->MCR = 0; // no Match Control actions 28 | LPC_TIM3->CCR = 0; // no Capture Control actions 29 | LPC_TIM3->EMR = 0; // no External Match (controls external match pins) 30 | LPC_TIM3->TCR = 0b10; // reset Timer Control (0b10=Reset, 0b01=Enable) 31 | LPC_TIM3->TCR = 0b01; // enable Timer Control (0b10=Reset, 0b01=Enable) 32 | } 33 | -------------------------------------------------------------------------------- /grbl-lpc/delay.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Copyright 2017 Todd Fleming 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | // IN THE SOFTWARE. 22 | 23 | #include "LPC17xx.h" 24 | 25 | void delay_init(); 26 | 27 | // Get current time in clock cycles 28 | inline uint32_t get_time() 29 | { 30 | return LPC_TIM3->TC; 31 | } 32 | 33 | // Wait until get_time() is numCycles past startTime. Handles timer wrap. 34 | inline void delay_loop(uint32_t startTime, uint32_t numCycles) 35 | { 36 | while (get_time() - startTime < numCycles) 37 | ; 38 | } 39 | 40 | inline void delay_us(uint32_t us) 41 | { 42 | delay_loop(get_time(), uint32_t(uint64_t(SystemCoreClock) * us / 1'000'000)); 43 | } 44 | 45 | inline void delay_ms(uint32_t ms) 46 | { 47 | delay_loop(get_time(), uint32_t(uint64_t(SystemCoreClock) * ms / 1000)); 48 | } 49 | -------------------------------------------------------------------------------- /grbl-lpc/flash.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Todd Fleming 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #include "grbl.h" 22 | 23 | static constexpr unsigned flash_sector = 15; // Last 4k sector 24 | static constexpr unsigned flash_addr = 0xF000; // Last 4k sector 25 | static constexpr unsigned flash_size = 1024; // Only using 1k of a 4k sector 26 | static char *flash_memory = (char *)flash_addr; // Flash memory 27 | static char flash_buffer[flash_size] __attribute__((aligned(4))); // Copy of flash memory 28 | using Iap = void(unsigned[], unsigned[]); // IAP entry point function 29 | static const Iap *iap = (Iap *)0x1FFF1FF1; // IAP entry point address 30 | 31 | void eeprom_init() 32 | { 33 | memcpy(flash_buffer, flash_memory, flash_size); // Copy flash memory into local flash buffer 34 | } 35 | 36 | void eeprom_commit() 37 | { 38 | if (!memcmp(flash_buffer, flash_memory, flash_size)) 39 | return; // No changes to commit 40 | unsigned prepCommand[5] = { 41 | 50, // Prepare sector(s) for write operation 42 | flash_sector, // Start sector 43 | flash_sector, // End sector 44 | }; 45 | unsigned eraseCommand[5] = { 46 | 52, // Erase sector(s) 47 | flash_sector, // Start sector 48 | flash_sector, // End sector 49 | SystemCoreClock / 1000, // CPU clock frequency in kHz 50 | }; 51 | unsigned writeCommand[5] = { 52 | 51, // Copy RAM to Flash 53 | flash_addr, // Destination flash address (256-byte boundary) 54 | (unsigned)flash_buffer, // Source RAM address (word boundary) 55 | flash_size, // Number of bytes to write (must be: 256, 512, 1024, 4096) 56 | SystemCoreClock / 1000, // CPU clock frequency in kHz 57 | }; 58 | unsigned output[5]; 59 | // Run In-Application Programming (IAP) routines 60 | iap(prepCommand, output); 61 | iap(eraseCommand, output); 62 | iap(prepCommand, output); 63 | iap(writeCommand, output); 64 | } 65 | 66 | unsigned char eeprom_get_char(unsigned int addr) 67 | { 68 | return flash_buffer[addr]; 69 | } 70 | 71 | void eeprom_put_char(unsigned int addr, unsigned char new_value) 72 | { 73 | flash_buffer[addr] = new_value; 74 | } 75 | 76 | static unsigned char memcpy_with_checksum(char *dest, char *src, unsigned size) 77 | { 78 | unsigned char checksum = 0; 79 | while (size--) 80 | { 81 | checksum = ((checksum << 1) || (checksum >> 7)) + *src; 82 | *dest++ = *src++; 83 | } 84 | return checksum; 85 | } 86 | 87 | void memcpy_to_eeprom_with_checksum(unsigned int destination, char *source, unsigned int size) 88 | { 89 | auto checksum = memcpy_with_checksum(flash_buffer + destination, source, size); 90 | flash_buffer[destination + size] = checksum; 91 | } 92 | 93 | int memcpy_from_eeprom_with_checksum(char *destination, unsigned int source, unsigned int size) 94 | { 95 | auto checksum = memcpy_with_checksum(destination, flash_buffer + source, size); 96 | return checksum == flash_buffer[source + size]; 97 | } 98 | -------------------------------------------------------------------------------- /grbl-lpc/isr_init.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Todd Fleming 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #include "grbl.h" 22 | 23 | void isr_init() 24 | { 25 | // Set all interrupts and system handlers to lowest priority 26 | for (auto &ip : NVIC->IP) 27 | ip = 31 << 3; 28 | for (auto &shp : SCB->SHP) 29 | shp = 31 << 3; 30 | 31 | // Stepper ISR needs highest priority 32 | NVIC->IP[TIMER1_IRQn] = 0; 33 | } 34 | -------------------------------------------------------------------------------- /grbl-lpc/pwm_driver.cpp: -------------------------------------------------------------------------------- 1 | // PWM Driver - LPC176x - Single edge only, does not support double edge PWM 2 | // 3 | // Copyright 2017 Brett Fleming 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | // IN THE SOFTWARE. 22 | 23 | #include "pwm_driver.h" 24 | #include "LPC17xx.h" 25 | 26 | //#include "grbl.h" 27 | 28 | //LPC_PWM1_BASE 29 | //LPC_PWM1 is of type LPC_PWM_TypeDef at Address LPC_PWM1_BASE 30 | 31 | /* 32 | Theory of operation: Initialize, start running, change width any time while running. 33 | 34 | pwm_init(PWM1_CH1, 1000, 0); 35 | pwm_enable(PWM1_CH1); 36 | pwm_set_width(250); 37 | sleep(1) 38 | pwm_set_width(500); 39 | sleep(1) 40 | pwm_set_width(999); 41 | sleep(1) 42 | pwm_disable(PWM1_CH1); 43 | */ 44 | 45 | 46 | const PWM_Channel_Config PWM1_CH1 = { 47 | &(LPC_PWM1->MR1), //Match Register 48 | (1 << 9), //PWM Enable 49 | (1 << 1), //Latch Enable Register 50 | (0x2 << 4), //PINSEL3 - P1.18 51 | (0x1 << 0) //PINSEL4 - P2.0 52 | }; 53 | 54 | const PWM_Channel_Config PWM1_CH2 = { 55 | &(LPC_PWM1->MR2), //Match Register 56 | (1 << 10), //PWM Enable 57 | (1 << 2), //Latch Enable Register 58 | (0x2 << 8), //PINSEL3 - P1.20 59 | (0x1 << 2) //PINSEL4 - P2.1 60 | }; 61 | 62 | const PWM_Channel_Config PWM1_CH3 = { 63 | &(LPC_PWM1->MR3), //Match Register 64 | (1 << 11), //PWM Enable 65 | (1 << 3), //Latch Enable Register 66 | (0x2 << 10), //PINSEL3 - P1.21 67 | (0x1 << 4) //PINSEL4 - P2.2 68 | }; 69 | 70 | const PWM_Channel_Config PWM1_CH4 = { 71 | &(LPC_PWM1->MR4), //Match Register 72 | (1 << 12), //PWM Enable 73 | (1 << 4), //Latch Enable Register 74 | (0x2 << 14), //PINSEL3 - P1.23 75 | (0x1 << 6) //PINSEL4 - P2.3 76 | }; 77 | 78 | const PWM_Channel_Config PWM1_CH5 = { 79 | &(LPC_PWM1->MR5), //Match Register 80 | (1 << 13), //PWM Enable 81 | (1 << 5), //Latch Enable Register 82 | (0x2 << 16), //PINSEL3 - P1.24 83 | (0x1 << 8) //PINSEL4 - P2.4 84 | }; 85 | 86 | const PWM_Channel_Config PWM1_CH6 = { 87 | &(LPC_PWM1->MR6), //Match Register 88 | (1 << 14), //PWM Enable 89 | (1 << 6), //Latch Enable Register 90 | (0x2 << 20), //PINSEL3 - P1.26 91 | (0x1 << 10) //PINSEL4 - P2.5 92 | }; 93 | 94 | 95 | //UM10360 LPC17xx Chapter 24 - Pulse Width Modulation 96 | 97 | // 98 | // channel - Which of the 6 PWM channels to init. 99 | // period - what is the overall period, in PCLK cycles, for ALL PWMs (not just the provided one) 100 | // 101 | void pwm_init(PWM_Channel_Config* channel, bool primaryPin, bool secondaryPin, uint32_t period, uint32_t width) { 102 | 103 | //Power up PWM Circuitry - Defaulted to on at reset, but doesn't hurt to make sure 104 | LPC_SC->PCONP |= 1 << 6; // Power up the PWM 105 | 106 | //Pin mode selections 107 | if (primaryPin) LPC_PINCON->PINSEL3 |= channel->PINSEL3_Enable_Mask; 108 | if (secondaryPin) LPC_PINCON->PINSEL4 |= channel->PINSEL4_Enable_Mask; 109 | 110 | //PWM Control Register - Disable output for channel 111 | LPC_PWM1->PCR &= ~channel->PCR_Enable_Mask; 112 | 113 | //Match Control - Continous operation (no interrupts, reset counter on MSR0 match (period)) 114 | LPC_PWM1->MCR = (1 << 1); 115 | 116 | //PWM Control Register - Single Edge (0 for bits 2-6) mode for all PWMs 117 | LPC_PWM1->PCR &= 0xFF00; 118 | 119 | //Disable Capture 120 | LPC_PWM1->CCR = 0x0000; 121 | 122 | //PWM Timer Control Register - Counter Enable, PWM Enable 123 | LPC_PWM1->TCR = (1 << 0) | (1 << 2); 124 | 125 | pwm_set_period(period); 126 | pwm_set_width(channel, width); 127 | } 128 | 129 | void pwm_set_period(uint32_t period) { 130 | LPC_PWM1->MR0 = period; 131 | 132 | //If we are running, this will make the MRx register on the next cycle 133 | LPC_PWM1->LER = 0x00000001; 134 | } 135 | 136 | void pwm_set_width(PWM_Channel_Config* channel, uint32_t width) { 137 | *(channel->MRn) = width; 138 | 139 | //If we are running, this will make the MRx register on the next cycle 140 | LPC_PWM1->LER = channel->LER_Enable_Mask; 141 | } 142 | 143 | void pwm_enable(PWM_Channel_Config* channel) { 144 | //PWM Control Register - Enable output for channel 145 | LPC_PWM1->PCR |= channel->PCR_Enable_Mask; 146 | } 147 | 148 | void pwm_disable(PWM_Channel_Config* channel) { 149 | //PWM Control Register - Disable output for channel 150 | LPC_PWM1->PCR &= ~channel->PCR_Enable_Mask; 151 | } 152 | 153 | -------------------------------------------------------------------------------- /grbl-lpc/pwm_driver.h: -------------------------------------------------------------------------------- 1 | // PWM Driver - LPC176x 2 | // 3 | // Copyright 2017 Brett Fleming 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | // IN THE SOFTWARE. 22 | 23 | #include 24 | 25 | typedef struct _PWM_Channel_Config { 26 | volatile uint32_t* MRn; //LPC_PWM1->MR1 through MR6 27 | uint32_t PCR_Enable_Mask; 28 | uint32_t LER_Enable_Mask; 29 | //PWM Output Mapping PWM1 PWM2 PWM3 PWM4 PWM5 PWM6 30 | uint32_t PINSEL3_Enable_Mask; //For PWM support on (P1.18, P1.20, P1.21, P1.23, P1.24, P1.26) 31 | uint32_t PINSEL4_Enable_Mask; //For PWM support on (P2.0, P2.1, P2.2, P2.3, P2.4, P2.5) 32 | } const PWM_Channel_Config; 33 | 34 | extern PWM_Channel_Config PWM1_CH1; 35 | extern PWM_Channel_Config PWM1_CH2; 36 | extern PWM_Channel_Config PWM1_CH3; 37 | extern PWM_Channel_Config PWM1_CH4; 38 | extern PWM_Channel_Config PWM1_CH5; 39 | extern PWM_Channel_Config PWM1_CH6; 40 | 41 | void pwm_init(PWM_Channel_Config* channel, bool primaryPin, bool secondaryPin, uint32_t period, uint32_t width); 42 | void pwm_set_period(uint32_t period); 43 | void pwm_set_width(PWM_Channel_Config* channel, uint32_t width); 44 | void pwm_enable(PWM_Channel_Config* channel); 45 | void pwm_disable(PWM_Channel_Config* channel); 46 | 47 | -------------------------------------------------------------------------------- /grbl-lpc/util/delay.h: -------------------------------------------------------------------------------- 1 | #define F_CPU SystemCoreClock 2 | -------------------------------------------------------------------------------- /grbl/coolant_control.c: -------------------------------------------------------------------------------- 1 | /* 2 | coolant_control.c - coolant control methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #include "grbl.h" 22 | 23 | 24 | void coolant_init() 25 | { 26 | COOLANT_FLOOD_DDR |= (1 << COOLANT_FLOOD_BIT); // Configure as output pin 27 | #ifdef ENABLE_M7 28 | COOLANT_MIST_DDR |= (1 << COOLANT_MIST_BIT); 29 | #endif 30 | coolant_stop(); 31 | } 32 | 33 | 34 | // Returns current coolant output state. Overrides may alter it from programmed state. 35 | uint8_t coolant_get_state() 36 | { 37 | uint8_t cl_state = COOLANT_STATE_DISABLE; 38 | #ifdef INVERT_COOLANT_FLOOD_PIN 39 | if (bit_isfalse(COOLANT_FLOOD_PORT,(1 << COOLANT_FLOOD_BIT))) { 40 | #else 41 | if (bit_istrue(COOLANT_FLOOD_PORT,(1 << COOLANT_FLOOD_BIT))) { 42 | #endif 43 | cl_state |= COOLANT_STATE_FLOOD; 44 | } 45 | #ifdef ENABLE_M7 46 | #ifdef INVERT_COOLANT_MIST_PIN 47 | if (bit_isfalse(COOLANT_MIST_PORT,(1 << COOLANT_MIST_BIT))) { 48 | #else 49 | if (bit_istrue(COOLANT_MIST_PORT,(1 << COOLANT_MIST_BIT))) { 50 | #endif 51 | cl_state |= COOLANT_STATE_MIST; 52 | } 53 | #endif 54 | return(cl_state); 55 | } 56 | 57 | 58 | // Directly called by coolant_init(), coolant_set_state(), and mc_reset(), which can be at 59 | // an interrupt-level. No report flag set, but only called by routines that don't need it. 60 | void coolant_stop() 61 | { 62 | #ifdef INVERT_COOLANT_FLOOD_PIN 63 | COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT); 64 | #else 65 | COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT); 66 | #endif 67 | delay_ms(1); // workaround for toolchain error 68 | #ifdef ENABLE_M7 69 | #ifdef INVERT_COOLANT_MIST_PIN 70 | COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT); 71 | #else 72 | COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT); 73 | #endif 74 | #endif 75 | } 76 | 77 | 78 | // Main program only. Immediately sets flood coolant running state and also mist coolant, 79 | // if enabled. Also sets a flag to report an update to a coolant state. 80 | // Called by coolant toggle override, parking restore, parking retract, sleep mode, g-code 81 | // parser program end, and g-code parser coolant_sync(). 82 | void coolant_set_state(uint8_t mode) 83 | { 84 | if (sys.abort) { return; } // Block during abort. 85 | 86 | if (mode == COOLANT_DISABLE) { 87 | 88 | coolant_stop(); 89 | 90 | } else { 91 | 92 | if (mode & COOLANT_FLOOD_ENABLE) { 93 | #ifdef INVERT_COOLANT_FLOOD_PIN 94 | COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT); 95 | #else 96 | COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT); 97 | #endif 98 | } 99 | delay_ms(1); // workaround for toolchain error 100 | 101 | #ifdef ENABLE_M7 102 | if (mode & COOLANT_MIST_ENABLE) { 103 | #ifdef INVERT_COOLANT_MIST_PIN 104 | COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT); 105 | #else 106 | COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT); 107 | #endif 108 | } 109 | #endif 110 | 111 | } 112 | sys.report_ovr_counter = 0; // Set to report change immediately 113 | } 114 | 115 | 116 | // G-code parser entry-point for setting coolant state. Forces a planner buffer sync and bails 117 | // if an abort or check-mode is active. 118 | void coolant_sync(uint8_t mode) 119 | { 120 | if (sys.state == STATE_CHECK_MODE) { return; } 121 | protocol_buffer_synchronize(); // Ensure coolant turns on when specified in program. 122 | coolant_set_state(mode); 123 | } 124 | -------------------------------------------------------------------------------- /grbl/coolant_control.h: -------------------------------------------------------------------------------- 1 | /* 2 | coolant_control.h - spindle control methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef coolant_control_h 22 | #define coolant_control_h 23 | 24 | #define COOLANT_NO_SYNC false 25 | #define COOLANT_FORCE_SYNC true 26 | 27 | #define COOLANT_STATE_DISABLE 0 // Must be zero 28 | #define COOLANT_STATE_FLOOD bit(0) 29 | #define COOLANT_STATE_MIST bit(1) 30 | 31 | 32 | // Initializes coolant control pins. 33 | void coolant_init(); 34 | 35 | // Returns current coolant output state. Overrides may alter it from programmed state. 36 | uint8_t coolant_get_state(); 37 | 38 | // Immediately disables coolant pins. 39 | void coolant_stop(); 40 | 41 | // Sets the coolant pins according to state specified. 42 | void coolant_set_state(uint8_t mode); 43 | 44 | // G-code parser entry-point for setting coolant states. Checks for and executes additional conditions. 45 | void coolant_sync(uint8_t mode); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /grbl/eeprom.c: -------------------------------------------------------------------------------- 1 | // This file has been prepared for Doxygen automatic documentation generation. 2 | /*! \file ******************************************************************** 3 | * 4 | * Atmel Corporation 5 | * 6 | * \li File: eeprom.c 7 | * \li Compiler: IAR EWAAVR 3.10c 8 | * \li Support mail: avr@atmel.com 9 | * 10 | * \li Supported devices: All devices with split EEPROM erase/write 11 | * capabilities can be used. 12 | * The example is written for ATmega48. 13 | * 14 | * \li AppNote: AVR103 - Using the EEPROM Programming Modes. 15 | * 16 | * \li Description: Example on how to use the split EEPROM erase/write 17 | * capabilities in e.g. ATmega48. All EEPROM 18 | * programming modes are tested, i.e. Erase+Write, 19 | * Erase-only and Write-only. 20 | * 21 | * $Revision: 1.6 $ 22 | * $Date: Friday, February 11, 2005 07:16:44 UTC $ 23 | ****************************************************************************/ 24 | #include 25 | #include 26 | 27 | #ifdef xxxxx // replaced by flash.cpp 28 | 29 | /* These EEPROM bits have different names on different devices. */ 30 | #ifndef EEPE 31 | #define EEPE EEWE //!< EEPROM program/write enable. 32 | #define EEMPE EEMWE //!< EEPROM master program/write enable. 33 | #endif 34 | 35 | /* These two are unfortunately not defined in the device include files. */ 36 | #define EEPM1 5 //!< EEPROM Programming Mode Bit 1. 37 | #define EEPM0 4 //!< EEPROM Programming Mode Bit 0. 38 | 39 | /* Define to reduce code size. */ 40 | #define EEPROM_IGNORE_SELFPROG //!< Remove SPM flag polling. 41 | 42 | /*! \brief Read byte from EEPROM. 43 | * 44 | * This function reads one byte from a given EEPROM address. 45 | * 46 | * \note The CPU is halted for 4 clock cycles during EEPROM read. 47 | * 48 | * \param addr EEPROM address to read from. 49 | * \return The byte read from the EEPROM address. 50 | */ 51 | unsigned char eeprom_get_char( unsigned int addr ) 52 | { 53 | do {} while( EECR & (1< 0; size--) { 135 | checksum = (checksum << 1) || (checksum >> 7); 136 | checksum += *source; 137 | eeprom_put_char(destination++, *(source++)); 138 | } 139 | eeprom_put_char(destination, checksum); 140 | } 141 | 142 | int memcpy_from_eeprom_with_checksum(char *destination, unsigned int source, unsigned int size) { 143 | unsigned char data, checksum = 0; 144 | for(; size > 0; size--) { 145 | data = eeprom_get_char(source++); 146 | checksum = (checksum << 1) || (checksum >> 7); 147 | checksum += data; 148 | *(destination++) = data; 149 | } 150 | return(checksum == eeprom_get_char(source)); 151 | } 152 | 153 | #endif // xxxxx 154 | 155 | // end of file 156 | -------------------------------------------------------------------------------- /grbl/eeprom.h: -------------------------------------------------------------------------------- 1 | /* 2 | eeprom.h - EEPROM methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2009-2011 Simen Svale Skogsrud 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef eeprom_h 22 | #define eeprom_h 23 | 24 | unsigned char eeprom_get_char(unsigned int addr); 25 | void eeprom_put_char(unsigned int addr, unsigned char new_value); 26 | void memcpy_to_eeprom_with_checksum(unsigned int destination, char *source, unsigned int size); 27 | int memcpy_from_eeprom_with_checksum(char *destination, unsigned int source, unsigned int size); 28 | void eeprom_init(); 29 | void eeprom_commit(); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /grbl/examples/grblUpload/grblUpload.ino: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | This sketch compiles and uploads Grbl to your 328p-based Arduino! 3 | 4 | To use: 5 | - First make sure you have imported Grbl source code into your Arduino 6 | IDE. There are details on our Github website on how to do this. 7 | 8 | - Select your Arduino Board and Serial Port in the Tools drop-down menu. 9 | NOTE: Grbl only officially supports 328p-based Arduinos, like the Uno. 10 | Using other boards will likely not work! 11 | 12 | - Then just click 'Upload'. That's it! 13 | 14 | For advanced users: 15 | If you'd like to see what else Grbl can do, there are some additional 16 | options for customization and features you can enable or disable. 17 | Navigate your file system to where the Arduino IDE has stored the Grbl 18 | source code files, open the 'config.h' file in your favorite text 19 | editor. Inside are dozens of feature descriptions and #defines. Simply 20 | comment or uncomment the #defines or alter their assigned values, save 21 | your changes, and then click 'Upload' here. 22 | 23 | Copyright (c) 2015 Sungeun K. Jeon 24 | Released under the MIT-license. See license.txt for details. 25 | ***********************************************************************/ 26 | 27 | #include 28 | 29 | // Do not alter this file! 30 | -------------------------------------------------------------------------------- /grbl/examples/grblUpload/license.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Sungeun K. Jeon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /grbl/examples/grblWrite_BuildInfo/grblWrite_BuildInfo.ino: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | This sketch writes a `$I` build info string directly into Arduino EEPROM 3 | 4 | To use: 5 | - Just alter the "build_info_line" string to whatever you'd like. Then 6 | compile and upload this sketch to your Arduino. 7 | 8 | - If your Arduino is blinking slowly, your string has already been 9 | written to your EEPROM and been verified by checksums! That's it! 10 | 11 | - If you Arduino LED is blinking fast, something went wrong and the 12 | checksums don't match. You can optionally connect to the Arduino via 13 | the serial monitor, and the sketch will show what its doing. 14 | 15 | NOTE: This sketch is provided as a tool template for OEMs who may need 16 | to restrict users from altering their build info, so they can place 17 | important product information here when enabling the restriction. 18 | 19 | NOTE: When uploading Grbl to the Arduino with this sketch on it, make 20 | sure you see the slow blink before you start the upload process. This 21 | ensures you aren't flashing Grbl when it's in mid-write of the EEPROM. 22 | 23 | Copyright (c) 2016 Sungeun K. Jeon for Gnea Research LLC 24 | Released under the MIT-license. See license.txt for details. 25 | ***********************************************************************/ 26 | 27 | #include 28 | #include 29 | 30 | #define SERIAL_BAUD_RATE 115200 31 | #define LINE_LENGTH 80U // Grbl line length 32 | #define BYTE_LOCATION 942U // Grbl build info EEPROM address. 33 | 34 | 35 | // ----- CHANGE THIS LINE ----- 36 | 37 | char build_info_line[LINE_LENGTH] = "Testing123."; 38 | 39 | // ----------------------------- 40 | 41 | 42 | uint8_t status = false; 43 | int ledPin = 13; // LED connected to digital pin 13 44 | 45 | void setup() { 46 | Serial.begin(SERIAL_BAUD_RATE); 47 | delay(500); 48 | 49 | uint32_t address = BYTE_LOCATION; 50 | uint32_t size = LINE_LENGTH; 51 | char *write_pointer = (char*)build_info_line; 52 | uint8_t write_checksum = 0; 53 | for (; size>0; size--) { 54 | write_checksum = (write_checksum << 1) || (write_checksum >> 7); 55 | write_checksum += *write_pointer; 56 | EEPROM.put(address++, *(write_pointer++)); 57 | } 58 | EEPROM.put(address,write_checksum); 59 | 60 | Serial.print(F("-> Writing line to EEPROM: '")); 61 | Serial.print(build_info_line); 62 | Serial.print(F("'\n\r-> Write checksum: ")); 63 | Serial.println(write_checksum,DEC); 64 | 65 | size = LINE_LENGTH; 66 | address = BYTE_LOCATION; 67 | uint8_t data = 0; 68 | char read_line[LINE_LENGTH]; 69 | char *read_pointer = (char*)read_line; 70 | uint8_t read_checksum = 0; 71 | uint8_t stored_checksum = 0; 72 | for(; size > 0; size--) { 73 | data = EEPROM.read(address++); 74 | read_checksum = (read_checksum << 1) || (read_checksum >> 7); 75 | read_checksum += data; 76 | *(read_pointer++) = data; 77 | } 78 | stored_checksum = EEPROM.read(address); 79 | 80 | Serial.print(F("<- Reading line from EEPROM: '")); 81 | Serial.print(read_line); 82 | Serial.print("'\n\r<- Read checksum: "); 83 | Serial.println(read_checksum,DEC); 84 | 85 | if ((read_checksum == write_checksum) && (read_checksum == stored_checksum)) { 86 | status = true; 87 | Serial.print(F("SUCCESS! All checksums match!\r\n")); 88 | } else { 89 | if (write_checksum != stored_checksum) { 90 | Serial.println(F("ERROR! Write and stored EEPROM checksums don't match!")); 91 | } else { 92 | Serial.println(F("ERROR! Read and stored checksums don't match!")); 93 | } 94 | } 95 | pinMode(ledPin, OUTPUT); // sets the digital pin as output 96 | } 97 | 98 | void loop() { 99 | // Blink to let user know EEPROM write status. 100 | // Slow blink is 'ok'. Fast blink is an 'error'. 101 | digitalWrite(ledPin, HIGH); // sets the LED on 102 | if (status) { delay(1500); } // Slow blink 103 | else { delay(100); } // Rapid blink 104 | digitalWrite(ledPin, LOW); // sets the LED off 105 | if (status) { delay(1500); } 106 | else { delay(100); } 107 | } 108 | 109 | 110 | -------------------------------------------------------------------------------- /grbl/examples/grblWrite_BuildInfo/license.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Sungeun K. Jeon for Gnea Research LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /grbl/grbl.h: -------------------------------------------------------------------------------- 1 | /* 2 | grbl.h - main Grbl include file 3 | Part of Grbl 4 | 5 | Copyright (c) 2015-2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef grbl_h 22 | #define grbl_h 23 | 24 | // Grbl versioning system 25 | #define GRBL_VERSION "1.1f" 26 | #define GRBL_VERSION_BUILD "20171008" 27 | 28 | // Define standard libraries used by Grbl. 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | // Define the Grbl system include files. NOTE: Do not alter organization. 42 | #include "debug.h" 43 | #include "config.h" 44 | #include "delay.h" 45 | #include "nuts_bolts.h" 46 | #include "settings.h" 47 | #include "system.h" 48 | #include "defaults.h" 49 | #include "cpu_map.h" 50 | #include "planner.h" 51 | #include "coolant_control.h" 52 | #include "eeprom.h" 53 | #include "gcode.h" 54 | #include "limits.h" 55 | #include "motion_control.h" 56 | #include "planner.h" 57 | #include "print.h" 58 | #include "probe.h" 59 | #include "protocol.h" 60 | #include "report.h" 61 | #include "serial.h" 62 | #include "spindle_control.h" 63 | #include "stepper.h" 64 | #include "jog.h" 65 | #include "current_control.h" 66 | 67 | // --------------------------------------------------------------------------------------- 68 | // COMPILE-TIME ERROR CHECKING OF DEFINE VALUES: 69 | 70 | #ifndef HOMING_CYCLE_0 71 | #error "Required HOMING_CYCLE_0 not defined." 72 | #endif 73 | 74 | #if defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) && !defined(VARIABLE_SPINDLE) 75 | #error "USE_SPINDLE_DIR_AS_ENABLE_PIN may only be used with VARIABLE_SPINDLE enabled" 76 | #endif 77 | 78 | /* 79 | #if defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) && !defined(CPU_MAP_ATMEGA328P) 80 | #error "USE_SPINDLE_DIR_AS_ENABLE_PIN may only be used with a 328p processor" 81 | #endif 82 | */ 83 | 84 | #if !defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) && defined(SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED) 85 | #error "SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED may only be used with USE_SPINDLE_DIR_AS_ENABLE_PIN enabled" 86 | #endif 87 | 88 | #if defined(PARKING_ENABLE) 89 | #if defined(HOMING_FORCE_SET_ORIGIN) 90 | #error "HOMING_FORCE_SET_ORIGIN is not supported with PARKING_ENABLE at this time." 91 | #endif 92 | #endif 93 | 94 | #if defined(ENABLE_PARKING_OVERRIDE_CONTROL) 95 | #if !defined(PARKING_ENABLE) 96 | #error "ENABLE_PARKING_OVERRIDE_CONTROL must be enabled with PARKING_ENABLE." 97 | #endif 98 | #endif 99 | 100 | /* restriction removed 101 | #if defined(SPINDLE_PWM_MIN_VALUE) 102 | #if !(SPINDLE_PWM_MIN_VALUE > 0) 103 | #error "SPINDLE_PWM_MIN_VALUE must be greater than zero." 104 | #endif 105 | #endif 106 | */ 107 | 108 | #if (REPORT_WCO_REFRESH_BUSY_COUNT < REPORT_WCO_REFRESH_IDLE_COUNT) 109 | #error "WCO busy refresh is less than idle refresh." 110 | #endif 111 | #if (REPORT_OVR_REFRESH_BUSY_COUNT < REPORT_OVR_REFRESH_IDLE_COUNT) 112 | #error "Override busy refresh is less than idle refresh." 113 | #endif 114 | #if (REPORT_WCO_REFRESH_IDLE_COUNT < 2) 115 | #error "WCO refresh must be greater than one." 116 | #endif 117 | #if (REPORT_OVR_REFRESH_IDLE_COUNT < 1) 118 | #error "Override refresh must be greater than zero." 119 | #endif 120 | 121 | // --------------------------------------------------------------------------------------- 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /grbl/jog.c: -------------------------------------------------------------------------------- 1 | /* 2 | jog.h - Jogging methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #include "grbl.h" 22 | 23 | 24 | // Sets up valid jog motion received from g-code parser, checks for soft-limits, and executes the jog. 25 | uint8_t jog_execute(plan_line_data_t *pl_data, parser_block_t *gc_block) 26 | { 27 | // Initialize planner data struct for jogging motions. 28 | // NOTE: Spindle and coolant are allowed to fully function with overrides during a jog. 29 | pl_data->feed_rate = gc_block->values.f; 30 | pl_data->condition |= PL_COND_FLAG_NO_FEED_OVERRIDE; 31 | #ifdef USE_LINE_NUMBERS 32 | pl_data->line_number = gc_block->values.n; 33 | #endif 34 | 35 | if (bit_istrue(settings.flags,BITFLAG_SOFT_LIMIT_ENABLE)) { 36 | if (system_check_travel_limits(gc_block->values.xyza)) { return(STATUS_TRAVEL_EXCEEDED); } 37 | } 38 | 39 | // Valid jog command. Plan, set state, and execute. 40 | mc_line(gc_block->values.xyza,pl_data); 41 | if (sys.state == STATE_IDLE) { 42 | if (plan_get_current_block() != NULL) { // Check if there is a block to execute. 43 | sys.state = STATE_JOG; 44 | st_prep_buffer(); 45 | st_wake_up(); // NOTE: Manual start. No state machine required. 46 | } 47 | } 48 | 49 | return(STATUS_OK); 50 | } 51 | -------------------------------------------------------------------------------- /grbl/jog.h: -------------------------------------------------------------------------------- 1 | /* 2 | jog.h - Jogging methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef jog_h 22 | #define jog_h 23 | 24 | #include "gcode.h" 25 | 26 | // System motion line numbers must be zero. 27 | #define JOG_LINE_NUMBER 0 28 | 29 | // Sets up valid jog motion received from g-code parser, checks for soft-limits, and executes the jog. 30 | uint8_t jog_execute(plan_line_data_t *pl_data, parser_block_t *gc_block); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /grbl/limits.h: -------------------------------------------------------------------------------- 1 | /* 2 | limits.h - code pertaining to limit-switches and performing the homing cycle 3 | Part of Grbl 4 | 5 | Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef limits_h 23 | #define limits_h 24 | 25 | 26 | // Initialize the limits module 27 | void limits_init(); 28 | 29 | // Disables hard limits. 30 | void limits_disable(); 31 | 32 | // Returns limit state as a bit-wise uint8 variable. 33 | uint8_t limits_get_state(); 34 | 35 | // Perform one portion of the homing cycle based on the input settings. 36 | void limits_go_home(uint8_t cycle_mask); 37 | 38 | // Check for soft limit violations 39 | void limits_soft_check(float *target); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /grbl/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | main.c - An embedded CNC Controller with rs274/ngc (g-code) support 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #include "grbl.h" 23 | 24 | void isr_init(); 25 | 26 | /*Holding space for dummy registers*/ 27 | extern DummyReg NotUsed; 28 | extern DummyReg PCICR; 29 | extern DummyReg PCIE1; 30 | 31 | // Declare system global variable structure 32 | system_t sys; 33 | int32_t sys_position[N_AXIS]; // Real-time machine (aka home) position vector in steps. 34 | int32_t sys_probe_position[N_AXIS]; // Last probe position in machine coordinates and steps. 35 | volatile uint8_t sys_probe_state; // Probing state value. Used to coordinate the probing cycle with stepper ISR. 36 | volatile uint8_t sys_rt_exec_state; // Global realtime executor bitflag variable for state management. See EXEC bitmasks. 37 | volatile uint8_t sys_rt_exec_alarm; // Global realtime executor bitflag variable for setting various alarms. 38 | volatile uint8_t sys_rt_exec_motion_override; // Global realtime executor bitflag variable for motion-based overrides. 39 | volatile uint8_t sys_rt_exec_accessory_override; // Global realtime executor bitflag variable for spindle/coolant overrides. 40 | 41 | int main(void) 42 | { 43 | // Initialize system upon power-up. 44 | debug_init(); // Initialize debug leds 45 | isr_init(); // Set ISR priorities (stepper ISR uses Timer1) 46 | delay_init(); // Setup delay timer (uses Timer3) 47 | serial_init(); // Setup serial baud rate and interrupts 48 | eeprom_init(); // Init EEPROM or Flash 49 | settings_init(); // Load Grbl settings from EEPROM 50 | current_init(); // Configure stepper driver current 51 | stepper_init(); // Configure stepper pins and interrupt timers (uses Timer1) 52 | system_init(); // Configure pinout pins and pin-change interrupt 53 | 54 | memset(sys_position,0,sizeof(sys_position)); // Clear machine position. 55 | sei(); // Enable interrupts 56 | 57 | // Initialize system state. 58 | #ifdef FORCE_INITIALIZATION_ALARM 59 | // Force Grbl into an ALARM state upon a power-cycle or hard reset. 60 | sys.state = STATE_ALARM; 61 | #else 62 | sys.state = STATE_IDLE; 63 | #endif 64 | 65 | // Check for power-up and set system alarm if homing is enabled to force homing cycle 66 | // by setting Grbl's alarm state. Alarm locks out all g-code commands, including the 67 | // startup scripts, but allows access to settings and internal commands. Only a homing 68 | // cycle '$H' or kill alarm locks '$X' will disable the alarm. 69 | // NOTE: The startup script will run after successful completion of the homing cycle, but 70 | // not after disabling the alarm locks. Prevents motion startup blocks from crashing into 71 | // things uncontrollably. Very bad. 72 | #ifdef HOMING_INIT_LOCK 73 | if (bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) { sys.state = STATE_ALARM; } 74 | #endif 75 | 76 | // Grbl initialization loop upon power-up or a system abort. For the latter, all processes 77 | // will return to this loop to be cleanly re-initialized. 78 | for(;;) { 79 | 80 | // Reset system variables. 81 | uint8_t prior_state = sys.state; 82 | memset(&sys, 0, sizeof(system_t)); // Clear system struct variable. 83 | sys.state = prior_state; 84 | sys.f_override = DEFAULT_FEED_OVERRIDE; // Set to 100% 85 | sys.r_override = DEFAULT_RAPID_OVERRIDE; // Set to 100% 86 | sys.spindle_speed_ovr = DEFAULT_SPINDLE_SPEED_OVERRIDE; // Set to 100% 87 | memset(sys_probe_position,0,sizeof(sys_probe_position)); // Clear probe position. 88 | sys_probe_state = 0; // PROBE_OFF 89 | sys_rt_exec_state = 0; // EXEC_STATUS_REPORT 90 | sys_rt_exec_alarm = 0; 91 | sys_rt_exec_motion_override = 0; 92 | sys_rt_exec_accessory_override = 0; 93 | 94 | // Reset Grbl primary systems. 95 | serial_reset_read_buffer(); // Clear serial read buffer 96 | gc_init(); // Set g-code parser to default state 97 | spindle_init(); // Configure spindle pins and PWM values 98 | coolant_init(); // Configure coolant pins 99 | limits_init(); // Configure limit input pins and interrupts 100 | probe_init(); // Configure probe input pin 101 | plan_reset(); // Clear block buffer and planner variables 102 | st_reset(); // Clear stepper subsystem variables. 103 | 104 | // Sync cleared gcode and planner positions to current system position. 105 | plan_sync_position(); // Synchronize plan position with (actual) system position 106 | gc_sync_position(); // Synchronize g-code position with (actual) system position 107 | 108 | // Print welcome message. Indicates an initialization has occured at power-up or with a reset. 109 | report_init_message(); 110 | 111 | // Start Grbl main loop. Processes program inputs and executes them. 112 | protocol_main_loop(); 113 | 114 | } 115 | return 0; /* Never reached */ 116 | } 117 | -------------------------------------------------------------------------------- /grbl/motion_control.h: -------------------------------------------------------------------------------- 1 | /* 2 | motion_control.h - high level interface for issuing motion commands 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef motion_control_h 23 | #define motion_control_h 24 | 25 | 26 | // System motion commands must have a line number of zero. 27 | #define HOMING_CYCLE_LINE_NUMBER 0 28 | #define PARKING_MOTION_LINE_NUMBER 0 29 | 30 | #define HOMING_CYCLE_ALL 0 // Must be zero. 31 | #define HOMING_CYCLE_X bit(X_AXIS) 32 | #define HOMING_CYCLE_Y bit(Y_AXIS) 33 | #define HOMING_CYCLE_Z bit(Z_AXIS) 34 | #define HOMING_CYCLE_A bit(A_AXIS) 35 | //#define HOMING_CYCLE_B bit(B_AXIS) 36 | //#define HOMING_CYCLE_C bit(C_AXIS) 37 | 38 | 39 | // Execute linear motion in absolute millimeter coordinates. Feed rate given in millimeters/second 40 | // unless invert_feed_rate is true. Then the feed_rate means that the motion should be completed in 41 | // (1 minute)/feed_rate time. 42 | void mc_line(float *target, plan_line_data_t *pl_data); 43 | 44 | // Execute an arc in offset mode format. position == current xyz, target == target xyz, 45 | // offset == offset from current xyz, axis_XXX defines circle plane in tool space, axis_linear is 46 | // the direction of helical travel, radius == circle radius, is_clockwise_arc boolean. Used 47 | // for vector transformation direction. 48 | void mc_arc(float *target, plan_line_data_t *pl_data, float *position, float *offset, float radius, 49 | uint8_t axis_0, uint8_t axis_1, uint8_t axis_linear, uint8_t is_clockwise_arc); 50 | 51 | // Dwell for a specific number of seconds 52 | void mc_dwell(float seconds); 53 | 54 | // Perform homing cycle to locate machine zero. Requires limit switches. 55 | void mc_homing_cycle(uint8_t cycle_mask); 56 | 57 | // Perform tool length probe cycle. Requires probe switch. 58 | uint8_t mc_probe_cycle(float *target, plan_line_data_t *pl_data, uint8_t parser_flags); 59 | 60 | // Handles updating the override control state. 61 | void mc_override_ctrl_update(uint8_t override_state); 62 | 63 | // Plans and executes the single special motion case for parking. Independent of main planner buffer. 64 | void mc_parking_motion(float *parking_target, plan_line_data_t *pl_data); 65 | 66 | // Performs system reset. If in motion state, kills all motion and sets system alarm. 67 | void mc_reset(); 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /grbl/nuts_bolts.c: -------------------------------------------------------------------------------- 1 | /* 2 | nuts_bolts.c - Shared functions 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #include "grbl.h" 23 | 24 | 25 | #define MAX_INT_DIGITS 8 // Maximum number of digits in int32 (and float) 26 | 27 | 28 | // Extracts a floating point value from a string. The following code is based loosely on 29 | // the avr-libc strtod() function by Michael Stumpf and Dmitry Xmelkov and many freely 30 | // available conversion method examples, but has been highly optimized for Grbl. For known 31 | // CNC applications, the typical decimal value is expected to be in the range of E0 to E-4. 32 | // Scientific notation is officially not supported by g-code, and the 'E' character may 33 | // be a g-code word on some CNC systems. So, 'E' notation will not be recognized. 34 | // NOTE: Thanks to Radu-Eosif Mihailescu for identifying the issues with using strtod(). 35 | uint8_t read_float(char *line, uint8_t *char_counter, float *float_ptr) 36 | { 37 | char *ptr = line + *char_counter; 38 | unsigned char c; 39 | 40 | // Grab first character and increment pointer. No spaces assumed in line. 41 | c = *ptr++; 42 | 43 | // Capture initial positive/minus character 44 | bool isnegative = false; 45 | if (c == '-') { 46 | isnegative = true; 47 | c = *ptr++; 48 | } else if (c == '+') { 49 | c = *ptr++; 50 | } 51 | 52 | // Extract number into fast integer. Track decimal in terms of exponent value. 53 | uint32_t intval = 0; 54 | int8_t exp = 0; 55 | uint8_t ndigit = 0; 56 | bool isdecimal = false; 57 | while(1) { 58 | c -= '0'; 59 | if (c <= 9) { 60 | ndigit++; 61 | if (ndigit <= MAX_INT_DIGITS) { 62 | if (isdecimal) { exp--; } 63 | intval = (((intval << 2) + intval) << 1) + c; // intval*10 + c 64 | } else { 65 | if (!(isdecimal)) { exp++; } // Drop overflow digits 66 | } 67 | } else if (c == (('.'-'0') & 0xff) && !(isdecimal)) { 68 | isdecimal = true; 69 | } else { 70 | break; 71 | } 72 | c = *ptr++; 73 | } 74 | 75 | // Return if no digits have been read. 76 | if (!ndigit) { return(false); }; 77 | 78 | // Convert integer into floating point. 79 | float fval; 80 | fval = (float)intval; 81 | 82 | // Apply decimal. Should perform no more than two floating point multiplications for the 83 | // expected range of E0 to E-4. 84 | if (fval != 0) { 85 | while (exp <= -2) { 86 | fval *= 0.01; 87 | exp += 2; 88 | } 89 | if (exp < 0) { 90 | fval *= 0.1; 91 | } else if (exp > 0) { 92 | do { 93 | fval *= 10.0; 94 | } while (--exp > 0); 95 | } 96 | } 97 | 98 | // Assign floating point value with correct sign. 99 | if (isnegative) { 100 | *float_ptr = -fval; 101 | } else { 102 | *float_ptr = fval; 103 | } 104 | 105 | *char_counter = ptr - line - 1; // Set char_counter to next statement 106 | 107 | return(true); 108 | } 109 | 110 | 111 | // Non-blocking delay function used for general operation and suspend features. 112 | void delay_sec(float seconds, uint8_t mode) 113 | { 114 | uint16_t i = ceil(1000/DWELL_TIME_STEP*seconds); 115 | while (i-- > 0) { 116 | if (sys.abort) { return; } 117 | if (mode == DELAY_MODE_DWELL) { 118 | protocol_execute_realtime(); 119 | } else { // DELAY_MODE_SYS_SUSPEND 120 | // Execute rt_system() only to avoid nesting suspend loops. 121 | protocol_exec_rt_system(); 122 | if (sys.suspend & SUSPEND_RESTART_RETRACT) { return; } // Bail, if safety door reopens. 123 | } 124 | delay_ms(DWELL_TIME_STEP); // Delay DWELL_TIME_STEP increment 125 | } 126 | } 127 | 128 | 129 | // Simple hypotenuse computation function. 130 | float hypot_f(float x, float y) { return(sqrt(x*x + y*y)); } 131 | 132 | 133 | float convert_delta_vector_to_unit_vector(float *vector) 134 | { 135 | uint8_t idx; 136 | float magnitude = 0.0; 137 | for (idx=0; idx. 20 | */ 21 | 22 | #ifndef nuts_bolts_h 23 | #define nuts_bolts_h 24 | 25 | #ifndef false 26 | #define false 0 27 | #define true 1 28 | #endif 29 | 30 | #define SOME_LARGE_VALUE 1.0E+38 31 | 32 | // Axis array index values. Must start with 0 and be continuous. 33 | #define N_AXIS 4 // Number of axes 34 | #define X_AXIS 0 // Axis indexing value. 35 | #define Y_AXIS 1 36 | #define Z_AXIS 2 37 | #define A_AXIS 3 38 | //#define B_AXIS 4 39 | //#define C_AXIS 5 40 | 41 | // CoreXY motor assignments. DO NOT ALTER. 42 | // NOTE: If the A and B motor axis bindings are changed, this effects the CoreXY equations. 43 | #ifdef COREXY 44 | #define A_MOTOR X_AXIS // Must be X_AXIS 45 | #define B_MOTOR Y_AXIS // Must be Y_AXIS 46 | #endif 47 | 48 | // Conversions 49 | #define MM_PER_INCH (25.40) 50 | #define INCH_PER_MM (0.0393701) 51 | #define TICKS_PER_MICROSECOND (F_CPU/1000000) 52 | 53 | #define DELAY_MODE_DWELL 0 54 | #define DELAY_MODE_SYS_SUSPEND 1 55 | 56 | // Useful macros 57 | #define clear_vector(a) memset(a, 0, sizeof(a)) 58 | #define clear_vector_float(a) memset(a, 0.0, sizeof(float)*N_AXIS) 59 | // #define clear_vector_long(a) memset(a, 0.0, sizeof(long)*N_AXIS) 60 | #define max(a,b) (((a) > (b)) ? (a) : (b)) 61 | #define min(a,b) (((a) < (b)) ? (a) : (b)) 62 | #define isequal_position_vector(a,b) !(memcmp(a, b, sizeof(float)*N_AXIS)) 63 | 64 | // Bit field and masking macros 65 | #define bit(n) (1 << n) 66 | #define bit_true(x,mask) (x) |= (mask) 67 | #define bit_false(x,mask) (x) &= ~(mask) 68 | #define bit_istrue(x,mask) ((x & mask) != 0) 69 | #define bit_isfalse(x,mask) ((x & mask) == 0) 70 | 71 | // Read a floating point value from a string. Line points to the input buffer, char_counter 72 | // is the indexer pointing to the current character of the line, while float_ptr is 73 | // a pointer to the result variable. Returns true when it succeeds 74 | uint8_t read_float(char *line, uint8_t *char_counter, float *float_ptr); 75 | 76 | // Non-blocking delay function used for general operation and suspend features. 77 | void delay_sec(float seconds, uint8_t mode); 78 | 79 | // Computes hypotenuse, avoiding avr-gcc's bloated version and the extra error checking. 80 | float hypot_f(float x, float y); 81 | 82 | float convert_delta_vector_to_unit_vector(float *vector); 83 | float limit_value_by_axis_maximum(float *max_value, float *unit_vec); 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /grbl/planner.h: -------------------------------------------------------------------------------- 1 | /* 2 | planner.h - buffers movement commands and manages the acceleration profile plan 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef planner_h 23 | #define planner_h 24 | 25 | 26 | // The number of linear motions that can be in the plan at any give time 27 | #ifndef BLOCK_BUFFER_SIZE 28 | #ifdef USE_LINE_NUMBERS 29 | #define BLOCK_BUFFER_SIZE 15 30 | #else 31 | #define BLOCK_BUFFER_SIZE 16 32 | #endif 33 | #endif 34 | 35 | // Returned status message from planner. 36 | #define PLAN_OK true 37 | #define PLAN_EMPTY_BLOCK false 38 | 39 | // Define planner data condition flags. Used to denote running conditions of a block. 40 | #define PL_COND_FLAG_RAPID_MOTION bit(0) 41 | #define PL_COND_FLAG_SYSTEM_MOTION bit(1) // Single motion. Circumvents planner state. Used by home/park. 42 | #define PL_COND_FLAG_NO_FEED_OVERRIDE bit(2) // Motion does not honor feed override. 43 | #define PL_COND_FLAG_INVERSE_TIME bit(3) // Interprets feed rate value as inverse time when set. 44 | #define PL_COND_FLAG_SPINDLE_CW bit(4) 45 | #define PL_COND_FLAG_SPINDLE_CCW bit(5) 46 | #define PL_COND_FLAG_COOLANT_FLOOD bit(6) 47 | #define PL_COND_FLAG_COOLANT_MIST bit(7) 48 | #define PL_COND_MOTION_MASK (PL_COND_FLAG_RAPID_MOTION|PL_COND_FLAG_SYSTEM_MOTION|PL_COND_FLAG_NO_FEED_OVERRIDE) 49 | #define PL_COND_ACCESSORY_MASK (PL_COND_FLAG_SPINDLE_CW|PL_COND_FLAG_SPINDLE_CCW|PL_COND_FLAG_COOLANT_FLOOD|PL_COND_FLAG_COOLANT_MIST) 50 | 51 | 52 | // This struct stores a linear movement of a g-code block motion with its critical "nominal" values 53 | // are as specified in the source g-code. 54 | typedef struct { 55 | // Fields used by the bresenham algorithm for tracing the line 56 | // NOTE: Used by stepper algorithm to execute the block correctly. Do not alter these values. 57 | uint32_t steps[N_AXIS]; // Step count along each axis 58 | uint32_t step_event_count; // The maximum step axis count and number of steps required to complete this block. 59 | uint32_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h) 60 | 61 | // Block condition data to ensure correct execution depending on states and overrides. 62 | uint8_t condition; // Block bitflag variable defining block run conditions. Copied from pl_line_data. 63 | #ifdef USE_LINE_NUMBERS 64 | int32_t line_number; // Block line number for real-time reporting. Copied from pl_line_data. 65 | #endif 66 | 67 | // Fields used by the motion planner to manage acceleration. Some of these values may be updated 68 | // by the stepper module during execution of special motion cases for replanning purposes. 69 | float entry_speed_sqr; // The current planned entry speed at block junction in (mm/min)^2 70 | float max_entry_speed_sqr; // Maximum allowable entry speed based on the minimum of junction limit and 71 | // neighboring nominal speeds with overrides in (mm/min)^2 72 | float acceleration; // Axis-limit adjusted line acceleration in (mm/min^2). Does not change. 73 | float millimeters; // The remaining distance for this block to be executed in (mm). 74 | // NOTE: This value may be altered by stepper algorithm during execution. 75 | 76 | // Stored rate limiting data used by planner when changes occur. 77 | float max_junction_speed_sqr; // Junction entry speed limit based on direction vectors in (mm/min)^2 78 | float rapid_rate; // Axis-limit adjusted maximum rate for this block direction in (mm/min) 79 | float programmed_rate; // Programmed rate of this block (mm/min). 80 | 81 | #ifdef VARIABLE_SPINDLE 82 | // Stored spindle speed data used by spindle overrides and resuming methods. 83 | float spindle_speed; // Block spindle speed. Copied from pl_line_data. 84 | #endif 85 | } plan_block_t; 86 | 87 | 88 | // Planner data prototype. Must be used when passing new motions to the planner. 89 | typedef struct { 90 | float feed_rate; // Desired feed rate for line motion. Value is ignored, if rapid motion. 91 | float spindle_speed; // Desired spindle speed through line motion. 92 | uint8_t condition; // Bitflag variable to indicate planner conditions. See defines above. 93 | #ifdef USE_LINE_NUMBERS 94 | int32_t line_number; // Desired line number to report when executing. 95 | #endif 96 | } plan_line_data_t; 97 | 98 | 99 | // Initialize and reset the motion plan subsystem 100 | void plan_reset(); // Reset all 101 | void plan_reset_buffer(); // Reset buffer only. 102 | 103 | // Add a new linear movement to the buffer. target[N_AXIS] is the signed, absolute target position 104 | // in millimeters. Feed rate specifies the speed of the motion. If feed rate is inverted, the feed 105 | // rate is taken to mean "frequency" and would complete the operation in 1/feed_rate minutes. 106 | uint8_t plan_buffer_line(float *target, plan_line_data_t *pl_data); 107 | 108 | // Called when the current block is no longer needed. Discards the block and makes the memory 109 | // availible for new blocks. 110 | void plan_discard_current_block(); 111 | 112 | // Gets the planner block for the special system motion cases. (Parking/Homing) 113 | plan_block_t *plan_get_system_motion_block(); 114 | 115 | // Gets the current block. Returns NULL if buffer empty 116 | plan_block_t *plan_get_current_block(); 117 | 118 | // Called periodically by step segment buffer. Mostly used internally by planner. 119 | uint8_t plan_next_block_index(uint8_t block_index); 120 | 121 | // Called by step segment buffer when computing executing block velocity profile. 122 | float plan_get_exec_block_exit_speed_sqr(); 123 | 124 | // Called by main program during planner calculations and step segment buffer during initialization. 125 | float plan_compute_profile_nominal_speed(plan_block_t *block); 126 | 127 | // Re-calculates buffered motions profile parameters upon a motion-based override change. 128 | void plan_update_velocity_profile_parameters(); 129 | 130 | // Reset the planner position vector (in steps) 131 | void plan_sync_position(); 132 | 133 | // Reinitialize plan with a partially completed block 134 | void plan_cycle_reinitialize(); 135 | 136 | // Returns the number of available blocks are in the planner buffer. 137 | uint8_t plan_get_block_buffer_available(); 138 | 139 | // Returns the number of active blocks are in the planner buffer. 140 | // NOTE: Deprecated. Not used unless classic status reports are enabled in config.h 141 | uint8_t plan_get_block_buffer_count(); 142 | 143 | // Returns the status of the block ring buffer. True, if buffer is full. 144 | uint8_t plan_check_full_buffer(); 145 | 146 | void plan_get_planner_mpos(float *target); 147 | 148 | 149 | #endif 150 | -------------------------------------------------------------------------------- /grbl/print.c: -------------------------------------------------------------------------------- 1 | /* 2 | print.c - Functions for formatting output strings 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #include "grbl.h" 23 | 24 | 25 | void printString(const char *s) 26 | { 27 | while (*s) 28 | serial_write(*s++); 29 | } 30 | 31 | 32 | // Print a string stored in PGM-memory 33 | void printPgmString(const char *s) 34 | { 35 | char c; 36 | while ((c = pgm_read_byte_near(s++))) 37 | serial_write(c); 38 | } 39 | 40 | 41 | // void printIntegerInBase(unsigned long n, unsigned long base) 42 | // { 43 | // unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. 44 | // unsigned long i = 0; 45 | // 46 | // if (n == 0) { 47 | // serial_write('0'); 48 | // return; 49 | // } 50 | // 51 | // while (n > 0) { 52 | // buf[i++] = n % base; 53 | // n /= base; 54 | // } 55 | // 56 | // for (; i > 0; i--) 57 | // serial_write(buf[i - 1] < 10 ? 58 | // '0' + buf[i - 1] : 59 | // 'A' + buf[i - 1] - 10); 60 | // } 61 | 62 | 63 | // Prints an uint8 variable in base 10. 64 | void print_uint8_base10(uint8_t n) 65 | { 66 | uint8_t digit_a = 0; 67 | uint8_t digit_b = 0; 68 | if (n >= 100) { // 100-255 69 | digit_a = '0' + n % 10; 70 | n /= 10; 71 | } 72 | if (n >= 10) { // 10-99 73 | digit_b = '0' + n % 10; 74 | n /= 10; 75 | } 76 | serial_write('0' + n); 77 | if (digit_b) { serial_write(digit_b); } 78 | if (digit_a) { serial_write(digit_a); } 79 | } 80 | 81 | 82 | // Prints an uint8 variable in base 2 with desired number of desired digits. 83 | void print_uint8_base2_ndigit(uint8_t n, uint8_t digits) { 84 | unsigned char buf[digits]; 85 | uint8_t i = 0; 86 | 87 | for (; i < digits; i++) { 88 | buf[i] = n % 2 ; 89 | n /= 2; 90 | } 91 | 92 | for (; i > 0; i--) 93 | serial_write('0' + buf[i - 1]); 94 | } 95 | 96 | 97 | void print_uint32_base10(uint32_t n) 98 | { 99 | if (n == 0) { 100 | serial_write('0'); 101 | return; 102 | } 103 | 104 | unsigned char buf[10]; 105 | uint8_t i = 0; 106 | 107 | while (n > 0) { 108 | buf[i++] = n % 10; 109 | n /= 10; 110 | } 111 | 112 | for (; i > 0; i--) 113 | serial_write('0' + buf[i-1]); 114 | } 115 | 116 | 117 | void printInteger(long n) 118 | { 119 | if (n < 0) { 120 | serial_write('-'); 121 | print_uint32_base10(-n); 122 | } else { 123 | print_uint32_base10(n); 124 | } 125 | } 126 | 127 | 128 | // Convert float to string by immediately converting to a long integer, which contains 129 | // more digits than a float. Number of decimal places, which are tracked by a counter, 130 | // may be set by the user. The integer is then efficiently converted to a string. 131 | // NOTE: AVR '%' and '/' integer operations are very efficient. Bitshifting speed-up 132 | // techniques are actually just slightly slower. Found this out the hard way. 133 | void printFloat(float n, uint8_t decimal_places) 134 | { 135 | if (n < 0) { 136 | serial_write('-'); 137 | n = -n; 138 | } 139 | 140 | uint8_t decimals = decimal_places; 141 | while (decimals >= 2) { // Quickly convert values expected to be E0 to E-4. 142 | n *= 100; 143 | decimals -= 2; 144 | } 145 | if (decimals) { n *= 10; } 146 | n += 0.5; // Add rounding factor. Ensures carryover through entire value. 147 | 148 | // Generate digits backwards and store in string. 149 | unsigned char buf[13]; 150 | uint8_t i = 0; 151 | uint32_t a = (long)n; 152 | while(a > 0) { 153 | buf[i++] = (a % 10) + '0'; // Get digit 154 | a /= 10; 155 | } 156 | while (i < decimal_places) { 157 | buf[i++] = '0'; // Fill in zeros to decimal point for (n < 1) 158 | } 159 | if (i == decimal_places) { // Fill in leading zero, if needed. 160 | buf[i++] = '0'; 161 | } 162 | 163 | // Print the generated string. 164 | for (; i > 0; i--) { 165 | if (i == decimal_places) { serial_write('.'); } // Insert decimal point in right place. 166 | serial_write(buf[i-1]); 167 | } 168 | } 169 | 170 | 171 | // Floating value printing handlers for special variables types used in Grbl and are defined 172 | // in the config.h. 173 | // - CoordValue: Handles all position or coordinate values in inches or mm reporting. 174 | // - RateValue: Handles feed rate and current velocity in inches or mm reporting. 175 | void printFloat_CoordValue(float n) { 176 | if (bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)) { 177 | printFloat(n*INCH_PER_MM,N_DECIMAL_COORDVALUE_INCH); 178 | } else { 179 | printFloat(n,N_DECIMAL_COORDVALUE_MM); 180 | } 181 | } 182 | 183 | void printFloat_RateValue(float n) { 184 | if (bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)) { 185 | printFloat(n*INCH_PER_MM,N_DECIMAL_RATEVALUE_INCH); 186 | } else { 187 | printFloat(n,N_DECIMAL_RATEVALUE_MM); 188 | } 189 | } 190 | 191 | // Debug tool to print free memory in bytes at the called point. 192 | // NOTE: Keep commented unless using. Part of this function always gets compiled in. 193 | // void printFreeMemory() 194 | // { 195 | // extern int __heap_start, *__brkval; 196 | // uint16_t free; // Up to 64k values. 197 | // free = (int) &free - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 198 | // printInteger((int32_t)free); 199 | // printString(" "); 200 | // } 201 | -------------------------------------------------------------------------------- /grbl/print.h: -------------------------------------------------------------------------------- 1 | /* 2 | print.h - Functions for formatting output strings 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef print_h 23 | #define print_h 24 | 25 | 26 | void printString(const char *s); 27 | 28 | void printPgmString(const char *s); 29 | 30 | void printInteger(long n); 31 | 32 | void print_uint32_base10(uint32_t n); 33 | 34 | // Prints an uint8 variable in base 10. 35 | void print_uint8_base10(uint8_t n); 36 | 37 | // Prints an uint8 variable in base 2 with desired number of desired digits. 38 | void print_uint8_base2_ndigit(uint8_t n, uint8_t digits); 39 | 40 | void printFloat(float n, uint8_t decimal_places); 41 | 42 | // Floating value printing handlers for special variables types used in Grbl. 43 | // - CoordValue: Handles all position or coordinate values in inches or mm reporting. 44 | // - RateValue: Handles feed rate and current velocity in inches or mm reporting. 45 | void printFloat_CoordValue(float n); 46 | void printFloat_RateValue(float n); 47 | 48 | // Debug tool to print free memory in bytes at the called point. Not used otherwise. 49 | void printFreeMemory(); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /grbl/probe.c: -------------------------------------------------------------------------------- 1 | /* 2 | probe.c - code pertaining to probing methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2014-2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #include "grbl.h" 22 | 23 | 24 | // Inverts the probe pin state depending on user settings and probing cycle mode. 25 | uint32_t probe_invert_mask; 26 | 27 | 28 | // Probe pin initialization routine. 29 | void probe_init() 30 | { 31 | PROBE_DDR &= ~(PROBE_MASK); // Configure as input pins 32 | #ifdef DISABLE_PROBE_PIN_PULL_UP 33 | PROBE_PORT &= ~(PROBE_MASK); // Normal low operation. Requires external pull-down. 34 | #else 35 | PROBE_PORT |= PROBE_MASK; // Enable internal pull-up resistors. Normal high operation. 36 | #endif 37 | probe_configure_invert_mask(false); // Initialize invert mask. 38 | } 39 | 40 | 41 | // Called by probe_init() and the mc_probe() routines. Sets up the probe pin invert mask to 42 | // appropriately set the pin logic according to setting for normal-high/normal-low operation 43 | // and the probing cycle modes for toward-workpiece/away-from-workpiece. 44 | void probe_configure_invert_mask(uint8_t is_probe_away) 45 | { 46 | probe_invert_mask = 0; // Initialize as zero. 47 | if (bit_isfalse(settings.flags,BITFLAG_INVERT_PROBE_PIN)) { probe_invert_mask ^= PROBE_MASK; } 48 | if (is_probe_away) { probe_invert_mask ^= PROBE_MASK; } 49 | } 50 | 51 | 52 | // Returns the probe pin state. Triggered = true. Called by gcode parser and probe state monitor. 53 | uint8_t probe_get_state() { 54 | if ((PROBE_PIN & PROBE_MASK) ^ probe_invert_mask) { 55 | return 1; 56 | } else { 57 | return 0; 58 | } 59 | } 60 | 61 | 62 | // Monitors probe pin state and records the system position when detected. Called by the 63 | // stepper ISR per ISR tick. 64 | // NOTE: This function must be extremely efficient as to not bog down the stepper ISR. 65 | void probe_state_monitor() 66 | { 67 | if (probe_get_state()) { 68 | sys_probe_state = PROBE_OFF; 69 | memcpy(sys_probe_position, sys_position, sizeof(sys_position)); 70 | bit_true(sys_rt_exec_state, EXEC_MOTION_CANCEL); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /grbl/probe.h: -------------------------------------------------------------------------------- 1 | /* 2 | probe.h - code pertaining to probing methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2014-2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | 21 | #ifndef probe_h 22 | #define probe_h 23 | 24 | // Values that define the probing state machine. 25 | #define PROBE_OFF 0 // Probing disabled or not in use. (Must be zero.) 26 | #define PROBE_ACTIVE 1 // Actively watching the input pin. 27 | 28 | // Probe pin initialization routine. 29 | void probe_init(); 30 | 31 | // Called by probe_init() and the mc_probe() routines. Sets up the probe pin invert mask to 32 | // appropriately set the pin logic according to setting for normal-high/normal-low operation 33 | // and the probing cycle modes for toward-workpiece/away-from-workpiece. 34 | void probe_configure_invert_mask(uint8_t is_probe_away); 35 | 36 | // Returns probe pin state. Triggered = true. Called by gcode parser and probe state monitor. 37 | uint8_t probe_get_state(); 38 | 39 | // Monitors probe pin state and records the system position when detected. Called by the 40 | // stepper ISR per ISR tick. 41 | void probe_state_monitor(); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /grbl/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | protocol.h - controls Grbl execution protocol and procedures 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef protocol_h 23 | #define protocol_h 24 | 25 | // Line buffer size from the serial input stream to be executed. 26 | // NOTE: Not a problem except for extreme cases, but the line buffer size can be too small 27 | // and g-code blocks can get truncated. Officially, the g-code standards support up to 256 28 | // characters. In future versions, this will be increased, when we know how much extra 29 | // memory space we can invest into here or we re-write the g-code parser not to have this 30 | // buffer. 31 | #ifndef LINE_BUFFER_SIZE 32 | #define LINE_BUFFER_SIZE 80 33 | #endif 34 | 35 | // Starts Grbl main loop. It handles all incoming characters from the serial port and executes 36 | // them as they complete. It is also responsible for finishing the initialization procedures. 37 | void protocol_main_loop(); 38 | 39 | // Checks and executes a realtime command at various stop points in main program 40 | void protocol_execute_realtime(); 41 | void protocol_exec_rt_system(); 42 | 43 | // Executes the auto cycle feature, if enabled. 44 | void protocol_auto_cycle_start(); 45 | 46 | // Block until all buffered steps are executed 47 | void protocol_buffer_synchronize(); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /grbl/report.h: -------------------------------------------------------------------------------- 1 | /* 2 | report.h - reporting and messaging methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | #ifndef report_h 21 | #define report_h 22 | 23 | // Define Grbl status codes. Valid values (0-255) 24 | #define STATUS_OK 0 25 | #define STATUS_EXPECTED_COMMAND_LETTER 1 26 | #define STATUS_BAD_NUMBER_FORMAT 2 27 | #define STATUS_INVALID_STATEMENT 3 28 | #define STATUS_NEGATIVE_VALUE 4 29 | #define STATUS_SETTING_DISABLED 5 30 | #define STATUS_SETTING_STEP_PULSE_MIN 6 31 | #define STATUS_SETTING_READ_FAIL 7 32 | #define STATUS_IDLE_ERROR 8 33 | #define STATUS_SYSTEM_GC_LOCK 9 34 | #define STATUS_SOFT_LIMIT_ERROR 10 35 | #define STATUS_OVERFLOW 11 36 | #define STATUS_MAX_STEP_RATE_EXCEEDED 12 37 | #define STATUS_CHECK_DOOR 13 38 | #define STATUS_LINE_LENGTH_EXCEEDED 14 39 | #define STATUS_TRAVEL_EXCEEDED 15 40 | #define STATUS_INVALID_JOG_COMMAND 16 41 | 42 | #define STATUS_GCODE_UNSUPPORTED_COMMAND 20 43 | #define STATUS_GCODE_MODAL_GROUP_VIOLATION 21 44 | #define STATUS_GCODE_UNDEFINED_FEED_RATE 22 45 | #define STATUS_GCODE_COMMAND_VALUE_NOT_INTEGER 23 46 | #define STATUS_GCODE_AXIS_COMMAND_CONFLICT 24 47 | #define STATUS_GCODE_WORD_REPEATED 25 48 | #define STATUS_GCODE_NO_AXIS_WORDS 26 49 | #define STATUS_GCODE_INVALID_LINE_NUMBER 27 50 | #define STATUS_GCODE_VALUE_WORD_MISSING 28 51 | #define STATUS_GCODE_UNSUPPORTED_COORD_SYS 29 52 | #define STATUS_GCODE_G53_INVALID_MOTION_MODE 30 53 | #define STATUS_GCODE_AXIS_WORDS_EXIST 31 54 | #define STATUS_GCODE_NO_AXIS_WORDS_IN_PLANE 32 55 | #define STATUS_GCODE_INVALID_TARGET 33 56 | #define STATUS_GCODE_ARC_RADIUS_ERROR 34 57 | #define STATUS_GCODE_NO_OFFSETS_IN_PLANE 35 58 | #define STATUS_GCODE_UNUSED_WORDS 36 59 | #define STATUS_GCODE_G43_DYNAMIC_AXIS_ERROR 37 60 | #define STATUS_GCODE_MAX_VALUE_EXCEEDED 38 61 | 62 | // Define Grbl alarm codes. Valid values (1-255). 0 is reserved. 63 | #define ALARM_HARD_LIMIT_ERROR EXEC_ALARM_HARD_LIMIT 64 | #define ALARM_SOFT_LIMIT_ERROR EXEC_ALARM_SOFT_LIMIT 65 | #define ALARM_ABORT_CYCLE EXEC_ALARM_ABORT_CYCLE 66 | #define ALARM_PROBE_FAIL_INITIAL EXEC_ALARM_PROBE_FAIL_INITIAL 67 | #define ALARM_PROBE_FAIL_CONTACT EXEC_ALARM_PROBE_FAIL_CONTACT 68 | #define ALARM_HOMING_FAIL_RESET EXEC_ALARM_HOMING_FAIL_RESET 69 | #define ALARM_HOMING_FAIL_DOOR EXEC_ALARM_HOMING_FAIL_DOOR 70 | #define ALARM_HOMING_FAIL_PULLOFF EXEC_ALARM_HOMING_FAIL_PULLOFF 71 | #define ALARM_HOMING_FAIL_APPROACH EXEC_ALARM_HOMING_FAIL_APPROACH 72 | 73 | // Define Grbl feedback message codes. Valid values (0-255). 74 | #define MESSAGE_CRITICAL_EVENT 1 75 | #define MESSAGE_ALARM_LOCK 2 76 | #define MESSAGE_ALARM_UNLOCK 3 77 | #define MESSAGE_ENABLED 4 78 | #define MESSAGE_DISABLED 5 79 | #define MESSAGE_SAFETY_DOOR_AJAR 6 80 | #define MESSAGE_CHECK_LIMITS 7 81 | #define MESSAGE_PROGRAM_END 8 82 | #define MESSAGE_RESTORE_DEFAULTS 9 83 | #define MESSAGE_SPINDLE_RESTORE 10 84 | #define MESSAGE_SLEEP_MODE 11 85 | 86 | // Prints system status messages. 87 | void report_status_message(uint8_t status_code); 88 | 89 | // Prints system alarm messages. 90 | void report_alarm_message(uint8_t alarm_code); 91 | 92 | // Prints miscellaneous feedback messages. 93 | void report_feedback_message(uint8_t message_code); 94 | 95 | // Prints welcome message 96 | void report_init_message(); 97 | 98 | // Prints Grbl help and current global settings 99 | void report_grbl_help(); 100 | 101 | // Prints Grbl global settings 102 | void report_grbl_settings(); 103 | 104 | // Prints an echo of the pre-parsed line received right before execution. 105 | void report_echo_line_received(char *line); 106 | 107 | // Prints realtime status report 108 | void report_realtime_status(); 109 | 110 | // Prints recorded probe position 111 | void report_probe_parameters(); 112 | 113 | // Prints Grbl NGC parameters (coordinate offsets, probe) 114 | void report_ngc_parameters(); 115 | 116 | // Prints current g-code parser mode state 117 | void report_gcode_modes(); 118 | 119 | // Prints startup line when requested and executed. 120 | void report_startup_line(uint8_t n, char *line); 121 | void report_execute_startup_message(char *line, uint8_t status_code); 122 | 123 | // Prints build info and user info 124 | void report_build_info(char *line); 125 | 126 | #ifdef DEBUG 127 | void report_realtime_debug(); 128 | #endif 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /grbl/serial.h: -------------------------------------------------------------------------------- 1 | /* 2 | serial.c - Low level functions for sending and recieving bytes via the serial port 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef serial_h 23 | #define serial_h 24 | 25 | 26 | #ifndef RX_BUFFER_SIZE 27 | #define RX_BUFFER_SIZE 1024 28 | #endif 29 | #ifndef TX_BUFFER_SIZE 30 | #ifdef USE_LINE_NUMBERS 31 | #define TX_BUFFER_SIZE 112 32 | #else 33 | #define TX_BUFFER_SIZE 104 34 | #endif 35 | #endif 36 | 37 | #define SERIAL_NO_DATA 0xff 38 | 39 | 40 | void serial_init(); 41 | 42 | // Writes one byte to the TX serial buffer. Called by main program. 43 | void serial_write(uint8_t data); 44 | 45 | // Fetches the first byte in the serial read buffer. Called by main program. 46 | uint8_t serial_read(); 47 | 48 | // Reset and empty data in read buffer. Used by e-stop and reset. 49 | void serial_reset_read_buffer(); 50 | 51 | // Returns the number of bytes available in the RX serial buffer. 52 | uint16_t serial_get_rx_buffer_available(); 53 | 54 | // Returns the number of bytes used in the RX serial buffer. 55 | // NOTE: Deprecated. Not used unless classic status reports are enabled in config.h. 56 | uint16_t serial_get_rx_buffer_count(); 57 | 58 | // Returns the number of bytes used in the TX serial buffer. 59 | // NOTE: Not used except for debugging and ensuring no TX bottlenecks. 60 | uint8_t serial_get_tx_buffer_count(); 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /grbl/settings.h: -------------------------------------------------------------------------------- 1 | /* 2 | settings.h - eeprom configuration handling 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef settings_h 23 | #define settings_h 24 | 25 | #include "grbl.h" 26 | 27 | 28 | // Version of the EEPROM data. Will be used to migrate existing data from older versions of Grbl 29 | // when firmware is upgraded. Always stored in byte 0 of EEPROM. 30 | #define SETTINGS_VERSION 11 // NOTE: Check settings_reset() when moving to next version. 31 | 32 | // Define bit flag masks for the boolean settings in settings.flag. 33 | #define BITFLAG_REPORT_INCHES bit(0) 34 | #define BITFLAG_LASER_MODE bit(1) 35 | #define BITFLAG_INVERT_ST_ENABLE bit(2) 36 | #define BITFLAG_HARD_LIMIT_ENABLE bit(3) 37 | #define BITFLAG_HOMING_ENABLE bit(4) 38 | #define BITFLAG_SOFT_LIMIT_ENABLE bit(5) 39 | #define BITFLAG_INVERT_LIMIT_PINS bit(6) 40 | #define BITFLAG_INVERT_PROBE_PIN bit(7) 41 | 42 | // Define status reporting boolean enable bit flags in settings.status_report_mask 43 | #define BITFLAG_RT_STATUS_POSITION_TYPE bit(0) 44 | #define BITFLAG_RT_STATUS_BUFFER_STATE bit(1) 45 | 46 | // Define settings restore bitflags. 47 | #define SETTINGS_RESTORE_DEFAULTS bit(0) 48 | #define SETTINGS_RESTORE_PARAMETERS bit(1) 49 | #define SETTINGS_RESTORE_STARTUP_LINES bit(2) 50 | #define SETTINGS_RESTORE_BUILD_INFO bit(3) 51 | #ifndef SETTINGS_RESTORE_ALL 52 | #define SETTINGS_RESTORE_ALL 0xFF // All bitflags 53 | #endif 54 | 55 | // Define EEPROM memory address location values for Grbl settings and parameters 56 | // NOTE: The Atmega328p has 1KB EEPROM. The upper half is reserved for parameters and 57 | // the startup script. The lower half contains the global settings and space for future 58 | // developments. 59 | // Note: Address 0 of EEPROM is reserved for SETTINGS_VERSION. 60 | #define EEPROM_ADDR_GLOBAL 1U 61 | #define EEPROM_ADDR_PARAMETERS 512U 62 | #define EEPROM_ADDR_STARTUP_BLOCK 768U 63 | #define EEPROM_ADDR_BUILD_INFO 942U 64 | 65 | // Define EEPROM address indexing for coordinate parameters 66 | #define N_COORDINATE_SYSTEM 6 // Number of supported work coordinate systems (from index 1) 67 | #define SETTING_INDEX_NCOORD N_COORDINATE_SYSTEM+1 // Total number of system stored (from index 0) 68 | // NOTE: Work coordinate indices are (0=G54, 1=G55, ... , 6=G59) 69 | #define SETTING_INDEX_G28 N_COORDINATE_SYSTEM // Home position 1 70 | #define SETTING_INDEX_G30 N_COORDINATE_SYSTEM+1 // Home position 2 71 | // #define SETTING_INDEX_G92 N_COORDINATE_SYSTEM+2 // Coordinate offset (G92.2,G92.3 not supported) 72 | 73 | // Define Grbl axis settings numbering scheme. Starts at START_VAL, every INCREMENT, over N_SETTINGS. 74 | #define AXIS_N_SETTINGS 5 75 | #define AXIS_SETTINGS_START_VAL 100 // NOTE: Reserving settings values >= 100 for axis settings. Up to 255. 76 | #define AXIS_SETTINGS_INCREMENT 10 // Must be greater than the number of axis settings 77 | 78 | // Global persistent settings (Stored from byte EEPROM_ADDR_GLOBAL onwards) 79 | typedef struct { 80 | // Axis settings 81 | float steps_per_mm[N_AXIS]; 82 | float max_rate[N_AXIS]; 83 | float acceleration[N_AXIS]; 84 | float max_travel[N_AXIS]; // NOTE: Stored as a negative value 85 | float current[N_AXIS]; 86 | 87 | // Remaining Grbl settings 88 | uint8_t pulse_microseconds; 89 | uint8_t step_invert_mask; 90 | uint8_t dir_invert_mask; 91 | uint8_t stepper_idle_lock_time; // If max value 255, steppers do not disable. 92 | uint8_t status_report_mask; // Mask to indicate desired report data. 93 | float junction_deviation; 94 | float arc_tolerance; 95 | 96 | float spindle_pwm_freq; // Hz 97 | float spindle_pwm_off_value; // Percent 98 | float spindle_pwm_min_value; // Percent 99 | float spindle_pwm_max_value; // Percent 100 | float rpm_max; 101 | float rpm_min; 102 | 103 | uint8_t flags; // Contains default boolean settings 104 | 105 | uint8_t homing_dir_mask; 106 | float homing_feed_rate; 107 | float homing_seek_rate; 108 | uint16_t homing_debounce_delay; 109 | float homing_pulloff; 110 | } settings_t; 111 | extern settings_t settings; 112 | 113 | // Initialize the configuration subsystem (load settings from EEPROM) 114 | void settings_init(); 115 | 116 | // Helper function to clear and restore EEPROM defaults 117 | void settings_restore(uint8_t restore_flag); 118 | 119 | // A helper method to set new settings from command line 120 | uint8_t settings_store_global_setting(uint8_t parameter, float value); 121 | 122 | // Stores the protocol line variable as a startup line in EEPROM 123 | void settings_store_startup_line(uint8_t n, char *line); 124 | 125 | // Reads an EEPROM startup line to the protocol line variable 126 | uint8_t settings_read_startup_line(uint8_t n, char *line); 127 | 128 | // Stores build info user-defined string 129 | void settings_store_build_info(char *line); 130 | 131 | // Reads build info user-defined string 132 | uint8_t settings_read_build_info(char *line); 133 | 134 | // Writes selected coordinate data to EEPROM 135 | void settings_write_coord_data(uint8_t coord_select, float *coord_data, bool force, bool commit); 136 | 137 | // Reads selected coordinate data from EEPROM 138 | uint8_t settings_read_coord_data(uint8_t coord_select, float *coord_data); 139 | 140 | // Returns the step pin mask according to Grbl's internal axis numbering 141 | uint32_t get_step_pin_mask(uint8_t i); 142 | 143 | // Returns the direction pin mask according to Grbl's internal axis numbering 144 | uint32_t get_direction_pin_mask(uint8_t i); 145 | 146 | // Returns the limit pin mask according to Grbl's internal axis numbering 147 | uint32_t get_limit_pin_mask(uint8_t i); 148 | 149 | 150 | #endif 151 | -------------------------------------------------------------------------------- /grbl/spindle_control.c: -------------------------------------------------------------------------------- 1 | /* 2 | spindle_control.c - spindle control methods 3 | Part of Grbl 4 | 5 | Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #include "grbl.h" 23 | #include "pwm_driver.h" 24 | 25 | 26 | #ifdef VARIABLE_SPINDLE 27 | static float pwm_gradient; // Precalulated value to speed up rpm to PWM conversions. 28 | float spindle_pwm_period; 29 | float spindle_pwm_off_value; 30 | float spindle_pwm_min_value; 31 | float spindle_pwm_max_value; 32 | #endif 33 | 34 | 35 | void spindle_init() 36 | { 37 | #ifdef VARIABLE_SPINDLE 38 | spindle_pwm_period = (SystemCoreClock / settings.spindle_pwm_freq); 39 | spindle_pwm_off_value = (spindle_pwm_period * settings.spindle_pwm_off_value / 100); 40 | spindle_pwm_min_value = (spindle_pwm_period * settings.spindle_pwm_min_value / 100); 41 | spindle_pwm_max_value = (spindle_pwm_period * settings.spindle_pwm_max_value / 100); 42 | pwm_init(&SPINDLE_PWM_CHANNEL, SPINDLE_PWM_USE_PRIMARY_PIN, SPINDLE_PWM_USE_SECONDARY_PIN, spindle_pwm_period, 0); 43 | pwm_enable(&SPINDLE_PWM_CHANNEL); 44 | 45 | // Configure variable spindle PWM and enable pin, if requried. On the Uno, PWM and enable are 46 | // combined unless configured otherwise. 47 | #ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN 48 | SPINDLE_ENABLE_DDR |= (1<= settings.rpm_max) { 142 | sys.spindle_speed = settings.rpm_max; 143 | pwm_value = spindle_pwm_max_value - 1; 144 | } 145 | else { 146 | sys.spindle_speed = rpm; 147 | pwm_value = floor((rpm - settings.rpm_min) * pwm_gradient) + spindle_pwm_min_value; 148 | if(pwm_value >= spindle_pwm_max_value) 149 | pwm_value = spindle_pwm_max_value - 1; 150 | } 151 | return(pwm_value); 152 | } 153 | #endif 154 | 155 | 156 | // Immediately sets spindle running state with direction and spindle rpm via PWM, if enabled. 157 | // Called by g-code parser spindle_sync(), parking retract and restore, g-code program end, 158 | // sleep, and spindle stop override. 159 | #ifdef VARIABLE_SPINDLE 160 | void spindle_set_state(uint8_t state, float rpm) 161 | #else 162 | void _spindle_set_state(uint8_t state) 163 | #endif 164 | { 165 | if (sys.abort) { return; } // Block during abort. 166 | if (state == SPINDLE_DISABLE) { // Halt or set spindle direction and rpm. 167 | 168 | #ifdef VARIABLE_SPINDLE 169 | sys.spindle_speed = 0.0; 170 | #endif 171 | spindle_stop(); 172 | 173 | } else { 174 | 175 | #ifndef USE_SPINDLE_DIR_AS_ENABLE_PIN 176 | if (state == SPINDLE_ENABLE_CW) { 177 | SPINDLE_DIRECTION_PORT &= ~(1<. 20 | */ 21 | 22 | #ifndef spindle_control_h 23 | #define spindle_control_h 24 | 25 | #define SPINDLE_NO_SYNC false 26 | #define SPINDLE_FORCE_SYNC true 27 | 28 | #define SPINDLE_STATE_DISABLE 0 // Must be zero. 29 | #define SPINDLE_STATE_CW bit(0) 30 | #define SPINDLE_STATE_CCW bit(1) 31 | 32 | 33 | // Initializes spindle pins and hardware PWM, if enabled. 34 | void spindle_init(); 35 | 36 | // Returns current spindle output state. Overrides may alter it from programmed states. 37 | uint8_t spindle_get_state(); 38 | 39 | // Called by g-code parser when setting spindle state and requires a buffer sync. 40 | // Immediately sets spindle running state with direction and spindle rpm via PWM, if enabled. 41 | // Called by spindle_sync() after sync and parking motion/spindle stop override during restore. 42 | #ifdef VARIABLE_SPINDLE 43 | extern float spindle_pwm_period; 44 | extern float spindle_pwm_off_value; 45 | extern float spindle_pwm_min_value; 46 | extern float spindle_pwm_max_value; 47 | 48 | // Called by g-code parser when setting spindle state and requires a buffer sync. 49 | void spindle_sync(uint8_t state, float rpm); 50 | 51 | // Sets spindle running state with direction, enable, and spindle PWM. 52 | void spindle_set_state(uint8_t state, float rpm); 53 | 54 | // Sets spindle PWM quickly for stepper ISR. Also called by spindle_set_state(). 55 | void spindle_set_speed(uint32_t pwm_value); 56 | 57 | // Computes PWM register value for the given RPM for quick updating. 58 | uint32_t spindle_compute_pwm_value(float rpm); 59 | 60 | #else 61 | 62 | // Called by g-code parser when setting spindle state and requires a buffer sync. 63 | #define spindle_sync(state, rpm) _spindle_sync(state) 64 | void _spindle_sync(uint8_t state); 65 | 66 | // Sets spindle running state with direction and enable. 67 | #define spindle_set_state(state, rpm) _spindle_set_state(state) 68 | void _spindle_set_state(uint8_t state); 69 | 70 | #endif 71 | 72 | // Stop and start spindle routines. Called by all spindle routines and stepper ISR. 73 | void spindle_stop(); 74 | 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /grbl/stepper.h: -------------------------------------------------------------------------------- 1 | /* 2 | stepper.h - stepper motor driver: executes motion plans of planner.c using the stepper motors 3 | Part of Grbl 4 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud 7 | 8 | Grbl is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | Grbl is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with Grbl. If not, see . 20 | */ 21 | 22 | #ifndef stepper_h 23 | #define stepper_h 24 | 25 | #ifndef SEGMENT_BUFFER_SIZE 26 | #define SEGMENT_BUFFER_SIZE 6 27 | #endif 28 | 29 | // Initialize and setup the stepper motor subsystem 30 | void stepper_init(); 31 | 32 | // Enable steppers, but cycle does not start unless called by motion control or realtime command. 33 | void st_wake_up(); 34 | 35 | // Immediately disables steppers 36 | void st_go_idle(); 37 | 38 | // Generate the step and direction port invert masks. 39 | void st_generate_step_dir_invert_masks(); 40 | 41 | // Reset the stepper subsystem variables 42 | void st_reset(); 43 | 44 | // Changes the run state of the step segment buffer to execute the special parking motion. 45 | void st_parking_setup_buffer(); 46 | 47 | // Restores the step segment buffer to the normal run state after a parking motion. 48 | void st_parking_restore_buffer(); 49 | 50 | // Reloads step segment buffer. Called continuously by realtime execution system. 51 | void st_prep_buffer(); 52 | 53 | // Called by planner_recalculate() when the executing block is updated by the new plan. 54 | void st_update_plan_block_parameters(); 55 | 56 | // Called by realtime status reporting if realtime rate reporting is enabled in config.h. 57 | float st_get_realtime_rate(); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /lpc17xx/RTE_Components.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cprezzi/grbl-LPC/72d029ed2a9e020ae049fc6b92851f013a352ae7/lpc17xx/RTE_Components.h -------------------------------------------------------------------------------- /lpc17xx/_exit.c: -------------------------------------------------------------------------------- 1 | void _exit() 2 | { 3 | while (1) 4 | ; 5 | } 6 | -------------------------------------------------------------------------------- /lpc17xx/firmware.ld: -------------------------------------------------------------------------------- 1 | /* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED 2 | * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF 3 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. 4 | * THE AUTHORS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR 5 | * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. USE IT AT YOUR OWN RISK */ 6 | 7 | /* This linker script is for firmware.bin, which is compatible with the sdcard bootloader. 8 | */ 9 | 10 | MEMORY 11 | { 12 | /* LPC1768 : 512k ROM + 64k SRAM */ 13 | /*------------------------------ */ 14 | 15 | /* On-chip ROM is a readable (r), executable region (x) */ 16 | /* On-chip SRAM is a readable (r), writable (w) and */ 17 | /* executable region (x) */ 18 | 19 | /* vector table */ 20 | VECT (rx) : ORIGIN = 0x00004000, LENGTH = 4k 21 | 22 | /* ROM. Skips the remaining 4k flash sectors so they can be used for persistent data */ 23 | IROM (rx) : ORIGIN = 0x00010000, LENGTH = 0x70000 /* 512k - 0x10000 */ 24 | 25 | /* local static RAM - 32k for LPC1756 */ 26 | IRAM0 (rwx) : ORIGIN = 0x10000000, LENGTH = 32736 /* 32k-32: 32 bytes at top reserved by IAP */ 27 | 28 | /* AHB SRAM - 16k for LPC1756 - often used for USB */ 29 | IRAM1 (rwx) : ORIGIN = 0x2007C000, LENGTH = 16k 30 | IRAM2 (rwx) : ORIGIN = 0x20080000, LENGTH = 16k 31 | } 32 | 33 | /* SECTION command : Define mapping of input sections */ 34 | /* into output sections. */ 35 | 36 | SECTIONS 37 | { 38 | /******************************************/ 39 | /* code section */ 40 | 41 | .isr_vector_section : 42 | { 43 | KEEP(*(.isr_vector .isr_vector.*)) 44 | } >VECT 45 | 46 | /* "normal" code */ 47 | .text : 48 | { 49 | *(.text .text.*) 50 | *(.gnu.linkonce.t.*) 51 | *(.glue_7) 52 | *(.glue_7t) 53 | *(.gcc_except_table) 54 | *(.rodata .rodata*) 55 | *(.gnu.linkonce.r.*) 56 | } >IROM 57 | 58 | /******************************************/ 59 | /* .ctors .dtors are used for c++ constructors/destructors */ 60 | .ctors : 61 | { 62 | . = ALIGN(4); 63 | PROVIDE(__ctors_start = .); 64 | KEEP(*(SORT(.ctors.*))) 65 | KEEP(*(.ctors)) 66 | PROVIDE(__ctors_end = .); 67 | } >IROM 68 | 69 | .dtors : 70 | { 71 | . = ALIGN(4); 72 | PROVIDE(__dtors_start = .); 73 | KEEP(*(SORT(.dtors.*))) 74 | KEEP(*(.dtors)) 75 | PROVIDE(__dtors_end = .); 76 | 77 | . = ALIGN(4); 78 | /* End Of .text section */ 79 | _etext = .; 80 | _sifastcode = .; 81 | } >IROM 82 | 83 | /**************************************************/ 84 | /* fastcode - copied at startup & executed in RAM */ 85 | 86 | .fastcode : 87 | { 88 | . = ALIGN (4); 89 | _sfastcode = . ; 90 | 91 | *(.glue_7t) *(.glue_7) 92 | *(.fastcode) 93 | 94 | /* add other modules here ... */ 95 | 96 | . = ALIGN (4); 97 | _efastcode = . ; 98 | _sidata = .; 99 | } >IRAM0 AT>IROM 100 | 101 | /******************************************/ 102 | /* This used for USB RAM section */ 103 | .usb_ram (NOLOAD): 104 | { 105 | *.o (USB_RAM) 106 | } > IRAM1 107 | 108 | /******************************************/ 109 | /* data section */ 110 | .data : 111 | { 112 | _sidata = LOADADDR (.data); 113 | . = ALIGN(4); 114 | _sdata = .; 115 | 116 | *(vtable vtable.*) 117 | *(.data .data.*) 118 | *(.gnu.linkonce.d*) 119 | 120 | . = ALIGN(4); 121 | _edata = . ; 122 | } >IRAM0 AT>IROM 123 | 124 | /******************************************/ 125 | /* For no-init variables section */ 126 | .bss (NOLOAD) : 127 | { 128 | . = ALIGN(4); 129 | _sbss = . ; 130 | __bss_start__ = .; 131 | 132 | *(.bss .bss.*) 133 | *(.gnu.linkonce.b*) 134 | *(COMMON) 135 | 136 | . = ALIGN(4); 137 | _ebss = . ; 138 | __bss_end__ = .; 139 | } >IRAM0 140 | 141 | /******************************************/ 142 | /* For stack section */ 143 | .stackarea (NOLOAD) : 144 | { 145 | . = ALIGN(8); 146 | _sstack = .; 147 | 148 | *(.stackarea .stackarea.*) 149 | 150 | . = ALIGN(8); 151 | _estack = .; 152 | 153 | . = ALIGN(4); 154 | _end = . ; 155 | PROVIDE (end = .); 156 | 157 | } > IRAM0 158 | 159 | /******************************************/ 160 | /* Stabs debugging sections. */ 161 | .stab 0 : { *(.stab) } 162 | .stabstr 0 : { *(.stabstr) } 163 | .stab.excl 0 : { *(.stab.excl) } 164 | .stab.exclstr 0 : { *(.stab.exclstr) } 165 | .stab.index 0 : { *(.stab.index) } 166 | .stab.indexstr 0 : { *(.stab.indexstr) } 167 | /* .comment 0 : { *(.comment) } */ 168 | /* DWARF debug sections. 169 | Symbols in the DWARF debugging sections are relative to the beginning 170 | of the section so we begin them at 0. */ 171 | /* DWARF 1 */ 172 | .debug 0 : { *(.debug) } 173 | .line 0 : { *(.line) } 174 | /* GNU DWARF 1 extensions */ 175 | .debug_srcinfo 0 : { *(.debug_srcinfo) } 176 | .debug_sfnames 0 : { *(.debug_sfnames) } 177 | /* DWARF 1.1 and DWARF 2 */ 178 | .debug_aranges 0 : { *(.debug_aranges) } 179 | .debug_pubnames 0 : { *(.debug_pubnames) } 180 | /* DWARF 2 */ 181 | .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } 182 | .debug_abbrev 0 : { *(.debug_abbrev) } 183 | .debug_line 0 : { *(.debug_line) } 184 | .debug_frame 0 : { *(.debug_frame) } 185 | .debug_str 0 : { *(.debug_str) } 186 | .debug_loc 0 : { *(.debug_loc) } 187 | .debug_macinfo 0 : { *(.debug_macinfo) } 188 | /* SGI/MIPS DWARF 2 extensions */ 189 | .debug_weaknames 0 : { *(.debug_weaknames) } 190 | .debug_funcnames 0 : { *(.debug_funcnames) } 191 | .debug_typenames 0 : { *(.debug_typenames) } 192 | .debug_varnames 0 : { *(.debug_varnames) } 193 | } 194 | -------------------------------------------------------------------------------- /lpc17xx/grbl.ld: -------------------------------------------------------------------------------- 1 | /* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED 2 | * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF 3 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. 4 | * THE AUTHORS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR 5 | * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. USE IT AT YOUR OWN RISK */ 6 | 7 | /* This linker script is for grbl.hex, the standalone build (not compatible with sdcard bootloader) 8 | */ 9 | 10 | MEMORY 11 | { 12 | /* LPC1768 : 512k ROM + 64k SRAM */ 13 | /*------------------------------ */ 14 | 15 | /* On-chip ROM is a readable (r), executable region (x) */ 16 | /* On-chip SRAM is a readable (r), writable (w) and */ 17 | /* executable region (x) */ 18 | 19 | /* vector table */ 20 | VECT (rx) : ORIGIN = 0x00000000, LENGTH = 4k 21 | 22 | /* ROM. Skips the remaining 4k flash sectors so they can be used for persistent data */ 23 | IROM (rx) : ORIGIN = 0x00010000, LENGTH = 0x70000 /* 512k - 0x10000 */ 24 | 25 | /* local static RAM - 32k for LPC1756 */ 26 | IRAM0 (rwx) : ORIGIN = 0x10000000, LENGTH = 32736 /* 32k-32: 32 bytes at top reserved by IAP */ 27 | 28 | /* AHB SRAM - 16k for LPC1756 - often used for USB */ 29 | IRAM1 (rwx) : ORIGIN = 0x2007C000, LENGTH = 16k 30 | IRAM2 (rwx) : ORIGIN = 0x20080000, LENGTH = 16k 31 | } 32 | 33 | /* SECTION command : Define mapping of input sections */ 34 | /* into output sections. */ 35 | 36 | SECTIONS 37 | { 38 | /******************************************/ 39 | /* code section */ 40 | 41 | .isr_vector_section : 42 | { 43 | KEEP(*(.isr_vector .isr_vector.*)) 44 | } >VECT 45 | 46 | /* "normal" code */ 47 | .text : 48 | { 49 | *(.text .text.*) 50 | *(.gnu.linkonce.t.*) 51 | *(.glue_7) 52 | *(.glue_7t) 53 | *(.gcc_except_table) 54 | *(.rodata .rodata*) 55 | *(.gnu.linkonce.r.*) 56 | } >IROM 57 | 58 | /******************************************/ 59 | /* .ctors .dtors are used for c++ constructors/destructors */ 60 | .ctors : 61 | { 62 | . = ALIGN(4); 63 | PROVIDE(__ctors_start = .); 64 | KEEP(*(SORT(.ctors.*))) 65 | KEEP(*(.ctors)) 66 | PROVIDE(__ctors_end = .); 67 | } >IROM 68 | 69 | .dtors : 70 | { 71 | . = ALIGN(4); 72 | PROVIDE(__dtors_start = .); 73 | KEEP(*(SORT(.dtors.*))) 74 | KEEP(*(.dtors)) 75 | PROVIDE(__dtors_end = .); 76 | 77 | . = ALIGN(4); 78 | /* End Of .text section */ 79 | _etext = .; 80 | _sifastcode = .; 81 | } >IROM 82 | 83 | /**************************************************/ 84 | /* fastcode - copied at startup & executed in RAM */ 85 | 86 | .fastcode : 87 | { 88 | . = ALIGN (4); 89 | _sfastcode = . ; 90 | 91 | *(.glue_7t) *(.glue_7) 92 | *(.fastcode) 93 | 94 | /* add other modules here ... */ 95 | 96 | . = ALIGN (4); 97 | _efastcode = . ; 98 | _sidata = .; 99 | } >IRAM0 AT>IROM 100 | 101 | /******************************************/ 102 | /* This used for USB RAM section */ 103 | .usb_ram (NOLOAD): 104 | { 105 | *.o (USB_RAM) 106 | } > IRAM1 107 | 108 | /******************************************/ 109 | /* data section */ 110 | .data : 111 | { 112 | _sidata = LOADADDR (.data); 113 | . = ALIGN(4); 114 | _sdata = .; 115 | 116 | *(vtable vtable.*) 117 | *(.data .data.*) 118 | *(.gnu.linkonce.d*) 119 | 120 | . = ALIGN(4); 121 | _edata = . ; 122 | } >IRAM0 AT>IROM 123 | 124 | /******************************************/ 125 | /* For no-init variables section */ 126 | .bss (NOLOAD) : 127 | { 128 | . = ALIGN(4); 129 | _sbss = . ; 130 | __bss_start__ = .; 131 | 132 | *(.bss .bss.*) 133 | *(.gnu.linkonce.b*) 134 | *(COMMON) 135 | 136 | . = ALIGN(4); 137 | _ebss = . ; 138 | __bss_end__ = .; 139 | } >IRAM0 140 | 141 | /******************************************/ 142 | /* For stack section */ 143 | .stackarea (NOLOAD) : 144 | { 145 | . = ALIGN(8); 146 | _sstack = .; 147 | 148 | *(.stackarea .stackarea.*) 149 | 150 | . = ALIGN(8); 151 | _estack = .; 152 | 153 | . = ALIGN(4); 154 | _end = . ; 155 | PROVIDE (end = .); 156 | 157 | } > IRAM0 158 | 159 | /******************************************/ 160 | /* Stabs debugging sections. */ 161 | .stab 0 : { *(.stab) } 162 | .stabstr 0 : { *(.stabstr) } 163 | .stab.excl 0 : { *(.stab.excl) } 164 | .stab.exclstr 0 : { *(.stab.exclstr) } 165 | .stab.index 0 : { *(.stab.index) } 166 | .stab.indexstr 0 : { *(.stab.indexstr) } 167 | /* .comment 0 : { *(.comment) } */ 168 | /* DWARF debug sections. 169 | Symbols in the DWARF debugging sections are relative to the beginning 170 | of the section so we begin them at 0. */ 171 | /* DWARF 1 */ 172 | .debug 0 : { *(.debug) } 173 | .line 0 : { *(.line) } 174 | /* GNU DWARF 1 extensions */ 175 | .debug_srcinfo 0 : { *(.debug_srcinfo) } 176 | .debug_sfnames 0 : { *(.debug_sfnames) } 177 | /* DWARF 1.1 and DWARF 2 */ 178 | .debug_aranges 0 : { *(.debug_aranges) } 179 | .debug_pubnames 0 : { *(.debug_pubnames) } 180 | /* DWARF 2 */ 181 | .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } 182 | .debug_abbrev 0 : { *(.debug_abbrev) } 183 | .debug_line 0 : { *(.debug_line) } 184 | .debug_frame 0 : { *(.debug_frame) } 185 | .debug_str 0 : { *(.debug_str) } 186 | .debug_loc 0 : { *(.debug_loc) } 187 | .debug_macinfo 0 : { *(.debug_macinfo) } 188 | /* SGI/MIPS DWARF 2 extensions */ 189 | .debug_weaknames 0 : { *(.debug_weaknames) } 190 | .debug_funcnames 0 : { *(.debug_funcnames) } 191 | .debug_typenames 0 : { *(.debug_typenames) } 192 | .debug_varnames 0 : { *(.debug_varnames) } 193 | } 194 | -------------------------------------------------------------------------------- /lpc17xx/system_LPC17xx.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file: system_LPC17xx.h 3 | * @purpose: CMSIS Cortex-M3 Device Peripheral Access Layer Header File 4 | * for the NXP LPC17xx Device Series 5 | * @version: V1.02 6 | * @date: 27. July 2009 7 | *---------------------------------------------------------------------------- 8 | * 9 | * Copyright (C) 2009 ARM Limited. All rights reserved. 10 | * 11 | * ARM Limited (ARM) is supplying this software for use with Cortex-M3 12 | * processor based microcontrollers. This file can be freely distributed 13 | * within development tools that are supporting such ARM based processors. 14 | * 15 | * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED 16 | * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF 17 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. 18 | * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR 19 | * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. 20 | * 21 | ******************************************************************************/ 22 | 23 | 24 | #ifndef __SYSTEM_LPC17xx_H 25 | #define __SYSTEM_LPC17xx_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 32 | 33 | 34 | /** 35 | * Initialize the system 36 | * 37 | * @param none 38 | * @return none 39 | * 40 | * @brief Setup the microcontroller system. 41 | * Initialize the System and update the SystemCoreClock variable. 42 | */ 43 | extern void SystemInit (void); 44 | 45 | /** 46 | * Update SystemCoreClock variable 47 | * 48 | * @param none 49 | * @return none 50 | * 51 | * @brief Updates the SystemCoreClock with current core Clock 52 | * retrieved from cpu registers. 53 | */ 54 | extern void SystemCoreClockUpdate (void); 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif /* __SYSTEM_LPC17xx_H */ 61 | --------------------------------------------------------------------------------