CubeMX とAlternateFunction

CubeMX を使うと、ピンアサインの設定が楽になるらしいので、試してみた。デフォルトの複数機能から選択することは簡単にできた。

 

だが、Zumo Shield の光センサアレイは、6本のADCが必要。4本は上記の機能で選択できた。が、残り2本、PB4,PB5をADCに割り当てることはできなかった。

 

ARMならば、AF機能を使えばできたはず。具体的な方法を調べる。

 

発見した!

RM0368
Reference manual
STM32F401xB/C and STM32F401xD/E
advanced ARM®-based 32-bit MCUs

8.3 GPIO functional description

8.3.2 I/O pin multiplexer and mapping

Peripheral alternate function
For the ADC, configure the desired I/O as analog in the GPIOx_MODER register.

 

GPIOではなくADCとして端子を使いたい場合、GPIO port mode register を設定する。

f:id:kzono:20160816201444p:plain

 

今、PortAとPortBをGPIOではなくADCにしたいので、MODER0[1:0]MODER1[1:0] を11:Analog mode にする。0x0000000F と or をとればよい。

 

あとは、ADC側の設定をすればよいはず。全部で 16ch あるので、それを PortA, PortB に接続する。

 そもそも PortA , PortB, PortC は[0:15] と、それぞれ 16bit ある。Arduinoヘッダには少ししかつながっていないが、Morph ヘッダにはつながっている。

f:id:kzono:20160816211209p:plain

リファレンスマニュアルの該当箇所は、

11.3.3 Channel selection
There are 16 multiplexed channels. It is possible to organize the conversions in two groups:
regular and injected. A group consists of a sequence of conversions that can be done on
any channel and in any order. For instance, it is possible to implement the conversion
sequence in the following order: ADC_IN3, ADC_IN8, ADC_IN2, ADC_IN2, ADC_IN0,
ADC_IN2, ADC_IN2, ADC_IN15.
• A regular group is composed of up to 16 conversions. The regular channels and their
order in the conversion sequence must be selected in the ADC_SQRx registers. The
total number of conversions in the regular group must be written in the L[3:0] bits in the
ADC_SQR1 register.

ADC_AQR1 - ADC_AQR3 に設定すればよさそう。 

 

。。。うーん、違うみたい。AD変換を行う順番を制御するためのレジスタっぽい。GPIOのどのビットをADCのどのチャネルに接続するか、その設定を知りたいのだが。