├── .cproject ├── .gitignore ├── .project ├── .settings ├── com.atollic.truestudio.debug.hardware_device.prefs ├── language.settings.xml └── org.eclipse.cdt.managedbuilder.core.prefs ├── LICENSE ├── Libraries ├── CMSIS │ ├── CMSIS END USER LICENCE AGREEMENT.pdf │ ├── Device │ │ └── ST │ │ │ └── STM32F10x │ │ │ ├── Include │ │ │ ├── stm32f10x.h │ │ │ └── system_stm32f10x.h │ │ │ └── Release_Notes.html │ ├── Include │ │ ├── arm_common_tables.h │ │ ├── arm_math.h │ │ ├── core_cm3.h │ │ ├── core_cmFunc.h │ │ └── core_cmInstr.h │ ├── README.txt │ └── index.htm ├── 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 ├── stm_lib │ ├── inc │ │ ├── misc.h │ │ ├── stm32f10x_exti.h │ │ ├── stm32f10x_flash.h │ │ ├── stm32f10x_gpio.h │ │ ├── stm32f10x_rcc.h │ │ ├── stm32f10x_tim.h │ │ └── stm32f10x_usart.h │ └── src │ │ ├── misc.c │ │ ├── stm32f10x_exti.c │ │ ├── stm32f10x_flash.c │ │ ├── stm32f10x_gpio.c │ │ ├── stm32f10x_rcc.c │ │ ├── stm32f10x_tim.c │ │ └── stm32f10x_usart.c ├── stm_usb_fs_lib │ ├── inc │ │ ├── usb_conf.hh │ │ ├── usb_core.h │ │ ├── usb_def.h │ │ ├── usb_init.h │ │ ├── usb_int.h │ │ ├── usb_lib.h │ │ ├── usb_mem.h │ │ ├── usb_regs.h │ │ ├── usb_sil.h │ │ └── usb_type.h │ └── src │ │ ├── usb_core.c │ │ ├── usb_init.c │ │ ├── usb_int.c │ │ ├── usb_mem.c │ │ ├── usb_regs.c │ │ └── usb_sil.c ├── usb │ ├── CVS │ │ ├── Entries │ │ ├── Entries.Extra │ │ ├── Entries.Extra.Old │ │ ├── Entries.Old │ │ ├── Repository │ │ └── Root │ ├── hw_config.c │ ├── hw_config.h │ ├── platform_config.h │ ├── stm32f10x_it.h │ ├── usb_conf.h │ ├── usb_desc.c │ ├── usb_desc.c.bak │ ├── usb_desc.h │ ├── usb_endp.c │ ├── usb_endp.c.bak │ ├── usb_istr.c │ ├── usb_istr.h │ ├── usb_prop.c │ ├── usb_prop.h │ ├── usb_pwr.c │ └── usb_pwr.h └── util │ ├── CVS │ ├── Entries │ ├── Entries.Extra │ ├── Entries.Extra.Old │ ├── Entries.Old │ ├── Repository │ └── Root │ ├── stm32eeprom.h │ └── stm32f10x_it.c ├── README.md ├── docs ├── STM32F103C8T8_Bluepill.pptx └── STM32F103C8T8_Bluepill_PinDiagram.png ├── grbl_stm32.elf.launch ├── src ├── startup_stm32f10x_md.c ├── stm32f10x_conf.h └── system_stm32f10x.c └── stm32_flash.ld /.gitignore: -------------------------------------------------------------------------------- 1 | /Debug/ 2 | /Release/ 3 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | grbl_stm32 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /.settings/com.atollic.truestudio.debug.hardware_device.prefs: -------------------------------------------------------------------------------- 1 | BOARD=None 2 | CODE_LOCATION=FLASH 3 | ENDIAN=Little-endian 4 | MCU=STM32F103C8 5 | MCU_VENDOR=STMicroelectronics 6 | MODEL=Pro 7 | PROBE=ST-LINK 8 | PROJECT_FORMAT_VERSION=2 9 | TARGET=STM32 10 | VERSION=9.0.0 11 | eclipse.preferences.version=1 12 | -------------------------------------------------------------------------------- /.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /.settings/org.eclipse.cdt.managedbuilder.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | environment/buildEnvironmentInclude/com.atollic.truestudio.configuration.release.321943791/CPATH/delimiter=; 3 | environment/buildEnvironmentInclude/com.atollic.truestudio.configuration.release.321943791/CPATH/operation=remove 4 | environment/buildEnvironmentInclude/com.atollic.truestudio.configuration.release.321943791/C_INCLUDE_PATH/delimiter=; 5 | environment/buildEnvironmentInclude/com.atollic.truestudio.configuration.release.321943791/C_INCLUDE_PATH/operation=remove 6 | environment/buildEnvironmentInclude/com.atollic.truestudio.configuration.release.321943791/append=true 7 | environment/buildEnvironmentInclude/com.atollic.truestudio.configuration.release.321943791/appendContributed=true 8 | environment/buildEnvironmentInclude/com.atollic.truestudio.exe.debug.440560047/CPATH/delimiter=; 9 | environment/buildEnvironmentInclude/com.atollic.truestudio.exe.debug.440560047/CPATH/operation=remove 10 | environment/buildEnvironmentInclude/com.atollic.truestudio.exe.debug.440560047/C_INCLUDE_PATH/delimiter=; 11 | environment/buildEnvironmentInclude/com.atollic.truestudio.exe.debug.440560047/C_INCLUDE_PATH/operation=remove 12 | environment/buildEnvironmentInclude/com.atollic.truestudio.exe.debug.440560047/append=true 13 | environment/buildEnvironmentInclude/com.atollic.truestudio.exe.debug.440560047/appendContributed=true 14 | environment/buildEnvironmentLibrary/com.atollic.truestudio.configuration.release.321943791/LIBRARY_PATH/delimiter=; 15 | environment/buildEnvironmentLibrary/com.atollic.truestudio.configuration.release.321943791/LIBRARY_PATH/operation=remove 16 | environment/buildEnvironmentLibrary/com.atollic.truestudio.configuration.release.321943791/append=true 17 | environment/buildEnvironmentLibrary/com.atollic.truestudio.configuration.release.321943791/appendContributed=true 18 | environment/buildEnvironmentLibrary/com.atollic.truestudio.exe.debug.440560047/LIBRARY_PATH/delimiter=; 19 | environment/buildEnvironmentLibrary/com.atollic.truestudio.exe.debug.440560047/LIBRARY_PATH/operation=remove 20 | environment/buildEnvironmentLibrary/com.atollic.truestudio.exe.debug.440560047/append=true 21 | environment/buildEnvironmentLibrary/com.atollic.truestudio.exe.debug.440560047/appendContributed=true 22 | -------------------------------------------------------------------------------- /Libraries/CMSIS/CMSIS END USER LICENCE AGREEMENT.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helimp/grbl_stm32/2b0da66044d5f8f1eedbd8b2afb913b48dcef4ad/Libraries/CMSIS/CMSIS END USER LICENCE AGREEMENT.pdf -------------------------------------------------------------------------------- /Libraries/CMSIS/Device/ST/STM32F10x/Include/stm32f10x.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helimp/grbl_stm32/2b0da66044d5f8f1eedbd8b2afb913b48dcef4ad/Libraries/CMSIS/Device/ST/STM32F10x/Include/stm32f10x.h -------------------------------------------------------------------------------- /Libraries/CMSIS/Device/ST/STM32F10x/Include/system_stm32f10x.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f10x.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /** @addtogroup CMSIS 23 | * @{ 24 | */ 25 | 26 | /** @addtogroup stm32f10x_system 27 | * @{ 28 | */ 29 | 30 | /** 31 | * @brief Define to prevent recursive inclusion 32 | */ 33 | #ifndef __SYSTEM_STM32F10X_H 34 | #define __SYSTEM_STM32F10X_H 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /** @addtogroup STM32F10x_System_Includes 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @addtogroup STM32F10x_System_Exported_types 50 | * @{ 51 | */ 52 | 53 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /** @addtogroup STM32F10x_System_Exported_Constants 60 | * @{ 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** @addtogroup STM32F10x_System_Exported_Macros 68 | * @{ 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @addtogroup STM32F10x_System_Exported_Functions 76 | * @{ 77 | */ 78 | 79 | extern void SystemInit(void); 80 | extern void SystemCoreClockUpdate(void); 81 | /** 82 | * @} 83 | */ 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /*__SYSTEM_STM32F10X_H */ 90 | 91 | /** 92 | * @} 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 99 | -------------------------------------------------------------------------------- /Libraries/CMSIS/Include/arm_common_tables.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Copyright (C) 2010 ARM Limited. All rights reserved. 3 | * 4 | * $Date: 11. November 2010 5 | * $Revision: V1.0.2 6 | * 7 | * Project: CMSIS DSP Library 8 | * Title: arm_common_tables.h 9 | * 10 | * Description: This file has extern declaration for common tables like Bitreverse, reciprocal etc which are used across different functions 11 | * 12 | * Target Processor: Cortex-M4/Cortex-M3 13 | * 14 | * Version 1.0.2 2010/11/11 15 | * Documentation updated. 16 | * 17 | * Version 1.0.1 2010/10/05 18 | * Production release and review comments incorporated. 19 | * 20 | * Version 1.0.0 2010/09/20 21 | * Production release and review comments incorporated. 22 | * -------------------------------------------------------------------- */ 23 | 24 | #ifndef _ARM_COMMON_TABLES_H 25 | #define _ARM_COMMON_TABLES_H 26 | 27 | #include "arm_math.h" 28 | 29 | extern uint16_t armBitRevTable[256]; 30 | extern q15_t armRecipTableQ15[64]; 31 | extern q31_t armRecipTableQ31[64]; 32 | extern const q31_t realCoefAQ31[1024]; 33 | extern const q31_t realCoefBQ31[1024]; 34 | 35 | #endif /* ARM_COMMON_TABLES_H */ 36 | -------------------------------------------------------------------------------- /Libraries/CMSIS/README.txt: -------------------------------------------------------------------------------- 1 | * ------------------------------------------------------------------- 2 | * Copyright (C) 2011 ARM Limited. All rights reserved. 3 | * 4 | * Date: 25 July 2011 5 | * Revision: V2.10 6 | * 7 | * Project: Cortex Microcontroller Software Interface Standard (CMSIS) 8 | * Title: Release Note for CMSIS 9 | * 10 | * ------------------------------------------------------------------- 11 | 12 | 13 | NOTE - Open the index.html file to access CMSIS documentation 14 | 15 | 16 | The Cortex Microcontroller Software Interface Standard (CMSIS) provides a single standard across all 17 | Cortex-Mx processor series vendors. It enables code re-use and code sharing across software projects 18 | and reduces time-to-market for new embedded applications. 19 | 20 | CMSIS is released under the terms of the end user license agreement ("CMSIS END USER LICENCE AGREEMENT.pdf"). 21 | Any user of the software package is bound to the terms and conditions of the end user license agreement. 22 | 23 | 24 | You will find the following sub-directories: 25 | 26 | Documentation - Contains CMSIS documentation. 27 | 28 | DSP_Lib - MDK project files, Examples and source files etc.. to build the 29 | CMSIS DSP Software Library for Cortex-M0, Cortex-M3, Cortex-M4 processors. 30 | 31 | Include - CMSIS Core Support and CMSIS DSP Include Files. 32 | 33 | Lib - CMSIS DSP Binaries 34 | --- -------------------------------------------------------------------------------- /Libraries/CMSIS/index.htm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helimp/grbl_stm32/2b0da66044d5f8f1eedbd8b2afb913b48dcef4ad/Libraries/CMSIS/index.htm -------------------------------------------------------------------------------- /Libraries/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 | #ifdef AVRTARGET 27 | COOLANT_FLOOD_DDR |= (1 << COOLANT_FLOOD_BIT); // Configure as output pin 28 | #ifdef ENABLE_M7 29 | COOLANT_MIST_DDR |= (1 << COOLANT_MIST_BIT); 30 | #endif 31 | #endif 32 | #ifdef STM32F103C8 33 | GPIO_InitTypeDef GPIO_InitStructure; 34 | RCC_APB2PeriphClockCmd(RCC_COOLANT_FLOOD_PORT, ENABLE); 35 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 36 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 37 | GPIO_InitStructure.GPIO_Pin = 1 << COOLANT_FLOOD_BIT; 38 | GPIO_Init(COOLANT_FLOOD_PORT, &GPIO_InitStructure); 39 | 40 | RCC_APB2PeriphClockCmd(RCC_COOLANT_MIST_PORT, ENABLE); 41 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 42 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 43 | GPIO_InitStructure.GPIO_Pin = 1 << COOLANT_MIST_BIT; 44 | GPIO_Init(COOLANT_MIST_PORT, &GPIO_InitStructure); 45 | #endif 46 | coolant_stop(); 47 | } 48 | 49 | 50 | // Returns current coolant output state. Overrides may alter it from programmed state. 51 | uint8_t coolant_get_state() 52 | { 53 | uint8_t cl_state = COOLANT_STATE_DISABLE; 54 | #if defined(AVRTARGET) || defined(STM32F103C8) 55 | #ifdef INVERT_COOLANT_FLOOD_PIN 56 | if (bit_isfalse( 57 | #ifdef AVRTARGET 58 | COOLANT_FLOOD_PORT 59 | #else 60 | GPIO_ReadOutputData(COOLANT_FLOOD_PORT) 61 | #endif 62 | ,(1 << COOLANT_FLOOD_BIT))) { 63 | #else 64 | if (bit_istrue( 65 | #ifdef AVRTARGET 66 | COOLANT_FLOOD_PORT 67 | #else 68 | GPIO_ReadOutputData(COOLANT_FLOOD_PORT) 69 | #endif 70 | ,(1 << COOLANT_FLOOD_BIT))) { 71 | #endif 72 | cl_state |= COOLANT_STATE_FLOOD; 73 | } 74 | #ifdef ENABLE_M7 75 | #ifdef INVERT_COOLANT_MIST_PIN 76 | if (bit_isfalse( 77 | #ifdef AVRTARGET 78 | COOLANT_MIST_PORT 79 | #else 80 | GPIO_ReadOutputData(COOLANT_MIST_PORT) 81 | #endif 82 | ,(1 << COOLANT_MIST_BIT))) { 83 | #else 84 | if (bit_istrue( 85 | #ifdef AVRTARGET 86 | COOLANT_MIST_PORT 87 | #else 88 | GPIO_ReadOutputData(COOLANT_MIST_PORT) 89 | #endif 90 | ,(1 << COOLANT_MIST_BIT))) { 91 | #endif 92 | cl_state |= COOLANT_STATE_MIST; 93 | } 94 | #endif 95 | #endif 96 | return(cl_state); 97 | } 98 | 99 | 100 | // Directly called by coolant_init(), coolant_set_state(), and mc_reset(), which can be at 101 | // an interrupt-level. No report flag set, but only called by routines that don't need it. 102 | void coolant_stop() 103 | { 104 | #if defined(AVRTARGET) || defined(STM32F103C8) 105 | #ifdef INVERT_COOLANT_FLOOD_PIN 106 | #ifdef AVRTARGET 107 | COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT); 108 | #else 109 | GPIO_SetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT); 110 | #endif 111 | #else 112 | #ifdef AVRTARGET 113 | COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT); 114 | #else 115 | GPIO_ResetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT); 116 | #endif 117 | #endif 118 | #ifdef ENABLE_M7 119 | #ifdef INVERT_COOLANT_MIST_PIN 120 | #ifdef AVRTARGET 121 | COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT); 122 | #else 123 | GPIO_SetBits(COOLANT_MIST_PORT, 1 << COOLANT_MIST_BIT); 124 | #endif 125 | #else 126 | #ifdef AVRTARGET 127 | COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT); 128 | #else 129 | GPIO_ResetBits(COOLANT_MIST_PORT, 1 << COOLANT_MIST_BIT); 130 | #endif 131 | #endif 132 | #endif 133 | #endif 134 | } 135 | 136 | 137 | // Main program only. Immediately sets flood coolant running state and also mist coolant, 138 | // if enabled. Also sets a flag to report an update to a coolant state. 139 | // Called by coolant toggle override, parking restore, parking retract, sleep mode, g-code 140 | // parser program end, and g-code parser coolant_sync(). 141 | void coolant_set_state(uint8_t mode) 142 | { 143 | if (sys.abort) { return; } // Block during abort. 144 | 145 | if (mode == COOLANT_DISABLE) { 146 | 147 | coolant_stop(); 148 | 149 | } else { 150 | 151 | #if defined(AVRTARGET) || defined(STM32F103C8) 152 | if (mode & COOLANT_FLOOD_ENABLE) { 153 | #ifdef INVERT_COOLANT_FLOOD_PIN 154 | #ifdef AVRTARGET 155 | COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT); 156 | #else 157 | GPIO_ResetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT); 158 | #endif 159 | #else 160 | #ifdef AVRTARGET 161 | COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT); 162 | #else 163 | GPIO_SetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT); 164 | #endif 165 | #endif 166 | } 167 | 168 | #ifdef ENABLE_M7 169 | if (mode & COOLANT_MIST_ENABLE) { 170 | #ifdef INVERT_COOLANT_MIST_PIN 171 | #ifdef AVRTARGET 172 | COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT); 173 | #else 174 | GPIO_ResetBits(COOLANT_MIST_PORT, 1 << COOLANT_MIST_BIT); 175 | #endif 176 | #else 177 | #ifdef AVRTARGET 178 | COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT); 179 | #else 180 | GPIO_SetBits(COOLANT_MIST_PORT, 1 << COOLANT_MIST_BIT); 181 | #endif 182 | #endif 183 | } 184 | #endif 185 | #endif 186 | } 187 | sys.report_ovr_counter = 0; // Set to report change immediately 188 | } 189 | 190 | 191 | // G-code parser entry-point for setting coolant state. Forces a planner buffer sync and bails 192 | // if an abort or check-mode is active. 193 | void coolant_sync(uint8_t mode) 194 | { 195 | if (sys.state == STATE_CHECK_MODE) { return; } 196 | protocol_buffer_synchronize(); // Ensure coolant turns on when specified in program. 197 | coolant_set_state(mode); 198 | } 199 | -------------------------------------------------------------------------------- /Libraries/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 | -------------------------------------------------------------------------------- /Libraries/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 | #if defined(WIN32) || defined (STM32F103C8) 24 | void eeprom_init(); 25 | #endif 26 | unsigned char eeprom_get_char(unsigned int addr); 27 | void eeprom_put_char(unsigned int addr, unsigned char new_value); 28 | void memcpy_to_eeprom_with_checksum(unsigned int destination, char *source, unsigned int size); 29 | int memcpy_from_eeprom_with_checksum(char *destination, unsigned int source, unsigned int size); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /Libraries/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 | -------------------------------------------------------------------------------- /Libraries/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. -------------------------------------------------------------------------------- /Libraries/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 | -------------------------------------------------------------------------------- /Libraries/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. -------------------------------------------------------------------------------- /Libraries/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 "20170801" 27 | 28 | #if !defined(STM32F103C8) && !defined(WIN32) 29 | #define AVRTARGET 30 | #endif 31 | 32 | // Define standard libraries used by Grbl. 33 | #ifdef AVRTARGET 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #define PORTPINDEF uint8_t 42 | #endif 43 | #include 44 | #ifdef WIN32 45 | #include 46 | typedef signed char int8_t; 47 | typedef signed short int16_t; 48 | typedef signed int int32_t; 49 | typedef unsigned char uint8_t; 50 | typedef unsigned short uint16_t; 51 | typedef unsigned int uint32_t; 52 | typedef signed long long int64_t; 53 | typedef unsigned long long uint64_t; 54 | typedef int bool; 55 | #define false 0 56 | #define true 1 57 | #define truncf(x) (int32_t)x 58 | #define PSTR(x) x 59 | #define pgm_read_byte_near(x) *(x) 60 | #define _delay_ms(x) Sleep(x) 61 | #define M_PI 3.1415926f 62 | #define LOG(x,y) 63 | #define PORTPINDEF uint8_t 64 | #define printPgmString printString 65 | //#define NOEEPROMSUPPORT 66 | #endif 67 | #ifdef STM32F103C8 68 | #include "stm32f10x.h" 69 | #include "stm32f10x_gpio.h" 70 | #include "stm32f10x_exti.h" 71 | #include "stm32f10x_tim.h" 72 | #include "misc.h" 73 | #define PSTR(x) x 74 | #define pgm_read_byte_near(x) *(x) 75 | void _delay_ms(uint32_t x); 76 | void _delay_us(uint32_t x); 77 | #define false 0 78 | #define true 1 79 | #define PORTPINDEF uint16_t 80 | typedef int bool; 81 | //#define NOEEPROMSUPPORT 82 | #define printPgmString printString 83 | #endif 84 | #include 85 | #include 86 | #include 87 | 88 | // Define the Grbl system include files. NOTE: Do not alter organization. 89 | #include "config.h" 90 | #include "nuts_bolts.h" 91 | #include "settings.h" 92 | #include "system.h" 93 | #include "defaults.h" 94 | #include "cpu_map.h" 95 | #include "planner.h" 96 | #include "coolant_control.h" 97 | #include "eeprom.h" 98 | #include "gcode.h" 99 | #include "limits.h" 100 | #include "motion_control.h" 101 | #include "planner.h" 102 | #include "print.h" 103 | #include "probe.h" 104 | #include "protocol.h" 105 | #include "report.h" 106 | #include "serial.h" 107 | #include "spindle_control.h" 108 | #include "stepper.h" 109 | #include "jog.h" 110 | 111 | // --------------------------------------------------------------------------------------- 112 | // COMPILE-TIME ERROR CHECKING OF DEFINE VALUES: 113 | 114 | #ifndef HOMING_CYCLE_0 115 | #error "Required HOMING_CYCLE_0 not defined." 116 | #endif 117 | 118 | #if defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) && !defined(VARIABLE_SPINDLE) 119 | #error "USE_SPINDLE_DIR_AS_ENABLE_PIN may only be used with VARIABLE_SPINDLE enabled" 120 | #endif 121 | 122 | #if defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) && !defined(CPU_MAP_ATMEGA328P) 123 | #error "USE_SPINDLE_DIR_AS_ENABLE_PIN may only be used with a 328p processor" 124 | #endif 125 | 126 | #if !defined(USE_SPINDLE_DIR_AS_ENABLE_PIN) && defined(SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED) 127 | #error "SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED may only be used with USE_SPINDLE_DIR_AS_ENABLE_PIN enabled" 128 | #endif 129 | 130 | #if defined(PARKING_ENABLE) 131 | #if defined(HOMING_FORCE_SET_ORIGIN) 132 | #error "HOMING_FORCE_SET_ORIGIN is not supported with PARKING_ENABLE at this time." 133 | #endif 134 | #endif 135 | 136 | #if defined(ENABLE_PARKING_OVERRIDE_CONTROL) 137 | #if !defined(PARKING_ENABLE) 138 | #error "ENABLE_PARKING_OVERRIDE_CONTROL must be enabled with PARKING_ENABLE." 139 | #endif 140 | #endif 141 | 142 | #if defined(SPINDLE_PWM_MIN_VALUE) 143 | #if !(SPINDLE_PWM_MIN_VALUE > 0) 144 | #error "SPINDLE_PWM_MIN_VALUE must be greater than zero." 145 | #endif 146 | #endif 147 | 148 | #if (REPORT_WCO_REFRESH_BUSY_COUNT < REPORT_WCO_REFRESH_IDLE_COUNT) 149 | #error "WCO busy refresh is less than idle refresh." 150 | #endif 151 | #if (REPORT_OVR_REFRESH_BUSY_COUNT < REPORT_OVR_REFRESH_IDLE_COUNT) 152 | #error "Override busy refresh is less than idle refresh." 153 | #endif 154 | #if (REPORT_WCO_REFRESH_IDLE_COUNT < 2) 155 | #error "WCO refresh must be greater than one." 156 | #endif 157 | #if (REPORT_OVR_REFRESH_IDLE_COUNT < 1) 158 | #error "Override refresh must be greater than zero." 159 | #endif 160 | // --------------------------------------------------------------------------------------- 161 | 162 | #endif 163 | -------------------------------------------------------------------------------- /Libraries/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.xyz)) { return(STATUS_TRAVEL_EXCEEDED); } 37 | } 38 | 39 | // Valid jog command. Plan, set state, and execute. 40 | mc_line(gc_block->values.xyz, 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 | -------------------------------------------------------------------------------- /Libraries/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 | -------------------------------------------------------------------------------- /Libraries/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 | -------------------------------------------------------------------------------- /Libraries/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 | 35 | 36 | // Execute linear motion in absolute millimeter coordinates. Feed rate given in millimeters/second 37 | // unless invert_feed_rate is true. Then the feed_rate means that the motion should be completed in 38 | // (1 minute)/feed_rate time. 39 | void mc_line(float *target, plan_line_data_t *pl_data); 40 | 41 | // Execute an arc in offset mode format. position == current xyz, target == target xyz, 42 | // offset == offset from current xyz, axis_XXX defines circle plane in tool space, axis_linear is 43 | // the direction of helical travel, radius == circle radius, is_clockwise_arc boolean. Used 44 | // for vector transformation direction. 45 | void mc_arc(float *target, plan_line_data_t *pl_data, float *position, float *offset, float radius, 46 | uint8_t axis_0, uint8_t axis_1, uint8_t axis_linear, uint8_t is_clockwise_arc); 47 | 48 | // Dwell for a specific number of seconds 49 | void mc_dwell(float seconds); 50 | 51 | // Perform homing cycle to locate machine zero. Requires limit switches. 52 | void mc_homing_cycle(uint8_t cycle_mask); 53 | 54 | // Perform tool length probe cycle. Requires probe switch. 55 | uint8_t mc_probe_cycle(float *target, plan_line_data_t *pl_data, uint8_t parser_flags); 56 | 57 | // Handles updating the override control state. 58 | void mc_override_ctrl_update(uint8_t override_state); 59 | 60 | // Plans and executes the single special motion case for parking. Independent of main planner buffer. 61 | void mc_parking_motion(float *parking_target, plan_line_data_t *pl_data); 62 | 63 | // Performs system reset. If in motion state, kills all motion and sets system alarm. 64 | void mc_reset(); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /Libraries/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.01f; 87 | exp += 2; 88 | } 89 | if (exp < 0) { 90 | fval *= 0.1f; 91 | } else if (exp > 0) { 92 | do { 93 | fval *= 10.0f; 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 = (uint16_t)ceilf(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 | // Delays variable defined milliseconds. Compiler compatibility fix for _delay_ms(), 130 | // which only accepts constants in future compiler releases. 131 | void delay_ms(uint16_t ms) 132 | { 133 | while ( ms-- ) { _delay_ms(1); } 134 | } 135 | 136 | 137 | // Simple hypotenuse computation function. 138 | float hypot_f(float x, float y) { return(sqrtf(x*x + y*y)); } 139 | 140 | 141 | float convert_delta_vector_to_unit_vector(float *vector) 142 | { 143 | uint8_t idx; 144 | float magnitude = 0.0f; 145 | for (idx=0; idx. 20 | */ 21 | 22 | #ifndef nuts_bolts_h 23 | #define nuts_bolts_h 24 | #ifdef STM32F103C8 25 | #include "stm32f10x_rcc.h" 26 | #endif 27 | #include "float.h" 28 | #define false 0 29 | #define true 1 30 | 31 | #define SOME_LARGE_VALUE FLT_MAX 32 | 33 | // Axis array index values. Must start with 0 and be continuous. 34 | #define N_AXIS 3 // Number of axes 35 | #define X_AXIS 0 // Axis indexing value. 36 | #define Y_AXIS 1 37 | #define Z_AXIS 2 38 | // #define A_AXIS 3 39 | 40 | // CoreXY motor assignments. DO NOT ALTER. 41 | // NOTE: If the A and B motor axis bindings are changed, this effects the CoreXY equations. 42 | #ifdef COREXY 43 | #define A_MOTOR X_AXIS // Must be X_AXIS 44 | #define B_MOTOR Y_AXIS // Must be Y_AXIS 45 | #endif 46 | 47 | // Conversions 48 | #define MM_PER_INCH (25.40f) 49 | #define INCH_PER_MM (0.0393701f) 50 | #define TICKS_PER_MICROSECOND (F_CPU/1000000) 51 | #ifdef WIN32 52 | extern LARGE_INTEGER Win32Frequency; 53 | #define F_CPU Win32Frequency.QuadPart 54 | #endif 55 | #ifdef STM32F103C8 56 | #define F_CPU SystemCoreClock 57 | #endif 58 | #define DELAY_MODE_DWELL 0 59 | #define DELAY_MODE_SYS_SUSPEND 1 60 | 61 | // Useful macros 62 | #define clear_vector(a) memset(a, 0, sizeof(a)) 63 | #define clear_vector_float(a) memset(a, 0.0, sizeof(float)*N_AXIS) 64 | // #define clear_vector_long(a) memset(a, 0.0, sizeof(long)*N_AXIS) 65 | #define max(a,b) (((a) > (b)) ? (a) : (b)) 66 | #define min(a,b) (((a) < (b)) ? (a) : (b)) 67 | #define isequal_position_vector(a,b) !(memcmp(a, b, sizeof(float)*N_AXIS)) 68 | 69 | // Bit field and masking macros 70 | #define bit(n) (1 << n) 71 | #define bit_true(x,mask) (x) |= (mask) 72 | #define bit_false(x,mask) (x) &= ~(mask) 73 | #define bit_istrue(x,mask) ((x & mask) != 0) 74 | #define bit_isfalse(x,mask) ((x & mask) == 0) 75 | 76 | // Read a floating point value from a string. Line points to the input buffer, char_counter 77 | // is the indexer pointing to the current character of the line, while float_ptr is 78 | // a pointer to the result variable. Returns true when it succeeds 79 | uint8_t read_float(char *line, uint8_t *char_counter, float *float_ptr); 80 | 81 | // Non-blocking delay function used for general operation and suspend features. 82 | void delay_sec(float seconds, uint8_t mode); 83 | 84 | // Delays variable-defined milliseconds. Compiler compatibility fix for _delay_ms(). 85 | void delay_ms(uint16_t ms); 86 | 87 | 88 | // Computes hypotenuse, avoiding avr-gcc's bloated version and the extra error checking. 89 | float hypot_f(float x, float y); 90 | 91 | float convert_delta_vector_to_unit_vector(float *vector); 92 | float limit_value_by_axis_maximum(float *max_value, float *unit_vec); 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /Libraries/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 AVRTARGET 29 | #ifdef USE_LINE_NUMBERS 30 | #define BLOCK_BUFFER_SIZE 15 31 | #else 32 | #define BLOCK_BUFFER_SIZE 16 33 | #endif 34 | #else 35 | #define BLOCK_BUFFER_SIZE 36 36 | #endif 37 | #endif 38 | 39 | // Returned status message from planner. 40 | #define PLAN_OK true 41 | #define PLAN_EMPTY_BLOCK false 42 | 43 | // Define planner data condition flags. Used to denote running conditions of a block. 44 | #define PL_COND_FLAG_RAPID_MOTION bit(0) 45 | #define PL_COND_FLAG_SYSTEM_MOTION bit(1) // Single motion. Circumvents planner state. Used by home/park. 46 | #define PL_COND_FLAG_NO_FEED_OVERRIDE bit(2) // Motion does not honor feed override. 47 | #define PL_COND_FLAG_INVERSE_TIME bit(3) // Interprets feed rate value as inverse time when set. 48 | #define PL_COND_FLAG_SPINDLE_CW bit(4) 49 | #define PL_COND_FLAG_SPINDLE_CCW bit(5) 50 | #define PL_COND_FLAG_COOLANT_FLOOD bit(6) 51 | #define PL_COND_FLAG_COOLANT_MIST bit(7) 52 | #define PL_COND_MOTION_MASK (PL_COND_FLAG_RAPID_MOTION|PL_COND_FLAG_SYSTEM_MOTION|PL_COND_FLAG_NO_FEED_OVERRIDE) 53 | #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) 54 | 55 | 56 | // This struct stores a linear movement of a g-code block motion with its critical "nominal" values 57 | // are as specified in the source g-code. 58 | typedef struct { 59 | // Fields used by the bresenham algorithm for tracing the line 60 | // NOTE: Used by stepper algorithm to execute the block correctly. Do not alter these values. 61 | uint32_t steps[N_AXIS]; // Step count along each axis 62 | uint32_t step_event_count; // The maximum step axis count and number of steps required to complete this block. 63 | uint8_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h) 64 | 65 | // Block condition data to ensure correct execution depending on states and overrides. 66 | uint8_t condition; // Block bitflag variable defining block run conditions. Copied from pl_line_data. 67 | #ifdef USE_LINE_NUMBERS 68 | int32_t line_number; // Block line number for real-time reporting. Copied from pl_line_data. 69 | #endif 70 | 71 | // Fields used by the motion planner to manage acceleration. Some of these values may be updated 72 | // by the stepper module during execution of special motion cases for replanning purposes. 73 | float entry_speed_sqr; // The current planned entry speed at block junction in (mm/min)^2 74 | float max_entry_speed_sqr; // Maximum allowable entry speed based on the minimum of junction limit and 75 | // neighboring nominal speeds with overrides in (mm/min)^2 76 | float acceleration; // Axis-limit adjusted line acceleration in (mm/min^2). Does not change. 77 | float millimeters; // The remaining distance for this block to be executed in (mm). 78 | // NOTE: This value may be altered by stepper algorithm during execution. 79 | 80 | // Stored rate limiting data used by planner when changes occur. 81 | float max_junction_speed_sqr; // Junction entry speed limit based on direction vectors in (mm/min)^2 82 | float rapid_rate; // Axis-limit adjusted maximum rate for this block direction in (mm/min) 83 | float programmed_rate; // Programmed rate of this block (mm/min). 84 | 85 | #ifdef VARIABLE_SPINDLE 86 | // Stored spindle speed data used by spindle overrides and resuming methods. 87 | float spindle_speed; // Block spindle speed. Copied from pl_line_data. 88 | #endif 89 | } plan_block_t; 90 | 91 | 92 | // Planner data prototype. Must be used when passing new motions to the planner. 93 | typedef struct { 94 | float feed_rate; // Desired feed rate for line motion. Value is ignored, if rapid motion. 95 | float spindle_speed; // Desired spindle speed through line motion. 96 | uint8_t condition; // Bitflag variable to indicate planner conditions. See defines above. 97 | #ifdef USE_LINE_NUMBERS 98 | int32_t line_number; // Desired line number to report when executing. 99 | #endif 100 | } plan_line_data_t; 101 | 102 | 103 | // Initialize and reset the motion plan subsystem 104 | void plan_reset(); // Reset all 105 | void plan_reset_buffer(); // Reset buffer only. 106 | 107 | // Add a new linear movement to the buffer. target[N_AXIS] is the signed, absolute target position 108 | // in millimeters. Feed rate specifies the speed of the motion. If feed rate is inverted, the feed 109 | // rate is taken to mean "frequency" and would complete the operation in 1/feed_rate minutes. 110 | uint8_t plan_buffer_line(float *target, plan_line_data_t *pl_data); 111 | 112 | // Called when the current block is no longer needed. Discards the block and makes the memory 113 | // availible for new blocks. 114 | void plan_discard_current_block(); 115 | 116 | // Gets the planner block for the special system motion cases. (Parking/Homing) 117 | plan_block_t *plan_get_system_motion_block(); 118 | 119 | // Gets the current block. Returns NULL if buffer empty 120 | plan_block_t *plan_get_current_block(); 121 | 122 | // Called periodically by step segment buffer. Mostly used internally by planner. 123 | uint8_t plan_next_block_index(uint8_t block_index); 124 | 125 | // Called by step segment buffer when computing executing block velocity profile. 126 | float plan_get_exec_block_exit_speed_sqr(); 127 | 128 | // Called by main program during planner calculations and step segment buffer during initialization. 129 | float plan_compute_profile_nominal_speed(plan_block_t *block); 130 | 131 | // Re-calculates buffered motions profile parameters upon a motion-based override change. 132 | void plan_update_velocity_profile_parameters(); 133 | 134 | // Reset the planner position vector (in steps) 135 | void plan_sync_position(); 136 | 137 | // Reinitialize plan with a partially completed block 138 | void plan_cycle_reinitialize(); 139 | 140 | // Returns the number of available blocks are in the planner buffer. 141 | uint8_t plan_get_block_buffer_available(); 142 | 143 | // Returns the number of active blocks are in the planner buffer. 144 | // NOTE: Deprecated. Not used unless classic status reports are enabled in config.h 145 | uint8_t plan_get_block_buffer_count(); 146 | 147 | // Returns the status of the block ring buffer. True, if buffer is full. 148 | uint8_t plan_check_full_buffer(); 149 | 150 | void plan_get_planner_mpos(float *target); 151 | 152 | 153 | #endif 154 | -------------------------------------------------------------------------------- /Libraries/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 | #ifdef AVRTARGET 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 | #endif 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 | #if defined(AVRTARGET) || defined(STM32F103C8) 85 | unsigned char buf[digits]; 86 | #endif 87 | #ifdef WIN32 88 | unsigned char buf[20]; 89 | #endif 90 | uint8_t i = 0; 91 | 92 | for (; i < digits; i++) { 93 | buf[i] = n % 2 ; 94 | n /= 2; 95 | } 96 | 97 | for (; i > 0; i--) 98 | serial_write('0' + buf[i - 1]); 99 | } 100 | 101 | 102 | void print_uint32_base10(uint32_t n) 103 | { 104 | if (n == 0) { 105 | serial_write('0'); 106 | return; 107 | } 108 | 109 | unsigned char buf[10]; 110 | uint8_t i = 0; 111 | 112 | while (n > 0) { 113 | buf[i++] = n % 10; 114 | n /= 10; 115 | } 116 | 117 | for (; i > 0; i--) 118 | serial_write('0' + buf[i-1]); 119 | } 120 | 121 | 122 | void printInteger(long n) 123 | { 124 | if (n < 0) { 125 | serial_write('-'); 126 | print_uint32_base10(-n); 127 | } else { 128 | print_uint32_base10(n); 129 | } 130 | } 131 | 132 | 133 | // Convert float to string by immediately converting to a long integer, which contains 134 | // more digits than a float. Number of decimal places, which are tracked by a counter, 135 | // may be set by the user. The integer is then efficiently converted to a string. 136 | // NOTE: AVR '%' and '/' integer operations are very efficient. Bitshifting speed-up 137 | // techniques are actually just slightly slower. Found this out the hard way. 138 | void printFloat(float n, uint8_t decimal_places) 139 | { 140 | if (n < 0) { 141 | serial_write('-'); 142 | n = -n; 143 | } 144 | 145 | uint8_t decimals = decimal_places; 146 | while (decimals >= 2) { // Quickly convert values expected to be E0 to E-4. 147 | n *= 100; 148 | decimals -= 2; 149 | } 150 | if (decimals) { n *= 10; } 151 | n += 0.5; // Add rounding factor. Ensures carryover through entire value. 152 | 153 | // Generate digits backwards and store in string. 154 | unsigned char buf[13]; 155 | uint8_t i = 0; 156 | uint32_t a = (long)n; 157 | while(a > 0) { 158 | buf[i++] = (a % 10) + '0'; // Get digit 159 | a /= 10; 160 | } 161 | while (i < decimal_places) { 162 | buf[i++] = '0'; // Fill in zeros to decimal point for (n < 1) 163 | } 164 | if (i == decimal_places) { // Fill in leading zero, if needed. 165 | buf[i++] = '0'; 166 | } 167 | 168 | // Print the generated string. 169 | for (; i > 0; i--) { 170 | if (i == decimal_places) { serial_write('.'); } // Insert decimal point in right place. 171 | serial_write(buf[i-1]); 172 | } 173 | } 174 | 175 | 176 | // Floating value printing handlers for special variables types used in Grbl and are defined 177 | // in the config.h. 178 | // - CoordValue: Handles all position or coordinate values in inches or mm reporting. 179 | // - RateValue: Handles feed rate and current velocity in inches or mm reporting. 180 | void printFloat_CoordValue(float n) { 181 | if (bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)) { 182 | printFloat(n*INCH_PER_MM,N_DECIMAL_COORDVALUE_INCH); 183 | } else { 184 | printFloat(n,N_DECIMAL_COORDVALUE_MM); 185 | } 186 | } 187 | 188 | void printFloat_RateValue(float n) { 189 | if (bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)) { 190 | printFloat(n*INCH_PER_MM,N_DECIMAL_RATEVALUE_INCH); 191 | } else { 192 | printFloat(n,N_DECIMAL_RATEVALUE_MM); 193 | } 194 | } 195 | 196 | // Debug tool to print free memory in bytes at the called point. 197 | // NOTE: Keep commented unless using. Part of this function always gets compiled in. 198 | // void printFreeMemory() 199 | // { 200 | // extern int __heap_start, *__brkval; 201 | // uint16_t free; // Up to 64k values. 202 | // free = (int) &free - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 203 | // printInteger((int32_t)free); 204 | // printString(" "); 205 | // } 206 | -------------------------------------------------------------------------------- /Libraries/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 | -------------------------------------------------------------------------------- /Libraries/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 | uint8_t probe_invert_mask; 26 | 27 | 28 | // Probe pin initialization routine. 29 | void probe_init() 30 | { 31 | #ifdef AVRTARGET 32 | PROBE_DDR &= ~(PROBE_MASK); // Configure as input pins 33 | #ifdef DISABLE_PROBE_PIN_PULL_UP 34 | PROBE_PORT &= ~(PROBE_MASK); // Normal low operation. Requires external pull-down. 35 | #else 36 | PROBE_PORT |= PROBE_MASK; // Enable internal pull-up resistors. Normal high operation. 37 | #endif 38 | #endif 39 | #ifdef STM32F103C8 40 | GPIO_InitTypeDef GPIO_InitStructure; 41 | RCC_APB2PeriphClockCmd(RCC_PROBE_PORT, ENABLE); 42 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 43 | #ifdef DISABLE_PROBE_PIN_PULL_UP 44 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; 45 | #else 46 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; 47 | #endif 48 | GPIO_InitStructure.GPIO_Pin = PROBE_MASK; 49 | GPIO_Init(PROBE_PORT, &GPIO_InitStructure); 50 | #endif 51 | probe_configure_invert_mask(false); // Initialize invert mask. 52 | } 53 | 54 | 55 | // Called by probe_init() and the mc_probe() routines. Sets up the probe pin invert mask to 56 | // appropriately set the pin logic according to setting for normal-high/normal-low operation 57 | // and the probing cycle modes for toward-workpiece/away-from-workpiece. 58 | void probe_configure_invert_mask(uint8_t is_probe_away) 59 | { 60 | probe_invert_mask = 0; // Initialize as zero. 61 | if (bit_isfalse(settings.flags,BITFLAG_INVERT_PROBE_PIN)) { probe_invert_mask ^= PROBE_MASK; } 62 | if (is_probe_away) { probe_invert_mask ^= PROBE_MASK; } 63 | } 64 | 65 | 66 | // Returns the probe pin state. Triggered = true. Called by gcode parser and probe state monitor. 67 | uint8_t probe_get_state() 68 | { 69 | #ifdef AVRTARGET 70 | return((PROBE_PIN & PROBE_MASK) ^ probe_invert_mask); 71 | #endif 72 | #ifdef WIN32 73 | return 0; 74 | #endif 75 | #ifdef STM32F103C8 76 | return ((GPIO_ReadInputData(PROBE_PORT) & PROBE_MASK) ^ probe_invert_mask) != 0; 77 | #endif 78 | } 79 | 80 | 81 | // Monitors probe pin state and records the system position when detected. Called by the 82 | // stepper ISR per ISR tick. 83 | // NOTE: This function must be extremely efficient as to not bog down the stepper ISR. 84 | void probe_state_monitor() 85 | { 86 | if (probe_get_state()) { 87 | sys_probe_state = PROBE_OFF; 88 | memcpy(sys_probe_position, sys_position, sizeof(sys_position)); 89 | bit_true(sys_rt_exec_state, EXEC_MOTION_CANCEL); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Libraries/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 | -------------------------------------------------------------------------------- /Libraries/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 | -------------------------------------------------------------------------------- /Libraries/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 | #define STATUS_SETTING_DISABLED_LASER 17 42 | 43 | #define STATUS_GCODE_UNSUPPORTED_COMMAND 20 44 | #define STATUS_GCODE_MODAL_GROUP_VIOLATION 21 45 | #define STATUS_GCODE_UNDEFINED_FEED_RATE 22 46 | #define STATUS_GCODE_COMMAND_VALUE_NOT_INTEGER 23 47 | #define STATUS_GCODE_AXIS_COMMAND_CONFLICT 24 48 | #define STATUS_GCODE_WORD_REPEATED 25 49 | #define STATUS_GCODE_NO_AXIS_WORDS 26 50 | #define STATUS_GCODE_INVALID_LINE_NUMBER 27 51 | #define STATUS_GCODE_VALUE_WORD_MISSING 28 52 | #define STATUS_GCODE_UNSUPPORTED_COORD_SYS 29 53 | #define STATUS_GCODE_G53_INVALID_MOTION_MODE 30 54 | #define STATUS_GCODE_AXIS_WORDS_EXIST 31 55 | #define STATUS_GCODE_NO_AXIS_WORDS_IN_PLANE 32 56 | #define STATUS_GCODE_INVALID_TARGET 33 57 | #define STATUS_GCODE_ARC_RADIUS_ERROR 34 58 | #define STATUS_GCODE_NO_OFFSETS_IN_PLANE 35 59 | #define STATUS_GCODE_UNUSED_WORDS 36 60 | #define STATUS_GCODE_G43_DYNAMIC_AXIS_ERROR 37 61 | #define STATUS_GCODE_MAX_VALUE_EXCEEDED 38 62 | 63 | // Define Grbl alarm codes. Valid values (1-255). 0 is reserved. 64 | #define ALARM_HARD_LIMIT_ERROR EXEC_ALARM_HARD_LIMIT 65 | #define ALARM_SOFT_LIMIT_ERROR EXEC_ALARM_SOFT_LIMIT 66 | #define ALARM_ABORT_CYCLE EXEC_ALARM_ABORT_CYCLE 67 | #define ALARM_PROBE_FAIL_INITIAL EXEC_ALARM_PROBE_FAIL_INITIAL 68 | #define ALARM_PROBE_FAIL_CONTACT EXEC_ALARM_PROBE_FAIL_CONTACT 69 | #define ALARM_HOMING_FAIL_RESET EXEC_ALARM_HOMING_FAIL_RESET 70 | #define ALARM_HOMING_FAIL_DOOR EXEC_ALARM_HOMING_FAIL_DOOR 71 | #define ALARM_HOMING_FAIL_PULLOFF EXEC_ALARM_HOMING_FAIL_PULLOFF 72 | #define ALARM_HOMING_FAIL_APPROACH EXEC_ALARM_HOMING_FAIL_APPROACH 73 | 74 | // Define Grbl feedback message codes. Valid values (0-255). 75 | #define MESSAGE_CRITICAL_EVENT 1 76 | #define MESSAGE_ALARM_LOCK 2 77 | #define MESSAGE_ALARM_UNLOCK 3 78 | #define MESSAGE_ENABLED 4 79 | #define MESSAGE_DISABLED 5 80 | #define MESSAGE_SAFETY_DOOR_AJAR 6 81 | #define MESSAGE_CHECK_LIMITS 7 82 | #define MESSAGE_PROGRAM_END 8 83 | #define MESSAGE_RESTORE_DEFAULTS 9 84 | #define MESSAGE_SPINDLE_RESTORE 10 85 | #define MESSAGE_SLEEP_MODE 11 86 | 87 | // Prints system status messages. 88 | void report_status_message(uint8_t status_code); 89 | 90 | // Prints system alarm messages. 91 | void report_alarm_message(uint8_t alarm_code); 92 | 93 | // Prints miscellaneous feedback messages. 94 | void report_feedback_message(uint8_t message_code); 95 | 96 | // Prints welcome message 97 | void report_init_message(); 98 | 99 | // Prints Grbl help and current global settings 100 | void report_grbl_help(); 101 | 102 | // Prints Grbl global settings 103 | void report_grbl_settings(); 104 | 105 | // Prints an echo of the pre-parsed line received right before execution. 106 | void report_echo_line_received(char *line); 107 | 108 | // Prints realtime status report 109 | void report_realtime_status(); 110 | 111 | // Prints recorded probe position 112 | void report_probe_parameters(); 113 | 114 | // Prints Grbl NGC parameters (coordinate offsets, probe) 115 | void report_ngc_parameters(); 116 | 117 | // Prints current g-code parser mode state 118 | void report_gcode_modes(); 119 | 120 | // Prints startup line when requested and executed. 121 | void report_startup_line(uint8_t n, char *line); 122 | void report_execute_startup_message(char *line, uint8_t status_code); 123 | 124 | // Prints build info and user info 125 | void report_build_info(char *line); 126 | 127 | #ifdef DEBUG 128 | void report_realtime_debug(); 129 | #endif 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /Libraries/grbl/serial.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helimp/grbl_stm32/2b0da66044d5f8f1eedbd8b2afb913b48dcef4ad/Libraries/grbl/serial.c -------------------------------------------------------------------------------- /Libraries/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 | #ifdef AVRTARGET 26 | #ifndef RX_BUFFER_SIZE 27 | #define RX_BUFFER_SIZE 128 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 | #else 37 | #define RX_BUFFER_SIZE 254 38 | #ifndef WIN32 39 | #define TX_BUFFER_SIZE 128 // Do not try 256 it will not work for STM32. 40 | #else 41 | #define TX_BUFFER_SIZE 254 42 | #endif 43 | #endif 44 | 45 | #define SERIAL_NO_DATA 0xff 46 | 47 | #ifdef WIN32 48 | void winserial_init(char *pPort); 49 | #endif 50 | 51 | void serial_init(); 52 | 53 | // Writes one byte to the TX serial buffer. Called by main program. 54 | void serial_write(uint8_t data); 55 | 56 | // Fetches the first byte in the serial read buffer. Called by main program. 57 | uint8_t serial_read(); 58 | 59 | // Reset and empty data in read buffer. Used by e-stop and reset. 60 | void serial_reset_read_buffer(); 61 | 62 | // Returns the number of bytes available in the RX serial buffer. 63 | uint8_t serial_get_rx_buffer_available(); 64 | 65 | // Returns the number of bytes used in the RX serial buffer. 66 | // NOTE: Deprecated. Not used unless classic status reports are enabled in config.h. 67 | uint8_t serial_get_rx_buffer_count(); 68 | 69 | // Returns the number of bytes used in the TX serial buffer. 70 | // NOTE: Not used except for debugging and ensuring no TX bottlenecks. 71 | uint8_t serial_get_tx_buffer_count(); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /Libraries/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 10 // 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 | #define EEPROM_ADDR_GLOBAL 1U 60 | #define EEPROM_ADDR_PARAMETERS 512U 61 | #define EEPROM_ADDR_STARTUP_BLOCK 768U 62 | #define EEPROM_ADDR_BUILD_INFO 942U 63 | 64 | // Define EEPROM address indexing for coordinate parameters 65 | #define N_COORDINATE_SYSTEM 6 // Number of supported work coordinate systems (from index 1) 66 | #define SETTING_INDEX_NCOORD N_COORDINATE_SYSTEM+1 // Total number of system stored (from index 0) 67 | // NOTE: Work coordinate indices are (0=G54, 1=G55, ... , 6=G59) 68 | #define SETTING_INDEX_G28 N_COORDINATE_SYSTEM // Home position 1 69 | #define SETTING_INDEX_G30 N_COORDINATE_SYSTEM+1 // Home position 2 70 | // #define SETTING_INDEX_G92 N_COORDINATE_SYSTEM+2 // Coordinate offset (G92.2,G92.3 not supported) 71 | 72 | // Define Grbl axis settings numbering scheme. Starts at START_VAL, every INCREMENT, over N_SETTINGS. 73 | #define AXIS_N_SETTINGS 4 74 | #define AXIS_SETTINGS_START_VAL 100 // NOTE: Reserving settings values >= 100 for axis settings. Up to 255. 75 | #define AXIS_SETTINGS_INCREMENT 10 // Must be greater than the number of axis settings 76 | 77 | // Global persistent settings (Stored from byte EEPROM_ADDR_GLOBAL onwards) 78 | typedef struct { 79 | // Axis settings 80 | float steps_per_mm[N_AXIS]; 81 | float max_rate[N_AXIS]; 82 | float acceleration[N_AXIS]; 83 | float max_travel[N_AXIS]; 84 | 85 | // Remaining Grbl settings 86 | uint8_t pulse_microseconds; 87 | uint8_t step_invert_mask; 88 | uint8_t dir_invert_mask; 89 | uint8_t stepper_idle_lock_time; // If max value 255, steppers do not disable. 90 | uint8_t status_report_mask; // Mask to indicate desired report data. 91 | float junction_deviation; 92 | float arc_tolerance; 93 | 94 | float rpm_max; 95 | float rpm_min; 96 | 97 | uint8_t flags; // Contains default boolean settings 98 | 99 | uint8_t homing_dir_mask; 100 | float homing_feed_rate; 101 | float homing_seek_rate; 102 | uint16_t homing_debounce_delay; 103 | float homing_pulloff; 104 | } settings_t; 105 | extern settings_t settings; 106 | 107 | // Initialize the configuration subsystem (load settings from EEPROM) 108 | void settings_init(); 109 | 110 | // Helper function to clear and restore EEPROM defaults 111 | void settings_restore(uint8_t restore_flag); 112 | 113 | // A helper method to set new settings from command line 114 | uint8_t settings_store_global_setting(uint8_t parameter, float value); 115 | 116 | // Stores the protocol line variable as a startup line in EEPROM 117 | void settings_store_startup_line(uint8_t n, char *line); 118 | 119 | // Reads an EEPROM startup line to the protocol line variable 120 | uint8_t settings_read_startup_line(uint8_t n, char *line); 121 | 122 | // Stores build info user-defined string 123 | void settings_store_build_info(char *line); 124 | 125 | // Reads build info user-defined string 126 | uint8_t settings_read_build_info(char *line); 127 | 128 | // Writes selected coordinate data to EEPROM 129 | void settings_write_coord_data(uint8_t coord_select, float *coord_data); 130 | 131 | // Reads selected coordinate data from EEPROM 132 | uint8_t settings_read_coord_data(uint8_t coord_select, float *coord_data); 133 | 134 | #endif 135 | -------------------------------------------------------------------------------- /Libraries/grbl/spindle_control.h: -------------------------------------------------------------------------------- 1 | /* 2 | spindle_control.h - 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 | #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 | #ifdef STM32F103C8 44 | #define SPINDLE_PWM_TYPE uint16_t 45 | #else 46 | #define SPINDLE_PWM_TYPE uint8_t 47 | #endif 48 | 49 | // Called by g-code parser when setting spindle state and requires a buffer sync. 50 | void spindle_sync(uint8_t state, float rpm); 51 | 52 | // Sets spindle running state with direction, enable, and spindle PWM. 53 | void spindle_set_state(uint8_t state, float rpm); 54 | 55 | // Sets spindle PWM quickly for stepper ISR. Also called by spindle_set_state(). 56 | // NOTE: 328p PWM register is 8-bit. 57 | void spindle_set_speed(SPINDLE_PWM_TYPE pwm_value); 58 | 59 | // Computes 328p-specific PWM register value for the given RPM for quick updating. 60 | SPINDLE_PWM_TYPE spindle_compute_pwm_value(float rpm); 61 | 62 | #else 63 | 64 | // Called by g-code parser when setting spindle state and requires a buffer sync. 65 | #define spindle_sync(state, rpm) _spindle_sync(state) 66 | void _spindle_sync(uint8_t state); 67 | 68 | // Sets spindle running state with direction and enable. 69 | #define spindle_set_state(state, rpm) _spindle_set_state(state) 70 | void _spindle_set_state(uint8_t state); 71 | 72 | #endif 73 | 74 | // Stop and start spindle routines. Called by all spindle routines and stepper ISR. 75 | void spindle_stop(); 76 | 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /Libraries/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 | #ifdef AVRTARGET 27 | #define SEGMENT_BUFFER_SIZE 6 28 | #else 29 | #define SEGMENT_BUFFER_SIZE 10 30 | #endif 31 | #endif 32 | 33 | // Initialize and setup the stepper motor subsystem 34 | void stepper_init(); 35 | 36 | // Enable steppers, but cycle does not start unless called by motion control or realtime command. 37 | void st_wake_up(); 38 | 39 | // Immediately disables steppers 40 | void st_go_idle(); 41 | 42 | // Generate the step and direction port invert masks. 43 | void st_generate_step_dir_invert_masks(); 44 | 45 | // Reset the stepper subsystem variables 46 | void st_reset(); 47 | 48 | // Changes the run state of the step segment buffer to execute the special parking motion. 49 | void st_parking_setup_buffer(); 50 | 51 | // Restores the step segment buffer to the normal run state after a parking motion. 52 | void st_parking_restore_buffer(); 53 | 54 | // Reloads step segment buffer. Called continuously by realtime execution system. 55 | void st_prep_buffer(); 56 | 57 | // Called by planner_recalculate() when the executing block is updated by the new plan. 58 | void st_update_plan_block_parameters(); 59 | 60 | // Called by realtime status reporting if realtime rate reporting is enabled in config.h. 61 | float st_get_realtime_rate(); 62 | 63 | extern const PORTPINDEF step_pin_mask[N_AXIS]; 64 | extern const PORTPINDEF direction_pin_mask[N_AXIS]; 65 | extern const PORTPINDEF limit_pin_mask[N_AXIS]; 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /Libraries/stm_lib/inc/stm32f10x_exti.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_exti.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the EXTI firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_EXTI_H 25 | #define __STM32F10x_EXTI_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup EXTI 39 | * @{ 40 | */ 41 | 42 | /** @defgroup EXTI_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @brief EXTI mode enumeration 48 | */ 49 | 50 | typedef enum 51 | { 52 | EXTI_Mode_Interrupt = 0x00, 53 | EXTI_Mode_Event = 0x04 54 | }EXTIMode_TypeDef; 55 | 56 | #define IS_EXTI_MODE(MODE) (((MODE) == EXTI_Mode_Interrupt) || ((MODE) == EXTI_Mode_Event)) 57 | 58 | /** 59 | * @brief EXTI Trigger enumeration 60 | */ 61 | 62 | typedef enum 63 | { 64 | EXTI_Trigger_Rising = 0x08, 65 | EXTI_Trigger_Falling = 0x0C, 66 | EXTI_Trigger_Rising_Falling = 0x10 67 | }EXTITrigger_TypeDef; 68 | 69 | #define IS_EXTI_TRIGGER(TRIGGER) (((TRIGGER) == EXTI_Trigger_Rising) || \ 70 | ((TRIGGER) == EXTI_Trigger_Falling) || \ 71 | ((TRIGGER) == EXTI_Trigger_Rising_Falling)) 72 | /** 73 | * @brief EXTI Init Structure definition 74 | */ 75 | 76 | typedef struct 77 | { 78 | uint32_t EXTI_Line; /*!< Specifies the EXTI lines to be enabled or disabled. 79 | This parameter can be any combination of @ref EXTI_Lines */ 80 | 81 | EXTIMode_TypeDef EXTI_Mode; /*!< Specifies the mode for the EXTI lines. 82 | This parameter can be a value of @ref EXTIMode_TypeDef */ 83 | 84 | EXTITrigger_TypeDef EXTI_Trigger; /*!< Specifies the trigger signal active edge for the EXTI lines. 85 | This parameter can be a value of @ref EXTIMode_TypeDef */ 86 | 87 | FunctionalState EXTI_LineCmd; /*!< Specifies the new state of the selected EXTI lines. 88 | This parameter can be set either to ENABLE or DISABLE */ 89 | }EXTI_InitTypeDef; 90 | 91 | /** 92 | * @} 93 | */ 94 | 95 | /** @defgroup EXTI_Exported_Constants 96 | * @{ 97 | */ 98 | 99 | /** @defgroup EXTI_Lines 100 | * @{ 101 | */ 102 | 103 | #define EXTI_Line0 ((uint32_t)0x00001) /*!< External interrupt line 0 */ 104 | #define EXTI_Line1 ((uint32_t)0x00002) /*!< External interrupt line 1 */ 105 | #define EXTI_Line2 ((uint32_t)0x00004) /*!< External interrupt line 2 */ 106 | #define EXTI_Line3 ((uint32_t)0x00008) /*!< External interrupt line 3 */ 107 | #define EXTI_Line4 ((uint32_t)0x00010) /*!< External interrupt line 4 */ 108 | #define EXTI_Line5 ((uint32_t)0x00020) /*!< External interrupt line 5 */ 109 | #define EXTI_Line6 ((uint32_t)0x00040) /*!< External interrupt line 6 */ 110 | #define EXTI_Line7 ((uint32_t)0x00080) /*!< External interrupt line 7 */ 111 | #define EXTI_Line8 ((uint32_t)0x00100) /*!< External interrupt line 8 */ 112 | #define EXTI_Line9 ((uint32_t)0x00200) /*!< External interrupt line 9 */ 113 | #define EXTI_Line10 ((uint32_t)0x00400) /*!< External interrupt line 10 */ 114 | #define EXTI_Line11 ((uint32_t)0x00800) /*!< External interrupt line 11 */ 115 | #define EXTI_Line12 ((uint32_t)0x01000) /*!< External interrupt line 12 */ 116 | #define EXTI_Line13 ((uint32_t)0x02000) /*!< External interrupt line 13 */ 117 | #define EXTI_Line14 ((uint32_t)0x04000) /*!< External interrupt line 14 */ 118 | #define EXTI_Line15 ((uint32_t)0x08000) /*!< External interrupt line 15 */ 119 | #define EXTI_Line16 ((uint32_t)0x10000) /*!< External interrupt line 16 Connected to the PVD Output */ 120 | #define EXTI_Line17 ((uint32_t)0x20000) /*!< External interrupt line 17 Connected to the RTC Alarm event */ 121 | #define EXTI_Line18 ((uint32_t)0x40000) /*!< External interrupt line 18 Connected to the USB Device/USB OTG FS 122 | Wakeup from suspend event */ 123 | #define EXTI_Line19 ((uint32_t)0x80000) /*!< External interrupt line 19 Connected to the Ethernet Wakeup event */ 124 | 125 | #define IS_EXTI_LINE(LINE) ((((LINE) & (uint32_t)0xFFF00000) == 0x00) && ((LINE) != (uint16_t)0x00)) 126 | #define IS_GET_EXTI_LINE(LINE) (((LINE) == EXTI_Line0) || ((LINE) == EXTI_Line1) || \ 127 | ((LINE) == EXTI_Line2) || ((LINE) == EXTI_Line3) || \ 128 | ((LINE) == EXTI_Line4) || ((LINE) == EXTI_Line5) || \ 129 | ((LINE) == EXTI_Line6) || ((LINE) == EXTI_Line7) || \ 130 | ((LINE) == EXTI_Line8) || ((LINE) == EXTI_Line9) || \ 131 | ((LINE) == EXTI_Line10) || ((LINE) == EXTI_Line11) || \ 132 | ((LINE) == EXTI_Line12) || ((LINE) == EXTI_Line13) || \ 133 | ((LINE) == EXTI_Line14) || ((LINE) == EXTI_Line15) || \ 134 | ((LINE) == EXTI_Line16) || ((LINE) == EXTI_Line17) || \ 135 | ((LINE) == EXTI_Line18) || ((LINE) == EXTI_Line19)) 136 | 137 | 138 | /** 139 | * @} 140 | */ 141 | 142 | /** 143 | * @} 144 | */ 145 | 146 | /** @defgroup EXTI_Exported_Macros 147 | * @{ 148 | */ 149 | 150 | /** 151 | * @} 152 | */ 153 | 154 | /** @defgroup EXTI_Exported_Functions 155 | * @{ 156 | */ 157 | 158 | void EXTI_DeInit(void); 159 | void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct); 160 | void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct); 161 | void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line); 162 | FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line); 163 | void EXTI_ClearFlag(uint32_t EXTI_Line); 164 | ITStatus EXTI_GetITStatus(uint32_t EXTI_Line); 165 | void EXTI_ClearITPendingBit(uint32_t EXTI_Line); 166 | 167 | #ifdef __cplusplus 168 | } 169 | #endif 170 | 171 | #endif /* __STM32F10x_EXTI_H */ 172 | /** 173 | * @} 174 | */ 175 | 176 | /** 177 | * @} 178 | */ 179 | 180 | /** 181 | * @} 182 | */ 183 | 184 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 185 | -------------------------------------------------------------------------------- /Libraries/stm_lib/src/misc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file misc.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file provides all the miscellaneous firmware functions (add-on 8 | * to CMSIS functions). 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Includes ------------------------------------------------------------------*/ 24 | #include "misc.h" 25 | 26 | /** @addtogroup STM32F10x_StdPeriph_Driver 27 | * @{ 28 | */ 29 | 30 | /** @defgroup MISC 31 | * @brief MISC driver modules 32 | * @{ 33 | */ 34 | 35 | /** @defgroup MISC_Private_TypesDefinitions 36 | * @{ 37 | */ 38 | 39 | /** 40 | * @} 41 | */ 42 | 43 | /** @defgroup MISC_Private_Defines 44 | * @{ 45 | */ 46 | 47 | #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000) 48 | /** 49 | * @} 50 | */ 51 | 52 | /** @defgroup MISC_Private_Macros 53 | * @{ 54 | */ 55 | 56 | /** 57 | * @} 58 | */ 59 | 60 | /** @defgroup MISC_Private_Variables 61 | * @{ 62 | */ 63 | 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup MISC_Private_FunctionPrototypes 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup MISC_Private_Functions 77 | * @{ 78 | */ 79 | 80 | /** 81 | * @brief Configures the priority grouping: pre-emption priority and subpriority. 82 | * @param NVIC_PriorityGroup: specifies the priority grouping bits length. 83 | * This parameter can be one of the following values: 84 | * @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority 85 | * 4 bits for subpriority 86 | * @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority 87 | * 3 bits for subpriority 88 | * @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority 89 | * 2 bits for subpriority 90 | * @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority 91 | * 1 bits for subpriority 92 | * @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority 93 | * 0 bits for subpriority 94 | * @retval None 95 | */ 96 | void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup) 97 | { 98 | /* Check the parameters */ 99 | assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup)); 100 | 101 | /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */ 102 | SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup; 103 | } 104 | 105 | /** 106 | * @brief Initializes the NVIC peripheral according to the specified 107 | * parameters in the NVIC_InitStruct. 108 | * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains 109 | * the configuration information for the specified NVIC peripheral. 110 | * @retval None 111 | */ 112 | void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct) 113 | { 114 | uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F; 115 | 116 | /* Check the parameters */ 117 | assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd)); 118 | assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority)); 119 | assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority)); 120 | 121 | if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE) 122 | { 123 | /* Compute the Corresponding IRQ Priority --------------------------------*/ 124 | tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08; 125 | tmppre = (0x4 - tmppriority); 126 | tmpsub = tmpsub >> tmppriority; 127 | 128 | tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre; 129 | tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub; 130 | tmppriority = tmppriority << 0x04; 131 | 132 | NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority; 133 | 134 | /* Enable the Selected IRQ Channels --------------------------------------*/ 135 | NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = 136 | (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 137 | } 138 | else 139 | { 140 | /* Disable the Selected IRQ Channels -------------------------------------*/ 141 | NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = 142 | (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 143 | } 144 | } 145 | 146 | /** 147 | * @brief Sets the vector table location and Offset. 148 | * @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory. 149 | * This parameter can be one of the following values: 150 | * @arg NVIC_VectTab_RAM 151 | * @arg NVIC_VectTab_FLASH 152 | * @param Offset: Vector Table base offset field. This value must be a multiple 153 | * of 0x200. 154 | * @retval None 155 | */ 156 | void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset) 157 | { 158 | /* Check the parameters */ 159 | assert_param(IS_NVIC_VECTTAB(NVIC_VectTab)); 160 | assert_param(IS_NVIC_OFFSET(Offset)); 161 | 162 | SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80); 163 | } 164 | 165 | /** 166 | * @brief Selects the condition for the system to enter low power mode. 167 | * @param LowPowerMode: Specifies the new mode for the system to enter low power mode. 168 | * This parameter can be one of the following values: 169 | * @arg NVIC_LP_SEVONPEND 170 | * @arg NVIC_LP_SLEEPDEEP 171 | * @arg NVIC_LP_SLEEPONEXIT 172 | * @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE. 173 | * @retval None 174 | */ 175 | void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState) 176 | { 177 | /* Check the parameters */ 178 | assert_param(IS_NVIC_LP(LowPowerMode)); 179 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 180 | 181 | if (NewState != DISABLE) 182 | { 183 | SCB->SCR |= LowPowerMode; 184 | } 185 | else 186 | { 187 | SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode); 188 | } 189 | } 190 | 191 | /** 192 | * @brief Configures the SysTick clock source. 193 | * @param SysTick_CLKSource: specifies the SysTick clock source. 194 | * This parameter can be one of the following values: 195 | * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source. 196 | * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source. 197 | * @retval None 198 | */ 199 | void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource) 200 | { 201 | /* Check the parameters */ 202 | assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource)); 203 | if (SysTick_CLKSource == SysTick_CLKSource_HCLK) 204 | { 205 | SysTick->CTRL |= SysTick_CLKSource_HCLK; 206 | } 207 | else 208 | { 209 | SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8; 210 | } 211 | } 212 | 213 | /** 214 | * @} 215 | */ 216 | 217 | /** 218 | * @} 219 | */ 220 | 221 | /** 222 | * @} 223 | */ 224 | 225 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 226 | -------------------------------------------------------------------------------- /Libraries/stm_lib/src/stm32f10x_exti.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_exti.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file provides all the EXTI firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "stm32f10x_exti.h" 24 | 25 | /** @addtogroup STM32F10x_StdPeriph_Driver 26 | * @{ 27 | */ 28 | 29 | /** @defgroup EXTI 30 | * @brief EXTI driver modules 31 | * @{ 32 | */ 33 | 34 | /** @defgroup EXTI_Private_TypesDefinitions 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @} 40 | */ 41 | 42 | /** @defgroup EXTI_Private_Defines 43 | * @{ 44 | */ 45 | 46 | #define EXTI_LINENONE ((uint32_t)0x00000) /* No interrupt selected */ 47 | 48 | /** 49 | * @} 50 | */ 51 | 52 | /** @defgroup EXTI_Private_Macros 53 | * @{ 54 | */ 55 | 56 | /** 57 | * @} 58 | */ 59 | 60 | /** @defgroup EXTI_Private_Variables 61 | * @{ 62 | */ 63 | 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup EXTI_Private_FunctionPrototypes 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup EXTI_Private_Functions 77 | * @{ 78 | */ 79 | 80 | /** 81 | * @brief Deinitializes the EXTI peripheral registers to their default reset values. 82 | * @param None 83 | * @retval None 84 | */ 85 | void EXTI_DeInit(void) 86 | { 87 | EXTI->IMR = 0x00000000; 88 | EXTI->EMR = 0x00000000; 89 | EXTI->RTSR = 0x00000000; 90 | EXTI->FTSR = 0x00000000; 91 | EXTI->PR = 0x000FFFFF; 92 | } 93 | 94 | /** 95 | * @brief Initializes the EXTI peripheral according to the specified 96 | * parameters in the EXTI_InitStruct. 97 | * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure 98 | * that contains the configuration information for the EXTI peripheral. 99 | * @retval None 100 | */ 101 | void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct) 102 | { 103 | uint32_t tmp = 0; 104 | 105 | /* Check the parameters */ 106 | assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode)); 107 | assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger)); 108 | assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line)); 109 | assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd)); 110 | 111 | tmp = (uint32_t)EXTI_BASE; 112 | 113 | if (EXTI_InitStruct->EXTI_LineCmd != DISABLE) 114 | { 115 | /* Clear EXTI line configuration */ 116 | EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line; 117 | EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line; 118 | 119 | tmp += EXTI_InitStruct->EXTI_Mode; 120 | 121 | *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line; 122 | 123 | /* Clear Rising Falling edge configuration */ 124 | EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line; 125 | EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line; 126 | 127 | /* Select the trigger for the selected external interrupts */ 128 | if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling) 129 | { 130 | /* Rising Falling edge */ 131 | EXTI->RTSR |= EXTI_InitStruct->EXTI_Line; 132 | EXTI->FTSR |= EXTI_InitStruct->EXTI_Line; 133 | } 134 | else 135 | { 136 | tmp = (uint32_t)EXTI_BASE; 137 | tmp += EXTI_InitStruct->EXTI_Trigger; 138 | 139 | *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line; 140 | } 141 | } 142 | else 143 | { 144 | tmp += EXTI_InitStruct->EXTI_Mode; 145 | 146 | /* Disable the selected external lines */ 147 | *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line; 148 | } 149 | } 150 | 151 | /** 152 | * @brief Fills each EXTI_InitStruct member with its reset value. 153 | * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will 154 | * be initialized. 155 | * @retval None 156 | */ 157 | void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct) 158 | { 159 | EXTI_InitStruct->EXTI_Line = EXTI_LINENONE; 160 | EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt; 161 | EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling; 162 | EXTI_InitStruct->EXTI_LineCmd = DISABLE; 163 | } 164 | 165 | /** 166 | * @brief Generates a Software interrupt. 167 | * @param EXTI_Line: specifies the EXTI lines to be enabled or disabled. 168 | * This parameter can be any combination of EXTI_Linex where x can be (0..19). 169 | * @retval None 170 | */ 171 | void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line) 172 | { 173 | /* Check the parameters */ 174 | assert_param(IS_EXTI_LINE(EXTI_Line)); 175 | 176 | EXTI->SWIER |= EXTI_Line; 177 | } 178 | 179 | /** 180 | * @brief Checks whether the specified EXTI line flag is set or not. 181 | * @param EXTI_Line: specifies the EXTI line flag to check. 182 | * This parameter can be: 183 | * @arg EXTI_Linex: External interrupt line x where x(0..19) 184 | * @retval The new state of EXTI_Line (SET or RESET). 185 | */ 186 | FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line) 187 | { 188 | FlagStatus bitstatus = RESET; 189 | /* Check the parameters */ 190 | assert_param(IS_GET_EXTI_LINE(EXTI_Line)); 191 | 192 | if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET) 193 | { 194 | bitstatus = SET; 195 | } 196 | else 197 | { 198 | bitstatus = RESET; 199 | } 200 | return bitstatus; 201 | } 202 | 203 | /** 204 | * @brief Clears the EXTI's line pending flags. 205 | * @param EXTI_Line: specifies the EXTI lines flags to clear. 206 | * This parameter can be any combination of EXTI_Linex where x can be (0..19). 207 | * @retval None 208 | */ 209 | void EXTI_ClearFlag(uint32_t EXTI_Line) 210 | { 211 | /* Check the parameters */ 212 | assert_param(IS_EXTI_LINE(EXTI_Line)); 213 | 214 | EXTI->PR = EXTI_Line; 215 | } 216 | 217 | /** 218 | * @brief Checks whether the specified EXTI line is asserted or not. 219 | * @param EXTI_Line: specifies the EXTI line to check. 220 | * This parameter can be: 221 | * @arg EXTI_Linex: External interrupt line x where x(0..19) 222 | * @retval The new state of EXTI_Line (SET or RESET). 223 | */ 224 | ITStatus EXTI_GetITStatus(uint32_t EXTI_Line) 225 | { 226 | ITStatus bitstatus = RESET; 227 | uint32_t enablestatus = 0; 228 | /* Check the parameters */ 229 | assert_param(IS_GET_EXTI_LINE(EXTI_Line)); 230 | 231 | enablestatus = EXTI->IMR & EXTI_Line; 232 | if (((EXTI->PR & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET)) 233 | { 234 | bitstatus = SET; 235 | } 236 | else 237 | { 238 | bitstatus = RESET; 239 | } 240 | return bitstatus; 241 | } 242 | 243 | /** 244 | * @brief Clears the EXTI's line pending bits. 245 | * @param EXTI_Line: specifies the EXTI lines to clear. 246 | * This parameter can be any combination of EXTI_Linex where x can be (0..19). 247 | * @retval None 248 | */ 249 | void EXTI_ClearITPendingBit(uint32_t EXTI_Line) 250 | { 251 | /* Check the parameters */ 252 | assert_param(IS_EXTI_LINE(EXTI_Line)); 253 | 254 | EXTI->PR = EXTI_Line; 255 | } 256 | 257 | /** 258 | * @} 259 | */ 260 | 261 | /** 262 | * @} 263 | */ 264 | 265 | /** 266 | * @} 267 | */ 268 | 269 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 270 | -------------------------------------------------------------------------------- /Libraries/stm_lib/src/stm32f10x_flash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helimp/grbl_stm32/2b0da66044d5f8f1eedbd8b2afb913b48dcef4ad/Libraries/stm_lib/src/stm32f10x_flash.c -------------------------------------------------------------------------------- /Libraries/stm_lib/src/stm32f10x_usart.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helimp/grbl_stm32/2b0da66044d5f8f1eedbd8b2afb913b48dcef4ad/Libraries/stm_lib/src/stm32f10x_usart.c -------------------------------------------------------------------------------- /Libraries/stm_usb_fs_lib/inc/usb_def.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2010 STMicroelectronics ******************** 2 | * File Name : usb_def.h 3 | * Author : MCD Application Team 4 | * Version : V3.2.1 5 | * Date : 07/05/2010 6 | * Description : Definitions related to USB Core 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Define to prevent recursive inclusion -------------------------------------*/ 17 | #ifndef __USB_DEF_H 18 | #define __USB_DEF_H 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | /* Exported types ------------------------------------------------------------*/ 22 | typedef enum _RECIPIENT_TYPE 23 | { 24 | DEVICE_RECIPIENT, /* Recipient device */ 25 | INTERFACE_RECIPIENT, /* Recipient interface */ 26 | ENDPOINT_RECIPIENT, /* Recipient endpoint */ 27 | OTHER_RECIPIENT 28 | } RECIPIENT_TYPE; 29 | 30 | 31 | typedef enum _STANDARD_REQUESTS 32 | { 33 | GET_STATUS = 0, 34 | CLEAR_FEATURE, 35 | RESERVED1, 36 | SET_FEATURE, 37 | RESERVED2, 38 | SET_ADDRESS, 39 | GET_DESCRIPTOR, 40 | SET_DESCRIPTOR, 41 | GET_CONFIGURATION, 42 | SET_CONFIGURATION, 43 | GET_INTERFACE, 44 | SET_INTERFACE, 45 | TOTAL_sREQUEST, /* Total number of Standard request */ 46 | SYNCH_FRAME = 12 47 | } STANDARD_REQUESTS; 48 | 49 | /* Definition of "USBwValue" */ 50 | typedef enum _DESCRIPTOR_TYPE 51 | { 52 | DEVICE_DESCRIPTOR = 1, 53 | CONFIG_DESCRIPTOR, 54 | STRING_DESCRIPTOR, 55 | INTERFACE_DESCRIPTOR, 56 | ENDPOINT_DESCRIPTOR 57 | } DESCRIPTOR_TYPE; 58 | 59 | /* Feature selector of a SET_FEATURE or CLEAR_FEATURE */ 60 | typedef enum _FEATURE_SELECTOR 61 | { 62 | ENDPOINT_STALL, 63 | DEVICE_REMOTE_WAKEUP 64 | } FEATURE_SELECTOR; 65 | 66 | /* Exported constants --------------------------------------------------------*/ 67 | /* Definition of "USBbmRequestType" */ 68 | #define REQUEST_TYPE 0x60 /* Mask to get request type */ 69 | #define STANDARD_REQUEST 0x00 /* Standard request */ 70 | #define CLASS_REQUEST 0x20 /* Class request */ 71 | #define VENDOR_REQUEST 0x40 /* Vendor request */ 72 | 73 | #define RECIPIENT 0x1F /* Mask to get recipient */ 74 | 75 | /* Exported macro ------------------------------------------------------------*/ 76 | /* Exported functions ------------------------------------------------------- */ 77 | 78 | #endif /* __USB_DEF_H */ 79 | 80 | /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/ 81 | -------------------------------------------------------------------------------- /Libraries/stm_usb_fs_lib/inc/usb_init.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2010 STMicroelectronics ******************** 2 | * File Name : usb_init.h 3 | * Author : MCD Application Team 4 | * Version : V3.2.1 5 | * Date : 07/05/2010 6 | * Description : Initialization routines & global variables 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Define to prevent recursive inclusion -------------------------------------*/ 17 | #ifndef __USB_INIT_H 18 | #define __USB_INIT_H 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | /* Exported types ------------------------------------------------------------*/ 22 | /* Exported constants --------------------------------------------------------*/ 23 | /* Exported macro ------------------------------------------------------------*/ 24 | /* Exported functions ------------------------------------------------------- */ 25 | void USB_Init(void); 26 | 27 | /* External variables --------------------------------------------------------*/ 28 | /* The number of current endpoint, it will be used to specify an endpoint */ 29 | extern uint8_t EPindex; 30 | /* The number of current device, it is an index to the Device_Table */ 31 | /*extern uint8_t Device_no; */ 32 | /* Points to the DEVICE_INFO structure of current device */ 33 | /* The purpose of this register is to speed up the execution */ 34 | extern DEVICE_INFO* pInformation; 35 | /* Points to the DEVICE_PROP structure of current device */ 36 | /* The purpose of this register is to speed up the execution */ 37 | extern DEVICE_PROP* pProperty; 38 | /* Temporary save the state of Rx & Tx status. */ 39 | /* Whenever the Rx or Tx state is changed, its value is saved */ 40 | /* in this variable first and will be set to the EPRB or EPRA */ 41 | /* at the end of interrupt process */ 42 | extern USER_STANDARD_REQUESTS *pUser_Standard_Requests; 43 | 44 | extern uint16_t SaveState ; 45 | extern uint16_t wInterrupt_Mask; 46 | 47 | #endif /* __USB_INIT_H */ 48 | 49 | /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/ 50 | -------------------------------------------------------------------------------- /Libraries/stm_usb_fs_lib/inc/usb_int.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2010 STMicroelectronics ******************** 2 | * File Name : usb_int.h 3 | * Author : MCD Application Team 4 | * Version : V3.2.1 5 | * Date : 07/05/2010 6 | * Description : Endpoint CTR (Low and High) interrupt's service routines 7 | * prototypes 8 | ******************************************************************************** 9 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 10 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 11 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 12 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 13 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 14 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 15 | *******************************************************************************/ 16 | 17 | /* Define to prevent recursive inclusion -------------------------------------*/ 18 | #ifndef __USB_INT_H 19 | #define __USB_INT_H 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | /* Exported types ------------------------------------------------------------*/ 23 | /* Exported constants --------------------------------------------------------*/ 24 | /* Exported macro ------------------------------------------------------------*/ 25 | /* Exported functions ------------------------------------------------------- */ 26 | void CTR_LP(void); 27 | void CTR_HP(void); 28 | 29 | /* External variables --------------------------------------------------------*/ 30 | 31 | #endif /* __USB_INT_H */ 32 | 33 | /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/ 34 | -------------------------------------------------------------------------------- /Libraries/stm_usb_fs_lib/inc/usb_lib.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2010 STMicroelectronics ******************** 2 | * File Name : usb_lib.h 3 | * Author : MCD Application Team 4 | * Version : V3.2.1 5 | * Date : 07/05/2010 6 | * Description : USB library include files 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Define to prevent recursive inclusion -------------------------------------*/ 17 | #ifndef __USB_LIB_H 18 | #define __USB_LIB_H 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "stm32f10x.h" 22 | #include "usb_type.h" 23 | #include "usb_regs.h" 24 | #include "usb_def.h" 25 | #include "usb_core.h" 26 | #include "usb_init.h" 27 | #ifndef STM32F10X_CL 28 | #include "usb_mem.h" 29 | #include "usb_int.h" 30 | #endif /* STM32F10X_CL */ 31 | 32 | #include "usb_sil.h" 33 | 34 | #ifdef STM32F10X_CL 35 | #include "otgd_fs_cal.h" 36 | #include "otgd_fs_pcd.h" 37 | #include "otgd_fs_dev.h" 38 | #include "otgd_fs_int.h" 39 | #endif /* STM32F10X_CL */ 40 | 41 | 42 | /* Exported types ------------------------------------------------------------*/ 43 | /* Exported constants --------------------------------------------------------*/ 44 | /* Exported macro ------------------------------------------------------------*/ 45 | /* Exported functions ------------------------------------------------------- */ 46 | /* External variables --------------------------------------------------------*/ 47 | 48 | #endif /* __USB_LIB_H */ 49 | 50 | /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/ 51 | -------------------------------------------------------------------------------- /Libraries/stm_usb_fs_lib/inc/usb_mem.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2010 STMicroelectronics ******************** 2 | * File Name : usb_mem.h 3 | * Author : MCD Application Team 4 | * Version : V3.2.1 5 | * Date : 07/05/2010 6 | * Description : Utility prototypes functions for memory/PMA transfers 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Define to prevent recursive inclusion -------------------------------------*/ 17 | #ifndef __USB_MEM_H 18 | #define __USB_MEM_H 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | /* Exported types ------------------------------------------------------------*/ 22 | /* Exported constants --------------------------------------------------------*/ 23 | /* Exported macro ------------------------------------------------------------*/ 24 | /* Exported functions ------------------------------------------------------- */ 25 | void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); 26 | void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); 27 | 28 | /* External variables --------------------------------------------------------*/ 29 | 30 | #endif /*__USB_MEM_H*/ 31 | 32 | /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/ 33 | -------------------------------------------------------------------------------- /Libraries/stm_usb_fs_lib/inc/usb_sil.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2010 STMicroelectronics ******************** 2 | * File Name : usb_sil.h 3 | * Author : MCD Application Team 4 | * Version : V3.2.1 5 | * Date : 07/05/2010 6 | * Description : Simplified Interface Layer function prototypes. 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Define to prevent recursive inclusion -------------------------------------*/ 17 | #ifndef __USB_SIL_H 18 | #define __USB_SIL_H 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | /* Exported types ------------------------------------------------------------*/ 22 | /* Exported constants --------------------------------------------------------*/ 23 | /* Exported macro ------------------------------------------------------------*/ 24 | /* Exported functions ------------------------------------------------------- */ 25 | 26 | uint32_t USB_SIL_Init(void); 27 | uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize); 28 | uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer); 29 | 30 | /* External variables --------------------------------------------------------*/ 31 | 32 | #endif /* __USB_SIL_H */ 33 | 34 | /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/ 35 | -------------------------------------------------------------------------------- /Libraries/stm_usb_fs_lib/inc/usb_type.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2010 STMicroelectronics ******************** 2 | * File Name : usb_type.h 3 | * Author : MCD Application Team 4 | * Version : V3.2.1 5 | * Date : 07/05/2010 6 | * Description : Type definitions used by the USB Library 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Define to prevent recursive inclusion -------------------------------------*/ 17 | #ifndef __USB_TYPE_H 18 | #define __USB_TYPE_H 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "usb_conf.h" 22 | 23 | /* Exported types ------------------------------------------------------------*/ 24 | /* Exported constants --------------------------------------------------------*/ 25 | #ifndef NULL 26 | #define NULL ((void *)0) 27 | #endif 28 | 29 | typedef signed long s32; 30 | typedef signed short s16; 31 | typedef signed char s8; 32 | 33 | typedef volatile signed long vs32; 34 | typedef volatile signed short vs16; 35 | typedef volatile signed char vs8; 36 | 37 | typedef unsigned long u32; 38 | typedef unsigned short u16; 39 | typedef unsigned char u8; 40 | 41 | typedef unsigned long const uc32; /* Read Only */ 42 | typedef unsigned short const uc16; /* Read Only */ 43 | typedef unsigned char const uc8; /* Read Only */ 44 | 45 | typedef volatile unsigned long vu32; 46 | typedef volatile unsigned short vu16; 47 | typedef volatile unsigned char vu8; 48 | 49 | typedef volatile unsigned long const vuc32; /* Read Only */ 50 | typedef volatile unsigned short const vuc16; /* Read Only */ 51 | typedef volatile unsigned char const vuc8; /* Read Only */ 52 | 53 | #define FALSE 0 54 | #define TRUE 1 55 | typedef int bool; 56 | 57 | #ifndef __STM32F10x_H 58 | typedef enum { RESET = 0, SET = !RESET } FlagStatus, ITStatus; 59 | 60 | typedef enum { DISABLE = 0, ENABLE = !DISABLE} FunctionalState; 61 | 62 | typedef enum { ERROR = 0, SUCCESS = !ERROR} ErrorStatus; 63 | #endif 64 | /* Exported macro ------------------------------------------------------------*/ 65 | /* Exported functions ------------------------------------------------------- */ 66 | /* External variables --------------------------------------------------------*/ 67 | 68 | #endif /* __USB_TYPE_H */ 69 | 70 | /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/ 71 | -------------------------------------------------------------------------------- /Libraries/stm_usb_fs_lib/src/usb_init.c: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2010 STMicroelectronics ******************** 2 | * File Name : usb_init.c 3 | * Author : MCD Application Team 4 | * Version : V3.2.1 5 | * Date : 07/05/2010 6 | * Description : Initialization routines & global variables 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Includes ------------------------------------------------------------------*/ 17 | #include "usb_lib.h" 18 | 19 | /* Private typedef -----------------------------------------------------------*/ 20 | /* Private define ------------------------------------------------------------*/ 21 | /* Private macro -------------------------------------------------------------*/ 22 | /* Private variables ---------------------------------------------------------*/ 23 | /* The number of current endpoint, it will be used to specify an endpoint */ 24 | uint8_t EPindex; 25 | /* The number of current device, it is an index to the Device_Table */ 26 | /* uint8_t Device_no; */ 27 | /* Points to the DEVICE_INFO structure of current device */ 28 | /* The purpose of this register is to speed up the execution */ 29 | DEVICE_INFO *pInformation; 30 | /* Points to the DEVICE_PROP structure of current device */ 31 | /* The purpose of this register is to speed up the execution */ 32 | DEVICE_PROP *pProperty; 33 | /* Temporary save the state of Rx & Tx status. */ 34 | /* Whenever the Rx or Tx state is changed, its value is saved */ 35 | /* in this variable first and will be set to the EPRB or EPRA */ 36 | /* at the end of interrupt process */ 37 | uint16_t SaveState ; 38 | uint16_t wInterrupt_Mask; 39 | DEVICE_INFO Device_Info; 40 | USER_STANDARD_REQUESTS *pUser_Standard_Requests; 41 | 42 | /* Extern variables ----------------------------------------------------------*/ 43 | /* Private function prototypes -----------------------------------------------*/ 44 | /* Private functions ---------------------------------------------------------*/ 45 | 46 | /******************************************************************************* 47 | * Function Name : USB_Init 48 | * Description : USB system initialization 49 | * Input : None. 50 | * Output : None. 51 | * Return : None. 52 | *******************************************************************************/ 53 | void USB_Init(void) 54 | { 55 | pInformation = &Device_Info; 56 | pInformation->ControlState = 2; 57 | pProperty = &Device_Property; 58 | pUser_Standard_Requests = &User_Standard_Requests; 59 | /* Initialize devices one by one */ 60 | pProperty->Init(); 61 | } 62 | 63 | /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/ 64 | -------------------------------------------------------------------------------- /Libraries/stm_usb_fs_lib/src/usb_int.c: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2010 STMicroelectronics ******************** 2 | * File Name : usb_int.c 3 | * Author : MCD Application Team 4 | * Version : V3.2.1 5 | * Date : 07/05/2010 6 | * Description : Endpoint CTR (Low and High) interrupt's service routines 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | #ifndef STM32F10X_CL 16 | 17 | /* Includes ------------------------------------------------------------------*/ 18 | #include "usb_lib.h" 19 | 20 | /* Private typedef -----------------------------------------------------------*/ 21 | /* Private define ------------------------------------------------------------*/ 22 | /* Private macro -------------------------------------------------------------*/ 23 | /* Private variables ---------------------------------------------------------*/ 24 | __IO uint16_t SaveRState; 25 | __IO uint16_t SaveTState; 26 | 27 | /* Extern variables ----------------------------------------------------------*/ 28 | extern void (*pEpInt_IN[7])(void); /* Handles IN interrupts */ 29 | extern void (*pEpInt_OUT[7])(void); /* Handles OUT interrupts */ 30 | 31 | /* Private function prototypes -----------------------------------------------*/ 32 | /* Private functions ---------------------------------------------------------*/ 33 | 34 | /******************************************************************************* 35 | * Function Name : CTR_LP. 36 | * Description : Low priority Endpoint Correct Transfer interrupt's service 37 | * routine. 38 | * Input : None. 39 | * Output : None. 40 | * Return : None. 41 | *******************************************************************************/ 42 | void CTR_LP(void) 43 | { 44 | __IO uint16_t wEPVal = 0; 45 | /* stay in loop while pending ints */ 46 | while (((wIstr = _GetISTR()) & ISTR_CTR) != 0) 47 | { 48 | /* extract highest priority endpoint number */ 49 | EPindex = (uint8_t)(wIstr & ISTR_EP_ID); 50 | if (EPindex == 0) 51 | { 52 | /* Decode and service control endpoint interrupt */ 53 | /* calling related service routine */ 54 | /* (Setup0_Process, In0_Process, Out0_Process) */ 55 | 56 | /* save RX & TX status */ 57 | /* and set both to NAK */ 58 | 59 | 60 | SaveRState = _GetENDPOINT(ENDP0); 61 | SaveTState = SaveRState & EPTX_STAT; 62 | SaveRState &= EPRX_STAT; 63 | 64 | _SetEPRxTxStatus(ENDP0,EP_RX_NAK,EP_TX_NAK); 65 | 66 | /* DIR bit = origin of the interrupt */ 67 | 68 | if ((wIstr & ISTR_DIR) == 0) 69 | { 70 | /* DIR = 0 */ 71 | 72 | /* DIR = 0 => IN int */ 73 | /* DIR = 0 implies that (EP_CTR_TX = 1) always */ 74 | 75 | 76 | _ClearEP_CTR_TX(ENDP0); 77 | In0_Process(); 78 | 79 | /* before terminate set Tx & Rx status */ 80 | 81 | _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState); 82 | return; 83 | } 84 | else 85 | { 86 | /* DIR = 1 */ 87 | 88 | /* DIR = 1 & CTR_RX => SETUP or OUT int */ 89 | /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */ 90 | 91 | wEPVal = _GetENDPOINT(ENDP0); 92 | 93 | if ((wEPVal &EP_SETUP) != 0) 94 | { 95 | _ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */ 96 | Setup0_Process(); 97 | /* before terminate set Tx & Rx status */ 98 | 99 | _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState); 100 | return; 101 | } 102 | 103 | else if ((wEPVal & EP_CTR_RX) != 0) 104 | { 105 | _ClearEP_CTR_RX(ENDP0); 106 | Out0_Process(); 107 | /* before terminate set Tx & Rx status */ 108 | 109 | _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState); 110 | return; 111 | } 112 | } 113 | }/* if(EPindex == 0) */ 114 | else 115 | { 116 | /* Decode and service non control endpoints interrupt */ 117 | 118 | /* process related endpoint register */ 119 | wEPVal = _GetENDPOINT(EPindex); 120 | if ((wEPVal & EP_CTR_RX) != 0) 121 | { 122 | /* clear int flag */ 123 | _ClearEP_CTR_RX(EPindex); 124 | 125 | /* call OUT service function */ 126 | (*pEpInt_OUT[EPindex-1])(); 127 | 128 | } /* if((wEPVal & EP_CTR_RX) */ 129 | 130 | if ((wEPVal & EP_CTR_TX) != 0) 131 | { 132 | /* clear int flag */ 133 | _ClearEP_CTR_TX(EPindex); 134 | 135 | /* call IN service function */ 136 | (*pEpInt_IN[EPindex-1])(); 137 | } /* if((wEPVal & EP_CTR_TX) != 0) */ 138 | 139 | }/* if(EPindex == 0) else */ 140 | 141 | }/* while(...) */ 142 | } 143 | 144 | /******************************************************************************* 145 | * Function Name : CTR_HP. 146 | * Description : High Priority Endpoint Correct Transfer interrupt's service 147 | * routine. 148 | * Input : None. 149 | * Output : None. 150 | * Return : None. 151 | *******************************************************************************/ 152 | void CTR_HP(void) 153 | { 154 | uint32_t wEPVal = 0; 155 | 156 | while (((wIstr = _GetISTR()) & ISTR_CTR) != 0) 157 | { 158 | _SetISTR((uint16_t)CLR_CTR); /* clear CTR flag */ 159 | /* extract highest priority endpoint number */ 160 | EPindex = (uint8_t)(wIstr & ISTR_EP_ID); 161 | /* process related endpoint register */ 162 | wEPVal = _GetENDPOINT(EPindex); 163 | if ((wEPVal & EP_CTR_RX) != 0) 164 | { 165 | /* clear int flag */ 166 | _ClearEP_CTR_RX(EPindex); 167 | 168 | /* call OUT service function */ 169 | (*pEpInt_OUT[EPindex-1])(); 170 | 171 | } /* if((wEPVal & EP_CTR_RX) */ 172 | else if ((wEPVal & EP_CTR_TX) != 0) 173 | { 174 | /* clear int flag */ 175 | _ClearEP_CTR_TX(EPindex); 176 | 177 | /* call IN service function */ 178 | (*pEpInt_IN[EPindex-1])(); 179 | 180 | 181 | } /* if((wEPVal & EP_CTR_TX) != 0) */ 182 | 183 | }/* while(...) */ 184 | } 185 | 186 | #endif /* STM32F10X_CL */ 187 | 188 | /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/ 189 | -------------------------------------------------------------------------------- /Libraries/stm_usb_fs_lib/src/usb_mem.c: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2010 STMicroelectronics ******************** 2 | * File Name : usb_mem.c 3 | * Author : MCD Application Team 4 | * Version : V3.2.1 5 | * Date : 07/05/2010 6 | * Description : Utility functions for memory transfers to/from PMA 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | #ifndef STM32F10X_CL 16 | 17 | /* Includes ------------------------------------------------------------------*/ 18 | #include "usb_lib.h" 19 | 20 | /* Private typedef -----------------------------------------------------------*/ 21 | /* Private define ------------------------------------------------------------*/ 22 | /* Private macro -------------------------------------------------------------*/ 23 | /* Private variables ---------------------------------------------------------*/ 24 | /* Extern variables ----------------------------------------------------------*/ 25 | /* Private function prototypes -----------------------------------------------*/ 26 | /* Private functions ---------------------------------------------------------*/ 27 | /******************************************************************************* 28 | * Function Name : UserToPMABufferCopy 29 | * Description : Copy a buffer from user memory area to packet memory area (PMA) 30 | * Input : - pbUsrBuf: pointer to user memory area. 31 | * - wPMABufAddr: address into PMA. 32 | * - wNBytes: no. of bytes to be copied. 33 | * Output : None. 34 | * Return : None . 35 | *******************************************************************************/ 36 | void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) 37 | { 38 | uint32_t n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */ 39 | uint32_t i, temp1; 40 | uint16_t *pdwVal; 41 | pdwVal = (uint16_t *)(wPMABufAddr * 2 + PMAAddr); 42 | for (i = n; i != 0; i--) 43 | { 44 | temp1 = (uint16_t) * pbUsrBuf; 45 | pbUsrBuf++; 46 | *pdwVal++ = temp1 | (uint16_t) * pbUsrBuf << 8; 47 | pdwVal++; 48 | pbUsrBuf++; 49 | } 50 | } 51 | /******************************************************************************* 52 | * Function Name : PMAToUserBufferCopy 53 | * Description : Copy a buffer from user memory area to packet memory area (PMA) 54 | * Input : - pbUsrBuf = pointer to user memory area. 55 | * - wPMABufAddr = address into PMA. 56 | * - wNBytes = no. of bytes to be copied. 57 | * Output : None. 58 | * Return : None. 59 | *******************************************************************************/ 60 | void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) 61 | { 62 | uint32_t n = (wNBytes + 1) >> 1;/* /2*/ 63 | uint32_t i; 64 | uint32_t *pdwVal; 65 | pdwVal = (uint32_t *)(wPMABufAddr * 2 + PMAAddr); 66 | for (i = n; i != 0; i--) 67 | { 68 | *(uint16_t*)pbUsrBuf++ = *pdwVal++; 69 | pbUsrBuf++; 70 | } 71 | } 72 | 73 | #endif /* STM32F10X_CL */ 74 | /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/ 75 | -------------------------------------------------------------------------------- /Libraries/stm_usb_fs_lib/src/usb_sil.c: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2010 STMicroelectronics ******************** 2 | * File Name : usb_sil.c 3 | * Author : MCD Application Team 4 | * Version : V3.2.1 5 | * Date : 07/05/2010 6 | * Description : Simplified Interface Layer for Global Initialization and 7 | * Endpoint Rea/Write operations. 8 | ******************************************************************************** 9 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 10 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 11 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 12 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 13 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 14 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 15 | *******************************************************************************/ 16 | 17 | /* Includes ------------------------------------------------------------------*/ 18 | #include "usb_lib.h" 19 | 20 | /* Private typedef -----------------------------------------------------------*/ 21 | /* Private define ------------------------------------------------------------*/ 22 | /* Private macro -------------------------------------------------------------*/ 23 | /* Private variables ---------------------------------------------------------*/ 24 | /* Extern variables ----------------------------------------------------------*/ 25 | /* Private function prototypes -----------------------------------------------*/ 26 | /* Private functions ---------------------------------------------------------*/ 27 | 28 | /******************************************************************************* 29 | * Function Name : USB_SIL_Init 30 | * Description : Initialize the USB Device IP and the Endpoint 0. 31 | * Input : None. 32 | * Output : None. 33 | * Return : Status. 34 | *******************************************************************************/ 35 | uint32_t USB_SIL_Init(void) 36 | { 37 | #ifndef STM32F10X_CL 38 | 39 | /* USB interrupts initialization */ 40 | /* clear pending interrupts */ 41 | _SetISTR(0); 42 | wInterrupt_Mask = IMR_MSK; 43 | /* set interrupts mask */ 44 | _SetCNTR(wInterrupt_Mask); 45 | 46 | #else 47 | 48 | /* Perform OTG Device initialization procedure (including EP0 init) */ 49 | OTG_DEV_Init(); 50 | 51 | #endif /* STM32F10X_CL */ 52 | 53 | return 0; 54 | } 55 | 56 | /******************************************************************************* 57 | * Function Name : USB_SIL_Write 58 | * Description : Write a buffer of data to a selected endpoint. 59 | * Input : - bEpAddr: The address of the non control endpoint. 60 | * - pBufferPointer: The pointer to the buffer of data to be written 61 | * to the endpoint. 62 | * - wBufferSize: Number of data to be written (in bytes). 63 | * Output : None. 64 | * Return : Status. 65 | *******************************************************************************/ 66 | uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize) 67 | { 68 | #ifndef STM32F10X_CL 69 | 70 | /* Use the memory interface function to write to the selected endpoint */ 71 | UserToPMABufferCopy(pBufferPointer, GetEPTxAddr(bEpAddr & 0x7F), wBufferSize); 72 | 73 | /* Update the data length in the control register */ 74 | SetEPTxCount((bEpAddr & 0x7F), wBufferSize); 75 | 76 | #else 77 | 78 | /* Use the PCD interface layer function to write to the selected endpoint */ 79 | PCD_EP_Write (bEpAddr, pBufferPointer, wBufferSize); 80 | 81 | #endif /* STM32F10X_CL */ 82 | 83 | return 0; 84 | } 85 | 86 | /******************************************************************************* 87 | * Function Name : USB_SIL_Read 88 | * Description : Write a buffer of data to a selected endpoint. 89 | * Input : - bEpAddr: The address of the non control endpoint. 90 | * - pBufferPointer: The pointer to which will be saved the 91 | * received data buffer. 92 | * Output : None. 93 | * Return : Number of received data (in Bytes). 94 | *******************************************************************************/ 95 | uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer) 96 | { 97 | uint32_t DataLength = 0; 98 | 99 | #ifndef STM32F10X_CL 100 | 101 | /* Get the number of received data on the selected Endpoint */ 102 | DataLength = GetEPRxCount(bEpAddr & 0x7F); 103 | 104 | /* Use the memory interface function to write to the selected endpoint */ 105 | PMAToUserBufferCopy(pBufferPointer, GetEPRxAddr(bEpAddr & 0x7F), DataLength); 106 | 107 | #else 108 | 109 | USB_OTG_EP *ep; 110 | 111 | /* Get the structure pointer of the selected Endpoint */ 112 | ep = PCD_GetOutEP(bEpAddr); 113 | 114 | /* Get the number of received data */ 115 | DataLength = ep->xfer_len; 116 | 117 | /* Use the PCD interface layer function to read the selected endpoint */ 118 | PCD_EP_Read (bEpAddr, pBufferPointer, DataLength); 119 | 120 | #endif /* STM32F10X_CL */ 121 | 122 | /* Return the number of received data */ 123 | return DataLength; 124 | } 125 | 126 | /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/ 127 | -------------------------------------------------------------------------------- /Libraries/usb/CVS/Entries: -------------------------------------------------------------------------------- 1 | /usb_pwr.h/1.1/Sat Mar 19 10:14:24 2011// 2 | /usb_prop.h/1.1/Sat Mar 19 10:14:24 2011// 3 | /usb_istr.h/1.1/Sat Mar 19 10:14:24 2011// 4 | /usb_desc.h/1.1/Fri Mar 30 21:03:34 2012// 5 | /usb_conf.h/1.1/Sat Mar 19 10:14:24 2011// 6 | /stm32f10x_it.h/1.1/Sat Mar 19 10:14:24 2011// 7 | /platform_config.h/1.1/Tue Mar 1 04:44:10 2016// 8 | /hw_config.h/1.1/Wed Jun 1 01:57:17 2016// 9 | /usb_pwr.c/1.1/Sat Mar 19 10:14:26 2011// 10 | /usb_desc.c/1.1/Wed Jun 1 01:53:39 2016// 11 | /hw_config.c/1.1/Sat Nov 19 06:07:40 2016// 12 | /usb_istr.c/1.1/Wed Nov 16 07:23:56 2016// 13 | /usb_endp.c/1.3/Mon Nov 21 06:19:40 2016// 14 | /usb_prop.c/1.1/Mon Nov 21 07:52:24 2016// 15 | D 16 | -------------------------------------------------------------------------------- /Libraries/usb/CVS/Entries.Extra: -------------------------------------------------------------------------------- 1 | /usb_pwr.h///1468199674/ 2 | /usb_prop.h///1468199675/ 3 | /usb_istr.h///1468199675/ 4 | /usb_desc.h///1468199675/ 5 | /usb_conf.h///1468199675/ 6 | /stm32f10x_it.h///1468199675/ 7 | /platform_config.h///1468199675/ 8 | /hw_config.h///1468199675/ 9 | /usb_pwr.c///1468199675/ 10 | /usb_desc.c///1468199675/ 11 | /hw_config.c///1468199675/ 12 | /usb_istr.c///1468199675/ 13 | /usb_endp.c///1471019589/ 14 | /usb_prop.c///1468199675/ 15 | -------------------------------------------------------------------------------- /Libraries/usb/CVS/Entries.Extra.Old: -------------------------------------------------------------------------------- 1 | /usb_pwr.h///1468199674/ 2 | /usb_prop.h///1468199675/ 3 | /usb_istr.h///1468199675/ 4 | /usb_desc.h///1468199675/ 5 | /usb_conf.h///1468199675/ 6 | /stm32f10x_it.h///1468199675/ 7 | /platform_config.h///1468199675/ 8 | /hw_config.h///1468199675/ 9 | /usb_pwr.c///1468199675/ 10 | /usb_prop.c///1468199675/ 11 | /usb_desc.c///1468199675/ 12 | /hw_config.c///1468199675/ 13 | /usb_istr.c///1468199675/ 14 | /usb_endp.c///1471019589/ 15 | -------------------------------------------------------------------------------- /Libraries/usb/CVS/Entries.Old: -------------------------------------------------------------------------------- 1 | /usb_pwr.h/1.1/Sat Mar 19 10:14:24 2011// 2 | /usb_prop.h/1.1/Sat Mar 19 10:14:24 2011// 3 | /usb_istr.h/1.1/Sat Mar 19 10:14:24 2011// 4 | /usb_desc.h/1.1/Fri Mar 30 21:03:34 2012// 5 | /usb_conf.h/1.1/Sat Mar 19 10:14:24 2011// 6 | /stm32f10x_it.h/1.1/Sat Mar 19 10:14:24 2011// 7 | /platform_config.h/1.1/Tue Mar 1 04:44:10 2016// 8 | /hw_config.h/1.1/Wed Jun 1 01:57:17 2016// 9 | /usb_pwr.c/1.1/Sat Mar 19 10:14:26 2011// 10 | /usb_prop.c/1.1/Sat Mar 31 16:25:44 2012// 11 | /usb_desc.c/1.1/Wed Jun 1 01:53:39 2016// 12 | /hw_config.c/1.1/Sat Nov 19 06:07:40 2016// 13 | /usb_istr.c/1.1/Wed Nov 16 07:23:56 2016// 14 | /usb_endp.c/1.3/Mon Nov 21 06:19:40 2016// 15 | D 16 | -------------------------------------------------------------------------------- /Libraries/usb/CVS/Repository: -------------------------------------------------------------------------------- 1 | Code/grbl1.0d/stm32grbl/usb 2 | -------------------------------------------------------------------------------- /Libraries/usb/CVS/Root: -------------------------------------------------------------------------------- 1 | :local:E:/CVSRep 2 | -------------------------------------------------------------------------------- /Libraries/usb/hw_config.c: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2011 STMicroelectronics ******************** 2 | * File Name : hw_config.c 3 | * Author : MCD Application Team 4 | * Version : V3.3.0 5 | * Date : 21-March-2011 6 | * Description : Hardware Configuration & Setup 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | #include "stm32f10x_it.h" 17 | 18 | #include "usb_lib.h" 19 | #include "usb_prop.h" 20 | #include "usb_desc.h" 21 | #include "hw_config.h" 22 | #include "platform_config.h" 23 | #include "usb_pwr.h" 24 | #include "stm32f10x_rcc.h" 25 | #include "misc.h" 26 | 27 | ErrorStatus HSEStartUpStatus; 28 | 29 | static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len); 30 | 31 | /******************************************************************************* 32 | * Description : Configures Main system clocks & power 33 | *******************************************************************************/ 34 | void Set_System(void) 35 | { 36 | } 37 | 38 | /******************************************************************************* 39 | * Description : Configures USB Clock input (48MHz) 40 | *******************************************************************************/ 41 | void Set_USBClock(void) 42 | { 43 | /* Select USBCLK source */ 44 | RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5); 45 | 46 | /* Enable the USB clock */ 47 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE); 48 | } 49 | 50 | /******************************************************************************* 51 | * Description : Power-off system clocks and power while entering suspend mode 52 | *******************************************************************************/ 53 | void Enter_LowPowerMode(void) 54 | { 55 | /* Set the device state to suspend */ 56 | bDeviceState = SUSPENDED; 57 | } 58 | 59 | /******************************************************************************* 60 | * Description : Restores system clocks and power while exiting suspend mode 61 | *******************************************************************************/ 62 | void Leave_LowPowerMode(void) 63 | { 64 | DEVICE_INFO *pInfo = &Device_Info; 65 | 66 | /* Set the device state to the correct state */ 67 | if (pInfo->Current_Configuration != 0) 68 | { 69 | /* Device configured */ 70 | bDeviceState = CONFIGURED; 71 | } 72 | else 73 | { 74 | bDeviceState = ATTACHED; 75 | } 76 | } 77 | 78 | /******************************************************************************* 79 | * Description : Configures the USB interrupts 80 | *******************************************************************************/ 81 | void USB_Interrupts_Config(void) 82 | { 83 | NVIC_InitTypeDef NVIC_InitStructure; 84 | 85 | NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); 86 | 87 | NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn; 88 | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; 89 | NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; 90 | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 91 | NVIC_Init(&NVIC_InitStructure); 92 | } 93 | 94 | /******************************************************************************* 95 | * Description : Software Connection/Disconnection of USB Cable 96 | *******************************************************************************/ 97 | void USB_Cable_Config(FunctionalState NewState) 98 | { 99 | } 100 | 101 | /******************************************************************************* 102 | * Description : Create the serial number string descriptor. 103 | *******************************************************************************/ 104 | void Get_SerialNum(void) 105 | { 106 | uint32_t Device_Serial0, Device_Serial1, Device_Serial2; 107 | 108 | Device_Serial0 = *(__IO uint32_t*) (0x1FFFF7E8); 109 | Device_Serial1 = *(__IO uint32_t*) (0x1FFFF7EC); 110 | Device_Serial2 = *(__IO uint32_t*) (0x1FFFF7F0); 111 | 112 | Device_Serial0 += Device_Serial2; 113 | 114 | if (Device_Serial0 != 0) 115 | { 116 | IntToUnicode(Device_Serial0, &Virtual_Com_Port_StringSerial[2], 8); 117 | IntToUnicode(Device_Serial1, &Virtual_Com_Port_StringSerial[18], 4); 118 | } 119 | } 120 | 121 | /******************************************************************************* 122 | * Description : Convert Hex 32Bits value into char. 123 | *******************************************************************************/ 124 | static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len) 125 | { 126 | uint8_t idx = 0; 127 | 128 | for (idx = 0; idx < len; idx++) 129 | { 130 | if (((value >> 28)) < 0xA) 131 | { 132 | pbuf[2 * idx] = (value >> 28) + '0'; 133 | } 134 | else 135 | { 136 | pbuf[2 * idx] = (value >> 28) + 'A' - 10; 137 | } 138 | 139 | value = value << 4; 140 | 141 | pbuf[2 * idx + 1] = 0; 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /Libraries/usb/hw_config.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2011 STMicroelectronics ******************** 2 | * File Name : hw_config.h 3 | * Author : MCD Application Team 4 | * Version : V3.3.0 5 | * Date : 21-March-2011 6 | * Description : Hardware Configuration & Setup 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Define to prevent recursive inclusion -------------------------------------*/ 17 | #ifndef __HW_CONFIG_H 18 | #define __HW_CONFIG_H 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "usb_type.h" 22 | 23 | /* Exported types ------------------------------------------------------------*/ 24 | /* Exported constants --------------------------------------------------------*/ 25 | /* Exported macro ------------------------------------------------------------*/ 26 | /* Exported define -----------------------------------------------------------*/ 27 | #define MASS_MEMORY_START 0x04002000 28 | #define BULK_MAX_PACKET_SIZE 0x00000040 29 | #define LED_ON 0xF0 30 | #define LED_OFF 0xFF 31 | 32 | #define USART_RX_DATA_SIZE (64) 33 | /* Exported functions ------------------------------------------------------- */ 34 | void Set_System(void); 35 | void Set_USBClock(void); 36 | void Enter_LowPowerMode(void); 37 | void Leave_LowPowerMode(void); 38 | void USB_Interrupts_Config(void); 39 | void USB_Cable_Config(FunctionalState NewState); 40 | void USART_Config_Default(void); 41 | bool USART_Config(void); 42 | void OnUsbDataRx(uint8_t* data_buffer, uint8_t Nb_bytes); 43 | void Get_SerialNum(void); 44 | 45 | /* External variables --------------------------------------------------------*/ 46 | 47 | #endif /*__HW_CONFIG_H*/ 48 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 49 | -------------------------------------------------------------------------------- /Libraries/usb/platform_config.h: -------------------------------------------------------------------------------- 1 | #ifndef __PLATFORM_CONFIG_H 2 | #define __PLATFORM_CONFIG_H 3 | 4 | #include "stm32f10x.h" 5 | 6 | #endif /* __PLATFORM_CONFIG_H */ 7 | 8 | -------------------------------------------------------------------------------- /Libraries/usb/stm32f10x_it.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2011 STMicroelectronics ******************** 2 | * File Name : stm32f10x_it.h 3 | * Author : MCD Application Team 4 | * Version : V3.3.0 5 | * Date : 21-March-2011 6 | * Description : This file contains the headers of the interrupt handlers. 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Define to prevent recursive inclusion -------------------------------------*/ 17 | #ifndef __STM32F10x_IT_H 18 | #define __STM32F10x_IT_H 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "stm32f10x.h" 22 | 23 | /* Exported types ------------------------------------------------------------*/ 24 | /* Exported constants --------------------------------------------------------*/ 25 | /* Exported macro ------------------------------------------------------------*/ 26 | /* Exported functions ------------------------------------------------------- */ 27 | 28 | void NMI_Handler(void); 29 | void HardFault_Handler(void); 30 | void MemManage_Handler(void); 31 | void BusFault_Handler(void); 32 | void UsageFault_Handler(void); 33 | void SVC_Handler(void); 34 | void DebugMon_Handler(void); 35 | void PendSV_Handler(void); 36 | void SysTick_Handler(void); 37 | 38 | #ifndef STM32F10X_CL 39 | void USB_LP_CAN1_RX0_IRQHandler(void); 40 | #endif /* STM32F10X_CL */ 41 | 42 | #if defined (USE_STM3210B_EVAL) || defined (USE_STM3210E_EVAL) 43 | void USART1_IRQHandler(void); 44 | #endif /* USE_STM3210B_EVAL or USE_STM3210E_EVAL */ 45 | 46 | #ifdef USE_STM3210C_EVAL 47 | void USART2_IRQHandler(void); 48 | #endif /* USE_STM3210C_EVAL */ 49 | 50 | #ifdef STM32F10X_CL 51 | void OTG_FS_IRQHandler(void); 52 | #endif /* STM32F10X_CL */ 53 | 54 | #endif /* __STM32F10x_IT_H */ 55 | 56 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 57 | -------------------------------------------------------------------------------- /Libraries/usb/usb_desc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_desc.c 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 21-January-2013 7 | * @brief Descriptors for Virtual Com Port Demo 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "usb_lib.h" 31 | #include "usb_desc.h" 32 | 33 | /* USB Standard Device Descriptor */ 34 | const uint8_t Virtual_Com_Port_DeviceDescriptor[] = 35 | { 36 | 0x12, /* bLength */ 37 | USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */ 38 | 0x00, 39 | 0x02, /* bcdUSB = 2.00 */ 40 | 0x02, /* bDeviceClass: CDC */ 41 | 0x00, /* bDeviceSubClass */ 42 | 0x00, /* bDeviceProtocol */ 43 | 0x40, /* bMaxPacketSize0 */ 44 | 0x83, 45 | 0x04, /* idVendor = 0x0483 */ 46 | 0x40, 47 | 0x57, /* idProduct = 0x7540 */ 48 | 0x00, 49 | 0x02, /* bcdDevice = 2.00 */ 50 | 1, /* Index of string descriptor describing manufacturer */ 51 | 2, /* Index of string descriptor describing product */ 52 | 3, /* Index of string descriptor describing the device's serial number */ 53 | 0x01 /* bNumConfigurations */ 54 | }; 55 | 56 | const uint8_t Virtual_Com_Port_ConfigDescriptor[] = 57 | { 58 | /*Configuration Descriptor*/ 59 | 0x09, /* bLength: Configuration Descriptor size */ 60 | USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */ 61 | VIRTUAL_COM_PORT_SIZ_CONFIG_DESC, /* wTotalLength:no of returned bytes */ 62 | 0x00, 63 | 0x02, /* bNumInterfaces: 2 interface */ 64 | 0x01, /* bConfigurationValue: Configuration value */ 65 | 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ 66 | 0xC0, /* bmAttributes: self powered */ 67 | 0x32, /* MaxPower 0 mA */ 68 | /*Interface Descriptor*/ 69 | 0x09, /* bLength: Interface Descriptor size */ 70 | USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */ 71 | /* Interface descriptor type */ 72 | 0x00, /* bInterfaceNumber: Number of Interface */ 73 | 0x00, /* bAlternateSetting: Alternate setting */ 74 | 0x01, /* bNumEndpoints: One endpoints used */ 75 | 0x02, /* bInterfaceClass: Communication Interface Class */ 76 | 0x02, /* bInterfaceSubClass: Abstract Control Model */ 77 | 0x01, /* bInterfaceProtocol: Common AT commands */ 78 | 0x00, /* iInterface: */ 79 | /*Header Functional Descriptor*/ 80 | 0x05, /* bLength: Endpoint Descriptor size */ 81 | 0x24, /* bDescriptorType: CS_INTERFACE */ 82 | 0x00, /* bDescriptorSubtype: Header Func Desc */ 83 | 0x10, /* bcdCDC: spec release number */ 84 | 0x01, 85 | /*Call Management Functional Descriptor*/ 86 | 0x05, /* bFunctionLength */ 87 | 0x24, /* bDescriptorType: CS_INTERFACE */ 88 | 0x01, /* bDescriptorSubtype: Call Management Func Desc */ 89 | 0x00, /* bmCapabilities: D0+D1 */ 90 | 0x01, /* bDataInterface: 1 */ 91 | /*ACM Functional Descriptor*/ 92 | 0x04, /* bFunctionLength */ 93 | 0x24, /* bDescriptorType: CS_INTERFACE */ 94 | 0x02, /* bDescriptorSubtype: Abstract Control Management desc */ 95 | 0x02, /* bmCapabilities */ 96 | /*Union Functional Descriptor*/ 97 | 0x05, /* bFunctionLength */ 98 | 0x24, /* bDescriptorType: CS_INTERFACE */ 99 | 0x06, /* bDescriptorSubtype: Union func desc */ 100 | 0x00, /* bMasterInterface: Communication class interface */ 101 | 0x01, /* bSlaveInterface0: Data Class Interface */ 102 | /*Endpoint 2 Descriptor*/ 103 | 0x07, /* bLength: Endpoint Descriptor size */ 104 | USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ 105 | 0x82, /* bEndpointAddress: (IN2) */ 106 | 0x03, /* bmAttributes: Interrupt */ 107 | VIRTUAL_COM_PORT_INT_SIZE, /* wMaxPacketSize: */ 108 | 0x00, 109 | 0xFF, /* bInterval: */ 110 | /*Data class interface descriptor*/ 111 | 0x09, /* bLength: Endpoint Descriptor size */ 112 | USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: */ 113 | 0x01, /* bInterfaceNumber: Number of Interface */ 114 | 0x00, /* bAlternateSetting: Alternate setting */ 115 | 0x02, /* bNumEndpoints: Two endpoints used */ 116 | 0x0A, /* bInterfaceClass: CDC */ 117 | 0x00, /* bInterfaceSubClass: */ 118 | 0x00, /* bInterfaceProtocol: */ 119 | 0x00, /* iInterface: */ 120 | /*Endpoint 3 Descriptor*/ 121 | 0x07, /* bLength: Endpoint Descriptor size */ 122 | USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ 123 | 0x03, /* bEndpointAddress: (OUT3) */ 124 | 0x02, /* bmAttributes: Bulk */ 125 | VIRTUAL_COM_PORT_DATA_SIZE, /* wMaxPacketSize: */ 126 | 0x00, 127 | 0x00, /* bInterval: ignore for Bulk transfer */ 128 | /*Endpoint 1 Descriptor*/ 129 | 0x07, /* bLength: Endpoint Descriptor size */ 130 | USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ 131 | 0x81, /* bEndpointAddress: (IN1) */ 132 | 0x02, /* bmAttributes: Bulk */ 133 | VIRTUAL_COM_PORT_DATA_SIZE, /* wMaxPacketSize: */ 134 | 0x00, 135 | 0x00 /* bInterval */ 136 | }; 137 | 138 | /* USB String Descriptors */ 139 | const uint8_t Virtual_Com_Port_StringLangID[VIRTUAL_COM_PORT_SIZ_STRING_LANGID] = 140 | { 141 | VIRTUAL_COM_PORT_SIZ_STRING_LANGID, 142 | USB_STRING_DESCRIPTOR_TYPE, 143 | 0x09, 144 | 0x04 /* LangID = 0x0409: U.S. English */ 145 | }; 146 | 147 | const uint8_t Virtual_Com_Port_StringVendor[VIRTUAL_COM_PORT_SIZ_STRING_VENDOR] = 148 | { 149 | VIRTUAL_COM_PORT_SIZ_STRING_VENDOR, /* Size of Vendor string */ 150 | USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType*/ 151 | /* Manufacturer: "tomeko.net" */ 152 | 't', 0, 'o', 0, 'm', 0, 'e', 0, 'k', 0, 'o', 0, ' ', 0, 'n', 0, 153 | 'e', 0, 't', 0 154 | }; 155 | 156 | const uint8_t Virtual_Com_Port_StringProduct[VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT] = 157 | { 158 | VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT, /* bLength */ 159 | USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ 160 | /* Product name: "STM32F103C8T6" */ 161 | 'S', 0, 'T', 0, 'M', 0, '3', 0, '2', 0, 'F', 0, '1', 0, '0', 0, 162 | '3', 0, 'C', 0, '8', 0, 'T', 0, '6', 0 163 | }; 164 | 165 | uint8_t Virtual_Com_Port_StringSerial[VIRTUAL_COM_PORT_SIZ_STRING_SERIAL] = 166 | { 167 | VIRTUAL_COM_PORT_SIZ_STRING_SERIAL, /* bLength */ 168 | USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ 169 | 'S', 0, 'T', 0, 'M', 0, '3', 0, '2', 0 170 | }; 171 | 172 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 173 | -------------------------------------------------------------------------------- /Libraries/usb/usb_desc.c.bak: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2011 STMicroelectronics ******************** 2 | * File Name : usb_desc.c 3 | * Author : MCD Application Team 4 | * Version : V3.3.0 5 | * Date : 21-March-2011 6 | * Description : Descriptors for Virtual Com Port Demo 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Includes ------------------------------------------------------------------*/ 17 | #include "usb_lib.h" 18 | #include "usb_desc.h" 19 | 20 | /* USB Standard Device Descriptor */ 21 | const uint8_t Virtual_Com_Port_DeviceDescriptor[] = 22 | { 23 | 0x12, /* bLength */ 24 | USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */ 25 | 0x00, 26 | 0x02, /* bcdUSB = 2.00 */ 27 | 0x02, /* bDeviceClass: CDC */ 28 | 0x00, /* bDeviceSubClass */ 29 | 0x00, /* bDeviceProtocol */ 30 | 0x40, /* bMaxPacketSize0 */ 31 | 0x83, 32 | 0x04, /* idVendor = 0x0483 */ 33 | 0x40, 34 | 0x57, /* idProduct = 0x7540 */ 35 | 0x00, 36 | 0x02, /* bcdDevice = 2.00 */ 37 | 1, /* Index of string descriptor describing manufacturer */ 38 | 2, /* Index of string descriptor describing product */ 39 | 3, /* Index of string descriptor describing the device's serial number */ 40 | 0x01 /* bNumConfigurations */ 41 | }; 42 | 43 | const uint8_t Virtual_Com_Port_ConfigDescriptor[] = 44 | { 45 | /*Configuration Descriptor*/ 46 | 0x09, /* bLength: Configuration Descriptor size */ 47 | USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */ 48 | VIRTUAL_COM_PORT_SIZ_CONFIG_DESC, /* wTotalLength:no of returned bytes */ 49 | 0x00, 50 | 0x02, /* bNumInterfaces: 2 interface */ 51 | 0x01, /* bConfigurationValue: Configuration value */ 52 | 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ 53 | 0xC0, /* bmAttributes: self powered */ 54 | 0x32, /* MaxPower 0 mA */ 55 | /*Interface Descriptor*/ 56 | 0x09, /* bLength: Interface Descriptor size */ 57 | USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */ 58 | /* Interface descriptor type */ 59 | 0x00, /* bInterfaceNumber: Number of Interface */ 60 | 0x00, /* bAlternateSetting: Alternate setting */ 61 | 0x01, /* bNumEndpoints: One endpoints used */ 62 | 0x02, /* bInterfaceClass: Communication Interface Class */ 63 | 0x02, /* bInterfaceSubClass: Abstract Control Model */ 64 | 0x01, /* bInterfaceProtocol: Common AT commands */ 65 | 0x00, /* iInterface: */ 66 | /*Header Functional Descriptor*/ 67 | 0x05, /* bLength: Endpoint Descriptor size */ 68 | 0x24, /* bDescriptorType: CS_INTERFACE */ 69 | 0x00, /* bDescriptorSubtype: Header Func Desc */ 70 | 0x10, /* bcdCDC: spec release number */ 71 | 0x01, 72 | /*Call Management Functional Descriptor*/ 73 | 0x05, /* bFunctionLength */ 74 | 0x24, /* bDescriptorType: CS_INTERFACE */ 75 | 0x01, /* bDescriptorSubtype: Call Management Func Desc */ 76 | 0x00, /* bmCapabilities: D0+D1 */ 77 | 0x01, /* bDataInterface: 1 */ 78 | /*ACM Functional Descriptor*/ 79 | 0x04, /* bFunctionLength */ 80 | 0x24, /* bDescriptorType: CS_INTERFACE */ 81 | 0x02, /* bDescriptorSubtype: Abstract Control Management desc */ 82 | 0x02, /* bmCapabilities */ 83 | /*Union Functional Descriptor*/ 84 | 0x05, /* bFunctionLength */ 85 | 0x24, /* bDescriptorType: CS_INTERFACE */ 86 | 0x06, /* bDescriptorSubtype: Union func desc */ 87 | 0x00, /* bMasterInterface: Communication class interface */ 88 | 0x01, /* bSlaveInterface0: Data Class Interface */ 89 | /*Endpoint 2 Descriptor*/ 90 | 0x07, /* bLength: Endpoint Descriptor size */ 91 | USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ 92 | 0x82, /* bEndpointAddress: (IN2) */ 93 | 0x03, /* bmAttributes: Interrupt */ 94 | VIRTUAL_COM_PORT_INT_SIZE, /* wMaxPacketSize: */ 95 | 0x00, 96 | 0xFF, /* bInterval: */ 97 | /*Data class interface descriptor*/ 98 | 0x09, /* bLength: Endpoint Descriptor size */ 99 | USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: */ 100 | 0x01, /* bInterfaceNumber: Number of Interface */ 101 | 0x00, /* bAlternateSetting: Alternate setting */ 102 | 0x02, /* bNumEndpoints: Two endpoints used */ 103 | 0x0A, /* bInterfaceClass: CDC */ 104 | 0x00, /* bInterfaceSubClass: */ 105 | 0x00, /* bInterfaceProtocol: */ 106 | 0x00, /* iInterface: */ 107 | /*Endpoint 3 Descriptor*/ 108 | 0x07, /* bLength: Endpoint Descriptor size */ 109 | USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ 110 | 0x03, /* bEndpointAddress: (OUT3) */ 111 | 0x02, /* bmAttributes: Bulk */ 112 | VIRTUAL_COM_PORT_DATA_SIZE, /* wMaxPacketSize: */ 113 | 0x00, 114 | 0x00, /* bInterval: ignore for Bulk transfer */ 115 | /*Endpoint 1 Descriptor*/ 116 | 0x07, /* bLength: Endpoint Descriptor size */ 117 | USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */ 118 | 0x81, /* bEndpointAddress: (IN1) */ 119 | 0x02, /* bmAttributes: Bulk */ 120 | VIRTUAL_COM_PORT_DATA_SIZE, /* wMaxPacketSize: */ 121 | 0x00, 122 | 0x00 /* bInterval */ 123 | }; 124 | 125 | /* USB String Descriptors */ 126 | const uint8_t Virtual_Com_Port_StringLangID[VIRTUAL_COM_PORT_SIZ_STRING_LANGID] = 127 | { 128 | VIRTUAL_COM_PORT_SIZ_STRING_LANGID, 129 | USB_STRING_DESCRIPTOR_TYPE, 130 | 0x09, 131 | 0x04 /* LangID = 0x0409: U.S. English */ 132 | }; 133 | 134 | const uint8_t Virtual_Com_Port_StringVendor[VIRTUAL_COM_PORT_SIZ_STRING_VENDOR] = 135 | { 136 | VIRTUAL_COM_PORT_SIZ_STRING_VENDOR, /* Size of Vendor string */ 137 | USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType*/ 138 | /* Manufacturer: "tomeko.net" */ 139 | 't', 0, 'o', 0, 'm', 0, 'e', 0, 'k', 0, 'o', 0, ' ', 0, 'n', 0, 140 | 'e', 0, 't', 0 141 | }; 142 | 143 | const uint8_t Virtual_Com_Port_StringProduct[VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT] = 144 | { 145 | VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT, /* bLength */ 146 | USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ 147 | /* Product name: "miniscope v2c" */ 148 | 'm', 0, 'i', 0, 'n', 0, 'i', 0, 's', 0, 'c', 0, 'o', 0, 'p', 0, 149 | 'e', 0, ' ', 0, 'v', 0, '2', 0, 'c', 0 150 | }; 151 | 152 | uint8_t Virtual_Com_Port_StringSerial[VIRTUAL_COM_PORT_SIZ_STRING_SERIAL] = 153 | { 154 | VIRTUAL_COM_PORT_SIZ_STRING_SERIAL, /* bLength */ 155 | USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ 156 | 'S', 0, 'T', 0, 'M', 0, '3', 0, '2', 0, '1', 0, '0', 0 157 | }; 158 | 159 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 160 | -------------------------------------------------------------------------------- /Libraries/usb/usb_desc.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2011 STMicroelectronics ******************** 2 | * File Name : usb_desc.h 3 | * Author : MCD Application Team 4 | * Version : V3.3.0 5 | * Date : 21-March-2011 6 | * Description : Descriptor Header for Virtual COM Port Device 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Define to prevent recursive inclusion -------------------------------------*/ 17 | #ifndef __USB_DESC_H 18 | #define __USB_DESC_H 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | /* Exported types ------------------------------------------------------------*/ 22 | /* Exported constants --------------------------------------------------------*/ 23 | /* Exported macro ------------------------------------------------------------*/ 24 | /* Exported define -----------------------------------------------------------*/ 25 | #define USB_DEVICE_DESCRIPTOR_TYPE 0x01 26 | #define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02 27 | #define USB_STRING_DESCRIPTOR_TYPE 0x03 28 | #define USB_INTERFACE_DESCRIPTOR_TYPE 0x04 29 | #define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05 30 | 31 | #define VIRTUAL_COM_PORT_DATA_SIZE 64 32 | #define VIRTUAL_COM_PORT_INT_SIZE 8 33 | 34 | #define VIRTUAL_COM_PORT_SIZ_DEVICE_DESC 18 35 | #define VIRTUAL_COM_PORT_SIZ_CONFIG_DESC 67 36 | #define VIRTUAL_COM_PORT_SIZ_STRING_LANGID 4 37 | #define VIRTUAL_COM_PORT_SIZ_STRING_VENDOR 22 38 | #define VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT 28 39 | #define VIRTUAL_COM_PORT_SIZ_STRING_SERIAL 26 40 | 41 | #define STANDARD_ENDPOINT_DESC_SIZE 0x09 42 | 43 | /* Exported functions ------------------------------------------------------- */ 44 | extern const uint8_t Virtual_Com_Port_DeviceDescriptor[VIRTUAL_COM_PORT_SIZ_DEVICE_DESC]; 45 | extern const uint8_t Virtual_Com_Port_ConfigDescriptor[VIRTUAL_COM_PORT_SIZ_CONFIG_DESC]; 46 | 47 | extern const uint8_t Virtual_Com_Port_StringLangID[VIRTUAL_COM_PORT_SIZ_STRING_LANGID]; 48 | extern const uint8_t Virtual_Com_Port_StringVendor[VIRTUAL_COM_PORT_SIZ_STRING_VENDOR]; 49 | extern const uint8_t Virtual_Com_Port_StringProduct[VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT]; 50 | extern uint8_t Virtual_Com_Port_StringSerial[VIRTUAL_COM_PORT_SIZ_STRING_SERIAL]; 51 | 52 | #endif /* __USB_DESC_H */ 53 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 54 | -------------------------------------------------------------------------------- /Libraries/usb/usb_endp.c: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2011 STMicroelectronics ******************** 2 | * File Name : usb_endp.c 3 | * Author : MCD Application Team 4 | * Version : V3.3.0 5 | * Date : 21-March-2011 6 | * Description : Endpoint routines 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | #include "usb_lib.h" 17 | #include "usb_desc.h" 18 | #include "usb_mem.h" 19 | #include "hw_config.h" 20 | #include "usb_istr.h" 21 | #include "usb_pwr.h" 22 | #include "serial.h" 23 | uint8_t USB_Rx_Buffer[VIRTUAL_COM_PORT_DATA_SIZE]; 24 | 25 | extern uint8_t serial_tx_buffer[]; 26 | extern uint8_t serial_tx_buffer_head; 27 | extern volatile uint8_t serial_tx_buffer_tail; 28 | 29 | void EP3_OUT_Callback(void) 30 | { 31 | uint16_t USB_Rx_Cnt; 32 | 33 | /* Get the received data buffer and update the counter */ 34 | USB_Rx_Cnt = USB_SIL_Read(EP3_OUT, USB_Rx_Buffer); 35 | 36 | /* USB data will be immediately processed, this allow next USB traffic being 37 | NAKed till the end of the USART Xfer */ 38 | 39 | OnUsbDataRx(USB_Rx_Buffer, USB_Rx_Cnt); 40 | 41 | /* Enable the receive of data on EP3 */ 42 | SetEPRxValid(ENDP3); 43 | } 44 | void EP1_IN_Callback (void) 45 | { 46 | if (serial_tx_buffer_head != serial_tx_buffer_tail && (_GetEPTxStatus(ENDP1) == EP_TX_NAK)) 47 | { 48 | uint16_t USB_Tx_length; 49 | 50 | if (serial_tx_buffer_head > serial_tx_buffer_tail) 51 | USB_Tx_length = serial_tx_buffer_head - serial_tx_buffer_tail; 52 | else 53 | { 54 | USB_Tx_length = TX_BUFFER_SIZE - serial_tx_buffer_tail + serial_tx_buffer_head; 55 | } 56 | 57 | if (USB_Tx_length != 0) 58 | { 59 | if (USB_Tx_length > 64) 60 | USB_Tx_length = 64; 61 | 62 | // UserToPMABufferCopy(&serial_tx_buffer[serial_tx_buffer_tail], ENDP1_TXADDR, USB_Tx_length); 63 | { 64 | uint8_t *pbUsrBuf = serial_tx_buffer + serial_tx_buffer_tail; 65 | uint32_t n = (USB_Tx_length + 1) >> 1; /* n = (wNBytes + 1) / 2 */ 66 | uint32_t i, temp1; 67 | uint16_t *pdwVal; 68 | pdwVal = (uint16_t *)(ENDP1_TXADDR * 2 + PMAAddr); 69 | for (i = n; i != 0; i--) 70 | { 71 | temp1 = (uint16_t) * pbUsrBuf; 72 | pbUsrBuf++; 73 | if (pbUsrBuf - serial_tx_buffer == TX_BUFFER_SIZE) 74 | pbUsrBuf = serial_tx_buffer; 75 | 76 | *pdwVal++ = temp1 | (uint16_t) * pbUsrBuf << 8; 77 | pdwVal++; 78 | pbUsrBuf++; 79 | if (pbUsrBuf - serial_tx_buffer == TX_BUFFER_SIZE) 80 | pbUsrBuf = serial_tx_buffer; 81 | } 82 | } 83 | 84 | SetEPTxCount(ENDP1, USB_Tx_length); 85 | SetEPTxValid(ENDP1); 86 | 87 | serial_tx_buffer_tail += USB_Tx_length; 88 | if (serial_tx_buffer_tail >= TX_BUFFER_SIZE) 89 | serial_tx_buffer_tail -= TX_BUFFER_SIZE; 90 | } 91 | } 92 | } 93 | 94 | 95 | /* \brief Start Of Frame (SOF) callback 96 | */ 97 | void SOF_Callback(void) 98 | { 99 | if(bDeviceState == CONFIGURED) 100 | { 101 | /* Check the data to be sent through IN pipe */ 102 | EP1_IN_Callback(); 103 | } 104 | } 105 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 106 | 107 | -------------------------------------------------------------------------------- /Libraries/usb/usb_endp.c.bak: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2011 STMicroelectronics ******************** 2 | * File Name : usb_endp.c 3 | * Author : MCD Application Team 4 | * Version : V3.3.0 5 | * Date : 21-March-2011 6 | * Description : Endpoint routines 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | #include "usb_lib.h" 17 | #include "usb_desc.h" 18 | #include "usb_mem.h" 19 | #include "hw_config.h" 20 | #include "usb_istr.h" 21 | #include "usb_pwr.h" 22 | #include "serial.h" 23 | uint8_t USB_Rx_Buffer[VIRTUAL_COM_PORT_DATA_SIZE]; 24 | 25 | extern uint8_t serial_tx_buffer[]; 26 | extern uint8_t serial_tx_buffer_head; 27 | extern volatile uint8_t serial_tx_buffer_tail; 28 | 29 | void EP3_OUT_Callback(void) 30 | { 31 | uint16_t USB_Rx_Cnt; 32 | 33 | /* Get the received data buffer and update the counter */ 34 | USB_Rx_Cnt = USB_SIL_Read(EP3_OUT, USB_Rx_Buffer); 35 | 36 | /* USB data will be immediately processed, this allow next USB traffic being 37 | NAKed till the end of the USART Xfer */ 38 | 39 | OnUsbDataRx(USB_Rx_Buffer, USB_Rx_Cnt); 40 | 41 | /* Enable the receive of data on EP3 */ 42 | SetEPRxValid(ENDP3); 43 | } 44 | 45 | void EP1_IN_Callback (void) 46 | { 47 | if (serial_tx_buffer_head != serial_tx_buffer_tail) 48 | { 49 | uint16_t USB_Tx_length; 50 | 51 | if (serial_tx_buffer_head > serial_tx_buffer_tail) 52 | USB_Tx_length = serial_tx_buffer_head - serial_tx_buffer_tail; 53 | else 54 | { 55 | USB_Tx_length = TX_BUFFER_SIZE - serial_tx_buffer_tail; 56 | } 57 | 58 | if (USB_Tx_length != 0) 59 | { 60 | if (USB_Tx_length > 64) 61 | USB_Tx_length = 64; 62 | 63 | UserToPMABufferCopy(serial_tx_buffer + serial_tx_buffer_tail, ENDP1_TXADDR, USB_Tx_length); 64 | serial_tx_buffer_tail += USB_Tx_length; 65 | if (serial_tx_buffer_tail == TX_BUFFER_SIZE) 66 | serial_tx_buffer_tail = 0; 67 | 68 | SetEPTxCount(ENDP1, USB_Tx_length); 69 | SetEPTxValid(ENDP1); 70 | } 71 | } 72 | } 73 | 74 | 75 | /* \brief Start Of Frame (SOF) callback 76 | */ 77 | void SOF_Callback(void) 78 | { 79 | if(bDeviceState == CONFIGURED) 80 | { 81 | /* Check the data to be sent through IN pipe */ 82 | if (_GetEPTxStatus(ENDP1) == EP_TX_NAK) 83 | { 84 | EP1_IN_Callback(); 85 | } 86 | } 87 | } 88 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 89 | 90 | -------------------------------------------------------------------------------- /Libraries/usb/usb_istr.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2011 STMicroelectronics ******************** 2 | * File Name : usb_istr.h 3 | * Author : MCD Application Team 4 | * Version : V3.3.0 5 | * Date : 21-March-2011 6 | * Description : This file includes the peripherals header files in the 7 | * user application. 8 | ******************************************************************************** 9 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 10 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 11 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 12 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 13 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 14 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 15 | *******************************************************************************/ 16 | 17 | /* Define to prevent recursive inclusion -------------------------------------*/ 18 | #ifndef __USB_ISTR_H 19 | #define __USB_ISTR_H 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "usb_conf.h" 23 | 24 | /* Exported types ------------------------------------------------------------*/ 25 | /* Exported constants --------------------------------------------------------*/ 26 | /* Exported macro ------------------------------------------------------------*/ 27 | /* Exported functions ------------------------------------------------------- */ 28 | 29 | #ifndef STM32F10X_CL 30 | void USB_Istr(void); 31 | #else /* STM32F10X_CL */ 32 | u32 STM32_PCD_OTG_ISR_Handler(void); 33 | #endif /* STM32F10X_CL */ 34 | 35 | /* function prototypes Automatically built defining related macros */ 36 | 37 | void EP1_IN_Callback(void); 38 | void EP2_IN_Callback(void); 39 | void EP3_IN_Callback(void); 40 | void EP4_IN_Callback(void); 41 | void EP5_IN_Callback(void); 42 | void EP6_IN_Callback(void); 43 | void EP7_IN_Callback(void); 44 | 45 | void EP1_OUT_Callback(void); 46 | void EP2_OUT_Callback(void); 47 | void EP3_OUT_Callback(void); 48 | void EP4_OUT_Callback(void); 49 | void EP5_OUT_Callback(void); 50 | void EP6_OUT_Callback(void); 51 | void EP7_OUT_Callback(void); 52 | 53 | #ifndef STM32F10X_CL 54 | 55 | #ifdef CTR_CALLBACK 56 | void CTR_Callback(void); 57 | #endif 58 | 59 | #ifdef DOVR_CALLBACK 60 | void DOVR_Callback(void); 61 | #endif 62 | 63 | #ifdef ERR_CALLBACK 64 | void ERR_Callback(void); 65 | #endif 66 | 67 | #ifdef WKUP_CALLBACK 68 | void WKUP_Callback(void); 69 | #endif 70 | 71 | #ifdef SUSP_CALLBACK 72 | void SUSP_Callback(void); 73 | #endif 74 | 75 | #ifdef RESET_CALLBACK 76 | void RESET_Callback(void); 77 | #endif 78 | 79 | #ifdef SOF_CALLBACK 80 | void SOF_Callback(void); 81 | #endif 82 | 83 | #ifdef ESOF_CALLBACK 84 | void ESOF_Callback(void); 85 | #endif 86 | 87 | #else /* STM32F10X_CL */ 88 | 89 | /* Interrupt subroutines user callbacks prototypes. 90 | These callbacks are called into the respective interrupt subroutine functions 91 | and can be tailored for various user application purposes. 92 | Note: Make sure that the correspondent interrupt is enabled through the 93 | definition in usb_conf.h file */ 94 | void INTR_MODEMISMATCH_Callback(void); 95 | void INTR_SOFINTR_Callback(void); 96 | void INTR_RXSTSQLVL_Callback(void); 97 | void INTR_NPTXFEMPTY_Callback(void); 98 | void INTR_GINNAKEFF_Callback(void); 99 | void INTR_GOUTNAKEFF_Callback(void); 100 | void INTR_ERLYSUSPEND_Callback(void); 101 | void INTR_USBSUSPEND_Callback(void); 102 | void INTR_USBRESET_Callback(void); 103 | void INTR_ENUMDONE_Callback(void); 104 | void INTR_ISOOUTDROP_Callback(void); 105 | void INTR_EOPFRAME_Callback(void); 106 | void INTR_EPMISMATCH_Callback(void); 107 | void INTR_INEPINTR_Callback(void); 108 | void INTR_OUTEPINTR_Callback(void); 109 | void INTR_INCOMPLISOIN_Callback(void); 110 | void INTR_INCOMPLISOOUT_Callback(void); 111 | void INTR_WKUPINTR_Callback(void); 112 | 113 | /* Isochronous data update */ 114 | void INTR_RXSTSQLVL_ISODU_Callback(void); 115 | 116 | #endif /* STM32F10X_CL */ 117 | 118 | 119 | #endif /*__USB_ISTR_H*/ 120 | 121 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 122 | -------------------------------------------------------------------------------- /Libraries/usb/usb_prop.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2011 STMicroelectronics ******************** 2 | * File Name : usb_prop.h 3 | * Author : MCD Application Team 4 | * Version : V3.3.0 5 | * Date : 21-March-2011 6 | * Description : All processing related to Virtual COM Port Demo (Endpoint 0) 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Define to prevent recursive inclusion -------------------------------------*/ 17 | #ifndef __usb_prop_H 18 | #define __usb_prop_H 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | /* Exported types ------------------------------------------------------------*/ 22 | typedef struct 23 | { 24 | uint32_t bitrate; 25 | uint8_t format; 26 | uint8_t paritytype; 27 | uint8_t datatype; 28 | }LINE_CODING; 29 | 30 | /* Exported constants --------------------------------------------------------*/ 31 | /* Exported macro ------------------------------------------------------------*/ 32 | /* Exported define -----------------------------------------------------------*/ 33 | 34 | #define Virtual_Com_Port_GetConfiguration NOP_Process 35 | //#define Virtual_Com_Port_SetConfiguration NOP_Process 36 | #define Virtual_Com_Port_GetInterface NOP_Process 37 | #define Virtual_Com_Port_SetInterface NOP_Process 38 | #define Virtual_Com_Port_GetStatus NOP_Process 39 | #define Virtual_Com_Port_ClearFeature NOP_Process 40 | #define Virtual_Com_Port_SetEndPointFeature NOP_Process 41 | #define Virtual_Com_Port_SetDeviceFeature NOP_Process 42 | //#define Virtual_Com_Port_SetDeviceAddress NOP_Process 43 | 44 | #define SEND_ENCAPSULATED_COMMAND 0x00 45 | #define GET_ENCAPSULATED_RESPONSE 0x01 46 | #define SET_COMM_FEATURE 0x02 47 | #define GET_COMM_FEATURE 0x03 48 | #define CLEAR_COMM_FEATURE 0x04 49 | #define SET_LINE_CODING 0x20 50 | #define GET_LINE_CODING 0x21 51 | #define SET_CONTROL_LINE_STATE 0x22 52 | #define SEND_BREAK 0x23 53 | 54 | /* Exported functions ------------------------------------------------------- */ 55 | void Virtual_Com_Port_init(void); 56 | void Virtual_Com_Port_Reset(void); 57 | void Virtual_Com_Port_SetConfiguration(void); 58 | void Virtual_Com_Port_SetDeviceAddress (void); 59 | void Virtual_Com_Port_Status_In (void); 60 | void Virtual_Com_Port_Status_Out (void); 61 | RESULT Virtual_Com_Port_Data_Setup(uint8_t); 62 | RESULT Virtual_Com_Port_NoData_Setup(uint8_t); 63 | RESULT Virtual_Com_Port_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting); 64 | uint8_t *Virtual_Com_Port_GetDeviceDescriptor(uint16_t ); 65 | uint8_t *Virtual_Com_Port_GetConfigDescriptor(uint16_t); 66 | uint8_t *Virtual_Com_Port_GetStringDescriptor(uint16_t); 67 | 68 | uint8_t *Virtual_Com_Port_GetLineCoding(uint16_t Length); 69 | uint8_t *Virtual_Com_Port_SetLineCoding(uint16_t Length); 70 | 71 | #endif /* __usb_prop_H */ 72 | 73 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 74 | 75 | -------------------------------------------------------------------------------- /Libraries/usb/usb_pwr.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2011 STMicroelectronics ******************** 2 | * File Name : usb_pwr.h 3 | * Author : MCD Application Team 4 | * Version : V3.3.0 5 | * Date : 21-March-2011 6 | * Description : Connection/disconnection & power management header 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Define to prevent recursive inclusion -------------------------------------*/ 17 | #ifndef __USB_PWR_H 18 | #define __USB_PWR_H 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | /* Exported types ------------------------------------------------------------*/ 22 | typedef enum _RESUME_STATE 23 | { 24 | RESUME_EXTERNAL, 25 | RESUME_INTERNAL, 26 | RESUME_LATER, 27 | RESUME_WAIT, 28 | RESUME_START, 29 | RESUME_ON, 30 | RESUME_OFF, 31 | RESUME_ESOF 32 | } RESUME_STATE; 33 | 34 | typedef enum _DEVICE_STATE 35 | { 36 | UNCONNECTED, 37 | ATTACHED, 38 | POWERED, 39 | SUSPENDED, 40 | ADDRESSED, 41 | CONFIGURED 42 | } DEVICE_STATE; 43 | 44 | /* Exported constants --------------------------------------------------------*/ 45 | /* Exported macro ------------------------------------------------------------*/ 46 | /* Exported functions ------------------------------------------------------- */ 47 | void Suspend(void); 48 | void Resume_Init(void); 49 | void Resume(RESUME_STATE eResumeSetVal); 50 | RESULT PowerOn(void); 51 | RESULT PowerOff(void); 52 | 53 | /* External variables --------------------------------------------------------*/ 54 | extern __IO uint32_t bDeviceState; /* USB device status */ 55 | extern __IO bool fSuspendEnabled; /* true when suspend is possible */ 56 | 57 | #endif /*__USB_PWR_H*/ 58 | 59 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 60 | -------------------------------------------------------------------------------- /Libraries/util/CVS/Entries: -------------------------------------------------------------------------------- 1 | /stm32eeprom.h/1.1/Sun Jul 3 23:54:54 2016// 2 | /stm32f10x_it.c/1.1/Tue Mar 8 07:10:30 2016// 3 | D 4 | -------------------------------------------------------------------------------- /Libraries/util/CVS/Entries.Extra: -------------------------------------------------------------------------------- 1 | /stm32eeprom.h///1470196397/ 2 | /stm32f10x_it.c///1470196397/ 3 | -------------------------------------------------------------------------------- /Libraries/util/CVS/Entries.Extra.Old: -------------------------------------------------------------------------------- 1 | /stm32f10x_it.c//// 2 | /stm32eeprom.h//// 3 | -------------------------------------------------------------------------------- /Libraries/util/CVS/Entries.Old: -------------------------------------------------------------------------------- 1 | /stm32f10x_it.c/0/Initial stm32f10x_it.c// 2 | /stm32eeprom.h/0/Initial stm32eeprom.h// 3 | D 4 | -------------------------------------------------------------------------------- /Libraries/util/CVS/Repository: -------------------------------------------------------------------------------- 1 | Code/grbl1.0d/stm32grbl/util 2 | -------------------------------------------------------------------------------- /Libraries/util/CVS/Root: -------------------------------------------------------------------------------- 1 | :local:E:/CVSRep 2 | -------------------------------------------------------------------------------- /Libraries/util/stm32eeprom.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file EEPROM_Emulation/inc/eeprom.h 4 | * @author MCD Application Team 5 | * @version V3.1.0 6 | * @date 07/27/2009 7 | * @brief This file contains all the functions prototypes for the EEPROM 8 | * emulation firmware library. 9 | ****************************************************************************** 10 | * @copy 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2009 STMicroelectronics

