This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Blink Newbie help debug!

Hi Forum.

I'm new to ARM, but have experience with AVR. I'm just trying to make a Hello World with blinky LEDs. I have this board:

https://forum.micropython.org/viewtopic.php?t=3086

So ok, everything seems to be setup right. I can compile and also program the Flash, it verify's with no errors. There are two onboard LEDs connected to A6 and A7 (it says so in the link, but I have also double checked). I can't get them to blink or flash. 

This is my code:

#include "stm32f407xx.h"

void myDelay(int times){

	volatile int i, j;

	for (i = 0; i < times; ++i) {
		j++;
	}
}

void ini(void){
	RCC -> AHB1ENR |= RCC_AHB1ENR_GPIOAEN; //enable GPIO clock for AHB og RCC
	GPIOA -> MODER |= GPIO_MODER_MODER6_0 |GPIO_MODER_MODER7_0;
	GPIOA -> OTYPER &= ~(GPIO_OTYPER_OT_7|GPIO_OTYPER_OT_6);
	GPIOA -> OSPEEDR |= GPIO_OSPEEDER_OSPEEDR7_1 | GPIO_OSPEEDER_OSPEEDR6_1; //High speed 10
	GPIOA -> PUPDR &= ~(GPIO_PUPDR_PUPDR7 | GPIO_PUPDR_PUPDR6);

}


int main(void)
{

	void ini();

    while(1)
    {

    	GPIOA -> BSRRL |= 0x000000C0; //Bit Set 6 & 7
    	myDelay(200000);
    	GPIOA -> BSRRL |= 0x00C00000; //Bit 6 & 7 reset
    	myDelay(200000);
    }

    return 0;
}

I hope someone can help me se what I'm doing wrong?

Best Regards

Ole.

Parents
  • Hi Ole.

    Welcome to the ARM Cortex-M world! :)

    As you're coming from AVR, you're not used to that you need to switch on things, before they work.

    This is something you'll need to get used to.

    Each time you experience that a peripheral does not seem to work, you'll need to ask yourself:  "Have I turned on all the peripherals I'm using in the RCC?".

    In this case, you will need to turn on the GPIO clock power.

    That's done with something like this...

    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;

    As you see, the name of the bitmask is (quite cleverly) constructed from the peripheral being written to, then the register and finally the contents of that register.

    You should be able to find the details in RM0090 and the STM32F407 datasheet. :)

    -But why oh why is this so complicated - couldn't the peripherals just be turned on from the beginning ?

    The answer is that if they were, every Cortex-M would use a lot of power as soon as it's turned on; in most situations, this is undesirable; especially when running on battery power (whether it be a CR2032 backup-battery or a couple of 1.2V batteries).

    -So you'll have to remember to turn on the power-switch before you can expect light. ;)

    All peripherals need clock power, including (but not limited to) timers, DMA, GPIO, SPI, I2C, RTC, SD/MMC - yes, even RAM and Flash.

    By default, Flash and RAM is turned on.

Reply
  • Hi Ole.

    Welcome to the ARM Cortex-M world! :)

    As you're coming from AVR, you're not used to that you need to switch on things, before they work.

    This is something you'll need to get used to.

    Each time you experience that a peripheral does not seem to work, you'll need to ask yourself:  "Have I turned on all the peripherals I'm using in the RCC?".

    In this case, you will need to turn on the GPIO clock power.

    That's done with something like this...

    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;

    As you see, the name of the bitmask is (quite cleverly) constructed from the peripheral being written to, then the register and finally the contents of that register.

    You should be able to find the details in RM0090 and the STM32F407 datasheet. :)

    -But why oh why is this so complicated - couldn't the peripherals just be turned on from the beginning ?

    The answer is that if they were, every Cortex-M would use a lot of power as soon as it's turned on; in most situations, this is undesirable; especially when running on battery power (whether it be a CR2032 backup-battery or a couple of 1.2V batteries).

    -So you'll have to remember to turn on the power-switch before you can expect light. ;)

    All peripherals need clock power, including (but not limited to) timers, DMA, GPIO, SPI, I2C, RTC, SD/MMC - yes, even RAM and Flash.

    By default, Flash and RAM is turned on.

Children