2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Nucleo-F303K8 PIO STM32 でLチカ

Last updated at Posted at 2021-09-11

Nucleo-F303K8
VScode + PlatformIO
framework は stm32cube を頑張って使ってみる。

サンプルを修正して使う場合

サンプルコードを普通に手に入れて実行するけど,Lチカしない... 当たり前だよね... 以下の通り変更。

platformio.ini
[platformio]
default_envs = nucleo_f303k8

[env:nucleo_f303k8]
platform = ststm32
framework = stm32cube
board = nucleo_f303k8
build_flags = -DF3

ビルド対象を nucleo_f303k8 にセット。

次に main.c で,LEDの定義を変更。PB3に修正。

main.c
#define LED_PIN                                GPIO_PIN_3
#define LED_GPIO_PORT                          GPIOB
#define LED_GPIO_CLK_ENABLE()                  __HAL_RCC_GPIOB_CLK_ENABLE()

image.png

できた!

簡略化してみた

platformio.ini はそのままでも...

main.c
#include "stm32f3xx_hal.h"

void SysTick_Handler(void)
{
  HAL_IncTick();
}

int main(void)
{
  HAL_Init();

  // init PB3

  __HAL_RCC_GPIOB_CLK_ENABLE();
  GPIO_InitTypeDef GPIO_InitStruct;
  GPIO_InitStruct.Pin = GPIO_PIN_3;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  while (1)
  {
    HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_3);
    HAL_Delay(1000);
  }
}

#おまけ

普通にデバッグできる。素晴らしすぎ。

PERIPHERALSを展開していくと,レジスターが見える。以下はGPIOB - ODR3 が 1 つまりLEDが点灯しているところ。

image.png

2
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?