From d4cea3d89677b3711695f803f8bfe15c58d7d6ea Mon Sep 17 00:00:00 2001 From: Sergey Shchelkanov Date: Sat, 26 Aug 2023 17:49:31 +0300 Subject: [PATCH] move pm control to new file and move to main script --- mik32_eeprom.py | 45 ---------------------------------------- mik32_pm.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ mik32_spifi.py | 45 ---------------------------------------- mik32_upload.py | 3 +++ 4 files changed, 58 insertions(+), 90 deletions(-) create mode 100644 mik32_pm.py diff --git a/mik32_eeprom.py b/mik32_eeprom.py index 4c68bdc..b3919ed 100644 --- a/mik32_eeprom.py +++ b/mik32_eeprom.py @@ -4,46 +4,6 @@ import time from tclrpc import OpenOcdTclRpc from utils import bytes2words -# -------------------------- -# PM register offset -# -------------------------- -PM_BASE_ADDRESS = 0x000050000 - -PM_Clk_AHB_Set_OFFSET = 0x0C -PM_Clk_APB_M_Set_OFFSET = 0x14 -PM_Clk_APB_P_Set_OFFSET = 0x1C - -# -------------------------- -# PM register fields -# -------------------------- -# AHB BUS -PM_CLOCK_CPU_S = 0 -PM_CLOCK_CPU_M = (1 << PM_CLOCK_CPU_S) -PM_CLOCK_EEPROM_S = 1 -PM_CLOCK_EEPROM_M = (1 << PM_CLOCK_EEPROM_S) -PM_CLOCK_RAM_S = 2 -PM_CLOCK_RAM_M = (1 << PM_CLOCK_RAM_S) -PM_CLOCK_SPIFI_S = 3 -PM_CLOCK_SPIFI_M = (1 << PM_CLOCK_SPIFI_S) -PM_CLOCK_TCB_S = 4 -PM_CLOCK_TCB_M = (1 << PM_CLOCK_TCB_S) -PM_CLOCK_DMA_S = 5 -PM_CLOCK_DMA_M = (1 << PM_CLOCK_DMA_S) -PM_CLOCK_CRYPTO_S = 6 -PM_CLOCK_CRYPTO_M = (1 << PM_CLOCK_CRYPTO_S) -PM_CLOCK_CRC32_S = 7 -PM_CLOCK_CRC32_M = (1 << PM_CLOCK_CRC32_S) - -# APB M -PM_CLOCK_PM_S = 0 -PM_CLOCK_PM_M = (1 << PM_CLOCK_PM_S) - -# -------------------------- -# WU register offset -# -------------------------- -WU_BASE_ADDRESS = 0x00060000 - -WU_Clocks_OFFSET = 0x10 # -------------------------- # EEPROM register offset @@ -94,11 +54,6 @@ EEPROM_PAGE_MASK = 0x1F80 def eeprom_sysinit(openocd: OpenOcdTclRpc): print("MCU clock init...", flush=True) - openocd.write_word(WU_BASE_ADDRESS + WU_Clocks_OFFSET, 0x202) - openocd.write_word(PM_BASE_ADDRESS + PM_Clk_APB_P_Set_OFFSET, 0xffffffff) - openocd.write_word(PM_BASE_ADDRESS + PM_Clk_APB_M_Set_OFFSET, 0xffffffff) - openocd.write_word(PM_BASE_ADDRESS + PM_Clk_AHB_Set_OFFSET, 0xffffffff) - class EEPROM_Operation(Enum): READ = EEPROM_OP_RD diff --git a/mik32_pm.py b/mik32_pm.py new file mode 100644 index 0000000..c16c7cb --- /dev/null +++ b/mik32_pm.py @@ -0,0 +1,55 @@ +# -------------------------- +# PM register offset +# -------------------------- +PM_BASE_ADDRESS = 0x000050000 + +PM_Clk_AHB_Set_OFFSET = 0x0C +PM_Clk_APB_M_Set_OFFSET = 0x14 +PM_Clk_APB_P_Set_OFFSET = 0x1C + +# -------------------------- +# PM register fields +# -------------------------- + +# AHB BUS +PM_CLOCK_CPU_S = 0 +PM_CLOCK_CPU_M = (1 << PM_CLOCK_CPU_S) +PM_CLOCK_EEPROM_S = 1 +PM_CLOCK_EEPROM_M = (1 << PM_CLOCK_EEPROM_S) +PM_CLOCK_RAM_S = 2 +PM_CLOCK_RAM_M = (1 << PM_CLOCK_RAM_S) +PM_CLOCK_SPIFI_S = 3 +PM_CLOCK_SPIFI_M = (1 << PM_CLOCK_SPIFI_S) +PM_CLOCK_TCB_S = 4 +PM_CLOCK_TCB_M = (1 << PM_CLOCK_TCB_S) +PM_CLOCK_DMA_S = 5 +PM_CLOCK_DMA_M = (1 << PM_CLOCK_DMA_S) +PM_CLOCK_CRYPTO_S = 6 +PM_CLOCK_CRYPTO_M = (1 << PM_CLOCK_CRYPTO_S) +PM_CLOCK_CRC32_S = 7 +PM_CLOCK_CRC32_M = (1 << PM_CLOCK_CRC32_S) + +# APB M +PM_CLOCK_PM_S = 0 +PM_CLOCK_PM_M = (1 << PM_CLOCK_PM_S) + +# -------------------------- +# WU register offset +# -------------------------- +WU_BASE_ADDRESS = 0x00060000 + +WU_CLOCKS_BU_OFFSET = 0x10 + +# -------------------------- +# WU register fields +# -------------------------- + +# CLOCKS_BU + + + +def pm_init(): + openocd.write_word(WU_BASE_ADDRESS + WU_CLOCKS_BU_OFFSET, 0x202) + openocd.write_word(PM_BASE_ADDRESS + PM_Clk_APB_P_Set_OFFSET, 0xffffffff) + openocd.write_word(PM_BASE_ADDRESS + PM_Clk_APB_M_Set_OFFSET, 0xffffffff) + openocd.write_word(PM_BASE_ADDRESS + PM_Clk_AHB_Set_OFFSET, 0xffffffff) \ No newline at end of file diff --git a/mik32_spifi.py b/mik32_spifi.py index ea16fc2..46ac203 100644 --- a/mik32_spifi.py +++ b/mik32_spifi.py @@ -5,46 +5,6 @@ from tclrpc import TclException from tclrpc import OpenOcdTclRpc from mik32_dma import DMA, ChannelMode, ChannelIndex, ChannelAck, ChannelIncrement, ChannelPriority, ChannelRequest, ChannelSize -# -------------------------- -# PM register offset -# -------------------------- -PM_BASE_ADDRESS = 0x000050000 - -PM_Clk_AHB_Set_OFFSET = 0x0C -PM_Clk_APB_M_Set_OFFSET = 0x14 -PM_Clk_APB_P_Set_OFFSET = 0x1C - -# -------------------------- -# PM register fields -# -------------------------- -# AHB BUS -PM_CLOCK_CPU_S = 0 -PM_CLOCK_CPU_M = (1 << PM_CLOCK_CPU_S) -PM_CLOCK_EEPROM_S = 1 -PM_CLOCK_EEPROM_M = (1 << PM_CLOCK_EEPROM_S) -PM_CLOCK_RAM_S = 2 -PM_CLOCK_RAM_M = (1 << PM_CLOCK_RAM_S) -PM_CLOCK_SPIFI_S = 3 -PM_CLOCK_SPIFI_M = (1 << PM_CLOCK_SPIFI_S) -PM_CLOCK_TCB_S = 4 -PM_CLOCK_TCB_M = (1 << PM_CLOCK_TCB_S) -PM_CLOCK_DMA_S = 5 -PM_CLOCK_DMA_M = (1 << PM_CLOCK_DMA_S) -PM_CLOCK_CRYPTO_S = 6 -PM_CLOCK_CRYPTO_M = (1 << PM_CLOCK_CRYPTO_S) -PM_CLOCK_CRC32_S = 7 -PM_CLOCK_CRC32_M = (1 << PM_CLOCK_CRC32_S) - -# APB M -PM_CLOCK_PM_S = 0 -PM_CLOCK_PM_M = (1 << PM_CLOCK_PM_S) - -# -------------------------- -# WU register offset -# -------------------------- -WU_BASE_ADDRESS = 0x00060000 - -WU_Clocks_OFFSET = 0x10 # -------------------------- # SPIFI register offset @@ -240,11 +200,6 @@ def spifi_init_periphery(openocd: OpenOcdTclRpc): def spifi_init(openocd: OpenOcdTclRpc): print("MCU clock init", flush=True) - openocd.write_word(WU_BASE_ADDRESS + WU_Clocks_OFFSET, 0x202) - openocd.write_word(PM_BASE_ADDRESS + PM_Clk_APB_P_Set_OFFSET, 0xffffffff) - openocd.write_word(PM_BASE_ADDRESS + PM_Clk_APB_M_Set_OFFSET, 0xffffffff) - openocd.write_word(PM_BASE_ADDRESS + PM_Clk_AHB_Set_OFFSET, 0xffffffff) - spifi_init_periphery(openocd) control = openocd.read_word(SPIFI_CONFIG_CTRL) diff --git a/mik32_upload.py b/mik32_upload.py index 30a81c2..7afe403 100644 --- a/mik32_upload.py +++ b/mik32_upload.py @@ -9,6 +9,7 @@ from tclrpc import OpenOcdTclRpc, TclException import mik32_eeprom import mik32_spifi import mik32_ram +import mik32_pm from mik32_parsers import * @@ -319,6 +320,8 @@ def upload_file( openocd.run(f"log_output \"{log_path}\"") openocd.run(f"debug_level 1") + mik32_pm.pm_init() + if (pages.pages_eeprom.__len__() > 0): start_time = time.perf_counter()