cancel
Showing results for 
Search instead for 
Did you mean: 

Address jump function

NandhakumarGanesan
Associate II

Hi,

 in my project I am try to jump 0x8002000 address . but I am facing some failure,

 

typedef void (*FunctionPointer)(void);
 
// Example function to jump to another address
void jumpToAddress(uint32_t * address) {
 
//address =0x800029c;
    // Define a function pointer with the address
    FunctionPointer jumpFunction = (FunctionPointer)address;
    //void (*jumpFunction)(void) = (void (*)(void))address;
 
    // Disable interrupts if needed
       __disable_irq();
 
       // Set the program counter (PC) to the new address
       SCB->VTOR = address;
 
       // Execute an instruction to ensure that the jump takes effect
       __DSB();
       __ISB();
 
       // Re-enable interrupts if needed
       __enable_irq();
 
    // Call the function via the function pointer
    jumpFunction();
}
 
 
this is my address jump function .
 

int main(void)
{
/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */
SystemClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */
MX_GPIO_Init();
/* USER CODE BEGIN 2 */
//myFunction();
jumpToAddress(0x8002000);

/* USER CODE END 2 */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}

this is my main function.

 

NandhakumarGanesan_0-1716892537128.png

this image is my .map file for my project.

I am try to jump 0x8002000 address my project  shown ,

 

NandhakumarGanesan_1-1716892659863.png

 

 

this output. so kindly help to me.

thanks

1 ACCEPTED SOLUTION

Accepted Solutions

Vector tables need to be on 512-byte boundaries.

They are tables of addresses, not code.

Thr function pointer needs to be odd, per how the CMx processor indicates 16-bit Thumb code.

Have a working/reporting HardFault_Handler so you know it got there.

Learn to use the debugger so you can step the code and understand behaviour and failure.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

3 REPLIES 3

Vector tables need to be on 512-byte boundaries.

They are tables of addresses, not code.

Thr function pointer needs to be odd, per how the CMx processor indicates 16-bit Thumb code.

Have a working/reporting HardFault_Handler so you know it got there.

Learn to use the debugger so you can step the code and understand behaviour and failure.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

thanks for your response.

I am a beginner for ARM  Based controller. So kindly  explain for this address jumping process or kindly give sample code for this process or kindly share document for this process.

 

 

 

hi,

 

I am try below  mentioned method in way Hardfaulthandler error is happend.

NandhakumarGanesan_0-1716897132891.png

kindly help to me. I am struggling  past 4 days .