This is an automated email from Gerrit.

Tarek BOCHKATI (tarek.bouchk...@gmail.com) just uploaded a new patch set to 
Gerrit, which you can find at http://openocd.zylin.com/6432

-- gerrit

commit 0f5faf9b6b1d331a9e689ba64e06c60b4d0d30c3
Author: Tarek BOCHKATI <tarek.bouchk...@gmail.com>
Date:   Thu Jul 29 23:34:33 2021 +0100

    target/stm32l5x: add option bytes helpers [RFC]
    
    # this patch depends on #6425..6427
    
    this extension, adds the following commands to ease option bytes 
manipulation:
     - stm32l5x_ob_list <bank_num>
     - stm32l5x_ob_get  <bank_num> <option_name>
     - stm32l5x_ob_set  <bank_num> <option_name> <option_value>
    
    Change-Id: I6fcc4a01dab38358987a8cb831623ef84c6ffee3
    Signed-off-by: Tarek BOCHKATI <tarek.bouchk...@gmail.com>

diff --git a/tcl/target/stm32l5x.cfg b/tcl/target/stm32l5x.cfg
index a3755fc..438240e 100644
--- a/tcl/target/stm32l5x.cfg
+++ b/tcl/target/stm32l5x.cfg
@@ -198,3 +198,142 @@ $_TARGETNAME configure -event trace-config {
        # assignment
        mmw 0xE0044004 0x00000020 0
 }
+
+# STL32L5x option bytes
+#      {option         offset  bit_pos length  }
+set _stm32l5x_options {
+       {RDP                    0x40    0       8       }
+       {BOR_LEV                0x40    8       3       }
+       {nRST_STOP              0x40    12      1       }
+       {nRST_STDBY             0x40    13      1       }
+       {nRST_SHDW              0x40    14      1       }
+       {IWDG_SW                0x40    16      1       }
+       {IWDG_STOP              0x40    17      1       }
+       {IWDG_STDBY             0x40    18      1       }
+       {WWDG_SW                0x40    19      1       }
+       {SWAP_BANK              0x40    20      1       }
+       {DB256                  0x40    21      1       }
+       {DBANK                  0x40    22      1       }
+       {SRAM2_PE               0x40    24      1       }
+       {SRAM2_RST              0x40    25      1       }
+       {nSWBOOT0               0x40    26      1       }
+       {nBOOT0                 0x40    27      1       }
+       {PA15_PUPEN             0x40    28      1       }
+       {TZEN                   0x40    31      1       }
+       {NSBOOTADD0             0x44    7       25      }
+       {NSBOOTADD1             0x48    7       25      }
+       {SECBOOTADD0    0x4C    7       25      }
+       {BOOT_LOCK              0x4C    0       1       }
+       {SECWM1_PSTRT   0x50    0       7       }
+       {SECWM1_PEND    0x50    16      7       }
+       {HDP1EN                 0x54    31      1       }
+       {HDP1_PEND              0x54    16      7       }
+       {WRP1A_PSTRT    0x58    0       7       }
+       {WRP1A_PEND             0x58    16      7       }
+       {WRP1B_PSTRT    0x5C    0       7       }
+       {WRP1B_PEND             0x5C    16      7       }
+       {SECWM2_PSTRT   0x60    0       7       }
+       {SECWM2_PEND    0x60    16      7       }
+       {HDP2EN                 0x64    31      1       }
+       {HDP2_PEND              0x64    16      7       }
+       {WRP2A_PSTRT    0x68    0       7       }
+       {WRP2A_PEND             0x68    16      7       }
+       {WRP2B_PSTRT    0x6C    0       7       }
+       {WRP2B_PEND             0x6C    16      7       }
+}
+
+lappend _telnet_autocomplete_skip _stm32l5x_bank_check
+proc _stm32l5x_bank_check {bank_num} {
+       # check the specified bank_num
+       set banks [flash list]
+       if { ($bank_num < 0) || ($bank_num >= [llength $banks]) } {
+               log error "the specified flash bank does not exist"
+               return 0
+       }
+
+       # check the flash driver
+       set flash_driver [dict get [lindex $banks $bank_num] driver]
+       if { $flash_driver != "stm32l4x" } {
+               log error "the specified flash bank driver is incompatible"
+               return 0
+       }
+
+       return 1
+}
+
+lappend _telnet_autocomplete_skip _stm32l5x_ob_get_impl
+proc _stm32l5x_ob_get_impl {target ob} {
+       set ob_reg  [lindex $ob 1]
+       set ob_pos  [lindex $ob 2]
+       set ob_len  [lindex $ob 3]
+       set ob_mask [expr (1 << $ob_len) - 1]
+
+       $target mem2array value_list 32 [expr 0x40022000 + $ob_reg] 1
+       set reg_value $value_list(0)
+
+       return [expr ($reg_value >> $ob_pos) & $ob_mask ]
+}
+
+proc stm32l5x_ob_get {bank_num ob_name} {
+       global _stm32l5x_options
+
+       if { ![_stm32l5x_bank_check $bank_num] } {
+               return
+       }
+
+       set target [dict get [lindex [flash list] $bank_num] target]
+
+       foreach ob $_stm32l5x_options {
+               if { [string equal $ob_name [lindex $ob 0]] } {
+                       set ob_value [_stm32l5x_ob_get_impl $target $ob]
+                       echo [format "  %s : 0x%X" $ob_name $ob_value]
+                       return
+               }
+       }
+
+       log error "unknown option '$ob_name'"
+}
+
+proc stm32l5x_ob_list {bank_num} {
+       global _stm32l5x_options
+
+       if { ![_stm32l5x_bank_check $bank_num] } {
+               return
+       }
+
+       set target [dict get [lindex [flash list] $bank_num] target]
+
+       foreach ob $_stm32l5x_options {
+               set ob_name [lindex $ob 0]
+               set ob_value [_stm32l5x_ob_get_impl $target $ob]
+               echo [format "  %-12s : 0x%X" $ob_name $ob_value]
+       }
+}
+
+lappend _telnet_autocomplete_skip _stm32l5x_ob_set_impl
+proc _stm32l5x_ob_set_impl {bank_num ob value} {
+       set ob_reg   [lindex $ob 1]
+       set ob_pos   [lindex $ob 2]
+       set ob_len   [lindex $ob 3]
+       set ob_mask  [expr [expr (1 << $ob_len) - 1] << $ob_pos]
+       set ob_value [expr $value << $ob_pos]
+
+       stm32l4x option_write $bank_num $ob_reg [format "0x%X" $ob_value] 
[format "0x%X" $ob_mask]
+}
+
+proc stm32l5x_ob_set {bank_num ob_name value} {
+       global _stm32l5x_options
+
+       if { ![_stm32l5x_bank_check $bank_num] } {
+               return
+       }
+
+       foreach ob $_stm32l5x_options {
+               if { [string equal $ob_name [lindex $ob 0]] } {
+                       set ob_value [_stm32l5x_ob_set_impl $bank_num $ob 
$value]
+                       return
+               }
+       }
+
+       log error "unknown option '$ob_name'"
+}

-- 

Reply via email to