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

STM32: Starting from scratch

Greetings,

First of all, let me apologize in advance for the mistakes in my grammar. Not an english speaker here. I hope, howewer, that this can be understood.

I have recently started to move away from PIC microcontrollers (Mainly PIC18F family) to ARM microcontrollers. I chosed STM32 because of the inexpensive Discovery Boards, wich I could use before doing a board for the project I need to do. I saw that some libraries could be used, but back in the day when I was first learning about microcontrollers, teacher never allowed us to use anything complex, since it "obscured" what happened in the microcontroller. Those were good times, learning in ASM with small microcontrollers... Anyway, now, some ten years after that, I still like to do things "as close to the action" as I can. So, I found this tutorial for setting up GNU GCC in Keil [http://m8051.blogspot.com.es/2012/10/using-gcc-in-keil-best-of-both-worlds.html] and made it work with some minor changes (Only in preprocessor directives I had to change anything, I think, and there is not much difference between Keil 4 and 5 versions). I wanted to do the usual "blink the leds" starting program, in this case, blinking them each time the user button on the Discovery board was pressed.

So far, it compiles ok, it programs ok, but I can't see anything. And debugging isn't helping: I get a lot of "Cannot Access Memory" lines, but it doesn't stop in a breakpoint.

Anyway, here is my code:

#include <stm32f10x.h>
void _exit(int code)///New lib SysCall
{
    while(1);
}

int main()
{
  unsigned long i;

  // Clock enable for GPIO Ports A&C
    RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;


    RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;

    GPIOA->CRL = 0x44444440; // PA0 floating input
    GPIOC->CRH = 0x444444AA; // PC8 y PC9 push-pull outputs


        //At reset, PC8 should be lit, and PC9 should be off
    GPIOC->BSRR = GPIO_BSRR_BS8; // 0x00000100 --> Set PC8
    GPIOC->BSRR = GPIO_BSRR_BR9; // 0x02000000 --> Reset PC9

    while(1)
    {
        if(GPIOA->IDR & 1) // Button pressed
        {
             if(GPIOC->ODR & GPIO_ODR_ODR8) // PC8 estaba a 1
             {
                GPIOC->BSRR = GPIO_BSRR_BR8; // 0x01000000 --> Reset PC8
                GPIOC->BSRR = GPIO_BSRR_BS9; // 0x00000200 --> Set PC9
             }
             else // PC8 estaba a 0
             {
                GPIOC->BSRR = GPIO_BSRR_BS8; // 0x00000100 --> Set PC8
                GPIOC->BSRR = GPIO_BSRR_BR9; // 0x02000000 --> Reset PC9
              }
        }
    //Dummy Loop
        for(i=0;i<0x1FFFFF;i++);
    }
}


P.S.: I am thinking that I did not configure the system clock. Probably it's the problem, but anyway, I leave this in case that is not the problem, or anyone want to tell me anything about the code or resources to start with STM32 programming.

Thanks in advance!

Regards

Parents
  • Ok, seems that now I can't even read a datasheet.

    GPIOA->CRL = 0x44444440; // PA0 floating input
    GPIOC->CRH = 0x444444AA; // PC8 y PC9 push-pull outputs
    


    Should be

    GPIOA->CRL = 0x44444444; // PA0 floating input
    GPIOC->CRH = 0x44444422; // PC8 y PC9 push-pull outputs
    


    So, for PA0 I have
    Mode 00 --> Input
    CNF1=0, CNF=1 ==> Input floating
    (Well, that is the reset value)

    And for PC8/PC9
    Mode = 10 --> Max Output speed 2MHz
    CNF1=0, CNF0=0 ==> General purpose output, Push-pull output

    Since with 0x444444AA
    PC8/PC9
    Mode = 10 --> Max Output speed 2MHz
    CNF1=1, CNF0=0 ==> Alternate function, Push-pull output

    But changing this did not solve the problem

Reply
  • Ok, seems that now I can't even read a datasheet.

    GPIOA->CRL = 0x44444440; // PA0 floating input
    GPIOC->CRH = 0x444444AA; // PC8 y PC9 push-pull outputs
    


    Should be

    GPIOA->CRL = 0x44444444; // PA0 floating input
    GPIOC->CRH = 0x44444422; // PC8 y PC9 push-pull outputs
    


    So, for PA0 I have
    Mode 00 --> Input
    CNF1=0, CNF=1 ==> Input floating
    (Well, that is the reset value)

    And for PC8/PC9
    Mode = 10 --> Max Output speed 2MHz
    CNF1=0, CNF0=0 ==> General purpose output, Push-pull output

    Since with 0x444444AA
    PC8/PC9
    Mode = 10 --> Max Output speed 2MHz
    CNF1=1, CNF0=0 ==> Alternate function, Push-pull output

    But changing this did not solve the problem

Children