Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Added writing and reading for STM32WL option bytes #1227

Merged
merged 1 commit into from Feb 16, 2022

Conversation

AlexKlimaj
Copy link
Contributor

This PR adds reading and writing the option bytes on the STM32WL.

src/option_bytes.c Outdated Show resolved Hide resolved
@AlexKlimaj
Copy link
Contributor Author

I added the while loop. Unfortunately I'm having trouble testing this. The STM32WL modules from Seed Studio come with flash protection enabled. I'm trying to turn off flash protection to write the chip. I can do it in STMCubeProgrammer but I'm struggling to get it done here.

When the module isn't in reset, I can read the option bytes. 3ffff0bb
But I am unable to write them. Flash memory is write protected

When I put the module in reset, I am unable to read the option bytes, getting only 0's.
But writing the option bytes looks like it is successful, but when I take it out of reset and read, they haven't changed.

@Ant-ON
Copy link
Collaborator

Ant-ON commented Feb 16, 2022

@AlexKlimaj May be before downgrade RDP need erase WRP bytes

@AlexKlimaj
Copy link
Contributor Author

Here is the log from downgrading RDP in STM32CubeProgrammer. I don't see it erasing the WRP bytes.

11:18:12:235 : STLinkUSBDriver.dll loaded
11:18:12:249 : STLinkUSBDriver.dll loaded
11:18:12:249 : ST-LINK SN  : 50FF72067265575445271867
11:18:12:249 : ST-LINK FW  : V2J35S7
11:18:12:249 : Voltage     : 3.19V
11:18:12:250 : SWD freq    : 4000 KHz
11:18:12:250 : Connect mode: Normal
11:18:12:250 : Reset mode  : Software reset
11:18:12:333 : Device ID   : 0x497
11:18:12:503 : flash loader C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin/FlashLoader/0x497.stldr is loaded
11:18:12:503 : Reading data...
11:18:12:506 : r ap 0 @0x1FFF75E0 0x00000004 bytes
11:18:12:610 : UPLOADING OPTION BYTES DATA ...
11:18:12:610 :   Bank          : 0x00
11:18:12:610 :   Address       : 0x58004020
11:18:12:610 :   Size          : 104 Bytes
11:18:12:611 : Reading data...
11:18:12:634 : r ap 0 @0x58004020 0x00000068 bytes
11:18:12:637 : UPLOADING OPTION BYTES DATA ...
11:18:12:637 :   Bank          : 0x00
11:18:12:637 :   Address       : 0x58004020
11:18:12:637 :   Size          : 104 Bytes
11:18:12:637 : Reading data...
11:18:12:637 : r ap 0 @0x58004020 0x00000068 bytes
11:18:12:652 : UPLOADING ...
11:18:12:652 :   Size          : 2456 Bytes
11:18:12:652 :   Address       : 0x8000000
11:18:12:652 : Read progress:
11:18:12:654 : Reading data...
11:18:12:654 : r ap 0 @0x08000000 0x00000998 bytes
11:18:12:654 : Error: Data read failed
11:18:17:268 : Option byte command : -ob  RDP=170 

