LoginSignup
1
1

More than 5 years have passed since last update.

STM32L152C-DISCOVERY + STM32CubeMX + MDK-ARM Lite で、Lチカをやってみた (その3~Lチカコード実行)

Last updated at Posted at 2015-04-21

MDK-ARM - Lチカコードをかく。

  1. 左のプロジェクトから、main.cを開く。(Project: Test01 -> Test01 Configuration -> Application/User)
  2. 下にスクロールしていくと、int main(void)が現れ、 その中に while (1)が出てくる。
  3. 下のように、コードを記述。(/* USER CODE BEGIN 3 */ から /* USER CODE END 3 */の間にユーザコードを書くといいんだろう。)
main.c
...
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
    #define LED_GPIO_PORT         GPIOB
    #define LED_GREEN_GPIO_PIN    GPIO_PIN_7
    #define LED_BLUE_GPIO_PIN     GPIO_PIN_6
    HAL_GPIO_WritePin(LED_GPIO_PORT, LED_GREEN_GPIO_PIN, GPIO_PIN_SET);
    HAL_Delay(125);
    HAL_GPIO_WritePin(LED_GPIO_PORT, LED_GREEN_GPIO_PIN, GPIO_PIN_RESET);
    HAL_Delay(125);

  }
  /* USER CODE END 3 */

}
...

Build、Burn, Debug Run

  1. Project -> Build target (F7)

  2. Flash -> Download (Erase => Program -> Verify ってのがステータスバーに現れる)

  3. Debug -> Start/Stop Debug Session (Ctrl+F5) # Evaluationだよ、ってDialogで、[OK]

  4. mainの一行目で、Breakしてとまる。

  5. Debug->Run(F5) で実行 => ボードの緑のLEDがちかちかする。

  6. # ショートカットキー Run(F5), Step(F11), Step Over(F10), Step Out(Ctrl+F11), Run to Cursor Line(Ctrl+F10)

build.log
Build target 'Test01 Configuration'
compiling system_stm32l1xx.c...
assembling startup_stm32l152xc.s...
compiling stm32l1xx_hal_lcd.c...
compiling stm32l1xx_hal_flash_ex.c...
compiling stm32l1xx_hal_pwr.c...
compiling stm32l1xx_hal_flash_ramfunc.c...
compiling stm32l1xx_hal_dma.c...
compiling stm32l1xx_hal.c...
compiling stm32l1xx_hal_rcc_ex.c...
compiling stm32l1xx_hal_rcc.c...
compiling stm32l1xx_hal_flash.c...
compiling stm32l1xx_hal_adc_ex.c...
compiling stm32l1xx_hal_cortex.c...
compiling stm32l1xx_hal_gpio.c...
compiling stm32l1xx_hal_adc.c...
compiling stm32l1xx_hal_pwr_ex.c...
compiling main.c...
compiling stm32l1xx_it.c...
compiling stm32l1xx_hal_msp.c...
linking...
Program Size: Code=7236 RO-data=356 RW-data=36 ZI-data=1156  
FromELF: creating hex file...
"Test01 Configuration\Test01 Configuration.axf" - 0 Error(s), 0 Warning(s).
Build Time Elapsed:  00:00:06
1
1
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
1
1