I-O DATA DEV2 / Mbed 2 deprecated MCU-STDY2

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 //勉強会
00003 //STM32 L0 GPIO定義 address 0x5000 0000
00004 // __IO は     volatile 
00005 // uint32_t は  unsigned long 
00006  struct GPIO_
00007 {
00008   __IO uint32_t MODER;       /*!< GPIO port mode register,               Address offset: 0x00      */
00009   __IO uint32_t OTYPER;      /*!< GPIO port output type register,        Address offset: 0x04      */
00010   __IO uint32_t OSPEEDR;     /*!< GPIO port output speed register,       Address offset: 0x08      */
00011   __IO uint32_t PUPDR;       /*!< GPIO port pull-up/pull-down register,  Address offset: 0x0C      */
00012   __IO uint32_t IDR;         /*!< GPIO port input data register,         Address offset: 0x10      */
00013   __IO uint32_t ODR;         /*!< GPIO port output data register,        Address offset: 0x14      */
00014   __IO uint32_t BSRR;        /*!< GPIO port bit set/reset  register,     Address offset: 0x18      */
00015   __IO uint32_t LCKR;        /*!< GPIO port configuration lock register, Address offset: 0x1C      */
00016   __IO uint32_t AFR[2];      /*!< GPIO alternate function registers,     Address offset: 0x20-0x24 */
00017   __IO uint32_t BRR;         /*!< GPIO Bit Reset register,               Address offset: 0x28      */
00018 };
00019 typedef struct  GPIO_ GPIO_T;
00020 
00021 DigitalOut myled(LED1);
00022 
00023 int main() {
00024     int i=0;
00025     GPIO_T *pGPIO = (GPIO_T *)0x50000000;    //GPIO A base address
00026     printf("\r\nGPIO Struct TEST\r\n");     
00027     while(1) { 
00028       wait(1);
00029 ///      myled = !myled;
00030 #if 0
00031       //LED port is GPIO_A bit 5
00032       if (i&1) 
00033         //pGPIO->ODR??; 
00034       else 
00035         //pGPIO->ODR??; 
00036 #else
00037       if (i&1) 
00038         pGPIO->BSRR = 0x20; //GPIO A BIT5 reset 
00039       else 
00040         pGPIO->BRR = 0x20 ; ////GPIO A BIT5 set
00041 
00042 #endif        
00043      i++;      
00044     }
00045 }