1. 程式人生 > >GRBL七: STM32程式碼移植——IO

GRBL七: STM32程式碼移植——IO

首先看引腳對映,關於引腳的定義都在pin_map.h中

其實感覺GRBL的引腳這地做的不太人性,因為他的幾個引腳都是用的同一個IO通道且是挨在一起的,程式中對引腳的操作也是按照挨在一起的演算法進行的,如果用的是不一個通道IO

且重複的話就不適合了,例如如果X_STEP使用A0  Y_STEP使用B0這樣就會出現錯誤,可以使用不同通道,但是要確保X_STEP_BIT ,Y_STEP_BIT  , Z_STEP_BIT  ,X_DIRECTION_BIT ,Y_DIRECTION_BIT ,Z_DIRECTION_BIT 使用的是不同位,這是預設的情況,也可以在引數中修改這些bit的具體位置$6的值就是這六個引腳的對映

pin_map.h

/*
  pin_map.h - Pin mapping configuration file
  Part of Grbl

  The MIT License (MIT)

  GRBL(tm) - Embedded CNC g-code interpreter and motion-controller
  Copyright (c) 2013 Sungeun K. Jeon

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
*/

/* The pin_map.h file serves as a central pin mapping settings file for different processor
   types, i.e. AVR 328p or AVR Mega 2560. Grbl officially supports the Arduino Uno, but the 
   other supplied pin mappings are supplied by users, so your results may vary. */

#ifndef pin_map_h
#define pin_map_h
//add by zjk for stm32
#ifdef PIN_MAP_STM32 // AVR 328p, Officially supported by Grbl.

  // Serial port pins
//  #define SERIAL_RX USART_RX_vect
//  #define SERIAL_UDRE USART_UDRE_vect

  // NOTE: All step bit and direction pins must be on the same port.
//  #define STEPPING_DDR       DDRD
//  #define STEPPING_PORT      PORTD
//  #define X_STEP_BIT         2  // Uno Digital Pin 2
//  #define Y_STEP_BIT         3  // Uno Digital Pin 3
//  #define Z_STEP_BIT         4  // Uno Digital Pin 4
//  #define X_DIRECTION_BIT    5  // Uno Digital Pin 5
//  #define Y_DIRECTION_BIT    6  // Uno Digital Pin 6
//  #define Z_DIRECTION_BIT    7  // Uno Digital Pin 7
//  #define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)) // All step bits
//  #define DIRECTION_MASK ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)) // All direction bits
//  #define STEPPING_MASK (STEP_MASK | DIRECTION_MASK) // All stepping-related bits (step/direction)
  #define X_STEP_PORT      GPIOA->ODR
  #define Y_STEP_PORT      GPIOD->ODR
  #define Z_STEP_PORT
  #define X_STEP_BIT         8  // PA8
  #define Y_STEP_BIT         15  // PD15
  #define Z_STEP_BIT
  #define X_STEP_MASK      (1<<X_STEP_BIT)
  #define Y_STEP_MASK      (1<<Y_STEP_BIT)
  #define Z_STEP_MASK	   (1<<Z_STEP_BIT)
  #define X_STEP_TRASLATE(a)  ((a>>2)<<X_STEP_BIT) 
  #define Y_STEP_TRASLATE(a)  ((a>>3)<<Y_STEP_BIT)
  #define Z_STEP_TRASLATE(a)  ((a>>4)<<Z_STEP_BIT)

  #define X_DIRECTION_PORT	GPIOA->ODR
  #define Y_DIRECTION_PORT	GPIOA->ODR
  #define Z_DIRECTION_PORT
  #define X_DIRECTION_BIT    6  // PC6
  #define Y_DIRECTION_BIT    2  // PA2
  #define Z_DIRECTION_BIT
  #define X_DIRECTION_MASK   (1<<X_DIRECTION_BIT)
  #define Y_DIRECTION_MASK   (1<<Y_DIRECTION_BIT)
  #define Z_DIRECTION_MASK   (1<<Z_DIRECTION_BIT)
  #define X_DIRECTION_TRASLATE(a) ((a>>5)<<X_DIRECTION_BIT)
  #define Y_DIRECTION_TRASLATE(a) (a) 
  #define Z_DIRECTION_TRASLATE(a) ((a>>7)<<Z_DIRECTION_BIT) 

  #define X_STEP_EN   GPIO_SetBits(GPIOA , GPIO_Pin_8) 
  #define X_STEP_DIS  GPIO_ResetBits(GPIOA , GPIO_Pin_8)  
  #define Y_STEP_EN	  GPIO_SetBits(GPIOD , GPIO_Pin_15)
  #define Y_STEP_DIS  GPIO_ResetBits(GPIOD , GPIO_Pin_15)
  #define STEPPING_EN	X_STEP_EN;Y_STEP_EN
  #define STEPPING_DIS	X_STEP_DIS;Y_STEP_DIS 
  
  #define X_DIRECTION_EN   GPIO_SetBits(GPIOA , GPIO_Pin_6)
  #define X_DIRECTION_DIS  GPIO_ResetBits(GPIOA , GPIO_Pin_6)
  #define Y_DIRECTION_EN   GPIO_SetBits(GPIOA , GPIO_Pin_2)
  #define Y_DIRECTION_DIS  GPIO_ResetBits(GPIOA , GPIO_Pin_2)
  #define DIRECTION_EN	 X_DIRECTION_EN;Y_DIRECTION_EN
  #define DIRECTION_DIS	 X_DIRECTION_DIS;Y_DIRECTION_DIS


