2009年6月30日火曜日

VIMが大好き!

最初はVIMのこと使いにくいと思いました。
少しつつ勉強しながら、大好きになりました。
やはり、メインキーボードだけ、なんでもできるのはかっこういいでしょう ^^

VIMでtagの使い方を探していた時、下記のURLを見つかりました。
ありがとう、勉強になりました!

2009年6月26日金曜日

NVICの優先順位について

ここ参照します。
http://blog.ednchina.com/STM32/143803/message.aspx

簡単に言えば、STM32の優先グループが五つのモードがあります。

/* 0 bits for pre-emption priority 4 bits for subpriority */
#define NVIC_PriorityGroup_0 ((u32)0x700)

/* 1 bits for pre-emption priority 3 bits for subpriority */
#define NVIC_PriorityGroup_1 ((u32)0x600)

/* 2 bits for pre-emption priority 2 bits for subpriority */
#define NVIC_PriorityGroup_2 ((u32)0x500)

/* 3 bits for pre-emption priority 1 bits for subpriority */
#define NVIC_PriorityGroup_3 ((u32)0x400)

/* 4 bits for pre-emption priority 0 bits for subpriority */
#define NVIC_PriorityGroup_4 ((u32)0x300)

割り込みを発生する時、優先順位高いの関数が優先順位低いの関数を中断して先に実行する。

pre-emptionの数字が低いの方が優先順位が高い、例えば:0が1より優先が高い。
pre-emptionは同じの場合、subpriorityの数字を確認する、小さいの方が高い。

わたしのコードが下記を示す

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN_RX0_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

/* Enable USART1 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_Init(&NVIC_InitStructure);

/* Enable the DMA1 Channel1 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

優先1、USART1
優先2、USB
優先3、DMA1

2009年6月22日月曜日

ADCのサンプルコード

ANALOG INPUT:PA.4(ADC_AIN_CHANNEL_X)、PC.4(ADC_AIN_CHANNEL_Y)、PC.5(ADC_AIN_CHANNEL_Z)
DMA1を利用して、X Y Z情報がADC1_DR_AddressからADC_ConvertedValueXに自動保存します。
ADC_ConvertedValueX[0]=X
ADC_ConvertedValueX[1]=Y
ADC_ConvertedValueX[2]=Z

サンプルコードが下記に示す。

void ADC_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;

/* Enable DMA1 clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

/* Enable ADC1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

/* DMA1 channel1 configuration ---------------------------------------------*/
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValueX[0];
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 3;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;/*DMA_MemoryInc_Disable;*/
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);

/* Enable DMA1 channel1 */
DMA_Cmd(DMA1_Channel1, ENABLE);

/* Enable the DMA1 Channel1 Transfer complete interrupt */
DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);

/* ADC1 configuration ------------------------------------------------------*/
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 3;
ADC_Init(ADC1, &ADC_InitStructure);

/* ADC1 regular channel configuration */
ADC_RegularChannelConfig(ADC1, ADC_AIN_CHANNEL_X, 1, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_AIN_CHANNEL_Y, 2, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_AIN_CHANNEL_Z, 3, ADC_SampleTime_55Cycles5);

/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);

/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);

/* Enable ADC1 reset calibaration register */
ADC_ResetCalibration(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1));

/* Start ADC1 calibaration */
ADC_StartCalibration(ADC1);

/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));
}

今、OpenJTAGを使ってデバック環境でX、Y、Z情報をきちんと取りますが、デバッグ以外の場合がDMA1の割り込みを発生しません。
何で?

2009年6月12日金曜日

MAX3232の接続方式

こんな感じです、正しいはずなんですが、何か動かない…

2009年6月8日月曜日

Virtual Com Portがやっとできました ^_^

STM32の割り込みサービスルーチン(stm32f10x_it)が更新していないのせいだ、
割り込み関数正しく処理されていませんので、USBデバイスが認識をできなくなた。

hw_config.cにNVICの定義が下記の通り

  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

  NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN_RX0_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

で、今のstm32f10x_itにこの割り込み関数が空っぽだ。
void USB_LP_CAN_RX0_IRQHandler(void)
{
}

stm32f10x_itを調整して(crt0_STM32xが古いので、調整も必要です)
void USB_LP_CAN_RX0_IRQHandler(void)
{
  USB_Istr();
}

OpenJTAGを外して、ボードだけPCに挿入してみると、デバイスが見つかりました!

USB認識には、OpenJTAGが直接使わないですが、
でもおかげで、あやし所を確認できました、JTAGがいいものですね ^^


2009年6月5日金曜日

工欲善其事,必先利其器

