2023年5月21日 星期日

HT32F52352 開發套件裝 QMK 測試

萬事起頭,最快進入狀況的方式是找一個範例來改。在 qmk_firmware 中,搜尋程式碼中有 HT32 關鍵字的程式,很幸運找到 keyboards/annepro2,然後就沒別的了。

這支  Anne Pro 2 的鍵盤,MCU 是 HT32F52342,和 HT32F52352 的差別在於其 flash 只有一半。

BootLoader 測試

說明中提到要用 [OpenAnnePro / AnnePro2-Tools] 來寫入產生的 bin image。從原來鍵盤 dump 出來的 IAP (In Application Programming) bootloader 則可在 OpenAnnePro / AnnePro2-Bootloader 找到。這是從 Anne Pro 2 C15 鍵盤 dump 出來的 image。

為了能儘快測試 HT32 連 TrackPoint 的功能,需要有一個測試環境,能使用 IAP 的方式寫入鍵盤 image 比較方便。 HT32F52342 和 HT32F52352 只有 flash 大小不同,且後者比前者大,就來試試 Anne Pro 2 的 bootloader 和 qmk 設定吧。

 用 git clone 把 AnnePro2-Bootloader 的所有資料下載,再用下面的指令寫入開發板的 MCU。

eLink2pro -a bootloader.bin  firmware

接上裝置後使用 dmesg 看到的訊息如下

[491032.173213] usb 1-7.4.3: new full-speed USB device number 15 using xhci_hcd
[491032.250654] usb 1-7.4.3: New USB device found, idVendor=04d9, idProduct=8008, bcdDevice= 1.00
[491032.250671] usb 1-7.4.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[491032.250677] usb 1-7.4.3: Product: USB-HID IAP
[491032.250681] usb 1-7.4.3: Manufacturer: HOLTEK
[491032.250685] usb 1-7.4.3: SerialNumber: SN0000000001
[491032.262570] input: HOLTEK USB-HID IAP as /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7.4/1-7.4.3/1-7.4.3:1.0/0003:04D9:8008.0010/input/input27
[491032.314697] hid-generic 0003:04D9:8008.0010: input,hidraw6: USB HID v1.10 Keyboard [HOLTEK USB-HID IAP] on usb-0000:00:14.0-7.4.3/input0
[491032.315905] input: HOLTEK USB-HID IAP as /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7.4/1-7.4.3/1-7.4.3:1.1/0003:04D9:8008.0011/input/input28
[491032.316052] hid-generic 0003:04D9:8008.0011: input,hidraw7: USB HID v1.10 Device [HOLTEK USB-HID IAP] on usb-0000:00:14.0-7.4.3/input1

如 bootloader 的說明,裝置的 ID 為 04d9:8008,裝置描述則為 HOLTEK USB-HID IAP。因為其判斷沒有正確的 AP,就直接進入 IAP。

接下來,使用 qmk 指令產生 annepro2/c15 的 image,指令如下

$ qmk compile -kb ajtest/annepro2/c15 -km default 

產生的 image 為 annepro2_c15_default.bin。指令如下,必須使用 sudo 才有權限寫入

$ sudo ./annepro2_tools annepro2_c15_default.bin 

拔掉重新連線,使用 dmesg 看到的訊息如下

