理想的なPIC開発環境-個人的な経験

サイトの革新に関連して、私はついに地下から抜け出し、有用なものを書くことにしました。 さて、私はさまざまなマイクロコントローラー(MK)をプログラミングし、Eclipseのファンなので、それについて書くことにしました。 PICプログラミングの知識の歴史から始め、職務や趣味のためにPICファミリのMKをプログラミングする人向けのヒントで終わりますが、他のMKアーキテクチャでも同じヒントが機能します。



水曜日、大学での4年生のときに鉄工に取り組みました。科学技術センターで実践的なトレーニングコースを受講し、実際に今日まで働いています。 当時、私たちの会社の主流は、C51とARMベースのMKにKeil uVision2を使用することでした。 ただし、単一の信号(オン/オフボタン)の監視や制御など、PICの単純なタスクに夢中になり、最初の開発環境はメモ帳(紙とコンピューター、PICの紙の本)でした。 私の開発環境は次のようになりました。











ファイルをコンパイルするために、コンパイラの実行可能ファイルと、私がまったく考えずに使用したbatファイルを提供してくれました。コンパイラが何であるかさえわかりません。 一般的に、過酷な時期は...



ああ、誰かがメモ帳++のような奇跡があると私に言ったら!








それからMPASMがありましたが、それは貧弱で、私はそれについてほとんど何も覚えていません。 私の意見では、ノートブックの下にプログラムを作成しました。



MPLAB IDE



スキルが向上するにつれて、メモ帳の代わりに、MPLAB IDEのように思えた最もクールなものを使用できることを学びました。











以下が含まれます。





ただし、この開発環境をよく見ると、その惨めさと後進性は、多少なりとも良い条件に慣れているプログラマーを怖がらせることができますが、それについては知りませんでした。 組み込みライブラリ関数のヘルプを個別に開いて、何、どこ、何が呼び出されているかを確認する必要があります。 初心者向け-不可能なタスク。 ただし、トピックフォーラムでは、どのコンパイラを使用するのが良いかという質問が寄せられています。 誰かがMPLAB IDEを使い続けます。



ミクロク



PICのタスクはどんどん減り、MKシリーズC51、ARM7(ARMv7と混同しないでください!)、Cortex-Mで開発の勢いが増し始めました。 しかし、時々PICのプログラムを書くのに助けを求められ、好奇心から新しい開発ツールを試しました。

その時までに、私は長い間Keil uVision3で積極的にプログラミングを行っていました。以前のMBLAB IDEに戻りたくありませんでした。 そこで、PICKitプログラマーに付属するMikroCに会いました。











パンのセットは、MBLAB IDEとほぼ同じですが、さらに充実しています。





正直なところ、PICのプログラムの主なニッチを構成する小さな単純なプロジェクトの場合、これで十分です。 初心者でも、ヘルプを使用して簡単に理解でき、作業コードをすばやく作成できます。 ほとんどのPIC開発者はこの開発環境を使用しています。



何らかの方法で、MikroCで別のプロジェクトを作成したので、私はPICを安全に忘れてしまい、PICに戻ることはないと考えました。



しかし、物語は繰り返されるのが大好きです!



3年後の2013年には、 PIC18F4680が置かれた既製CD用のソフトウェアを開発するタスクがありました。 正直なところ、私はPICにそのようなモンスターがいることすら知りませんでした。いつも些細なことしか扱っていませんでした!



タスクは簡単ではありませんでした。インサーキットソフトウェアアップデート用のブートローダーの実装、ハードリアルタイムモードでの作業、ADC、外部DAC、制御ライン、いくつかのタイマーコンパレータの操作。



ちなみに、トピックから少し気を散らすもの:このプロジェクトでのみ、PICのメモリバンク、それらの機能、およびソフトウェア開発に課せられる制限を完全に理解しました。 たとえば、MKのすべてのバンクにはそれぞれ256バイトがあります。 そして自分自身を殺すこともできますが、PICの場合、これらの256バイトを超える構造を作成することはできません-交換プロトコルを実装する際に制限が表面化しますが、