今日は開発環境構築について、参照した資料を整理します。
◆ CodeSourcery G++
◆ Openocd
私の場合が安定のためバージョン1690をインストールした
./configure --enable-ft2232_libftdi --enable-usbprog
◆ Eclipse
 GDB Hardware Debuggingの導入:
◆ OpenJTAG
◆ FreeRTOSの導入

これから、シリアルとUSBを検証したいので、下記の資料が探す

以上


2009年6月4日木曜日

Eclipse & RTOSDemo

FreeRTOSがEclipseに導入の参照資料:

JTAGKey-Tinyの設定資料:

今回OpenJtagを利用したいので、Eclipse環境にopenocdの設定ファイルを改造することを必要と思う
openocdの設定ファイルは四つがあります。
◆ jtagkey.cfg
# default ports
telnet_port 4444
gdb_port 3333
tcl_port 6666

# interface configuration
interface ft2232
#ft2232_device_desc "Amontec JTAGkey A"
ft2232_device_desc "USB<=>JTAG&RS232
#ft2232_layout jtagkey
ft2232_layout "jtagkey_prototype_v1
#ft2232_vid_pid 0x0403 0xcff8
ft2232_vid_pid 0x1457 0x511

#jtag_speed 30
#jtag_khz 500

◆ stm32_mdBZ.cfg
# for stm32 medium density RevB and Z

set _CHIPNAME stm32
set _ENDIAN little

# jtag speed
#jtag_khz 565

reset_config trst_and_srst srst_pulls_trst
jtag_nsrst_delay 100
jtag_ntrst_delay 100

#use combined on interfaces or targets that can't set TRST/SRST separately
reset_config trst_and_srst

#jtag scan chain
if { [info exists CPUTAPID ] } {
set _CPUTAPID $CPUTAPID
} else {
# See STM Document RM0008
# Section 26.6.3
set _CPUTAPID 0x3ba00477
}
jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID

if { [info exists BSTAPID ] } {
set _BSTAPID $BSTAPID
} else {
# See STM Document RM0008
# Section 26.6.2
# Medium Density RevA
# set _BSTAPID 0x06410041
# Rev B and Rev Z
# set _BSTAPID 0x16410041
# My board is a Rev B and Rev Z
set _BSTAPID 0x16410041
}
jtag newtap $_CHIPNAME bs -irlen 5 -ircapture 0x1 -irmask 0x1 -expected-id $_BSTAPID

set _TARGETNAME [format "%s.cpu" $_CHIPNAME]
target create $_TARGETNAME cortex_m3 -endian $_ENDIAN -chain-position $_TARGETNAME

$_TARGETNAME configure -work-area-virt 0 -work-area-phys 0x20000000 -work-area-size 16384 -work-area-backup 0

#flash bank stm32x 0 0 0 0 0
#The flash of my board is start from 0x8000000 and length is 128k
flash bank stm32x 0x08000000 0x20000 0 0 0

# For more information about the configuration files, take a look at:
# openocd.texi

◆ stm32_gdb.cfg
# default ports
telnet_port 4444
gdb_port 3333
tcl_port 6666

init
jtag_khz 565
#reset init
verify_ircapture disable

◆ stm32_program_eclipse.cfg
# default ports
telnet_port 4444
gdb_port 3333
tcl_port 6666

init
jtag_khz 565
#reset init
verify_ircapture disable

halt
wait halt
poll
stm32x mass_erase 0
#flash write_image C:/Projects/FreeRTOS/Demo/CORTEX_STM32Fxxx_Eclipse/RTOSDemo/RTOSDemo.bin 0x08000000 bin
flash write_image ./RTOSDemo/RTOSDemo.bin 0x8000000 bin
reset run
shutdown

STM32に書き込み場合が Run -> Externels Tools -> OpenOCD Programmerを使います。
デバックの場合が Run -> Externels Tools -> OpenOCD Serverを利用します。

Eclipse+OpenOCD+OpenJTAG+STM32の開発環境ができました!

d^_^b

2009年6月3日水曜日

zylincdtについて

Eclipse環境構築すると、大体二つの方式があります、
ELFファイルによってデバッグするの場合がzylincdtになります。
今回zylinを利用するつもりはないですが、一応メモします。

Eclipse CDT plugin | Eclipse update site | Mini FAQ
Zylin Embedded CDT
Zylin-embedded CDT works with the official Eclipse CDT 4.x or newer.

From time to time Zylin has some patches to CDT that are not yet part of the official CDT CVS HEAD. Normally there is also a bug report sent to CDT for each of the issues. These "work-in-progress-at-your-own-risk-thus-warned-patches" are kept in cdtpatches.txt together with the Zylin Embedded CDT source code.
Download & installation

   1. Install Eclipse 3.3 or newer. We recommend the Eclipse Classic 3.x package

      http://www.eclipse.org
   2. Eclipse CDT 4.x or newer

      http://www.eclipse.org/cdt
   3. Install Zylin-embedded CDT using, the update site

      http://opensource.zylin.com/zylincdt 

