F303K8のタイマ6を動作させています。 LED Blink work on TIM6 of F303K8
main.cpp@0:bdb2c9621ed3, 2016-07-24 (annotated)
- Committer:
- nameless129
- Date:
- Sun Jul 24 02:55:33 2016 +0000
- Revision:
- 0:bdb2c9621ed3
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nameless129 | 0:bdb2c9621ed3 | 1 | #include "mbed.h" |
nameless129 | 0:bdb2c9621ed3 | 2 | #include "stm32f3xx_hal_rcc.h" |
nameless129 | 0:bdb2c9621ed3 | 3 | #include "cmsis_nvic.h" |
nameless129 | 0:bdb2c9621ed3 | 4 | |
nameless129 | 0:bdb2c9621ed3 | 5 | DigitalOut myled(LED1); |
nameless129 | 0:bdb2c9621ed3 | 6 | static void MX_TIM6_Init(void); |
nameless129 | 0:bdb2c9621ed3 | 7 | static void MX_NVIC_Init(void); |
nameless129 | 0:bdb2c9621ed3 | 8 | |
nameless129 | 0:bdb2c9621ed3 | 9 | void TIM6_DAC1_IRQHandler2(void); |
nameless129 | 0:bdb2c9621ed3 | 10 | |
nameless129 | 0:bdb2c9621ed3 | 11 | TIM_HandleTypeDef htim6; |
nameless129 | 0:bdb2c9621ed3 | 12 | void TIM6_DAC1_IRQHandler2(void) |
nameless129 | 0:bdb2c9621ed3 | 13 | { |
nameless129 | 0:bdb2c9621ed3 | 14 | static uint8_t flag = 0; |
nameless129 | 0:bdb2c9621ed3 | 15 | myled = flag; |
nameless129 | 0:bdb2c9621ed3 | 16 | flag = !flag; |
nameless129 | 0:bdb2c9621ed3 | 17 | } |
nameless129 | 0:bdb2c9621ed3 | 18 | |
nameless129 | 0:bdb2c9621ed3 | 19 | static void MX_NVIC_Init(void) |
nameless129 | 0:bdb2c9621ed3 | 20 | { |
nameless129 | 0:bdb2c9621ed3 | 21 | /* TIM6_DAC1_IRQn interrupt configuration */ |
nameless129 | 0:bdb2c9621ed3 | 22 | HAL_NVIC_SetPriority(TIM6_DAC1_IRQn, 0, 0); |
nameless129 | 0:bdb2c9621ed3 | 23 | HAL_NVIC_EnableIRQ(TIM6_DAC1_IRQn); |
nameless129 | 0:bdb2c9621ed3 | 24 | } |
nameless129 | 0:bdb2c9621ed3 | 25 | |
nameless129 | 0:bdb2c9621ed3 | 26 | /* TIM6 init function */ |
nameless129 | 0:bdb2c9621ed3 | 27 | static void MX_TIM6_Init(void) |
nameless129 | 0:bdb2c9621ed3 | 28 | { |
nameless129 | 0:bdb2c9621ed3 | 29 | __TIM6_CLK_ENABLE(); |
nameless129 | 0:bdb2c9621ed3 | 30 | htim6.Instance = TIM6; |
nameless129 | 0:bdb2c9621ed3 | 31 | htim6.Init.Prescaler = 1; |
nameless129 | 0:bdb2c9621ed3 | 32 | htim6.Init.CounterMode = TIM_COUNTERMODE_UP; |
nameless129 | 0:bdb2c9621ed3 | 33 | htim6.Init.Period = 256; |
nameless129 | 0:bdb2c9621ed3 | 34 | if (HAL_TIM_Base_Init(&htim6) != HAL_OK) { |
nameless129 | 0:bdb2c9621ed3 | 35 | while(1) { |
nameless129 | 0:bdb2c9621ed3 | 36 | } |
nameless129 | 0:bdb2c9621ed3 | 37 | } |
nameless129 | 0:bdb2c9621ed3 | 38 | HAL_TIM_Base_Start_IT(&htim6); |
nameless129 | 0:bdb2c9621ed3 | 39 | } |
nameless129 | 0:bdb2c9621ed3 | 40 | |
nameless129 | 0:bdb2c9621ed3 | 41 | int main() |
nameless129 | 0:bdb2c9621ed3 | 42 | { |
nameless129 | 0:bdb2c9621ed3 | 43 | MX_TIM6_Init(); |
nameless129 | 0:bdb2c9621ed3 | 44 | NVIC_SetVector(TIM6_DAC1_IRQn, (uint32_t)&TIM6_DAC1_IRQHandler2); |
nameless129 | 0:bdb2c9621ed3 | 45 | MX_NVIC_Init(); |
nameless129 | 0:bdb2c9621ed3 | 46 | while(1) { |
nameless129 | 0:bdb2c9621ed3 | 47 | } |
nameless129 | 0:bdb2c9621ed3 | 48 | while(0) { |
nameless129 | 0:bdb2c9621ed3 | 49 | myled = 1; // LED is ON |
nameless129 | 0:bdb2c9621ed3 | 50 | wait(0.2); // 200 ms |
nameless129 | 0:bdb2c9621ed3 | 51 | myled = 0; // LED is OFF |
nameless129 | 0:bdb2c9621ed3 | 52 | wait(1.0); // 1 sec |
nameless129 | 0:bdb2c9621ed3 | 53 | } |
nameless129 | 0:bdb2c9621ed3 | 54 | } |