[497734.509647] usb 1-7.4.3: new full-speed USB device number 19 using xhci_hcd
[497734.587567] usb 1-7.4.3: New USB device found, idVendor=feed, idProduct=ac15, bcdDevice=13.37
[497734.587584] usb 1-7.4.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[497734.587590] usb 1-7.4.3: Product: Anne Pro 2 C15 (QMK)
[497734.587594] usb 1-7.4.3: Manufacturer: Obins
[497734.594474] input: Obins Anne Pro 2 C15 (QMK) as /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7.4/1-7.4.3/1-7.4.3:1.0/0003:FEED:AC15.0019/input/input36
[497734.645861] hid-generic 0003:FEED:AC15.0019: input,hidraw6: USB HID v1.11 Keyboard [Obins Anne Pro 2 C15 (QMK)] on usb-0000:00:14.0-7.4.3/input0
[497734.646396] input: Obins Anne Pro 2 C15 (QMK) System Control as /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7.4/1-7.4.3/1-7.4.3:1.1/0003:FEED:AC15.001A/input/input37
[497734.697975] input: Obins Anne Pro 2 C15 (QMK) Consumer Control as /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7.4/1-7.4.3/1-7.4.3:1.1/0003:FEED:AC15.001A/input/input38
[497734.698267] hid-generic 0003:FEED:AC15.001A: input,hidraw7: USB HID v1.11 Device [Obins Anne Pro 2 C15 (QMK)] on usb-0000:00:14.0-7.4.3/input1 

裝置的 ID 變成 feed:ac15,裝置描述為 Obins Anne Pro 2 C15 (QMK),此為 info.json 裡的 name 設定的字串。使用鍵盤測試軟體,如 [https://en.key-test.ru]。將 row 接腳 C2 逐一與 col 接腳 C4 和 C5短路,確定為 'Esc' 和 '1',表示鍵盤功能正確。

進入 IAP 的方式,按著 ESC 鍵不放,再連上鍵盤。對應 ESC 鍵的 row 接腳為 C2,對應的 col 接腳為 C4。把 C2 和 C4 短路再連上鍵盤,成功進入 IAP 模式。

至此算是又往目標邁進一步,接下來就可以測試連接 TrackPoint 的功能。更進一步,必須要有可用的 HT32F1654 的 bootloader,才能改阿米洛68鍵盤。

TrackPoint 連接測試

依照  Anne Pro 2 設定好鍵盤,測試 OK。再加上 ps2 mouse 的功能,先使用較單純的 busywait-version。但是並沒有想像中的順利,加上 mouse 功能後,接上鍵盤,大約要等半分鐘以上鍵盤才有反應。剛好前陣子測 OpenOCD 不順利,買了個 USB Logic Analyzer,正好可以看一下波形。大約半分鐘以後,clock 和 data 才出現波形。

但不論怎麼改,都無法成功。只好想辦法用  QMK 的 debug 功能。從 QMK toolbox 看到的訊息,這樣比較有點方向了。


追蹤了好久,發現是 wait_us() 的時間不對,大致上做了下列的修改。
$ sudo === 在 config.h 中加入 ===
#define WAIT_US_TIMER GPTD_BFTM0

=== 在 halconf.h 中加入 ===
#define HAL_USE_GPT TRUE 
#define HT32_GPT_USE_BFTM0 TRUE


=== \lib\chibios-contrib\os\hal\ports\HT32\LLD\TIMv1\hal_gpt_lld.h ===
/**
 * @brief   Driver configuration structure.
 * @note    It could be empty on some architectures.
 */
typedef struct {
  /**
   * @brief   Timer clock in Hz.
   * @note    The low level can use assertions in order to catch invalid
   *          frequency specifications.
   */
  gptfreq_t                 frequency;
  /**
   * @brief   Timer callback pointer.
   * @note    This callback is invoked on GPT counter events.
   */
  gptcallback_t             callback;
  /* End of the mandatory fields.*/
  /**
   * @brief TIM CR2 register initialization data.
   * @note  The value of this field should normally be equal to zero.
   */
  uint32_t                  cr2;
  /**
   * @brief TIM DIER register initialization data.
   * @note  The value of this field should normally be equal to zero.
   * @note  Only the DMA-related bits can be specified in this field.
   */
  uint32_t                  dier; 
} GPTConfig;

至此初步可以在 mcu 和 trackpoint 之間傳送指令和資料,但為了測試,drivers/ps2 目錄下的程式都被我改亂了,以致於無法正確取得資料。到官網下載原始檔,再重新編譯,功能就正常了。接下來,就是想辦法把 interrupt version 弄正常來。






沒有留言:

張貼留言

網誌存檔