LoginSignup
0
0

More than 5 years have passed since last update.

stm32f4-discoveryの作法 その5

Last updated at Posted at 2019-03-14

概要

stm32f4-discoveryの作法、調べてみた。
microsを、実装。

写真

image

サンプルコード

#include <stdio.h>
#include "stm32f4_discovery.h"
#include "printk.h"

volatile uint64_t ksystick;
uint64_t micros(void)
{
    return ksystick;
}
void SysTick_Handler(void)
{
    ksystick++;
    if (GPIO_ReadOutputDataBit(GPIOD, GPIO_Pin_15) == Bit_SET)
    {
        GPIO_ResetBits(GPIOD, GPIO_Pin_15);
    }
    else
    {
        GPIO_SetBits(GPIOD, GPIO_Pin_15);
    }
}
void delay(__IO uint32_t nCount)
{
    while(nCount--)
    {
    }
}
int main(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 |GPIO_Pin_13 | GPIO_Pin_14 |GPIO_Pin_15;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_Init(GPIOD, &GPIO_InitStructure);
    GPIO_ResetBits(GPIOD,GPIO_Pin_12 |GPIO_Pin_13 | GPIO_Pin_14 |GPIO_Pin_15);
    static char out[20];
    RCC_ClocksTypeDef RCC_Clocks;
    RCC_GetClocksFreq(&RCC_Clocks);
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000000);
    init_usart();
    while (1)
    {
        sprintf(out, "%d\r\n", micros());
        printk(out);
        printk(" ok\r\n");
        delay(0xFFFFFF);
    }
}




以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0