この時点で、Keil uVision3はかなりうんざりしていました。プロジェクトの複雑さが増し、Keilで利用できる機能が不足していたからです。 2011年以降、Eclipse、GCC、makefile構文を習得し、これらのツールを使用してすべてのプロジェクトを開始しました。 さらに、Eclipse + SDCCバンドルを使用してC51 MKでプロジェクトを実装した経験があります。 Keil uVision4の登場後、プログラミングの都合上、Eclipseに比べてまだ遅れているため、Keil uVision4をインストールし、30分間テストし、取り壊しました。



Eclipse + SDCC



Eclipseは現在、組み込みシステムのソフトウェア開発の分野における事実上の標準です。 人気ブランドのEclipseベースのIDEのリストを以下に示します。





オートコンプリート、オートコンプリートのツールチップ、マクロ、非アクティブなコードセクションの減光、便利なコードナビゲーションなど-すべてをリストするわけではありません-組み込みシステムの多くの開発者は完全に不慣れであり、これらすべての便利さを知らない:











MKのC / C ++での開発のための純粋なEclipseの主な問題は、Ironプログラマーを入力するのが難しいことです。 makefileで作成-これにはすべて、ドキュメントを読んで勉強し、インターネット上の初心者向けのヘルプやチュートリアルを見つけるために、かなりの初期努力が必要です。 私は、Eclipseで鉄のプログラマーのチームを翻訳した経験がある人として話しています。

私の開発チームのみ
この記事を読んだら-教えてください、少なくともHabrahabrのプロファイルハブがここで読んでいる方法を見つけます


ただし、1か月で構文を完全にマスターし、高品質のメイクファイルを作成すると、他のすべてのプロジェクトはローレット付きテンプレートに従って作成され、最小限の個別設定のみが必要になります。



また、PICでプロジェクトを設定するための追加のジェスチャーをいくつか作成する必要がありました。デフォルトでは、EclipseはGCC構文を理解します。 他のコンパイラ(CC18またはSDCC)に組み込まれているさまざまなマクロとディレクティブは、プロジェクトのコンパイル段階とインデックス作成段階で分離する必要があります。 コード内を移動するときに、エディターが不明なディレクティブで誤ったエラーを生成しないように、 eclipse-syntax.hファイルはプロジェクトソースに接続されます。

eclipse-syntax.h
#ifndef ECLIPSE_SYNTAX_H_ #define ECLIPSE_SYNTAX_H_ // keyword SDCC defined when compiling with SDCC compiler #ifndef SDCC #ifdef __SDCC_PIC18F4680 #error "SDCC not found, project compile will be with errors!" #endif // file not parsed through makefile - just for proper eclipse syntax #ifndef __CC18__ #error "__CC18__ not found, use `-D__CC18__` in makefile for proper CC18 compilation!" #define near #define far #define rom #define ram #define _asm #define _endasm #define Nop() #define ClrWdt() #define Sleep() #define Reset() #define clrwdt #define nop #define __code #define __data #define __xdata #define __sfr #define __sbit #define __naked #define __wparam #define __bit char #define __at(num) #else // __CC18__ defined - compile stage! #endif // __CC18__ #define __inline #define __asm #define __endasm #define __interrupt(x) #define INTERRUPT(x) #define USING(x) #define CRITICAL #define CRITICAL_START #define CRITICAL_END #define _REENTRANT #else // if SDCC defined #define INTERRUPT(x) __shadowregs __interrupt (x) //#define USING(x) __using (x) #define USING(x) #define CRITICAL __critical #define CRITICAL_START __critical { #define CRITICAL_END } #endif // SDCC defined #endif /* ECLIPSE_SYNTAX_H_ */
      
      







