The perfect development environment for PIC — personal experience

In connection with the innovations on the website, decided to finally come out of hiding and write something useful. Well, since I am programming different microcontrollers (MC) and am a fan of Eclipse, I decided about it and write. Start with your Dating stories with PIC programming, and finishes with tips for those who are on duty or because of Hobbies is programming the MC family PIC, but these tips will be fine for the other architectures MK.

Wednesday zhelezyachnikov I got in 2006 at the 4th year of study in the University, when I went for the internship at the scientific and technical center, where, in fact, work to this day. At that time in our company's mainstream was using Keil uVision2 for MK on the basis of the C51 and ARM. However, I slipped the simple tasks under the PIC, like a control one signal (button-off), and my first development environment was notebooks, paper and computer, plus books, paper, PIC. Looked my development environment like this:



To compile the files that gave me compiler executable and a. bat file that I used very lightly — don't even know what a compiler was there. In General, it was harsh times...

Oh, if I had someone then suggested that there is a miracle, like notepad++!


Then there was the MPASM, but he is miserable and told me about him almost nothing to remember. In my opinion, under it I also wrote in the notebook applets.

MPLAB IDE


With the improvement of my skills I learned that instead of Notepad you can use the coolest, as I then thought, MPLAB IDE:



It includes:

the
    the
  • CC18 and any other compiler that can be selected in the project settings;
  • the
  • a good set of library functions;
  • the
  • plug-in inc-files of the description of the MC family PIC, sharpened by the use of the assembler;
  • the
  • built-in debugger and programmer;
  • the
  • But most importantly — support for C language — it was for me a breath of fresh air!

Although, if you look at the development environment, its wretchedness and backwardness can scare away any little bit accustomed to good conditions be a programmer, but then I didn't know about it. Help on built-in library functions, it is necessary to open separately and look for what, where and how is called. For beginners — an impossible task. However, at the thematic forums people are still asking which compiler is best to use; someone continues to use MPLAB IDE.

MikroC


Problem for the PIC I threw up less and less, began to gain momentum with the development of MK series C51, ARM7 (not to be confused with ARMv7!), Cortex-m But sometimes I'm asked for help in writing programs for PIC, and I because of curiosity I tried the new tools.
By that time, have actively programmed in Keil uVision3 to return to the antediluvian IDE MBLAB did not want to. So I met with MikroC, which comes with the PICKit programmers:



A set of buns almost the same as in MBLAB IDE, but still richer:

the
    the
  • your own compiler
  • the
  • built-in library functions with easy and accessible description.
  • the
  • plug-in the. h file of the description of the MC family PIC;
  • the
  • a set of additional external tools
  • the
  • wide range of examples with source codes
  • the
  • built-in debugger and programmer;
  • the
  • built-in tabs of open files;
  • the
  • navigation features in file

Honestly, for small simple projects which constitute the primary niche of programs under the PIC, that is enough. Even beginners are normally dealt with through the help and quickly make a working code. Most of our developers dealing with PIC, using the environment during development.
Anyway, after making another project in MikroC, I forgot about the PIC and thought, that never to them will not come back.

However, the history likes to repeat itself!


After 3 years, in 2013, there was a task to develop FOR on the finished CD, which was laid PIC18F4680. Honestly, I didn't even know that PIC among the s there are monsters, always dealt only with the change!

The task was non-trivial — implementation of the bootloader for in-system software updates, work in hard real time work with ADC, an external DAC, control lines, multiple timers-Comparators.

By the way, a bit unrelated topic: just for this project I fully realized what the memory banks in the PIC, how they work and what restrictions to impose on software development. For example, all banks have MK to 256 bytes. And I want to kill myself, but for PIC it is impossible to create a structure, prevyschayuschuyu in terms of these 256 byte limit came out during the implementation of the exchange Protocol, but Oh well, move along...

By this time Keil uVision3 I was already pretty fed up, because the complexity of projects grew, and I lacked before Keil functionality. Somewhere in 2011, I have mastered the Eclipse GCC makefile syntax, and all their projects started with the use of these tools. Besides, I already had experience of using Eclipse bundles + SDCC for the project under C51 MK. After the appearance of Keil uVision4 I installed it, tested it half an hour and demolished, for the convenience of computer programming, it still lags far behind the Eclipse.

Eclipse + SDCC