//  #define STEPPERS_DISABLE_DDR    DDRB
//  #define STEPPERS_DISABLE_PORT   PORTB
//  #define STEPPERS_DISABLE_BIT    0  // Uno Digital Pin 8
//  #define STEPPERS_DISABLE_MASK (1<<STEPPERS_DISABLE_BIT)
  #define STEPPERS_DISABLE_EN  GPIO_SetBits(GPIOA , GPIO_Pin_3);GPIO_SetBits(GPIOA , GPIO_Pin_4) 
  #define STEPPERS_DISABLE_DIS  GPIO_ResetBits(GPIOA , GPIO_Pin_3);GPIO_ResetBits(GPIOA , GPIO_Pin_4)
  // NOTE: All limit bit pins must be on the same port
//  #define LIMIT_DDR       DDRB
//  #define LIMIT_PIN       PINB
//  #define LIMIT_PORT      PORTB
//  #define X_LIMIT_BIT     1  // Uno Digital Pin 9
//  #define Y_LIMIT_BIT     2  // Uno Digital Pin 10
//  #define Z_LIMIT_BIT     3  // Uno Digital Pin 11
//  #define LIMIT_INT       PCIE0  // Pin change interrupt enable pin
//  #define LIMIT_INT_vect  PCINT0_vect 
//  #define LIMIT_PCMSK     PCMSK0 // Pin change interrupt register
//  #define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)) // All limit bits

  //帶刀軸主軸電機
//  #define SPINDLE_ENABLE_DDR   DDRB
//  #define SPINDLE_ENABLE_PORT  PORTB
//  #define SPINDLE_ENABLE_BIT   4  // Uno Digital Pin 12
//
//  #define SPINDLE_DIRECTION_DDR   DDRB
//  #define SPINDLE_DIRECTION_PORT  PORTB
//  #define SPINDLE_DIRECTION_BIT   5  // Uno Digital Pin 13 (NOTE: D13 can't be pulled-high input due to LED.)	
  	


//  #define COOLANT_FLOOD_DDR   DDRC
//  #define COOLANT_FLOOD_PORT  PORTC
//  #define COOLANT_FLOOD_BIT   3  // Uno Analog Pin 3

  // NOTE: Uno analog pins 4 and 5 are reserved for an i2c interface, and may be installed at
  // a later date if flash and memory space allows.
  // #define ENABLE_M7  // Mist coolant disabled by default. Uncomment to enable.
  #ifdef ENABLE_M7
    #define COOLANT_MIST_DDR   DDRC
    #define COOLANT_MIST_PORT  PORTC
    #define COOLANT_MIST_BIT   4 // Uno Analog Pin 4
  #endif  

  // NOTE: All pinouts pins must be on the same port
  #define PINOUT_DDR       DDRC
  #define PINOUT_PIN       PINC
  #define PINOUT_PORT      PORTC
  #define PIN_RESET        0  // Uno Analog Pin 0
  #define PIN_FEED_HOLD    1  // Uno Analog Pin 1
  #define PIN_CYCLE_START  2  // Uno Analog Pin 2
  #define PINOUT_INT       PCIE1  // Pin change interrupt enable pin
  #define PINOUT_INT_vect  PCINT1_vect
  #define PINOUT_PCMSK     PCMSK1 // Pin change interrupt register
  #define PINOUT_MASK ((1<<PIN_RESET)|(1<<PIN_FEED_HOLD)|(1<<PIN_CYCLE_START))
  
