0
\$\begingroup\$

I have a stm32f051R8T6 Discovery board, and I compiled a simple blinking LED code to activate the LED's on the board itself. The code builds successfully and flashes the MCU but the MCU won't execute the code, I have reset it and tried programming it with a different code which worked in the past but still no luck, I am working in Coocox.

Once I have the hex file I flash the MCU with either the STM32 st-link unity or Coocox itself and both say it flashes successfully

I think the MCU is held under reset but I'm not sure and I don't know how to get it out.

THe link to the manual is here: http://www.st.com/content/ccc/resource/technical/document/user_manual/30/ae/6e/54/d3/b6/46/17/DM00050135.pdf/files/DM00050135.pdf/jcr:content/translations/en.DM00050135.pdf

Code is Below

#include "stm32f0xx.h"

void delay(const int d);

int main(void)
{
  // GPIOC Periph clock enable
  RCC->AHBENR |= RCC_AHBENR_GPIOCEN;

  // PC8 and PC9 in output mode
  GPIOC->MODER |= (GPIO_MODER_MODER8_0 | GPIO_MODER_MODER9_0);

  // Push pull mode selected
  GPIOC->OTYPER &= ~(GPIO_OTYPER_OT_8 | GPIO_OTYPER_OT_9);

  // Maximum speed setting
  GPIOC->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR8 | GPIO_OSPEEDER_OSPEEDR9);

  // Pull-up and pull-down resistors disabled
  GPIOC->PUPDR &= ~(GPIO_PUPDR_PUPDR8 | GPIO_PUPDR_PUPDR9);

  while(1)
  {
    // Set PC9
    GPIOC->BSRR = GPIO_BSRR_BS_9;
    // Reset PC8
    GPIOC->BSRR = GPIO_BSRR_BR_8;
    // Delay ~ 1 sec.
    delay(SystemCoreClock/8);

    // Reset PC9
    GPIOC->BSRR = GPIO_BSRR_BR_9;
    // Set PC8
    GPIOC->BSRR = GPIO_BSRR_BS_8;
    // Delay ~ 1 sec.
    delay(SystemCoreClock/8);
  }
}

void delay(const int d)
{
  volatile int i;

  for(i=d; i>0; i--){ ; }

  return;
}
\$\endgroup\$
3
  • \$\begingroup\$ What kind of debug equipment do you have? Multimeter? Oscilloscope? Logic analyzer? \$\endgroup\$
    – pipe
    Commented May 9, 2018 at 9:13
  • \$\begingroup\$ I have a Multimeter and an Oscilloscope available \$\endgroup\$
    – user150963
    Commented May 9, 2018 at 9:17
  • 1
    \$\begingroup\$ If you try to flash one of the example projects it doesn't work either? Can you run the code in debug mode to see what happens? \$\endgroup\$
    – po.pe
    Commented May 9, 2018 at 10:08

1 Answer 1

2
\$\begingroup\$

The problem lay with the Coocox library files, what I did was uninstall the program and re-installed it and it worked successfully.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.