If you are unfamiliar with Eclipse update sites, Subclipse provides helpful instructions. page:

http://subclipse.tigris.org/install.html 

OpenJTAGの2

openocd.cfgを下記のように修正した

telnet_port 4444
gdb_port 3333
gdb_memory_map enable
gdb_flash_program enable
interface ft2232
jtag_speed 1
ft2232_vid_pid 0x1457 0x5118
ft2232_latency 2
ft2232_layout "jtagkey_prototype_v1"
reset_config trst_and_srst

# script for stm32

# jtag speed
jtag_khz 500

jtag_nsrst_delay 100
jtag_ntrst_delay 100

reset_config trst_and_srst

jtag_device 4 0x1 0xf 0xe
jtag_device 5 0x1 0x1 0x1e

target create target0 cortex_m3 -endian little -chain-position 0

[new_target_name] configure -work-area-virt 0 -work-area-phys 0x20000000 -work-area-size 16384 -work-area-backup 0

flash bank stm32x 0x08000000 0x20000 0 0 0

openocdを実行する
kevinx@Ubuntu:~/workspace$ openocd
Open On-Chip Debugger 1.0 (2008-11-26-09:42) svn:unknown


BUGS? Read http://svn.berlios.de/svnroot/repos/openocd/trunk/BUGS


$URL: http://svn.berlios.de/svnroot/repos/openocd/trunk/src/openocd.c $
jtag_speed: 1
500 kHz
Info: JTAG device found: 0x3ba00477 (Manufacturer: 0x23b, Part: 0xba00, Version: 0x3)
Info: JTAG device found: 0x16410041 (Manufacturer: 0x020, Part: 0x6410, Version: 0x1)
Warning:no tcl port specified, using default port 6666

telnetに確認

kevinx@Ubuntu:~/workspace$ telnet 127.0.0.1 4444
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Open On-Chip Debugger
> poll
target state: unknown
> halt
target was in unknown state when halt was requested
> resume
> poll
target state: running
>

よくわからないですが、openocdができました!

2009年6月2日火曜日

OpenJTAGの1

今日はOpenJtagを試しました。
PCに接続してみたら

kevinx@Ubuntu:~/workspace$ openocd
Open On-Chip Debugger 1.0 (2008-10-04-09:26) svn:717
$URL: svn://svn.berlios.de/openocd/trunk/src/openocd.c $
Info: options.c:50 configuration_output_handler(): jtag_speed: 0, 0
Info: options.c:50 configuration_output_handler(): Open On-Chip Debugger 1.0 (2008-10-04-09:26) svn:717
Info: jtag.c:1389 jtag_examine_chain(): JTAG device found: 0x3ba00477 (Manufacturer: 0x23b, Part: 0xba00, Version: 0x3)
Info: jtag.c:1389 jtag_examine_chain(): JTAG device found: 0x16410041 (Manufacturer: 0x020, Part: 0x6410, Version: 0x1)
Error: jtag.c:1399 jtag_examine_chain(): number of discovered devices in JTAG chain (2) doesn't match configuration (1)
Error: jtag.c:1400 jtag_examine_chain(): check the config file and ensure proper JTAG communication (connections, speed, ...)
Error: jtag.c:1556 jtag_init_inner(): trying to validate configured JTAG chain anyway...
Error: jtag.c:1456 jtag_validate_chain(): Error validating JTAG scan chain, IR mismatch, scan returned 0x11
Error: jtag.c:1456 jtag_validate_chain(): Error validating JTAG scan chain, IR mismatch, scan returned 0x11
Error: jtag.c:1456 jtag_validate_chain(): Error validating JTAG scan chain, IR mismatch, scan returned 0x11
Error: jtag.c:1456 jtag_validate_chain(): Error validating JTAG scan chain, IR mismatch, scan returned 0x11
Error: jtag.c:1456 jtag_validate_chain(): Error validating JTAG scan chain, IR mismatch, scan returned 0x11
Error: jtag.c:1456 jtag_validate_chain(): Error validating JTAG scan chain, IR mismatch, scan returned 0x11
Error: jtag.c:1565 jtag_init_inner(): Could not validate JTAG chain, exit
Info: jtag.c:1389 jtag_examine_chain(): JTAG device found: 0x3ba00477 (Manufacturer: 0x23b, Part: 0xba00, Version: 0x3)
Info: jtag.c:1389 jtag_examine_chain(): JTAG device found: 0x16410041 (Manufacturer: 0x020, Part: 0x6410, Version: 0x1)
Error: jtag.c:1399 jtag_examine_chain(): number of discovered devices in JTAG chain (2) doesn't match configuration (1)
Error: jtag.c:1400 jtag_examine_chain(): check the config file and ensure proper JTAG communication (connections, speed, ...)
Error: jtag.c:1556 jtag_init_inner(): trying to validate configured JTAG chain anyway...
Error: jtag.c:1456 jtag_validate_chain(): Error validating JTAG scan chain, IR mismatch, scan returned 0x11
Error: jtag.c:1456 jtag_validate_chain(): Error validating JTAG scan chain, IR mismatch, scan returned 0x11
Error: jtag.c:1456 jtag_validate_chain(): Error validating JTAG scan chain, IR mismatch, scan returned 0x11
Error: jtag.c:1456 jtag_validate_chain(): Error validating JTAG scan chain, IR mismatch, scan returned 0x11
Error: jtag.c:1456 jtag_validate_chain(): Error validating JTAG scan chain, IR mismatch, scan returned 0x11
Error: jtag.c:1456 jtag_validate_chain(): Error validating JTAG scan chain, IR mismatch, scan returned 0x11
Error: jtag.c:1565 jtag_init_inner(): Could not validate JTAG chain, exit

