AnsweredAssumed Answered

GPIOA Clock enable bricks board

Question asked by jargin.matt on Dec 2, 2012
Latest reply on Dec 2, 2012 by jargin.matt
I am writing some code to enable SPI to use the accelerometer. But when I enable the GPIOA clock in RCC_AHB1ENR it bricks the board and I have to use the BOOT pin to reset it. Here is the piece of code that makes it brick.

RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOEEN; 

But when I change this line of code to:

RCC->AHB1ENR |=  RCC_AHB1ENR_GPIOEEN; 

It does not brick the board anymore. I checked the RCC_AHB1ENR_GPIOAEN define and it has the value 0x00000001 which is the right mask.

Why does it not like it when I enable the GPIOA clock?

Here is the entire program that I have written so far.

//Accelerometer
 
#include <stdio.h>
#include "STM32F4xx.h"
#include "LED.h"

 
#define CS_HIGH()   GPIOE->BSRRL |= (1<<3)
#define CS_LOW()    GPIOE->BSRRH |= (1<<3)
 
void SPI_init(void);
void acc_init(void);
unsigned char SPI_send(unsigned char data);
void acc_cmd(unsigned char cmd, unsigned char addr);
void acc_write(unsigned char data, unsigned char addr);
unsigned char acc_read(unsigned char addr);
unsigned char get_x_axis(void);
unsigned char get_y_axis(void);
unsigned char get_z_axis(void);
 
 
void delay(void);
 
 
 
int main(void)
{
    LED_Init();
    SPI_init();
     
     
    while(1)
    {
        LED_On(1);
        delay();
        LED_Off(1);
        delay();
    }
     
     
}
 
unsigned char SPI_send(unsigned char data)
{
    SPI1->DR = data;
    while(SPI1->SR & SPI_SR_BSY);  
    return SPI1->DR;
}
 
 
void acc_write(unsigned char data, unsigned char addr)
{
     
     
}
unsigned char acc_read(unsigned char addr)
{
    unsigned char data = 0;
     
     
     
     
    return data;
}
 
 
 
void SPI_init(void)
{
     
/*********PINOUT*************
    SCK = PA5
    MOSI = PA7
    MISO = PA6
    CS = PE3
    INT1 = PE0
    INT2 = PE1
*****************************/
     
     
        //Enable GPIO Clock
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN|RCC_AHB1ENR_GPIOEEN;
        //Enable pins as output or input
    GPIOA->MODER |= GPIO_MODER_MODER5_1|GPIO_MODER_MODER7_1;
    GPIOE->MODER |= GPIO_MODER_MODER3_0;
        //GPIO pin speed
    GPIOA->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR5_0|GPIO_OSPEEDER_OSPEEDR6_0|GPIO_OSPEEDER_OSPEEDR7_0; //25Mhz gpio
    GPIOE->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR0_0|GPIO_OSPEEDER_OSPEEDR1_0|GPIO_OSPEEDER_OSPEEDR3_0; //25Mhz gpio
        //Pull up configuration
    GPIOA->PUPDR |= GPIO_PUPDR_PUPDR6_0; //1 = pull down 0 = pull up default is pull up/down disabled
    GPIOE->PUPDR |= GPIO_PUPDR_PUPDR0_0|GPIO_PUPDR_PUPDR1_0;
         
 
     
        //Enable SPI Clock
    RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;
        //Enable Alternate Function on SPI pins and INT Pins
    GPIOA->AFR[1] |= 0x55500000;
     
     
        //Configure SPI for master mode and Fpclk/64
    SPI1->CR1 |= SPI_CR1_SPE|SPI_CR1_MSTR|SPI_CR1_BR_0;
     
}
 
 
void delay(void)
{
     
    unsigned long i = 0;
    for(i=0; i<5000000; i++)
    {
         
         
    }
}




Outcomes