20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __EEPROM_H 24 | #define __EEPROM_H 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "stm32f10x_flash.h" 28 | 29 | /* Exported constants --------------------------------------------------------*/ 30 | /* Define the STM32F10Xxx Flash page size depending on the used STM32 device */ 31 | #if defined (STM32F10X_LD) || defined (STM32F10X_MD) 32 | #define PAGE_SIZE (uint16_t)0x400 /* Page size = 1KByte */ 33 | #elif defined (STM32F10X_HD) || defined (STM32F10X_CL) 34 | #define PAGE_SIZE (uint16_t)0x800 /* Page size = 2KByte */ 35 | #endif 36 | 37 | /* EEPROM start address in Flash */ 38 | #define EEPROM_START_ADDRESS ((uint32_t)0x0801fc00) /* EEPROM emulation start address: 39 | after 64KByte of used Flash memory */ 40 | 41 | #endif /* __EEPROM_H */ 42 | 43 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # grbl_stm32 2 | GRBL for STM32 controller. 3 | 4 | ## Development Environment 5 | | | | 6 | |----------------------|---------------------------| 7 | | **IDE** | TrueSTUDIO for STM32 v9.0 | 8 | | **Controller board** | STM32F103C8T6 (Bluepill) | 9 | 10 | ## Reference 11 | - GRBL CNC controller ported to STM32 controller 12 | ```https://github.com/usbcnc/grbl``` 13 | - GRBL CNC controller 14 | ```https://github.com/gnea/grbl``` 15 | 16 | ## Pin Diagram 17 | 18 | ![STM32 Pin Diagram](https://github.com/helimp/grbl_stm32/blob/master/docs/STM32F103C8T8_Bluepill_PinDiagram.png?raw=true) 19 | -------------------------------------------------------------------------------- /docs/STM32F103C8T8_Bluepill.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helimp/grbl_stm32/2b0da66044d5f8f1eedbd8b2afb913b48dcef4ad/docs/STM32F103C8T8_Bluepill.pptx -------------------------------------------------------------------------------- /docs/STM32F103C8T8_Bluepill_PinDiagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helimp/grbl_stm32/2b0da66044d5f8f1eedbd8b2afb913b48dcef4ad/docs/STM32F103C8T8_Bluepill_PinDiagram.png -------------------------------------------------------------------------------- /grbl_stm32.elf.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/stm32f10x_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file RTC/Calendar/stm32f10x_conf.h 4 | * @author MCD Application Team 5 | * @version V3.4.0 6 | * @date 10/15/2010 7 | * @brief Library configuration file. 8 | ****************************************************************************** 9 | * @copy 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2010 STMicroelectronics