設定ファイルっぽいですね。
kevinx@Ubuntu:~/workspace$ more openocd.cfg
telnet_port 4444
gdb_port 3333
interface ft2232
jtag_speed 0
ft2232_vid_pid 0x1457 0x5118
ft2232_layout "jtagkey_prototype_v1"
reset_config trst_and_srst
jtag_device 4 0x1 0xf 0xe
daemon_startup attach
target arm920t little reset_run 0 arm920t
#arm7_9 fast_memory_access enable
working_area 0 0x200000 0x4000 backup
#flash bank cfi 0 0x100000 2 2 0
#debug_level 3
nand device s3c2440 0
run_and_halt_time 0 5000
ft2232_device_desc "USB<=>JTAG&RS232"

今回のターゲットはcortex-m3ですので、target arm920t はもちろんダメじゃないですか...
正しいの設定は何だろうかな...

2009年6月1日月曜日

Flash module organization (high-density devices)

RCC - register map and reset values

Control/status register (RCC_CSR)







Address: 0x24
Reset value: 0x0C00 0000, reset by system Reset, except reset flags by power Reset only.
Access: 0 ≤ wait state ≤ 3, word, half-word and byte access
Wait states are inserted in case of successive accesses to this register.

Backup domain control register (RCC_BDCR)







Address offset: 0x20
Reset value: 0x0000 0000, reset by Backup domain Reset.
Access: 0 ≤ wait state ≤ 3, word, half-word and byte access
Wait states are inserted in case of successive accesses to this register.
Note: LSEON, LSEBYP, RTCSEL and RTCEN bits of the Backup domain control register
(RCC_BDCR) are in the Backup domain. As a result, after Reset, these bits are writeprotected
and the DBP bit in the Power control register (PWR_CR) has to be set before
these can be modified. Refer to Section 5 on page 58 for further information. These bits are
only reset after a Backup domain Reset (see Section 6.1.3: Backup domain reset). Any
internal or external Reset will not have any effect on these bits.

APB1 peripheral clock enable register (RCC_APB1ENR)







Address: 0x1C
Reset value: 0x0000 0000
Access: word, half-word and byte access
No wait state, except if the access occurs while an access to a peripheral on APB1 domain
is on going. In this case, wait states are inserted until this access to APB1 peripheral is
finished.
Note: When the peripheral clock is not active, the peripheral register values may not be readable
by software and the returned value is always 0x0.

APB2 peripheral clock enable register (RCC_APB2ENR)






Address: 0x18
Reset value: 0x0000 0000
Access: word, half-word and byte access
No wait states, except if the access occurs while an access to a peripheral in the APB2
domain is on going. In this case, wait states are inserted until the access to APB2 peripheral
is finished.
Note: When the peripheral clock is not active, the peripheral register values may not be readable
by software and the returned value is always 0x0.

AHB peripheral clock enable register (RCC_AHBENR)







Address offset: 0x14
Reset value: 0x0000 0014
Access: no wait state, word, half-word and byte access
Note: When the peripheral clock is not active,the peripheral register values may not be readable
by software and the returned value is always 0x0.

APB1 peripheral reset register (RCC_APB1RSTR)







Address offset: 0x10
Reset value: 0x0000 0000
Access: no wait state, word, half-word and byte access

APB2 peripheral reset register (RCC_APB2RSTR)






Address offset: 0x0C
Reset value: 0x00000 0000
Access: no wait state, word, half-word and byte access

Clock interrupt register (RCC_CIR)







Address offset: 0x08
Reset value: 0x0000 0000
Access: no wait state, word, half-word and byte access