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

STM32L010とGPIOで約800khz(1.25us)を作る(節電4MHz内部電圧1.5V) HAL

Posted at

STM32L010とGPIOで約800khz(1.25us)を作る(節電4MHz内部電圧1.5V) HAL

x Mbedのリビジョン143

目的
GPIOのテスト

いろいろ
ごめん、当然、速度が上がらなかった。
667kHzで妥協
たぶん、秋月で買ったWS2812Bは、光るはず。
俺に続け!!
LED1個分(約5mA)を努力の結果、節電 ボタ電駆動できるかも?
VSCのcubeideに移植できるかも?



/* STM32L010F6P6  -> Mbed NUCLEO-L011K4 program by caa45040 */

//IO Sppd is The 667.53kHz (1.499us)

# include "mbed.h"

# define on1   0b0000000000010000
# define off1  0b0000000000000000

//DigitalOut myled(PA_4);

int main() {

    //クロックの初期化
    HAL_RCC_DeInit();

    //電圧を下げる
    __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);//4Mhz 1.5 560uA

    /* 4MHz */
    RCC_OscInitTypeDef RCC_OscInitStruct = {0};
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
    RCC_OscInitStruct.HSIState = RCC_HSI_DIV4;
    RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
    HAL_RCC_OscConfig(&RCC_OscInitStruct);
    RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                                  |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
    HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);

    /* PA4 OUTPUT MODE */
    __HAL_RCC_GPIOA_CLK_ENABLE();
    GPIO_InitTypeDef GPIO_InitStruct = {0};
    GPIO_InitStruct.Pin = GPIO_PIN_4;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    __disable_irq(); // disable interrupt
    //__enable_irq(); // enable interrupt

   //1:1
    while(1) {

        //1
        GPIOA->ODR = on1;
        GPIOA->ODR = on1;
        GPIOA->ODR = on1;

        GPIOA->ODR = off1;
        GPIOA->ODR = off1;


        //2
        GPIOA->ODR = on1;
        GPIOA->ODR = on1;

        GPIOA->ODR = off1;
        GPIOA->ODR = off1;
        GPIOA->ODR = off1;



    }//while

}//main


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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?