Use of Gpio:
Turn on the GPIO clock according to the manual register map to see on which bus, set a GPIO_INITTYPEDEF structure variable, according to the actual changes in the structure of each assignment, Gpio_init (gpio_typedef* gpiox, Gpio_ inittypedef* gpio_initstruct), the initialization is set.
Application-specific read-write direct call
/* GPIO Read and Write functions **********************************************/
uint8_t gpio_readinputdatabit (gpio_typedef* gpiox, uint16_t gpio_pin);
uint16_t Gpio_readinputdata (gpio_typedef* gpiox);
uint8_t gpio_readoutputdatabit (gpio_typedef* gpiox, uint16_t gpio_pin);
uint16_t Gpio_readoutputdata (gpio_typedef* gpiox);
void Gpio_setbits (gpio_typedef* gpiox, uint16_t gpio_pin);
void Gpio_resetbits (gpio_typedef* gpiox, uint16_t gpio_pin);
void Gpio_writebit (gpio_typedef* gpiox, uint16_t gpio_pin, bitaction bitval);
void Gpio_write (gpio_typedef* gpiox, uint16_t portval);
void Gpio_togglebits (gpio_typedef* gpiox, uint16_t gpio_pin);
Interrupt on pin level change on Exti peripheral:
First set the Gpio, remember pupd set as floating empty gpio_pupd_nopull;
Exti_inittypedef exti_keyscan_struct;
/*enable syscfg clock*/
Rcc_apb2periphclockcmd (rcc_apb2periph_syscfg,enable);
/*select pa0*/
Syscfg_extilineconfig (EXTI_PORTSOURCEGPIOA,EXTI_PINSOURCE0);
/*specifies the Exti lines to be enabled or Disabled.select exti0*/
Exti_keyscan_struct.exti_line = EXTI_LINE0;
/*specifies the new state of the selected Exti lines.*/
Exti_keyscan_struct.exti_linecmd = ENABLE;
/*specifies the mode for the Exti lines.set mode to intterrupt*/
Exti_keyscan_struct.exti_mode = Exti_mode_interrupt;
/*specifies the trigger signal active edge for the Exti lines.*/
Exti_keyscan_struct.exti_trigger = exti_trigger_rising;
Exti_init (&exti_keyscan_struct);
/* This section sets the interrupt priority, here I write a random, priority group is 0, preemption priority is 0, secondary priority is 1*/
Nvic_inittypedef nvic_initstruct;
/*configures the priority grouping:pre-emption and subpriority.*/
Nvic_prioritygroupconfig (nvic_prioritygroup_1);
/*!< Specifies the IRQ channel to is enabled or disabled. This parameter can is a enumerator of @ref Irqn_type enumeration (for the complete STM32 Devices IRQ Channels
List, refer to stm32f4xx.h file) */
Nvic_initstruct.nvic_irqchannel = exti0_irqn;//stm32f4xx Interrupt number Definition
/*!< Specifies whether the IRQ channel defined in Nvic_irqchannel would be enabled or disabled. This parameter can is set either to ENABLE or DISABLE */
Nvic_initstruct.nvic_irqchannelcmd = ENABLE;
/*!< Specifies the pre-emption priority for the IRQ channel specified in Nvic_irqchannel. This parameter can is a value between 0 and as described in the table @ref misc_nvic_priority_table
A lower priority value indicates a higher priority */
nvic_initstruct.nvic_irqchannelpreemptionpriority = 0;
/*!< Specifies the subpriority level for the IRQ channel specified in Nvic_irqchannel. This parameter can is a value between 0 and as described in the table @ref misc_nvic_priority_table
A lower priority value indicates a higher priority */
nvic_initstruct.nvic_irqchannelsubpriority = 1;
Nvic_init (&nvic_initstruct);
And then it's the interrupt function.
void Exti0_irqhandler (void)//The name cannot be changed, otherwise it goes into the part of the startup file that breaks the weak definition.
{
if ((Exti_getitstatus (EXTI_LINE0))!=reset)//See if it's really broken.
{
Why are you doing this?
}
Exti_clearitpendingbit (EXTI_LINE0);//Clear the mark before the break
}
SysTick:
This is in the kernel, CORE-M4 Universal;
Just call this function to configure __static_inline uint32_t systick_config (uint32_t ticks)
void Init_systick (uint32_t time)
{
/*systemcoreclock = 180mhz 1/time s interrupt*/
if (Systick_config (Systemcoreclock/time)) while (1);
}
void Delay_ms (uint32_t TIME0)
{
Delaytime = TIME0;
while (Delaytime! = 0);
}
The interruption is pre-written, so fill it in.
void Systick_handler (void)
{
if (delaytime!=0)
{
delaytime--;
}
}
STM32 Learning 2 (GPIO Exti SYSTICK)