#endif
//end zjk

#ifdef PIN_MAP_ARDUINO_UNO // AVR 328p, Officially supported by Grbl.

  // Serial port pins
  #define SERIAL_RX USART_RX_vect
  #define SERIAL_UDRE USART_UDRE_vect

  // NOTE: All step bit and direction pins must be on the same port.
  #define STEPPING_DDR       DDRD
  #define STEPPING_PORT      PORTD
  #define X_STEP_BIT         2  // Uno Digital Pin 2
  #define Y_STEP_BIT         3  // Uno Digital Pin 3
  #define Z_STEP_BIT         4  // Uno Digital Pin 4
  #define X_DIRECTION_BIT    5  // Uno Digital Pin 5
  #define Y_DIRECTION_BIT    6  // Uno Digital Pin 6
  #define Z_DIRECTION_BIT    7  // Uno Digital Pin 7
  #define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)) // All step bits
  #define DIRECTION_MASK ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)) // All direction bits
  #define STEPPING_MASK (STEP_MASK | DIRECTION_MASK) // All stepping-related bits (step/direction)

  #define STEPPERS_DISABLE_DDR    DDRB
  #define STEPPERS_DISABLE_PORT   PORTB
  #define STEPPERS_DISABLE_BIT    0  // Uno Digital Pin 8
  #define STEPPERS_DISABLE_MASK (1<<STEPPERS_DISABLE_BIT)

  // NOTE: All limit bit pins must be on the same port
  #define LIMIT_DDR       DDRB
  #define LIMIT_PIN       PINB
  #define LIMIT_PORT      PORTB
  #define X_LIMIT_BIT     1  // Uno Digital Pin 9
  #define Y_LIMIT_BIT     2  // Uno Digital Pin 10
  #define Z_LIMIT_BIT     3  // Uno Digital Pin 11
  #define LIMIT_INT       PCIE0  // Pin change interrupt enable pin
  #define LIMIT_INT_vect  PCINT0_vect 
  #define LIMIT_PCMSK     PCMSK0 // Pin change interrupt register
  #define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)) // All limit bits

  #define SPINDLE_ENABLE_DDR   DDRB
  #define SPINDLE_ENABLE_PORT  PORTB
  #define SPINDLE_ENABLE_BIT   4  // Uno Digital Pin 12

  #define SPINDLE_DIRECTION_DDR   DDRB
  #define SPINDLE_DIRECTION_PORT  PORTB
  #define SPINDLE_DIRECTION_BIT   5  // Uno Digital Pin 13 (NOTE: D13 can't be pulled-high input due to LED.)

  #define COOLANT_FLOOD_DDR   DDRC
  #define COOLANT_FLOOD_PORT  PORTC
  #define COOLANT_FLOOD_BIT   3  // Uno Analog Pin 3

  // NOTE: Uno analog pins 4 and 5 are reserved for an i2c interface, and may be installed at
  // a later date if flash and memory space allows.
  // #define ENABLE_M7  // Mist coolant disabled by default. Uncomment to enable.
  #ifdef ENABLE_M7
    #define COOLANT_MIST_DDR   DDRC
    #define COOLANT_MIST_PORT  PORTC
    #define COOLANT_MIST_BIT   4 // Uno Analog Pin 4
  #endif  

  // NOTE: All pinouts pins must be on the same port
  #define PINOUT_DDR       DDRC
  #define PINOUT_PIN       PINC
  #define PINOUT_PORT      PORTC
  #define PIN_RESET        0  // Uno Analog Pin 0
  #define PIN_FEED_HOLD    1  // Uno Analog Pin 1
  #define PIN_CYCLE_START  2  // Uno Analog Pin 2
  #define PINOUT_INT       PCIE1  // Pin change interrupt enable pin
  #define PINOUT_INT_vect  PCINT1_vect
  #define PINOUT_PCMSK     PCMSK1 // Pin change interrupt register
  #define PINOUT_MASK ((1<<PIN_RESET)|(1<<PIN_FEED_HOLD)|(1<<PIN_CYCLE_START))
  