19 | */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32F10x_CONF_H 23 | #define __STM32F10x_CONF_H 24 | 25 | /* Includes ------------------------------------------------------------------*/ 26 | /* Uncomment the line below to enable peripheral header file inclusion */ 27 | /* #include "stm32f10x_adc.h" */ 28 | /* #include "stm32f10x_bkp.h" */ 29 | /* #include "stm32f10x_can.h" */ 30 | /* #include "stm32f10x_cec.h" */ 31 | /* #include "stm32f10x_crc.h" */ 32 | /* #include "stm32f10x_dac.h" */ 33 | /* #include "stm32f10x_dbgmcu.h" */ 34 | /* #include "stm32f10x_dma.h" */ 35 | /* #include "stm32f10x_exti.h" */ 36 | /* #include "stm32f10x_flash.h" */ 37 | /* #include "stm32f10x_fsmc.h" */ 38 | /* #include "stm32f10x_gpio.h" */ 39 | /* #include "stm32f10x_i2c.h" */ 40 | /* #include "stm32f10x_iwdg.h" */ 41 | /* #include "stm32f10x_pwr.h" */ 42 | /* #include "stm32f10x_rcc.h" */ 43 | /* #include "stm32f10x_rtc.h" */ 44 | /* #include "stm32f10x_sdio.h" */ 45 | /* #include "stm32f10x_spi.h" */ 46 | /* #include "stm32f10x_tim.h" */ 47 | /* #include "stm32f10x_usart.h" */ 48 | /* #include "stm32f10x_wwdg.h" */ 49 | /* #include "misc.h" */ /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ 50 | 51 | 52 | /* Exported types ------------------------------------------------------------*/ 53 | /* Exported constants --------------------------------------------------------*/ 54 | /* Uncomment the line below to expanse the "assert_param" macro in the 55 | Standard Peripheral Library drivers code */ 56 | /* #define USE_FULL_ASSERT 1 */ 57 | 58 | /* Exported macro ------------------------------------------------------------*/ 59 | #ifdef USE_FULL_ASSERT 60 | 61 | /** 62 | * @brief The assert_param macro is used for function's parameters check. 63 | * @param expr: If expr is false, it calls assert_failed function 64 | * which reports the name of the source file and the source 65 | * line number of the call that failed. 66 | * If expr is true, it returns no value. 67 | * @retval None 68 | */ 69 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 70 | /* Exported functions ------------------------------------------------------- */ 71 | void assert_failed(uint8_t* file, uint32_t line); 72 | #else 73 | #define assert_param(expr) ((void)0) 74 | #endif /* USE_FULL_ASSERT */ 75 | 76 | #endif /* __STM32F10x_CONF_H */ 77 | 78 | /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/ 79 | -------------------------------------------------------------------------------- /stm32_flash.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | File: stm32_flash.ld 4 | Info: Generated by Atollic TrueSTUDIO(R) 9.0.0 2019-01-22 5 | 6 | Abstract: Linker script for STM32F103C8 device 7 | Set heap size, stack size, stack location, memory areas and 8 | sections according to application requirements. 9 | 10 | The MIT License (MIT) 11 | Copyright (c) 2018 STMicroelectronics 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in all 21 | copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 29 | SOFTWARE. 30 | 31 | ****************************************************************************** 32 | */ 33 | 34 | /* Entry Point */ 35 | ENTRY(Reset_Handler) 36 | 37 | /* Highest address of the user mode stack */ 38 | _estack = 0x20005000; /* end of 20K RAM */ 39 | 40 | /* Generate a link error if heap and stack don't fit into RAM */ 41 | _Min_Heap_Size = 0; /* required amount of heap */ 42 | _Min_Stack_Size = 0x100; /* required amount of stack */ 43 | 44 | /* Specify the memory areas */ 45 | MEMORY 46 | { 47 | FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 64K 48 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K 49 | MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K 50 | } 51 | 52 | /* Define output sections */ 53 | SECTIONS 54 | { 55 | /* The startup code goes first into FLASH */ 56 | .isr_vector : 57 | { 58 | . = ALIGN(4); 59 | KEEP(*(.isr_vector)) /* Startup code */ 60 | . = ALIGN(4); 61 | } >FLASH 62 | 63 | /* The program code and other data goes into FLASH */ 64 | .text : 65 | { 66 | . = ALIGN(4); 67 | *(.text) /* .text sections (code) */ 68 | *(.text*) /* .text* sections (code) */ 69 | *(.glue_7) /* glue arm to thumb code */ 70 | *(.glue_7t) /* glue thumb to arm code */ 71 | *(.eh_frame) 72 | 73 | KEEP (*(.init)) 74 | KEEP (*(.fini)) 75 | 76 | . = ALIGN(4); 77 | _etext = .; /* define a global symbols at end of code */ 78 | } >FLASH 79 | 80 | /* Constant data goes into FLASH */ 81 | .rodata : 82 | { 83 | . = ALIGN(4); 84 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 85 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 86 | . = ALIGN(4); 87 | } >FLASH 88 | 89 | .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH 90 | .ARM : { 91 | __exidx_start = .; 92 | *(.ARM.exidx*) 93 | __exidx_end = .; 94 | } >FLASH 95 | 96 | .preinit_array : 97 | { 98 | PROVIDE_HIDDEN (__preinit_array_start = .); 99 | KEEP (*(.preinit_array*)) 100 | PROVIDE_HIDDEN (__preinit_array_end = .); 101 | } >FLASH 102 | .init_array : 103 | { 104 | PROVIDE_HIDDEN (__init_array_start = .); 105 | KEEP (*(SORT(.init_array.*))) 106 | KEEP (*(.init_array*)) 107 | PROVIDE_HIDDEN (__init_array_end = .); 108 | } >FLASH 109 | .fini_array : 110 | { 111 | PROVIDE_HIDDEN (__fini_array_start = .); 112 | KEEP (*(SORT(.fini_array.*))) 113 | KEEP (*(.fini_array*)) 114 | PROVIDE_HIDDEN (__fini_array_end = .); 115 | } >FLASH 116 | 117 | /* used by the startup to initialize data */ 118 | _sidata = LOADADDR(.data); 119 | 120 | /* Initialized data sections goes into RAM, load LMA copy after code */ 121 | .data : 122 | { 123 | . = ALIGN(4); 124 | _sdata = .; /* create a global symbol at data start */ 125 | *(.data) /* .data sections */ 126 | *(.data*) /* .data* sections */ 127 | 128 | . = ALIGN(4); 129 | _edata = .; /* define a global symbol at data end */ 130 | } >RAM AT> FLASH 131 | 132 | /* Uninitialized data section */ 133 | . = ALIGN(4); 134 | .bss : 135 | { 136 | /* This is used by the startup in order to initialize the .bss secion */ 137 | _sbss = .; /* define a global symbol at bss start */ 138 | __bss_start__ = _sbss; 139 | *(.bss) 140 | *(.bss*) 141 | *(COMMON) 142 | 143 | . = ALIGN(4); 144 | _ebss = .; /* define a global symbol at bss end */ 145 | __bss_end__ = _ebss; 146 | } >RAM 147 | 148 | /* User_heap_stack section, used to check that there is enough RAM left */ 149 | ._user_heap_stack : 150 | { 151 | . = ALIGN(4); 152 | PROVIDE ( end = . ); 153 | PROVIDE ( _end = . ); 154 | . = . + _Min_Heap_Size; 155 | . = . + _Min_Stack_Size; 156 | . = ALIGN(4); 157 | } >RAM 158 | 159 | /* MEMORY_bank1 section, code must be located here explicitly */ 160 | /* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */ 161 | .memory_b1_text : 162 | { 163 | *(.mb1text) /* .mb1text sections (code) */ 164 | *(.mb1text*) /* .mb1text* sections (code) */ 165 | *(.mb1rodata) /* read-only data (constants) */ 166 | *(.mb1rodata*) 167 | } >MEMORY_B1 168 | 169 | /* Remove information from the standard libraries */ 170 | /DISCARD/ : 171 | { 172 | libc.a ( * ) 173 | libm.a ( * ) 174 | libgcc.a ( * ) 175 | } 176 | 177 | .ARM.attributes 0 : { *(.ARM.attributes) } 178 | } 179 | --------------------------------------------------------------------------------