STM32 blinky示例不起作用

时间:2018-01-12 17:41:07

标签: embedded stm32 mikroc

以下是MikroC的“简化眨眼”示例,旨在以肉眼可见的速度切换用户LED:

void main()
{
    GPIO_Clk_Enable(&GPIOA_BASE);
    GPIO_Digital_Output(&GPIOA_BASE, _GPIO_PINMASK_5);
    GPIOA_ODR |= (1<<_GPIO_PIN_5);
    while(1)
    {
      GPIOA_ODR ^= (1<<_GPIO_PIN_5);
      Delay_ms(300);
    }
}

此代码的预期结果是端口A5引脚(LED)将以300ms的速率切换。微控制器部分是NUCLEO板上的STM32L476RG。

实际结果仍然是 - 什么都没有。没有眨眼。

我已经通过从同一块板上加载hex文件来测试电路板,恢复“工厂”闪烁演示,响应按下用户按钮。有用。所以设备很好,编程过程正常。

我已经调试了调试器中的代码并观察了GPIOA_ODR寄存器是否按预期切换。

我的方案是使用“默认”按钮创建的,从MSI内部振荡器以4 MHZ运行核心,如下所示:

<?xml version="1.0"?>
<MCU_DEVICE_FLAGS>
  <DEVICE>
    <DEVICE_NAME>STM32L476RG</DEVICE_NAME>
    <SETTINGS>
      <COUNT>32</COUNT>
      <SETTING0>
        <NAME>MSI clock enable</NAME>
        <DESCRIPTION>MSI oscillator ON</DESCRIPTION>
      </SETTING0>
      <SETTING1>
        <NAME>MSI clock PLL enable</NAME>
        <DESCRIPTION>MSI PLL OFF</DESCRIPTION>
      </SETTING1>
      <SETTING2>
        <NAME>MSI clock range selection</NAME>
        <DESCRIPTION>MSI Range is provided in RCC_CSR register</DESCRIPTION>
      </SETTING2>
      <SETTING3>
        <NAME>MSI clock ranges in RCC_CR register</NAME>
        <DESCRIPTION>range 6 around 4MHz</DESCRIPTION>
      </SETTING3>
      <SETTING4>
        <NAME>HSI clock enable</NAME>
        <DESCRIPTION>HSI16 oscillator OFF</DESCRIPTION>
      </SETTING4>
      <SETTING5>
        <NAME>HSI16 always enable for peripheral kernels</NAME>
        <DESCRIPTION>No effect on HSI16 oscillator</DESCRIPTION>
      </SETTING5>
      <SETTING6>
        <NAME>HSI16 automatic start from Stop</NAME>
        <DESCRIPTION>HSI16 oscillator is not enabled by hardware when exiting Stop mode with MSI as wakeup clock</DESCRIPTION>
      </SETTING6>
      <SETTING7>
        <NAME>HSE clock enable</NAME>
        <DESCRIPTION>HSE oscillator OFF</DESCRIPTION>
      </SETTING7>
      <SETTING8>
        <NAME>HSE crystal oscillator bypass</NAME>
        <DESCRIPTION>HSE crystal oscillator not bypassed</DESCRIPTION>
      </SETTING8>
      <SETTING9>
        <NAME>Clock security system enable</NAME>
        <DESCRIPTION>Clock security system OFF</DESCRIPTION>
      </SETTING9>
      <SETTING10>
        <NAME>Main PLL enable</NAME>
        <DESCRIPTION>PLL OFF</DESCRIPTION>
      </SETTING10>
      <SETTING11>
        <NAME>SAI1 PLL enable</NAME>
        <DESCRIPTION>PLLSAI1 OFF</DESCRIPTION>
      </SETTING11>
      <SETTING12>
        <NAME>SAI2 PLL enable</NAME>
        <DESCRIPTION>PLLSAI2 OFF</DESCRIPTION>
      </SETTING12>
      <SETTING13>
        <NAME>System clock switch</NAME>
        <DESCRIPTION>MSI selected as system clock</DESCRIPTION>
      </SETTING13>
      <SETTING14>
        <NAME>Set and cleared by software to control the division factor of the AHB clock</NAME>
        <DESCRIPTION>SYSCLK not divided</DESCRIPTION>
      </SETTING14>
      <SETTING15>
        <NAME>APB low-speed prescaler (APB1)</NAME>
        <DESCRIPTION>HCLK not divided </DESCRIPTION>
      </SETTING15>
      <SETTING16>
        <NAME>APB high-speed prescaler (APB2)</NAME>
        <DESCRIPTION>HCLK not divided </DESCRIPTION>
      </SETTING16>
      <SETTING17>
        <NAME>Wakeup from Stop and CSS backup clock selection</NAME>
        <DESCRIPTION>MSI oscillator selected as wakeup from stop clock and CSS backup clock</DESCRIPTION>
      </SETTING17>
      <SETTING18>
        <NAME>Microcontroller clock output</NAME>
        <DESCRIPTION>MCO output disabled, no clock on MCO</DESCRIPTION>
      </SETTING18>
      <SETTING19>
        <NAME>Microcontroller clock output prescaler</NAME>
        <DESCRIPTION>MCO is divided by 1</DESCRIPTION>
      </SETTING19>
      <SETTING20>
        <NAME>Main PLL, PLLSAI1 and PLLSAI2 entry clock source</NAME>
        <DESCRIPTION>No clock sent to PLL, PLLSAI1 and PLLSAI2</DESCRIPTION>
      </SETTING20>
      <SETTING21>
        <NAME>Division factor for the main PLL and audio PLL (PLLSAI1 and PLLSAI2) input clock</NAME>
        <DESCRIPTION>PLLM = 1</DESCRIPTION>
      </SETTING21>
      <SETTING22>
        <NAME>Main PLL multiplication factor for VCO</NAME>
        <DESCRIPTION>16</DESCRIPTION>
      </SETTING22>
      <SETTING23>
        <NAME>Main PLL PLLSAI3CLK output enable</NAME>
        <DESCRIPTION>PLLSAI3CLK output disable</DESCRIPTION>
      </SETTING23>
      <SETTING24>
        <NAME>Main PLL division factor for PLLSAI3CLK (SAI1 and SAI2 clock)</NAME>
        <DESCRIPTION>PLLP = 7</DESCRIPTION>
      </SETTING24>
      <SETTING25>
        <NAME>Main PLL PLL48M1CLK output enable</NAME>
        <DESCRIPTION>PLL48M1CLK output disable</DESCRIPTION>
      </SETTING25>
      <SETTING26>
        <NAME>Main PLL division factor for PLL48M1CLK (48 MHz clock)</NAME>
        <DESCRIPTION>PLLQ = 2</DESCRIPTION>
      </SETTING26>
      <SETTING27>
        <NAME>Main PLL PLLCLK output enable</NAME>
        <DESCRIPTION>PLLCLK output disable</DESCRIPTION>
      </SETTING27>
      <SETTING28>
        <NAME>Main PLL division factor for PLLCLK (system clock)</NAME>
        <DESCRIPTION>PLLR = 2</DESCRIPTION>
      </SETTING28>
      <SETTING29>
        <NAME>LSI oscillator enable</NAME>
        <DESCRIPTION>LSI oscillator OFF</DESCRIPTION>
      </SETTING29>
      <SETTING30>
        <NAME>MSI range after Standby mode (RCC_CSR)</NAME>
        <DESCRIPTION>Range 6 around 4 MHz (reset value)</DESCRIPTION>
      </SETTING30>
      <SETTING31>
        <NAME>Core Voltage</NAME>
        <DESCRIPTION>VCORE = 1.2 V</DESCRIPTION>
      </SETTING31>
    </SETTINGS>
  </DEVICE>
</MCU_DEVICE_FLAGS>

问题:此默认方案或此简单代码无法解决此问题?

N.B。我选择了MikroC标签,即使这是STM32部件。 MikroC标签的定义错误地特定于PIC设备。

当我与供应商联系有关此问题时,他们给了我一个方案文件来加载。我试图加载它,但它甚至不会加载。它有一些拼写错误。根据上面的默认方案更正后,该示例仍然无法正常工作。他们选择了许多非默认设置。我的理由是,如果我使用默认(MSI)时钟和默认方案,我至少应该能够让器件以4MHz的频率运行,并有一个成功的起点进行进一步的改进。

最后,项目配置器中的配置寄存器值如下:

RCC_CR      : $40021000 : 0x00000061
RCC_CFGR    : $40021008 : 0x00000000
RCC_PLLCFGR : $4002100C : 0x00001000
RCC_CSR     : $40021094 : 0x00000600
PWR_CR1     : $40007000 : 0x00000200

1 个答案:

答案 0 :(得分:3)

GPIO_Digital_Output()将引脚配置为输出,但可能无法启用GPIO外设的时钟。尝试添加对GPIO_Clk_Enable(&GPIOC_BASE)的调用。