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?

1 ACCEPTED SOLUTION

Accepted Solutions
YAY.1
Senior

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

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

View solution in original post

17 REPLIES 17
Uwe Bonnes
Principal II

Look for In-Application programming (IAP)

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
Guru

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

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 Venmo
Up vote any posts that you find helpful, it shows what's working..

Sorry, :D

It is completely a typo.

Thank you for reply.

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

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 Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks for reply

I will try this

EDITED:

Sorry,

I could not understand your question.

And i want to ask some questions about your codes.

1)Can you explain this code 'orrs r1, r1' ?

Is that same with this ?

FLASH_interface EQU 0x40022000

FLASH_CR EQU 0x10

FLASH_KEYR EQU 0x04

BIT31 EQU 1 << 31

ldr r0, =(FLASH_interface + FLASH_CR)

 ldr r1, [r0]

 ldr r0, =(BIT31)

 str r0, r1

Not1):I tried your codes in simulation mode and its warning me that lr is empty.

It is saying that this will cause a HardFault.

There is no return address.

Not2): I tried your codes in STM32L4 simulation, but i think that it is not working or i could not understand what is it doing. Can you explane more, please ?

EDITED:

I searched keys are must be write but still i dont know how will i write something to the flash.I think i will write in banks.

but if i wrote a code like "ldr r0, =0x1", how can i read or run that ?

Is Writing to banks like flash_cr select page then lock then write you datas then unlock change page lock ... ?

Why we need start or end point ?

EDITED:

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

I should do pointer. 

THANKS FOR EVERYTHING

I can not go flash memory to run with pointer.

Sat Aug 22, 2020 19:45:04: Warning: The instruction at 0x08000416 tried to branch to the aligned (ARM) address 0x4002202C. This will cause a HardFault. 

Is there no way to run a code after save somewhere ?

Could i run a code that in a register ?