
MSP430を使って、
PC−>MC80+の変換ボードを作製します。
その1:準備、USBの勉強とパケットキャプチャ

2017年
8月27日
秋月のF5529ボードは入手済みです。今回は表示器としてドットタイプのLCDを選択しました。aitendoの128x64のパラレルタイプのLCDパネルとフレキ変換ボードです。

9月2日
ここの資料・その他の下にUSBspec.pdfというドキュメントあるので、入手して勉強しておきます。MSP430は最新版CCSがフリーになっているので採用してみました。まずはUSBの基本の所から調べていきます。CCSにはCDC(仮想COMポート)のサンプルコードがあって直ぐに動かすことができます。USB−MIDIはCDCに似ているのでCDCを修正してプログラムを作れるはずです。ここに情報があって、”どうやってMSP430でUSB−MIDIを作るの?”という質問です。以下はC3エコープログラムのCDCのデバイスディスクプリタのソース部。

上記のC3エコープログラムを書き込んでPCに挿すと、デバイスマネージャでベンダIDは2047、プロダクトIDは0300と確認できます。

まずはフリーのUSBのパケットキャプチャがないか調べました。マイクロソフトがフリーのツール(MMA)を出しています。ここに基本的な使い方があるので、早速使ってみます。上記のベンダとプロダクトIDを指定して表示させてみます。

デバイスの初期化では、上記のソースコードのデバイスディスクプリタがキャプチャされています。

Get Full Device Descriptorではソースで定義されている全てのディスクプリタがホストに読み込まれていることが分かります。

9月27日
上記にあるディスクリプタをそのまま真似して、C3エコープログラムのdescriptors.cの内容を書き換えます。
/*-----------------------------------------------------------------------------+
| Device Descriptor
|-----------------------------------------------------------------------------*/
uint8_t const abromDeviceDescriptor[SIZEOF_DEVICE_DESCRIPTOR] = {
SIZEOF_DEVICE_DESCRIPTOR,
// Length of this descriptor
DESC_TYPE_DEVICE,
// Type code of this descriptor
0x10,
0x01,
// Release of USB spec
0x00,
// Device's base class code
0x00,
// Device's sub class code
0x00,
// Device's protocol type code
EP0_PACKET_SIZE,
// End point 0's packet size
USB_VID&0xFF,
USB_VID>>8,
// Vendor ID for device, TI=0x0451
USB_PID&0xFF,
USB_PID>>8,
// Product ID for device
VER_FW_L,
VER_FW_H,
// Revision level of device
1,
// Index of manufacturer name string desc
2,
// Index of product name string desc
USB_STR_INDEX_SERNUM,
// Index of serial number string desc
1
// Number of configurations supported
};
/*-----------------------------------------------------------------------------+
|
Configuration
Descriptor
|
|-----------------------------------------------------------------------------*/
const struct abromConfigurationDescriptorGroup abromConfigurationDescriptorGroup=
{
/* Generic part */
{
// CONFIGURATION DESCRIPTOR (9 bytes)
SIZEOF_CONFIG_DESCRIPTOR,
DESC_TYPE_CONFIG,
0x65, 0x00,
USB_NUM_INTERFACES,
USB_CONFIG_VALUE,
0x00,
USB_SUPPORT_SELF_POWERED | USB_SUPPORT_REM_WAKE,
USB_MAX_POWER
},
{
/* start MIDI[0] 9+9+9+7+6+6+9+9+9+5+9+5=92*/
{
//INTERFACE DESCRIPTOR (9 bytes)
0x09,
0x04,
0x00,
0x00,
0x00,
0x01, //オーディオデバイス
0x01, //オーディオコントロール
0x00,
0x00,
//Class-specific AC Interface Descriptor (9)
0x09,
0x24,
0x01,
0x00,
0x01,
0x09, 0x00,
0x01,
0x01,
//MIDIStreaming Interface Descriptors
//Standard MS Interface Descriptor (9)
0x09,
0x04,
0x01,
0x00,
0x02,
0x01,
0x03,
0x00,
0x00,
//Class-specific MS Interface Descriptor (7)
0x07,
0x24,
0x01,
0x00, 0x01,
0x41, 0x00,
//MIDI IN Jack Descriptor (6)
0x06,
0x24,
0x02,
0x01,
0x01,
0x00,
//MIDI IN Jack Descriptor (6)
0x06,
0x24,
0x02,
0x02,
0x02,
0x00,
//MIDI OUT Jack Descriptor (9)
0x09,
0x24,
0x03,
0x01,
0x03,
0x01,
0x02,
0x01,
0x00,
//MIDI OUT Jack Descriptor (9)
0x09,
0x24,
0x03,
0x02,
0x04,
0x01,
0x01,
0x01,
0x00,
// Standard Bulk OUT (9)
0x09,
0x05,
0x01,
0x02,
0x40, 0x00,
0x00,
0x00,
0x00,
// Class MS Bulk OUT (5)
0x05,
0x25,
0x01,
0x01,
0x01,
// Standard Bulk IN (9)
0x09,
0x05,
0x81,
0x02,
0x40, 0x00,
0x00,
0x00,
0x00,
// Class MS Bulk IN (5)
0x05,
0x25,
0x01,
0x01,
0x03
}
}
名前も変えておきます。
38, // Length of this string descriptor
3, // bDescriptorType
'M',0x00,'I',0x00,'D',0x00,'I',0x00,'C',0x00,'O',0x00,
'N',0x00,'V',0x00,'-',0x00,'M',0x00,'C',0x00,'8',0x00,
'0',0x00,'+',0x00,' ',0x00,' ',0x00,' ',0x00,' ',0x00,
descriptors.h内で確保しているディスクリプタの長さも合わせます。
/************************************************CDC Descriptor**************************/
struct abromConfigurationDescriptorCdc
{
uint8_t midi_desc[92];
};
ビルドしてUSBコネクタをWin7のPCに挿すと標準のオーディオデバイス(MIDI)として認識されました。初め、名前を変えず、”MSP430−USB Example”のままでは、以前に登録されたCDCのドライバが使われてしまい、オーディオデバイスにならず少し悩みました。現在はまだ中身が何も無いので機能しません。

MMAでキャプチャした認識過程です。

