Monday, April 16, 2012

ARM STM32 Study Note_1/GPIO

Experiment 1. LED

* GPIO in STM32 has 8 modes, it is an enum variable defined in the stm32f10x_gpio.h
    typedef enum
    { GPIO_Mode_AIN = 0x0,
      GPIO_Mode_IN_FLOATING = 0x04,
      GPIO_Mode_IPD = 0x28,
      GPIO_Mode_IPU = 0x48,
      GPIO_Mode_Out_OD = 0x14,
      GPIO_Mode_Out_PP = 0x10,
      GPIO_Mode_AF_OD = 0x1C,
      GPIO_Mode_AF_PP = 0x18
    }GPIOMode_TypeDef;

* Before use GPIO, have to define the mode and speed
 
   GPIO_Speed_10MHz Output Maximum Frequency = 10 MHz

   GPIO_Speed_2MHz Output Maximum Frequency = 2 MHz
   GPIO_Speed_50MHz Output Maximum Frequency = 50 MHz
  
   typedef enum
  {
    GPIO_Speed_10MHz = 1,
    GPIO_Speed_2MHz,
    GPIO_Speed_50MHz
  }GPIOSpeed_TypeDef;

 


* Both Pin,speed and mode is in one structure defined in the stm32f10x_gpio.h
  typedef struct
 {
  u16 GPIO_Pin;
  GPIOSpeed_TypeDef GPIO_Speed;
  GPIOMode_TypeDef GPIO_Mode;
  } GPIO_InitTypeDef;

-Note:
 *RCC: Reset AND Clock Controler
 *There are three internal busses:
    -Advanced High Performance Bus (AHB)
    -Low speed Advanced Peripherial Bus (APB1)
    -High speed Advanced Peripherial Bus (APB2)

* RCC_APB2Periph_GPIOD => IO port D clock
 




* GPIO_Init function
 


* GPIO register structure


* GPIO_ResetBits/GPIO_SetBits




* Basic Variables 
  typedef unsigned long  u32;
  typedef unsigned short u16;
  typedef unsigned char  u8;
 
  #define     __IO    volatile                  /*!< defines 'read / write' permissions   */
 
  typedef unsigned           int uint32_t;     //in the stdint.h
 

* File Structure



Questions:
1. what is RCC_APB2Periph_AFIO, and how to use it?
 









No comments:

Post a Comment