1

Here is a "simplified blinky" example from MikroC meant to toggle the user LED at a rate that is visible to the naked eye:

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);
    }
}

The expected result of this code is that the port A5 pin (LED) will toggle at a 300ms rate. The microcontroller part is an STM32L476RG on a NUCLEO board.

The actual result is still -- nothing at all. No blinking.

I have tested the board by loading the hex file from an identical board onto it, restoring the "factory" blinking demo that responds to presses of the user button. It works. So the device is fine and the programming process is working.

I have stepped through the code in the debugger and watched GPIOA_ODR register toggle just as intended.

My Scheme, created by using the "Default" button, running the core at 4 MHZ from from the MSI internal oscillator, is as follows:

<?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>

Question: What is wrong with this default scheme or this simple code that prevents this from working?

N.B. I have chosen the MikroC tag even though this is an STM32 part. The definition for the MikroC tag is incorrectly specific to PIC devices.

When I contacted the vendor about this problem, they gave me a scheme file to load. I attempted to load it but it wouldn't even load. It had some spelling errors. After correcting them based on the default scheme above, the example still didn't work. They had chosen many non-default settings. My rationale is that if I'm using the default (MSI) clock and default scheme, I should at least be able to get the part to run at 4MHz and have a successful starting point for further improvements.

Finally, the configuration register values from the project configurator are as follows:

RCC_CR      : $40021000 : 0x00000061
RCC_CFGR    : $40021008 : 0x00000000
RCC_PLLCFGR : $4002100C : 0x00001000
RCC_CSR     : $40021094 : 0x00000600
PWR_CR1     : $40007000 : 0x00000200
TomServo
  • 7,248
  • 5
  • 30
  • 47
  • The listing exceeds the posting size limit for questions by a large margin. I cannot post the listing. – TomServo Jan 12 '18 at 18:08

1 Answers1

3

GPIO_Digital_Output() configures the pin as a output but it may not enable the clock to the GPIO peripheral. Try adding a call to GPIO_Clk_Enable(&GPIOC_BASE).

kkrambo
  • 6,643
  • 1
  • 17
  • 30
  • If that is true for this library then there you go. bit 2 of RCC_AHB2ENR 0x4002104C. – old_timer Jan 12 '18 at 19:23
  • 1
    Step through the code in the debugger. Does execution reach main? Does the ODR register toggle like you expect? – kkrambo Jan 13 '18 at 13:38
  • How are you observing the pin toggling? The delay of 1 ms is short so the pin may be toggling too fast for you to see. I doubt you'd be able to see an LED flash at that rate, for example. – kkrambo Jan 13 '18 at 13:43
  • I am checking for pin toggle on my oscilloscope. Duration of the delay makes no difference so far. – TomServo Jan 13 '18 at 22:29
  • +1 for being part of the necessary answer, from the few examples I've seen. But still no luck after enabling the clock on the port (see current code edit). – TomServo Jan 15 '18 at 15:06