LoginSignup
4
6

More than 5 years have passed since last update.

STM32L152C-DISCOVERY + STM32CubeMX + MDK-ARM Lite で、Lチカをやってみた (その4~FreeRTOS)

Last updated at Posted at 2015-04-21

STM32CubeMXで MiddleWareとして、FreeRTOSがついてくるので、それを使って、Lチカ。

手順

  1. その2 での設定に加えて、MiddleWares -> FREERTOS -> [v]Enableにチェックして、コード生成。
  2. MDK-ARM起動
  3. ST-Link Debugger周りなどの設定を同様
  4. コードを書く
main.c
...
/* USER CODE BEGIN 0 */
#define LED_GPIO_PORT           GPIOB
#define LED_GREEN_GPIO_PIN      GPIO_PIN_7
#define LED_BLUE_GPIO_PIN       GPIO_PIN_6

// せっかくなので、Taskつくる... defaultTaskってのがあるんだけど .
osThreadId LedGreenTaskHandle;
void StartLedGreenTask(void const * argument)
{
  /* Infinite loop */
  for(;;)
  {
    HAL_GPIO_WritePin(LED_GPIO_PORT,LED_GREEN_GPIO_PIN, GPIO_PIN_SET);
    osDelay(125);
    HAL_GPIO_WritePin(LED_GPIO_PORT,LED_GREEN_GPIO_PIN, GPIO_PIN_RESET);
    osDelay(125);
  }
}

/* USER CODE END 0 */

int main(void)
{
...
...
  /* Create the thread(s) */
  /* definition and creation of defaultTask */
  osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
  defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

  /* USER CODE BEGIN RTOS_THREADS */
  /* add threads, ... */

  // LedGreenTaskをosThreadCreateする .
  osThreadDef(LedGreenTask, StartLedGreenTask, osPriorityNormal, 0, 64);
  LedGreenTaskHandle = osThreadCreate(osThread(LedGreenTask), NULL);

  /* USER CODE END RTOS_THREADS */
...
...

あとは、 Build(F7), Burn(Flash->Download), Debug Start(Ctrl+F5), Run(F5)


osThreadCreate()osDelay()は、cmsis_os.cでの定義。FreeRTOSをラップしてる。

CMSIS := The Cortex Microcontroller Software Interface Standard
http://www.keil.com/pack/doc/CMSIS/General/html/index.html

The Cortex Microcontroller Software Interface Standard (CMSIS) is a vendor-independent hardware abstraction layer for the Cortex-M processor series and defines generic tool interfaces.

4
6
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
4
6