Skip to content

Commit

Permalink
Support MAX78000EXG+ by disabling the ROM loader
Browse files Browse the repository at this point in the history
  • Loading branch information
maximreza authored and rotx-eva committed Apr 8, 2024
1 parent 3f505cf commit 4a2b6d3
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
82 changes: 82 additions & 0 deletions ROM_loader_disable.gdbscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# To run the script:

# $ openocd -s "${TOOLCHAIN_PATH}/OpenOCD/scripts" -f interface/cmsis-dap.cfg -f target/max78000.cfg
# $ arm-none-eabi-gdb -batch -q -x ROM_loader_disable.gdbscript

set variable $fctl_base_addr=0x40029000
set variable $fctl_faddr=$fctl_base_addr+0x00
set variable $fctl_fcntl=$fctl_base_addr+0x08
set variable $fctl_acntl=$fctl_base_addr+0x40
set variable $fctl_fdata0=$fctl_base_addr+0x30
set variable $fctl_fdata1=$fctl_base_addr+0x34
set variable $fctl_fdata2=$fctl_base_addr+0x38
set variable $fctl_fdata3=$fctl_base_addr+0x3C

define pico
target remote 127.0.0.1:3333
set verbose off
end

define mrh
monitor reset halt
end

define MAX78000
pico
end

define lock_otp
# Write acntl to lock OTP
set *$fctl_acntl=0xdeadbeef
end

define unlock_otp
# First, put otp controller in known lock state.
lock_otp
# Write acntl to unlock OTP
set *$fctl_acntl=0x3a7f5ca3
set *$fctl_acntl=0xa1e34f20
set *$fctl_acntl=0x9608b2c1
end

# arg0 = address
# arg1 = 32-bit data
# arg2 = 32-bit data
# arg3 = 32-bit data
# arg4 = 32-bit data
define write_flash_128
# Unlock and Set width to 128 (bit 4 to zero)
set *$fctl_fcntl=*$fctl_fcntl | 0x20000000
set *$fctl_fcntl=*$fctl_fcntl & ~0x00000010
# Set address
set *$fctl_faddr=$arg0
# Set 128-bits of data
set *$fctl_fdata0=$arg1
set *$fctl_fdata1=$arg2
set *$fctl_fdata2=$arg3
set *$fctl_fdata3=$arg4
# start flash operation
set *$fctl_fcntl=*$fctl_fcntl | 0x20000001
while (0 != (*$fctl_fcntl & 0x7))
# Wait for flash write to complete
end
end

#####################################################
#################### WARNING ########################
# Executing this function permanently locks the ROM #
# bootloader. This operation cannot be reverted! ####
#####################################################

define MAX78000_write_bootloader_disable
unlock_otp
write_flash_128 0x00080130 0xFC000001 0x4116FFFF 0xFFFFFC00 0x543E0000
write_flash_128 0x00080140 0xFC000001 0x4116FFFF 0xFFFFFC00 0x543E0000
lock_otp
print "Done"
end

MAX78000
MAX78000_write_bootloader_disable


0 comments on commit 4a2b6d3

Please sign in to comment.