Jump to content
43oh

hard fault when accessing GPIO configuration registers via AHB


Recommended Posts

hello

 

I'm playing with my stellaris launchpad, I got openocd 0.7.0 working and I'm trying to write my own GPIO init code.

I wrote this generic routine to initialize the uart pins.

 

I've defined several flags, and according to the value of these flags, I'm attempting to write the appropriate GPIO configuration registers.

 

For that, I'm using the AHB access method, writing to BASE+OFF where

 

OFF is the offset of the required register (eg #define LM4F_GPIO_GPIODIR       0x400   // GPIO Direction)

 

BASE is 0x40058000 + (port<<16)

 

I'm using this because it's easier to compute the port base address.

 

Note that this method is using the AHB bus.

The other method, which I'm not using, relies on the APB bus, with a different base address, and an ugly hack for PE and PF.

 

However, this does not work, what I get is a hardfault. With a combination of google searches, I've managed to determine that

(hfsr = 1073741824= 0x40000000) => this is a forced hard fault

(cfsr = 33280 = 0x00008200) => BFSR=0x82 this is an unhandled Bus Fault, BFAR is valid and this is a precise data bus error.

PC correctly points to the faulting instruction, which is

ldr    r1, [r2, #0]
with:

r2 = 1074103296 = 0x40058400

which is the GPIO register I'm trying to read, before changing it and writing it back later.

I can confirm this is the failing address because

bfar = 1074103296 = 0x40058400

 

Okay...

 

So I'm wondering WHY I can't access the GPIO registers this way. Is this an "errata issue" ?

Do I have to set something up before accessing AHB registers?

 

I have already set the correct bit in the the RCGCGPIO register at 0x400FE000 + 0x608 with no problem, so the GPIO peripheral shall be working.

 

Do you have any idea before I rewrite my code to use the APB?

 

(please don't tell me that stellaristupperware already does this, because in my context, I cannot and will not use that).

 

Best regards :)

 

edit: this should work, see here: http://e2e.ti.com/support/microcontrollers/stellaris_arm/f/471/t/60248.aspx

 

edit 2: SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOF);

 

haha. I knew it. Now I need to write code for that. Going to read the datasheet again.

Link to post
Share on other sites

Hi,

It would be helpful to know the micro in use to tell you where to look - but, keeping things general, look for the following in the data sheet:

Register 9: GPIO High Performance Bus Control (GPIOHBCTL) offset 0x06C

This will help you to correctly initialize AHB reading/writing - only some settings to do.

Another thing: comitting PF is very easy to do...

Lyon

Link to post
Share on other sites

Yes, we crossed messages !

 

as always, writing about my problem made me find it.

 

I'm now setting the correct bit in GPIOHBCTL, and it works \o/

 

So guys, in order to access GPIO via the AHB addresses, you have to set the correct bit for your port in the GPIOHBCTL register, address 0x400fe000+0x06C , page 247 of datasheet !

 

Hope it can be useful to someone else!

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...