FreeMaster 是 NXP 提供 Real-time Debug 使用的工具,在需要偵測資料變化或調整控制演算法的情況下十分有用。FreeMaster 具有以下的特色功能:
- 在不使用 Debug 中斷的情況下對內部的參數做實時偵測。
- 以模擬示波器的方式顯示讀取的數據
- 直接修改被觀測中的變數
- 將觀測到的變數進行轉換,讓變數更容易被閱讀
- 操作直觀,簡單易用
1. FreeMaster SDK 添加
1.1 SDK 添加方式
1.2 freemaster_cfg.h 設置說明
FreeMaster 將所有的設置選項集成於名為 freemaster_cfg.h 的頭文件中,當 SDK 被添加到專案時,會由預設路徑拷貝一份作為範例的頭文件放入專案目錄的 include 資料夾下。在某些情況下 ( ex. 添加的專案是由 S32DS 建立的 Example 程式) 範例頭文件沒有被複製到專案中,則可以透過以下的路徑自行添加,再將檔案名稱更正為 freemaster_cfg.h。
C:\NXP\S32DS_Power_v2.1\S32DS\software\FreeMASTER_Serial_Communication_Driver_V2_0\src_platforms\MPC57xx\freemaster_cfg.h.example
關於 FreeMaster SDK 可以設置的選項的說明,可以在 User Guide 中,章節 “ 2.4.3 Configurable items ”之中找到。User Guide 路徑參考下方 :
C:\NXP\S32DS_Power_v2.1\S32DS\software\FreeMASTER_Serial_Communication_Driver_V2_0\doc\UserGuide\FMSTRSCIDRVUG.pdf
對於未使用的功能,FreeMaster SDK 都有預設的定義值,因此使用者只須要根據自己需要的功能定義即可。
1.2.1 FreeMaster 的工作模式設置
FreeMaster 可以設置自身的執行時間分配,共有三種配置可供選擇,僅有其中一個可以設置為 1,其餘都需設置為 0。
若 FreeMaster 使用中斷,需要將所使用通訊的中斷設置為 FMSTR_Isr()。
- #define FMSTR_LONG_INTR
將該項定義為 1,則 FreeMaster 完全於中斷當中運行。 - #define FMSTR_SHORT_INTR
將該項定義為 1,則 FreeMaster 僅於中斷中處理通訊,剩餘部分於 FMSTR_Poll() 中運行。 - #define FMSTR_POLL_DRIVEN
將該項定義為 1,則 FreeMaster 完全於 FMSTR_Poll() 當中運行。
1.2.2 FreeMaster 開啟 / 關閉
#define FMSTR_DISABLE
將該項定義為 1,則 FreeMaster停止運行。預設值為 0。
1.2.3 FreeMaster 使用的通訊種類
FreeMaster 需要定義使用的通訊與該通訊外設的 Memory Address Base。於 MPC5777C 可使用的通訊協定如下:
- #define FMSTR_USE_ESCI
將該項定義為 1,則 FreeMaster 設置 ESCI 為通訊端口。 - #define FMSTR_USE_MSCAN
將該項定義為 1,則 FreeMaster 設置 MSCAN為通訊端口。 - #define FMSTR_USE_FLEXCAN
將該項定義為 1,則 FreeMaster 設置 FlexCAN為通訊端口。
1.2.4 使用通訊的外設記憶體位址 ( 以 MPC5777C 為例 )
Memory Address Base 設置如下:
若使用 ESCI,則該項被需定義為想設置的通訊端口。MPC5777C ESCI 位址如下:
#define FMSTR_SCI_BASE 0xFFFB0000UL /* eSCI_A base on MPC5777C */
#define FMSTR_SCI_BASE 0xFFFB4000UL /* eSCI_B base on MPC5777C */
#define FMSTR_SCI_BASE 0xFFFB8000UL /* eSCI_C base on MPC5777C */
#define FMSTR_SCI_BASE 0xC3FB0000UL /* eSCI_D base on MPC5777C */
#define FMSTR_SCI_BASE 0xC3FB4000UL /* eSCI_E base on MPC5777C */
#define FMSTR_SCI_BASE 0xC3FB8000UL /* eSCI_F base on MPC5777C */
若使用 MSCAN / FlexCAN,則該項被需定義為想設置的通訊端口。MPC5777C MSCAN / FlexCAN 位址如下:
#define FMSTR_CAN_BASE 0xFFFC0000UL /* FlexCAN_A base on MPC5777C */
#define FMSTR_CAN_BASE 0xFFFC4000UL /* FlexCAN_B base on MPC5777C */
#define FMSTR_CAN_BASE 0xC3E60000UL /* FlexCAN_C base on MPC5777C */
#define FMSTR_CAN_BASE 0xC3E64000UL /* FlexCAN_D base on MPC5777C */
#define FMSTR_CAN_BASE 0xFFE30000UL /* M_CAN_0 base on MPC5777C */
#define FMSTR_CAN_BASE 0xFFE38000UL /* M_CAN_1 base on MPC5777C */
1.2.5 通訊外設的相關設置
- #define FMSTR_COMM_BUFFER_SIZE 0
該項定義 FreeMaster protocol 使用的 buffer size。設置為 0 時 SDK 會自動根據設置分配。 - #define FMSTR_COMM_RQUEUE_SIZE 32
該項定義 FreeMaster 在 FMSTR_SHORT_INTR 模式時,中斷中使用的 buffer size。預設為 32。 - #define FMSTR_FLEXCAN_TXMB 0
該項定義當 FreeMaster 使用 FlexCAN 進行通訊時,使用的 TX buffer number。 - #define FMSTR_FLEXCAN_RXMB 1
該項定義當 FreeMaster 使用 FlexCAN 進行通訊時,使用的 RX buffer number。
1.2.6 Memory 與 variable 讀寫功能
FreeMaster 在變數的讀寫功能上分為 Memory 與 variable,兩者的差異在通訊時 variable 支援 1, 2, 4-byte 讀寫。WRITEMEMASK 則是 bit 操作指令。以下是各項設置列表。
#define FMSTR_USE_READMEM 1 /* enable read memory commands */
#define FMSTR_USE_WRITEMEM 1 /* enable write memory commands */
#define FMSTR_USE_WRITEMEMMASK 1 /* enable write memory bits commands */
#define FMSTR_USE_READVAR 1 /* enable read variable fast commands */
#define FMSTR_USE_WRITEVAR 1 /* enable write variable fast commands */
#define FMSTR_USE_WRITEVARMASK 1 /* enable write variable bits fast commands */
1.2.7 Oscilloscope 設置
FreeMaster 可以針對 Oscilloscope 功能是否開啟,以及同時可以觀測的變數最大數量做設置。
#define FMSTR_USE_SCOPE 1 /* enable/disable scope support */
#define FMSTR_MAX_SCOPE_VARS 8 /* max. number of scope variables (2..8) */
1.2.8 Recorder 設置
- #define FMSTR_USE_RECORDER 1 /* enable/disable recorder support */
FreeMaster SDK 可以設置 Recorder 功能是否開啟,以及 - #define FMSTR_MAX_REC_VARS 8 /* max. number of recorder variables (2..8) */
FreeMaster SDK 可以設置同時觀測的變數最大數量 ( 2-8 )。 - #define FMSTR_REC_OWNBUFF 0 /* use user-allocated rec. buffer (1=yes) */
FreeMaster 可以不對 Buffer size 預先設置,而在程式中調用 FMSTR_SetUpRecBuff() API 進行 buffer 分配。 - #define FMSTR_REC_BUFF_SIZE 4096 /* built-in buffer size */
FreeMaster SDK 可以設置 Recorder 的 Buffer size - #define FMSTR_REC_TIMEBASE FMSTR_REC_BASE_MILLISEC(1)
若 Recorder() 在程式中是定時調用的,則可以設置 Recorder 的調用間隔時間,供 FreeMaster Tool 使用。時間的表示方式:
FMSTR_REC_BASE_SECONDS(x)
FMSTR_REC_BASE_MILLISEC(x)
FMSTR_REC_BASE_MICROSEC(x)
FMSTR_REC_BASE_NANOSEC(x) - #define FMSTR_REC_FLOAT_TRIG 0 /* enable/disable floating point triggering */
設置為 1 可以將 Recorder 的 Trigger value 設置為浮點數。
2. FreeMaster API 使用
2.1 FMSTR_Poll()
此函數除了 FMSTR_LONG_INTR 模式以外,皆須在 main.c 的背景循環函示中調用。
FMSTR_Poll 在FMSTR_SHORT_INTR 中會處理通訊中斷中收到的 FreeMaster tool 指令,並加以處理。
若使用 FMSTR_POLL_DRIVEN 模式,則包含通訊的工作也在該函式中處理。
2.2 FMSTR_Recorder()
在想要 Recorder 記錄變數的位置調用 FMSTR_Recorder 函式。