#endif


#ifdef PIN_MAP_ARDUINO_MEGA_2560 // Working @EliteEng

  // Serial port pins
  #define SERIAL_RX USART0_RX_vect
  #define SERIAL_UDRE USART0_UDRE_vect

  // Increase Buffers to make use of extra SRAM
  #define RX_BUFFER_SIZE 256
  #define TX_BUFFER_SIZE 128
  #define BLOCK_BUFFER_SIZE 36
  #define LINE_BUFFER_SIZE 100

  // NOTE: All step bit and direction pins must be on the same port.
  #define STEPPING_DDR      DDRA
  #define STEPPING_PORT     PORTA
  #define STEPPING_PIN      PINA
  #define X_STEP_BIT        2 // MEGA2560 Digital Pin 24
  #define Y_STEP_BIT        3 // MEGA2560 Digital Pin 25
  #define Z_STEP_BIT        4 // MEGA2560 Digital Pin 26
  #define X_DIRECTION_BIT   5 // MEGA2560 Digital Pin 27
  #define Y_DIRECTION_BIT   6 // MEGA2560 Digital Pin 28
  #define Z_DIRECTION_BIT   7 // MEGA2560 Digital Pin 29
  #define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)) // All step bits
  #define DIRECTION_MASK ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)) // All direction bits
  #define STEPPING_MASK (STEP_MASK | DIRECTION_MASK) // All stepping-related bits (step/direction)

  #define STEPPERS_DISABLE_DDR   DDRB
  #define STEPPERS_DISABLE_PORT  PORTB
  #define STEPPERS_DISABLE_BIT   7 // MEGA2560 Digital Pin 13
  #define STEPPERS_DISABLE_MASK (1<<STEPPERS_DISABLE_BIT)

  // NOTE: All limit bit pins must be on the same port
  #define LIMIT_DDR       DDRB
  #define LIMIT_PORT      PORTB
  #define LIMIT_PIN       PINB
  #define X_LIMIT_BIT     4 // MEGA2560 Digital Pin 10
  #define Y_LIMIT_BIT     5 // MEGA2560 Digital Pin 11
  #define Z_LIMIT_BIT     6 // MEGA2560 Digital Pin 12
  #define LIMIT_INT       PCIE0  // Pin change interrupt enable pin
  #define LIMIT_INT_vect  PCINT0_vect 
  #define LIMIT_PCMSK     PCMSK0 // Pin change interrupt register
  #define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)) // All limit bits

  #define SPINDLE_ENABLE_DDR   DDRC
  #define SPINDLE_ENABLE_PORT  PORTC
  #define SPINDLE_ENABLE_BIT   2 // MEGA2560 Digital Pin 35

  #define SPINDLE_DIRECTION_DDR   DDRC
  #define SPINDLE_DIRECTION_PORT  PORTC
  #define SPINDLE_DIRECTION_BIT   1 // MEGA2560 Digital Pin 36

  #define COOLANT_FLOOD_DDR   DDRC
  #define COOLANT_FLOOD_PORT  PORTC
  #define COOLANT_FLOOD_BIT   0 // MEGA2560 Digital Pin 37

  // #define ENABLE_M7  // Mist coolant disabled by default. Uncomment to enable.
  #ifdef ENABLE_M7
    #define COOLANT_MIST_DDR   DDRC
    #define COOLANT_MIST_PORT  PORTC
    #define COOLANT_MIST_BIT   3 // MEGA2560 Digital Pin 34
  #endif  

  // NOTE: All pinouts pins must be on the same port
  #define PINOUT_DDR       DDRK
  #define PINOUT_PIN       PINK
  #define PINOUT_PORT      PORTK
  #define PIN_RESET        0  // MEGA2560 Analog Pin 8
  #define PIN_FEED_HOLD    1  // MEGA2560 Analog Pin 9
  #define PIN_CYCLE_START  2  // MEGA2560 Analog Pin 10
  #define PINOUT_INT       PCIE2  // Pin change interrupt enable pin
  #define PINOUT_INT_vect  PCINT2_vect
  #define PINOUT_PCMSK     PCMSK2 // Pin change interrupt register
  #define PINOUT_MASK ((1<<PIN_RESET)|(1<<PIN_FEED_HOLD)|(1<<PIN_CYCLE_START))

