Skip to main content
sholojda
Associate III
May 10, 2022
Question

Why I can not call function from address 0x00000000 or 0x08000000?

  • May 10, 2022
  • 6 replies
  • 2299 views

I have created a pointer to function like void (*MyFun)(void); and I assigned first time 0x00000000 and the second time 0x08000000. in both cases after call MyFun(); I get HardFault error.

Why?

PS. This is simple project created in CubeIDE (default project for STM32F103) and I only add some lines of code to call MyFun();

This topic has been closed for replies.

6 replies

Muhammed Güler
Senior III
May 10, 2022

it represents the start of rom at two addresses. At the start of the rom, there is a vector table in the file called startup_stm32xxxxx.s, where you can see the contents. there is no executable code

gbm
Lead III
May 10, 2022

Besides the above, the function address for any Cortex-M must be an odd number (real function address with bit 0 set to 1). Generally: do not hardcode any function addresses; use proper type cast when you have to.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
sholojda
sholojdaAuthor
Associate III
May 10, 2022

I tried to call this MyFun with address 0x00000001, 0x00000004, 0x08000001, and 0x08000004 and still the same -> HardFault

Tesla DeLorean
Guru
May 10, 2022

Is there actually CODE​ there, or ADDRESSES in a vector table?

The.processor can't execute​ addresses!

F​or those you'll need to do a 32-bit read and transfer control to that location, rather than the table.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Muhammed Güler
Senior III
May 10, 2022

0x08000000 has stack end address in it

0x08000004 contains the address of the code to be processed after reset

0x08000008 contains the address of the NMI_Handler function

0x0800000c has the address of HardFault_Handler in it

...

the vector table continues to settle in this way.

These are defined in a file like startup_stm32h753xx.s

In order to work with these addresses, you need to define as pointer to pointer.

sholojda
sholojdaAuthor
Associate III
May 10, 2022

Yes, You're right. I didn't think of it that way. :(

sholojda
sholojdaAuthor
Associate III
May 11, 2022

Can you tell me how to create a pointer to pointer for fuction? Like in this example.

Address 0x08000004 holds address to code execute. How to use it?