さらに、SDCCでは、大規模なプロジェクトを既製のバイナリにリンクできませんでした。GPUtilsを構成する必要もありました。GPUtilsには、MK PICメモリカードのgpasm、gpdasm、gplink、および.lkrスクリプトが含まれます。 ただし、コードをデバッグする段階でSDCCで見つけた1つのバグのため、最終的にCC18コンパイラとリンカーに戻りました。 それにもかかわらず、SDCCとGPUtilsは完全に構成されました-苦しんでいる人のために、コンパイラとリンカーCC18、SDCC、GPUtilsを実行するためのオプションに関するmakefile部分を与えます:

メイクファイルの断片
 ########################################################### # project-specific compile options ########################################################### # Project definitions CHIP = 18F4680 DEFINES := -DPIC$(CHIP) #DEFINES += -D__SDCC_PIC$(CHIP) # use SDCC compiler DEFINES += -D__CC18__ # use MPLAB CC18 compiler #DEFINES += -DOPTIMIZE_BITFIELD_POINTER_GET # SDCC memory optimize for bitfield structures ########################################################### # common part for all sdcc-based projects ########################################################### SDCC_BASE = c:/DevTools/SDCC CC = "$(SDCC_BASE)/bin/sdcc.exe" LD = "$(SDCC_BASE)/bin/sdcc.exe" ELF2HEX = "$(SDCC_BASE)/bin/packihx.exe" HEX2BIN = "$(SDCC_BASE)/bin/makebin.exe" ########################################################### # common part for all MPLAB MCC18-based projects ########################################################### MPLAB_BASE = c:/DevTools/CC18 CC_MPLAB = "$(MPLAB_BASE)/bin/mcc18.exe" AS_MPLAB = $(MPLAB_BASE)/mpasm/mpasmwin.exe LD_MPLAB = $(MPLAB_BASE)/bin/mplink.exe ########################################################### # GPUtils used with SDCC for linking project ########################################################### GPUTILS_BASE = c:/DevTools/GNUPICutils GPASM = "$(GPUTILS_BASE)/bin/gpasm.exe" GPDASM = "$(GPUTILS_BASE)/bin/gpdasm.exe" GPLINK = "$(GPUTILS_BASE)/bin/gplink.exe" ########################################################### # C preprocessor flags for MPLAB MCC18 compiler ########################################################### #optimization parameters (default = full optimization) OPT_ENABLE_ALL := -O+ # Enable all optimizations (default) OPT_DEBUG :=-Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa- OPT :=$(OPT_ENABLE_ALL) #OPT :=$(OPT_DEBUG) CFLAGS_MPLAB := -p $(CHIP) CFLAGS_MPLAB += -I $(MPLAB_INC_DIR) CFLAGS_MPLAB += -nw=2066 # suppress Warning [2066] type qualifier mismatch in assignment CFLAGS_MPLAB += -ml # Large memory model CFLAGS_MPLAB += -ls # large stack (can span multiple banks) #CFLAGS_MPLAB += -scs # Enable default static locals #CFLAGS_MPLAB += -sco # Enable default overlay locals (statically allocate activation records). Ignored if set --extended CFLAGS_MPLAB += --extended # generate extended mode code COMPILE_MPLAB_STRING=$(CC_MPLAB) $(CFLAGS_MPLAB) $< -fo=$@ $(DEFINES) $(OPT) AFLAGS_MPLAB := /y AFLAGS_MPLAB += /rDEC # set default radix HEX/DEC/OCT AFLAGS_MPLAB += /l- # disable listing file #AFLAGS_MPLAB += /l$(OBJDIR_MPLAB) # enable listing file AFLAGS_MPLAB += /o # specify path for object files #AFLAGS_MPLAB += /o$(OBJDIR_MPLAB) # specify path for object files #AFLAGS_MPLAB += /q # enable quiet mode AFLAGS_MPLAB += /d__LARGE__ # define symbol AFLAGS_MPLAB += /p$(CHIP) # set processor type #ASSEMBLE_MPLAB_STRING=$(AS_MPLAB) $(AFLAGS_MPLAB) %< # used linker script LDFLAGS_MPLAB := $(CHIP)_g.lkr # objects to compile LDFLAGS_MPLAB += $(OBJS_MPLAB) LDFLAGS_MPLAB += $(MPLAB_LIBS) # specify chip for proper linking LDFLAGS_MPLAB += /p$(CHIP) # verbose mode operation #LDFLAGS_MPLAB += /v # generate report file for stack analysis LDFLAGS_MPLAB += /g # generate .LST file and no .COD file LDFLAGS_MPLAB += /i # do not invoke MP2COD (no .COD or .LST file) LDFLAGS_MPLAB += /w # link MPLAB libs LDFLAGS_MPLAB += /l $(MPLAB_LIB_DIR) # generate MAP file LDFLAGS_MPLAB += /m $(EXEDIR)/$(PROJECT_NAME)_mplab.map # set output file LDFLAGS_MPLAB += /o $(EXEDIR)/$(PROJECT_NAME)_mplab.hex ########################################################### # C preprocessor flags for SDCC v.3.3.0 compiler ########################################################### # ----- processor selection ----- CFLAGS := -m$(ARCH) CFLAGS += -p$(CHIP) # ----- preprocessor options ----- CFLAGS += $(INCS) CFLAGS += $(DEFINES) # ----- verbose & dependancy generate ----- # CFLAGS += -M # generate dependencies # CFLAGS += -E # # CFLAGS += -C # dont discard comments CFLAGS += -c # dont link file (ie have multiple source files) CFLAGS += $(DEBUG) # ----- common settings ----- #CFLAGS += --nostdinc # This will prevent the compiler from passing on the # default include path to the preprocessor. #CFLAGS += --nostdlib # This will prevent the compiler from passing on the # default library path to the linker. #CFLAGS += --less-pedantic # Disable some of the more pedantic warnings. CFLAGS += --stack-auto # All functions in the source file will be compiled as reentrant. # It automatically implies --int-long-reent and --float-reent. CFLAGS += --int-long-reent # Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant. CFLAGS += --float-reent # Floating point library is compiled as reentrant. #CFLAGS += --no-peep #CFLAGS += --funsigned-char # The default signedness for every type will be unsigned. #CFLAGS += --cyclomatic # This option will cause the compiler to generate an information # message for each function in the source file. The message contains # the number of edges and nodes the compiler detected in the # control flow graph of the function, and most importantly # the cyclomatic complexity. # ----- optimization options ----- #CFLAGS += --nogcse # Will not do global subexpression elimination, this option may be used # when the compiler creates undesirably large stack/data spaces to store # compiler temporaries. #CFLAGS += --noinvariant # Will not do loop invariant optimizations. #CFLAGS += --noinduction # Will not do loop induction optimizations. #CFLAGS += --nojtbound # Will not generate boundary condition check when switch statements # are implemented using jumptables. #CFLAGS += --noloopreverse # Will not do loop reversal optimization. #CFLAGS += --nolabelopt # Will not optimize labels (makes the dumpfiles more readable). CFLAGS += --nooverlay # The compiler will not overlay parameters and local variables of any function. CFLAGS += --peep-asm # Pass the inline assembler code through the peep hole optimizer. #CFLAGS += --opt-code-speed # Optimize for code speed rather than size #CFLAGS += --opt-code-size # Optimize for code size rather than speed CFLAGS += --fomit-frame-pointer # Frame pointer will be omitted when the function uses # no local variables. CFLAGS += --use-non-free # Search / include non-free licensed libraries and header files # ----- special options for pic16 port of SDCC ----- CFLAGS += --pstack-model=large # use stack model 'small' (default) or 'large' # don't use extended instruction set - SDCCman, $4.6.20.1 Known Bugs #CFLAGS += -y --extended # enable Extended Instruction Set/Literal Offset Addressing mode #CFLAGS += --pno-banksel # do not generate BANKSEL assembler directives CFLAGS += --obanksel=2 # set banksel optimization level (default=0 no) CFLAGS += --denable-peeps # explicit enable of peepholes CFLAGS += --no-optimize-goto # do NOT use (conditional) BRA instead of GOTO CFLAGS += --optimize-cmp # try to optimize some compares CFLAGS += --optimize-df # thoroughly analyze data flow (memory and time intensive!) #CFLAGS += --preplace-udata-with=udata_shr # Place udata variables at another section: udata_acs, udata_ovr, udata_shr #CFLAGS += --ivt-loc= # Set address of interrupt vector table. #CFLAGS += --nodefaultlibs # do not link default libraries when linking #CFLAGS += --use-crt= # use <crt-o> run-time initialization module #CFLAGS += --no-crt # do not link any default run-time initialization module #CFLAGS += --mplab-comp # enable compatibility mode for MPLAB utilities (MPASM/MPLINK) #CFLAGS += --asm= # Use alternative assembler #CFLAGS += --link= # Use alternative linker CFLAGS += --debug-xtra # show more debug info in assembly output CFLAGS += --debug-ralloc # dump register allocator debug file *.d CFLAGS += --pcode-verbose # dump pcode related info CFLAGS += --calltree # dump call tree in .calltree file #CFLAGS += --gstack # trace stack pointer push/pop to overflow ########################################################### # linker flags ########################################################### #gputils (GNU PIC Utils) used to link objects and libs. GPLINK_FLAGS = -c -m -w -r -I $(LIBDIR) -s $(GPUTILS_BASE)/lkr/$(CHIP)_g.lkr #SDCC linker not used #LDFLAGS := -m$(ARCH) #LDFLAGS += $(DEBUG) #LDFLAGS += --profile #LDFLAGS += --code-size $(FLASH_SIZE) # Code Segment size #LDFLAGS += --code-loc $(FLASH_LOC) # The start location of the code location, default value is 0 #LDFLAGS += --iram-size $(IRAM_SIZE) # Internal Ram size #LDFLAGS += --xram-loc $(XRAM_LOC) # The start location of the external ram, default value is 0 #LDFLAGS += --xram-size $(XRAM_SIZE) # External Ram size #LDFLAGS += --stack-loc $(STACK_LOC) # By default the stack is placed after the data segment. # Using this option the stack can be placed anywhere in the # internal memory space of the 8051. ############################################################################## # MPLAB CC18 compiler - linker $(HEX_MPLAB): $(OBJS_MPLAB) Makefile @echo "--- CC18 Linking objects to $(HEX_MPLAB) ..." @$(LD_MPLAB) $(LDFLAGS_MPLAB) ############################################################################## # SDCC compiler - linker $(HEX): $(OBJS) Makefile @echo "--- SDCC Linking objects to $(HEX) ..." $(GPLINK) $(GPLINK_FLAGS) -o $(HEX) $(OBJS) $(LIBS) $(GPDASM) -p$(CHIP) $(HEX) > $(DASM)
      
      









エピローグ



ご覧のように、最終的には外部コンパイラーで多数のEclipseを使用するようになりました。 コンパイルオプションの学習は必要であり、単純にそれを拒否するほど複雑なタスクではありません。プログラマーは必要に応じてそれらを学習して適用することができます。 最終的には、PICの下でプロジェクトを作成するために今日利用できる完璧な束を得たと思います。



すべての開発ツールをまとめると、Eclipseと組み合わせて使用​​するコンパイラーのリストがあり、プログラミングの際にこれを本当に楽しんでいます。



もちろん、必要に応じて、リストを簡単に補足できます。



私の話を読んだ後、誰かが最終的に古いIDEをやめて新しいIDEをマスターすることを自分で決めることを願っています。



がんばれ!



All Articles