Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Cortex M3 - Writing to memory problems.

Status
Not open for further replies.

Pheetuz

Full Member level 3
Full Member level 3
Joined
Feb 12, 2010
Messages
162
Helped
21
Reputation
42
Reaction score
19
Trophy points
1,298
Location
Brighton
Activity points
2,835
Hi Folks,

I have bought myself an Olimex STM32-P107 dev board to start having a play with, I figured something easy to do would be to flash an LED, I was wrong!
I downloaded the standard peripheral library, not so that I could use the inbuilt functions but so that I had some mnemonics for accessing registers, I tried accessing some of the port registers using said mnemonics, I didn't get any syntax errors or anything like that but nothing happened, I then tried to run the debugger so that I could see what was going on inside and it seems that the memory wasn't changing, I then figured screw the library and wrote out some pointers to change the registers directly, still the same problem!

I have ensured that the MPU is disabled, but is there anything else that I am overlooking?

Code:
 unsigned int * GPIO_C_CRL = (unsigned int *)0x40011000;
 unsigned int * MPU_CTRL = (unsigned int *)0xE000ED94;


int main(void)
{
  /* Infinite loop */
  while (1)
  {
	*GPIO_C_CRL = 0;
	*MPU_CTRL = 1;
  /* Set up the necessary registers to drive port C */

  }
}

/Pheetuz
 

The easiest way to configure a pin is to use the st library, like this:

Code:
GPIO_InitTypeDef GPIO_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); // give clock to the port C

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // output push pull
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; // pin 1
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // speed

GPIO_Init(GPIOC, &GPIO_InitStructure); // init the pin with the above structure

May be you are missing the clock initialization on the port.

Forget about MPU. It's disabled by default.
 
Thanks for your reply p.luc, your right, I haven't initialised the clock on the port, to be honest with you, I didn't even know there was one! What does this clock do? Limit the speed at which I can write to the port?
It is going to be tricky for me initialise the clock on the port when I cant write to memory anywhere on the uC though?

/Pheetuz
 

You can write any memory position you want.

If you want to see how the clock is enabled, take a look at the source code of RCC_APB2PeriphClockCmd().

Clocks on these MCU are about power consumption. You can, for example, clock the GPIOC and at the same time you can turn off the clock on the GPIOB if you are not using any pin on PORT B. This way you can play with power consumption. Think it as "why to give clock to a peripheral I don't use?".

Remember to give clock to the peripheral you're using before setting any parameter. This is valid for USART, I2C, SPI, GPIO, etc.
 
Yeah I get what your saying. My original problem was that I couldn't write to memory at all which makes it very difficult to turn a clock on to a port, is there anything wrong with the code that I wrote above??

/Pheetuz
 

The address of the configuration register is correct.
I'm 100% sure, but I think you have to clock the port before setting its registers.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top