11:18:17:281 : PROGRAMMING OPTION BYTES AREA ...
11:18:17:364 :   Bank          : 0x00
11:18:17:364 :   Address       : 0x58004020
11:18:17:364 :   Size          : 104 Bytes
11:18:17:364 : OB buffer: aaf0ff3fff000000000000007f0000007f000000ff00000000000000ffffffff00000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000ff00ff800080fffe
11:18:17:364 : Buffer program...
11:18:17:448 : halt ap 0 
11:18:17:449 : w ap 0 reg 15 PC   (0x20000000)  
11:18:17:453 : w ap 0 reg 17 MSP  (0x20000500)  
11:18:17:453 : w ap 0 reg 16 xPSR (0x01000000)  
11:18:17:458 : w ap 0 @0x20002B80 0x00000200 bytes
11:18:17:459 : w ap 0 @0x20000000 0x00000004 bytes
11:18:17:541 : w ap 0 @0x20000004 0x0000274C bytes
11:18:17:544 : w ap 0 @0x20002B80 0x00000068 bytes
11:18:17:545 : Loader write option bytes...
11:18:17:545 : Init flashloader...
11:18:17:546 : halt ap 0 
11:18:17:549 : w ap 0 reg 0 R0   0x00000001
11:18:17:551 : w ap 0 reg 1 R1   0x00000000
11:18:17:556 : w ap 0 reg 2 R2   0x00000000
11:18:17:556 : w ap 0 reg 3 R3   0x00000000
11:18:17:556 : w ap 0 reg 4 R4   0x00000000
11:18:17:556 : w ap 0 reg 5 R5   0x00000000
11:18:17:556 : w ap 0 reg 6 R6   0x00000000
11:18:17:558 : w ap 0 reg 7 R7   0x00000000
11:18:17:560 : w ap 0 reg 8 R8   0x00000000
11:18:17:560 : w ap 0 reg 9 R9   0x00000000
11:18:17:560 : w ap 0 reg 10 R10  0x00000000
11:18:17:564 : w ap 0 reg 11 R11  0x00000000
11:18:17:564 : w ap 0 reg 12 R12  0x00000000
11:18:17:564 : w ap 0 reg 13 SP   0x00000000
11:18:17:564 : w ap 0 reg 14 LR   0x20000001
11:18:17:564 : w ap 0 reg 15 PC   0x2000002F
11:18:17:565 : w ap 0 reg 16 xPSR 0x01000000
11:18:17:565 : w ap 0 reg 17 MSP  0x20002B4C
11:18:17:565 : w ap 0 reg 18 PSP  0x00000000
11:18:17:565 : run ap 0 
11:18:17:579 : halt ap 0 
11:18:17:579 : r ap 0 reg 0 R0   0x00000001
11:18:17:582 : w ap 0 reg 0 R0   0x58004020
11:18:17:583 : w ap 0 reg 1 R1   0x00000068
11:18:17:583 : w ap 0 reg 2 R2   0x20002B80
11:18:17:586 : w ap 0 reg 3 R3   0x00000002
11:18:17:591 : w ap 0 reg 4 R4   0x00000000
11:18:17:592 : w ap 0 reg 5 R5   0x00000000
11:18:17:592 : w ap 0 reg 6 R6   0x00000000
11:18:17:603 : w ap 0 reg 7 R7   0x00000000
11:18:17:620 : w ap 0 reg 8 R8   0x00000000
11:18:17:620 : w ap 0 reg 9 R9   0x00000000
11:18:17:620 : w ap 0 reg 10 R10  0x00000000
11:18:17:620 : w ap 0 reg 11 R11  0x00000000
11:18:17:620 : w ap 0 reg 12 R12  0x00000000
11:18:17:620 : w ap 0 reg 13 SP   0x00000000
11:18:17:620 : w ap 0 reg 14 LR   0x20000001
11:18:17:621 : w ap 0 reg 15 PC   0x20000439
11:18:17:622 : w ap 0 reg 16 xPSR 0x01000000
11:18:17:623 : w ap 0 reg 17 MSP  0x20002B4C
11:18:17:623 : w ap 0 reg 18 PSP  0x00000000
11:18:17:623 : run ap 0 
11:18:17:693 : WriteOB function terminated with connection error due to OB_Launch
11:18:17:694 : Reconnecting...
11:18:18:766 : STLinkUSBDriver.dll loaded
11:18:18:766 : ST-LINK SN  : 50FF72067265575445271867
11:18:18:766 : ST-LINK FW  : V2J35S7
11:18:18:777 : Voltage     : 3.19V
11:18:18:777 : SWD freq    : 4000 KHz
11:18:18:777 : Connect mode: Normal
11:18:18:778 : Reset mode  : Software reset
11:18:18:858 : Device ID   : 0x497
11:18:18:858 : Reconnected !
11:18:18:858 : Success with Time elapsed during Reconnect: 94 ms
11:18:18:858 : UPLOADING OPTION BYTES DATA ...
11:18:18:858 :   Bank          : 0x00
11:18:18:858 :   Address       : 0x58004020
11:18:18:858 :   Size          : 104 Bytes
11:18:18:859 : Reading data...
11:18:18:891 : r ap 0 @0x58004020 0x00000068 bytes
11:18:18:891 : OPTION BYTE PROGRAMMING VERIFICATION:
11:18:18:891 : Option Bytes successfully programmed
11:18:19:064 : UPLOADING OPTION BYTES DATA ...
11:18:19:066 :   Bank          : 0x00
11:18:19:067 :   Address       : 0x58004020
11:18:19:067 :   Size          : 104 Bytes
11:18:19:068 : Reading data...
11:18:19:068 : r ap 0 @0x58004020 0x00000068 bytes

@AlexKlimaj
Copy link
Contributor Author

I was able to write the option bytes by adding the ability to write to STM32WB_FLASH_OPTR.

@Nightwalker-87 Nightwalker-87 linked an issue Feb 16, 2022 that may be closed by this pull request
@Nightwalker-87 Nightwalker-87 added this to In progress in Release v1.8.0 via automation Feb 16, 2022
@Nightwalker-87 Nightwalker-87 added this to the v1.7.1 milestone Feb 16, 2022
@Nightwalker-87 Nightwalker-87 moved this from In progress to Review in progress in Release v1.8.0 Feb 16, 2022
Release v1.8.0 automation moved this from Review in progress to Reviewer approved Feb 16, 2022
@Nightwalker-87 Nightwalker-87 changed the title Add writing and reading STM32WL option bytes Added writing and reading for STM32WL option bytes Feb 16, 2022
@Nightwalker-87 Nightwalker-87 merged commit c4762e6 into stlink-org:develop Feb 16, 2022
Release v1.8.0 automation moved this from Reviewer approved to Done Feb 16, 2022
@stlink-org stlink-org locked as resolved and limited conversation to collaborators Feb 16, 2022
@Nightwalker-87 Nightwalker-87 changed the title Added writing and reading for STM32WL option bytes [feature] Added writing and reading for STM32WL option bytes Aug 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

[feature] Add Option Byte Support for STM32WLEx
3 participants