GigaDevice GD32A4 GD32F4 Option Bytes Programming

From SEGGER Knowledge Base
Jump to navigation Jump to search

GigaDevice GD32A4 and GD32F4 option bytes programming and SPC locking/unlocking features are implemented in the PCode_DevPro_GigaDevice_GD32A4_GD32F4.pex script file.

Important notes

  1. For the correct operation, the nRESET signal must be connected.
  2. Performing SPC level 1 unlocking starts regression sequence. Flash memory is completely erased in this case.
  3. Setting SPC to level 2 permanently locks the device. No unlock/regression possible.
  4. After option bytes write operation, the target device must be power-cycled.

Usage

DevPro -operation [operation_name] -if SWD -speed 4000 [parameter_name=value] -ScriptFile PCode_DevPro_GigaDevice_GD32A4_GD32F4.pex
Operation Parameters Values Description
ReadOptionBytes OptionName FMC_OBCTL0 Read Option byte control register 0.
FMC_OBCTL1 Read Option byte control register 1.
WriteOptionBytes OptionName FMC_OBCTL0 Write Option byte control register 0.
FMC_OBCTL1 Write Option byte control register 1.
Value 0xXXXXXXXX 32-bit value to be written to the register specified in "OptionName" parameter.

Detailed description

ReadOptionBytes

  • Reads and prints out description of the selected option-byte register.

WriteOptionBytes

  • Writes selected option-byte register. Using hex value is recommended.
Note:
Writing FMC_OBCTL0 register is used to lock device. The SPC[7:0] bits represent device locking level:
Value 0xAA - Device not locked
Value 0xBB or other than 0xAA or 0xCC - Level 1 protection
Value 0xCC - Level 2 protection

Examples

Reading option bytes register:

DevPro -operation ReadOptionBytes -if SWD -speed 4000 -SetConfigVal "OptionName=FMC_OBCTL0" -ScriptFile "PCode_DevPro_GigaDevice_GD32A4_GD32F4.pex"
SEGGER Device Provisioner V7.96l
Compiled Jun 12 2024 18:55:19

'q' to quit '?' for help

Command line: -operation ReadOptionBytes -if SWD -speed 4000 -SetConfigVal OptionName=FMC_OBCTL0 -ScriptFile PCode_DevPro_GigaDevice_GD32A4_GD32F4.pex
Opened script file: 'PCode_DevPro_GigaDevice_GD32A4_GD32F4.pex'
J-Link log: -----------------------------------------------------------------------------------------------
J-Link log: FMC_OBCTL0 value:                                  0x2FFFAAED
J-Link log: -----------------------------------------------------------------------------------------------
J-Link log: BOR threshold value BOR_TH[1:0]:                   0x00000003
J-Link log: |-> No BOR function
J-Link log: -----------------------------------------------------------------------------------------------
J-Link log: Boot bank value BB:                                0x00000000
J-Link log: |-> Boot from bank0
J-Link log: -----------------------------------------------------------------------------------------------
J-Link log: Watchdog value nWDG_HW:                            0x00000001
J-Link log: |-> Software free watchdog
J-Link log: -----------------------------------------------------------------------------------------------
J-Link log: Deepsleep reset value nRST_DPSLP:                  0x00000001
J-Link log: |-> No reset when entering Deep-sleep mode
J-Link log: -----------------------------------------------------------------------------------------------
J-Link log: Standby reset value nRST_STDBY:                    0x00000001
J-Link log: |-> No reset when entering standby mode
J-Link log: -----------------------------------------------------------------------------------------------
J-Link log: Security Protection code SPC[7:0]:                 0x000000AA
J-Link log: |-> No security protection
J-Link log: -----------------------------------------------------------------------------------------------
J-Link log: Erase/program protection of each sector WP0[11:0]: 0x00000FFF
J-Link log: -----------------------------------------------------------------------------------------------
J-Link log: Double banks or single bank selection:             0x00000000
J-Link log: |-> Single bank when flash size is 1M bytes
J-Link log: -----------------------------------------------------------------------------------------------
J-Link log: DBUS read protection:                              0x00000000
J-Link log: |-> The WPx bits used as erase/program protection of each sector

Writing option bytes register (setting SPC level 1 protection):

DevPro -operation WriteOptionBytes -if SWD -speed 4000 -SetConfigVal "OptionName=FMC_OBCTL0" -SetConfigVal "Value=0x2FFFBBED"-ScriptFile "PCode_DevPro_GigaDevice_GD32A4_GD32F4.pex"
SEGGER Device Provisioner V7.96l
Compiled Jun 12 2024 18:55:19

'q' to quit '?' for help

Command line: -operation WriteOptionBytes -if SWD -speed 4000 -SetConfigVal OptionName=FMC_OBCTL0 -SetConfigVal Value=0x2FFFBBED -ScriptFile PCode_DevPro_GigaDevice_GD32A4_GD32F4.pex
Opened script file: 'PCode_DevPro_GigaDevice_GD32A4_GD32F4.pex'
J-Link log: Option bytes programmed successfully