test gpio and access low level arm registers

Dependencies:   libmDot mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "rtos.h"
00003 #include "mDot.h"
00004 
00005 
00006 #define GPIO_PORT   PA_0
00007 
00008 RawSerial pc(PA_2,NC);
00009 
00010 // results:
00011 //              default  pullup  pulldown  pullnone  open drain
00012 // battery + close 0.00    0.00      0.00      0.00        0.00
00013 // battery + open  1.55    3.01      0.01  drifting    drifting
00014 // mdk + open      0.00    0.00      0.00      0.00        0.00
00015 // mdk + close     3.30    3.21      2.26      3.12        3.30
00016 //
00017 // conclusion: mdk has something connected to PA_0
00018 
00019 // https://developer.mbed.org/users/n0tform3/code/HelloWorld_IKS01A1/docs/1c6281289d67/stm32f4xx_8h_source.html
00020 
00021 
00022 void print_gpio_pa0_config(void) {
00023 
00024         pc.printf("MODER %x\r\n",GPIOA->MODER&0x3);
00025         pc.printf("OTYPER %x\r\n",GPIOA->OTYPER&0x1);
00026         pc.printf("OSPEEDR %x\r\n",GPIOA->OSPEEDR&0x3);
00027         pc.printf("PUPDR %x\r\n",GPIOA->PUPDR&0x3);
00028         pc.printf("IDR %x\r\n",GPIOA->IDR&0x1);
00029         pc.printf("ODR %x\r\n",GPIOA->ODR&0x1);
00030         pc.printf("BSRR %x\r\n",GPIOA->BSRR&0x1);
00031         pc.printf("LCKR %x\r\n",GPIOA->LCKR&0x1);
00032         pc.printf("AFR[0] %x\r\n",GPIOA->AFR[0]&0xf);
00033 }
00034     
00035 main() {
00036     
00037    pc.baud(115200);
00038     
00039     pc.printf("Build: " __DATE__ ", " __TIME__"\r\n");
00040     
00041     DigitalIn gpio_sensor(GPIO_PORT);
00042     pc.printf("pin mode: default\r\n");
00043     print_gpio_pa0_config();
00044     wait(10);
00045     
00046     // uint32_t lock = GPIOA->LCKR;
00047     // pc.printf("Read %x\r\n",lock);
00048     
00049     while(1) {
00050          
00051          gpio_sensor.mode(PullUp);
00052          pc.printf("pin mode: pullup\r\n");
00053          print_gpio_pa0_config();
00054          wait(10);
00055         
00056          gpio_sensor.mode(PullDown);
00057          pc.printf("pin mode: pulldown\r\n");
00058          print_gpio_pa0_config();
00059          wait(10);
00060          
00061          gpio_sensor.mode(PullNone);
00062          pc.printf("pin mode: pullnone\r\n");
00063          print_gpio_pa0_config();
00064          wait(10);
00065          
00066          gpio_sensor.mode(OpenDrain);
00067          pc.printf("pin mode: opendrain\r\n");
00068          print_gpio_pa0_config();
00069          wait(10);
00070     }
00071 }