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
First of all: sorry about 3 post that close in time, but i seem to be unable to find any "edit" button. Anyway: Now the program works... once you reset the board. I am used (As I said in the first post) to Microchip: there, I had my programmers/debuggers reset the target once it was programmed, unless I wanted the opposite. Assuming anything works the same is a huge mistake...
Debugging also works now, but in this case, I don't know if the reason it's the same (Having done a hard reset) or any other...