Currently, Eclipse is the de facto standard in software development for embedded systems. Here is a list of ides based on Eclipse, from popular brands:

the
    the
  • NXP LPCXpresso IDE
  • the
  • Freescale CodeWarrior
  • the
  • Xilinx Platform Studio
  • the
  • Texas Instruments CCS
  • the
  • Android Development Tools

Autocompletion, tooltips for auto-completion, macros, dimming the inactive parts of the source code, easy code navigation and much more, — I'm not going to list them all, many developers of embedded systems are completely not used to it and know all these buns make life much easier:



The main problem of the pure Eclipse to develop C/C++ under MK is the complexity of entering into a zhelezyachnye programmers, replacing the usual instruments working after installation in 1-2 clicks, on any plug-ins that require configuration or, even worse, manually written makefile require considerable initial effort in reading and studying the documentation, search for help and manuals for beginners on the Internet. I speak as someone who has had experience in translation of software teams-zhelezyachnikov Eclipse.
my team
If you have read this article, please let me know, though I know, as we read in the profile hubs on Habrahabr

However, in a month completely mastered the syntax and writing quality once the makefile, all other projects are created on the thumb template and require only minimal customization.

Also had to make some additional arrangements for setting up projects under PIC — by default, Eclipse understands GCC syntax. Various macros and directives embedded in other compilers (whether СС18 or SDCC), we have to split at compile time and at indexing stage of the project. To navigate in the code editor has not issued errors about unknown directives, the source code of the project connects the file eclipse syntax.h:
eclipse-syntax.h
#ifndef ECLIPSE_SYNTAX_H_
#define ECLIPSE_SYNTAX_H_

// SDCC keyword defined when compiling with SDCC compiler
#ifndef SDCC

#ifdef __SDCC_PIC18F4680
#error "SDCC not found, project will be compile with errors!"
#endif

// file not parsed through the makefile - just for eclipse proper syntax
#ifndef __CC18__
#error "__CC18__ not found, use `-D__CC18__` in makefile for proper compilation CC18!"

#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 defined SDCC

#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_ */


In addition, SDCC I failed to link a big project in the finished binary is also needed to configure the GPUtils, which includes gpasm, gpdasm, gplink and scripts .lkr memory card MC PIC. However, because I found one bug in SDCC at the stage of debugging I eventually returned to the CC18 compiler and linker. However, SDCC and GPUtils are fully configured for the suffering here is part of the makefile regarding options run compilers and linkers CC18, SDCC, GPUtils,
Pieces of a makefile
###########################################################
# project-specific compile options
###########################################################
# Project definitions
CHIP = 18F4680
DEFINES := -DPIC$(CHIP)
#DEFINES += -D__SDCC_PIC$(CHIP) # use SDCC compiler
DEFINES += -D__CC18__ # CC18 compiler use MPLAB
#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

###########################################################
# Used with GPUtils 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 file listing
#AFLAGS_MPLAB += /l$(OBJDIR_MPLAB) # enable listing file
AFLAGS_MPLAB += /o # specify the 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 the processor type

#ASSEMBLE_MPLAB_STRING=$(AS_MPLAB) $(AFLAGS_MPLAB) %<

# used linker script
LDFLAGS_MPLAB := $(CHIP)_g.lkr
# to compile objects
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 libs MPLAB
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 & generate dependancy-----
# CFLAGS += -M # generate dependencies
# CFLAGS += -E #
# CFLAGS += -C # dont discard comments

CFLAGS += -c # dont link file (i.e. 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

# 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 the 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, the 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.

##############################################################################
# CC18 compiler MPLAB - 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)



epilogue


As you can see, in the end, I came to use bundles Eclipse with external compilers. The study of the compilation options — necessary and not so difficult to just give it up, any programmer can examine and use when needed. I think in the end I got the perfect bundle, available today for creating projects for the PIC.

Collecting together all the development tools, here is a list of compilers that I use in conjunction with Eclipse and I get this real pleasure while programming:
the
    the
  • for CC18 PIC
  • the
  • for SDCC C51
  • the
  • gnu-arm-embedded software for ARM7 and Cortex-M
  • the
  • MinGW x86

Obviously, if necessary, the list can easily be supplemented.

I hope after reading my story, someone will decide finally to go with the old IDE and master new.

Go for it!
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Automatically create Liquibase migrations for PostgreSQL

Vkontakte sync with address book for iPhone. How it was done

What part of the archived web