Skip to main content
YAY.1
Senior
August 19, 2020
Solved

can stm32 program itself without not using programing pin ?

  • August 19, 2020
  • 5 replies
  • 2397 views

For example how can i do this with stm32f030cc?

This topic has been closed for replies.
Best answer by YAY.1

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

5 replies

Uwe Bonnes
Chief
August 19, 2020

Look for In-Application programming (IAP)

YAY.1
YAY.1Author
Senior
August 19, 2020

No, you did not understand,

i mean that if you will give cods, it will write cods of memory and when you said start it will make that cods.

And you can change that cods while it is still working(while it is waiting you).(no programmer connecting)

I want to make this own.

TDK
Super User
August 19, 2020

What is cods? You said it 4 times, it can't be a typo.

You can program flash memory with the HAL_FLASH_Program* routines.

"If you feel a post has answered your question, please click ""Accept as Solution""."
YAY.1
YAY.1Author
Senior
August 19, 2020

Sorry, :D

It is completely a typo.

Thank you for reply.

Tesla DeLorean
Guru
August 19, 2020

See assorted FLASH library examples included with CubeF0

STM32Cube_FW_F0_V1.10.1\Projects\STM32F030R8-Nucleo\Examples\FLASH\FLASH_EraseProgram

See also the library code, as it indicates some usage methods

STM32Cube_FW_F0_V1.10.1\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_flash.c

STM32Cube_FW_F0_V1.10.1\Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_flash_ex.c

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
YAY.1
YAY.1Author
Senior
August 19, 2020

Thanks for Reply.

Can i do this with assembly language ? (just i need writing a code to flash and then play that code)

I found Embedded Flash memory in Reference manual but

How can i write this for example "ldr r1, 0x1" ?

Tesla DeLorean
Guru
August 19, 2020

Pretty sure I could write it in assembly

"movs r1, #1" ?

Got STM32L4 code that has the following form

;-----------------------------------------------------------------------------
 
; Uses r0,r1
 EXPORT _UnlockFlash
_UnlockFlash ldr r0, =0x40022000 ; FLASH CTRL
 ldr r1, [r0, #0x14] ; FLASH_CR
 orrs r1, r1 ; LOCK - Bit 31
 bpl _UnlockFlash10
 ldr r1, =0x45670123 ; KEY1
 str r1, [r0, #0x08] ; FLASH_KEYR
 ldr r1, =0xCDEF89AB ; KEY2
 str r1, [r0, #0x08]
_UnlockFlash10 bx lr
 
;----------------------------------------------------------------------------

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
MM..1
Chief III
August 22, 2020

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...

YAY.1
YAY.1Author
Senior
August 22, 2020

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.

YAY.1
YAY.1AuthorBest answer
Senior
August 23, 2020

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

Tesla DeLorean
Guru
August 23, 2020

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 VenmoUp vote any posts that you find helpful, it shows what's working..
YAY.1
YAY.1Author
Senior
August 23, 2020

"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.