cancel
Showing results for 
Search instead for 
Did you mean: 

can stm32 program itself without not using programing pin ?

YAY.1
Senior

For example how can i do this with stm32f030cc?

17 REPLIES 17
MM..1
Chief III

You can run code in RAM then when i understand you can start static code in flash, in this load to ram asm prepared bin, jump to it, return to flash change ramcode and do this neverendly...

The orrs r1,r1 causes the processor to reevaluate the flags, for example Z and N flags. I'm checking if bit 31 is set or not, and branching based on that.

https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/condition-codes-1-condition-flags-and-codes

The subroutine is called with blx _UnlockFlash which saves the return address into the link register.

>>I succeed write and read but how will i run this hexadecimal code of like ldr r0, =(0x1) ?

What do you expect 'ldr r0, =(0x1)' would do? Illustrate entry and exit conditions, it's hard to empath what you mean here.

You want to load R0 with ONE?

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

thanks clive1,

I want to save some codes to the memory like

ldr r3, =(0x5)

ldr r2, =(0x3)

add r2, r3

then i want to run these codes from memory.(These codes will not be in its program so it will not be function)

How to execute code from external flash on STM32F407

How will i run a code from flash ?

Can you help me clive1 ?

Thank you.

I want to do this exactly.

But problem is hard fault.

Maybe i am doing wrong something.

I am using clive1 's codes

I cant branch to the ram or something, just in program.

To see the generate opcodes you would look at a listing file.

Generally for small constants you can load immediates, for value that don't work that way you need to load them from the literal pool.

Perhaps refer to some ARM assembly language texts

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

I hope you can understand what did i do in this codes :grinning_face: .

I change value of address of nop codes.

ldr r1, =(0x0800040c) // address of first saver nop
              ldr r0, =(0x2555)  ; ldr r5, =(0x55)
              str r0, [r1]
              ldr r1, =(0x08000410) // address of second saver nop
              ldr r0, =(0x2455)  ; ldr r4, =(0x55)
              str r0, [r1]
              nop  // first saver nop) ldr r5, =(0x55)
              nop  // nop this should nop because it is stucking when you load new code here
              nop  // second saver nop) ldr r4, =(0x55)
              ;nop  // if you will save new code this nop should nop
              ;nop  // if you save new code, you can save new code here

Ok, so "self modifying code"

This would be better done in RAM, as the flash writing is subtly different, and does expect the words being written to be in the erased state.

I'll note the opcodes are 16-bit wide, not 32-bit

Branching to RAM is possible, just remember that 16-Thumb code needs you to branch to the ODD address, not the EVEN one.

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

"This would be better done in RAM"

You are right but i could not do this because i could not prepare ram to store data but if i can do, i need to return back to the program.

I need to learn a lot :smiling_face_with_smiling_eyes:.

If i find a way that how will i do that with ram, i will add codes here.

I think that i need learn this "Direct memory access controller (DMA)"

Thank you everyone.