The. Net Micro Framework Portingkit

Source: Internet
Author: User

It should be easier to turn on the LED lights or get input IO status, open the port clock, and then read and write the relevant GPIO registers, but it will take some trouble to implement an input interrupt.

For STM32 (CORTEX-M3) chip, to achieve a GPIO interrupt generally requires the following steps:

1, configure the Clock Controller register (RCC) of the APB2RSTR, to ensure that the corresponding GPIOA ~ Gpiog clock to enable.

2. To set the correct input mode for the CRL (or CRH) of the Gpio register, such as the float input mode (which, of course, is set to input mode for receiving IO interrupts).

3, to pass the AFIO register interrupt input source, for the STM32 chip, with 19-way Exti, of which 3 are respectively connected to the PVD output, RTC Alarm events and USB wake-up events, the rest of the Gpioa ~ Gpiog 7*16=112 io point, Only 16-way IO input interrupts can be configured at the same time.

4, next to configure the exit register, according to the need to configure whether the rise along the trigger interrupt, or drop along the trigger interrupt or both trigger.

5, then more importantly, to configure the Nvic Setena registers, so that the corresponding EXTI0, EXTI1, EXTI2, EXTI3, EXTI4, exti9_5 or exti15_10 interrupt bit enabled, In addition, the priority of each interrupt is configured (provided that the interrupt Priority grouping register is configured to complete).

6, finally we want to set the interrupt vector table (the vector table to be relocated to memory, so as to facilitate dynamic modification), in the EXTI0, EXTI1, EXTI2, EXTI3, EXTI4, exti9_5 or exti15_10 the corresponding location, put our interrupt function of the entry address.

and PC platform program Development is different, basically you every step, can be very intuitive to see your progress and results, but for embedded development, if the above steps have any one aspect of the problem, your progress is zero, sometimes you will spend a day to repeatedly verify the value of each register is correct, In order to get the results you want. So the embedded development is the type of surprise, or into, or not, a gleam of the separation!

Let's talk about the detailed steps of the GPIO implementation, first adding the GPIO-related register description in the CortexM3.h header file:

struct Cortexm3_gpio
{
Static const UINT32 c_base = 0x40010800;
static const UINT32 A = 0;
Static const UINT32 B = 1;
Static const UINT32 C = 2;
Static const UINT32 D = 3;
Static const UINT32 E = 4;
Static const UINT32 F = 5;
Static const UINT32 G = 6;
Static const UINT32 gpio_mode_null = 0x00;
Static const UINT32 Gpio_mode_speed_10mhz = 0x01;
Static const UINT32 Gpio_mode_speed_2mhz = 0x02;
Static const UINT32 Gpio_mode_speed_50mhz = 0x03;
Static const UINT32 gpio_mode_in_floating = 0x04;  
/****/volatile UINT32 CRL;//configuration Register
/****/volatile UINT32 CRH;
 /****/volatile UINT32 IDR;   Data register
/****/volatile UINT32 ODR;
 /****/volatile UINT32 BSRR; Place reset registers
/****/volatile UINT32 BRR;//Reset registers
/****/volatile UINT32 lckr;//Lock Register
};
struct Corte   Xm3_exti
{
Static const UINT32 c_base = 0x40010400;
/****/volatile UINT32 IMR
/****/volatile UINT32 EMR;
/****/volatile UINT32 RTSR;
/****/volatile UINT32 FTSR;
/****/volatile UINT32 swier;
/****/volatile UINT32 PR;
};  
struct Cortexm3_afio
{
Static const UINT32 c_base = 0x40010000;
/****/volatile UINT32 EVCR;
/****/volatile UINT32 mapr;
/****/volatile UINT32 exticr[4];
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.