#endif

/* 
#ifdef PIN_MAP_CUSTOM_PROC
  // For a custom pin map or different processor, copy and paste one of the default pin map
  // settings above and modify it to your needs. Then, make sure the defined name is also
  // changed in the config.h file.
#endif
*/

#endif

pinmap中其實定義的是三種微控制器的引腳定義,具體使用哪一個在config.h中有定義,如下:
#define PIN_MAP_STM32
//#define PIN_MAP_ARDUINO_UNO

由於我修改的是STM32的,所以我額外定義了個STM32的選項,可以看到我使用的是不同通道的IO,所以定義起來就有所小不同,為了儘量少修改GRBL源程式,儘量修改定義這地方的程式碼,減少調用出程式碼的修改

stepper.c中關於引腳的初始化如下:

/ Initialize and start the stepper motor subsystem
void st_init()
{
  // Configure directions of interface pins
//  STEPPING_DDR |= STEPPING_MASK;
//  STEPPING_PORT = (STEPPING_PORT & ~STEPPING_MASK) | settings.invert_mask;
//  STEPPERS_DISABLE_DDR |= 1<<STEPPERS_DISABLE_BIT;
  //ZJK ADD FOR STEP_IO INIT 	
  GPIO_InitTypeDef GPIO_InitStructure;
  //X_STEP:PA8
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  X_STEP_PORT = (X_STEP_PORT & ~X_STEP_MASK) | (settings.invert_mask&X_STEP_MASK);
  //Y_STEP:PD15
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOD, &GPIO_InitStructure);
  Y_STEP_PORT = (Y_STEP_PORT & ~Y_STEP_MASK) | (settings.invert_mask&Y_STEP_MASK);
  //X_DIR :PA6
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  X_DIRECTION_PORT = (X_DIRECTION_PORT & ~X_DIRECTION_MASK) | (settings.invert_mask&X_DIRECTION_MASK);
  //Y_DIR :PA2
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  Y_DIRECTION_PORT = (Y_DIRECTION_PORT & ~Y_DIRECTION_MASK) | (settings.invert_mask&Y_DIRECTION_MASK);
  //X_RES :PA3
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  //Y_RES :PA4
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure); 
  //END ZJK STEPP_IO INIT
  //接下來是定時器的初始化參考:<a target=_blank href="http://blog.csdn.net/zhangjikuan/article/details/46697657">http://blog.csdn.net/zhangjikuan/article/details/46697657</a>
呼叫處如下所示:
//定時器4中斷服務函式
void TIM4_IRQHandler(void) //中斷服務函式名一定正確
{
	if(TIM4->SR&0X0001)//再次判斷是否更新事件
	{

	  // Reset stepping pins (leave the direction pins)
	  //STEPPING_PORT = (STEPPING_PORT & ~STEP_MASK) | (settings.invert_mask & STEP_MASK); 
	  X_STEP_PORT = (X_STEP_PORT & ~X_STEP_MASK) | (settings.invert_mask & X_STEP_MASK);
	  Y_STEP_PORT = (Y_STEP_PORT & ~Y_STEP_MASK) | (settings.invert_mask & Y_STEP_MASK);
	  //TCCR2B = 0; // Disable Timer2 to prevent re-entering this interrupt when it's not needed. 
	  //bit0=1關閉定時器
	  TIM4->CR1&=~0X01;
	}
	TIM4->SR&=~(1<<0); //狀態暫存器清除
}