PIC24 Support Libraries
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
SConstruct.py
Go to the documentation of this file.
1 # This file contains all that a SConstruct file normally contains.
2 # In order to use Doxygen, however, all Python files must end with
3 # a .py extension. So, SConstuct simply executes this file.
4 
5 # Documentation for this file. If the \file tag isn't present,
6 # this file won't be documented.
7 ## \file
8 # This file provides an automated build process for the
9 # \ref index "libraries" included in this collection.
10 # To use:
11 # -# Install SCons.
12 # -# Install the Microchip compiler. Make sure your path
13 # includes the directories in which the compiler binaries
14 # exist.
15 # -# From the command line, change to the directory in which
16 # this file lies.
17 # -# Execute <code>SCons</code>, which builds everything.
18 #
19 # The build process can be modified by passing options to
20 # SCons. See <code>SCons --help</code> for options specific
21 # to this build and <code>SCons -H</code> for generic SCons
22 # options.
23 #
24 # \todo
25 # - Figure out how to get Doxygen to generate valid links in the output
26 # produced by parsing this file
27 # - ESOS build (chap 14)
28 # - Some flags for I2C master/slave not done yet
29 # - Create some reset replacement that uses more of the functionality
30 # (calls functions from all our .c/.h files
31 
32 
33 import os
34 
35 ## Make sure SCons is recent enough.
36 EnsureSConsVersion(2, 0)
37 
38 
39 ## @{
40 # \name Create a Microchip MCC24 (PIC24F/H) Construction Environment
41 ###############################################################################
42 
43 ## Define command-line options to set processor, bootloader
44 opts = Variables()
45 opts.Add(EnumVariable('BOOTLDR', 'Determines bootloader type', 'msu',
46  allowed_values=('msu','none')))
47 
48 print "Creating a SCons build environment for Microchip C30 family"
49 env = Environment(
50  # Force SCons to set up for with gnu tools to start
51  # with reasonable defaults. Note: using platform = 'posix'
52  # causes SCons to try to call fork() when executing programs
53  # (such as compilers), which errors out on Windows.
54  tools = ['gcc', 'gnulink', 'ar', 'zip', 'packaging'],
55  options = opts,
56  # Copied and cobbled together from SCons\Tools\cc.py with mods
57  CCCOM = '$CC -c -o $TARGET $CFLAGS $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS $SOURCES',
58  CCCCOMSTR = 'Compiling $SOURCES',
59  CCFLAGS = '-mcpu=${MCU} -Wall -O1',
60  ARFLAGS = 'rcs',
61  ARSTR = 'Create static library: $TARGET',
62  OBJSUFFIX = '.o',
63  PROGSUFFIX = '.cof')
64 # Copy the host envrionment's path for our scons environment
65 # so scons can find C30 tools
66 env['ENV']['PATH'] = os.environ['PATH']
67 
68 # Adjust our environment to be specific the host OS
69 if os.name == 'posix':
70  print "Modifiying environment for Linux"
71  incDirs = Split( """include
72  /usr/pic30-elf/include
73  /usr/share/pic30-support/generic/h
74  /usr/share/pic30-support/pic24h/h
75  """)
76  libDirs = Split( """.
77  lib
78  """)
79  ## Change linux-specific environment variables
80  env.Replace(
81  CPPPATH = incDirs,
82  CC = 'pic30-elf-gcc',
83  LIBPATH = libDirs,
84  AR = 'pic30-elf-ar',
85  LINK = 'pic30-elf-gcc', # Copied from SCons\Tools\link.py with mods
86  )
87  #
88  # add the bin2hex program to the environment as a new builder
89  #
90  b2h = Builder(action = 'pic30-elf-bin2hex $SOURCE',
91  suffix = 'hex',
92  src_suffix = 'cof')
93  env.Append(BUILDERS = {'Hex' : b2h})
94 
95 elif os.name == 'nt':
96  print "Modifying environment for Windoze"
97  incDirs = Split( """lib/include
98  """)
99  libDirs = Split( """.
100  """)
101  # Change linux-specific environment variables
102  env.Replace(
103  CPPPATH = incDirs,
104  CC = 'pic30-gcc',
105  LIBPATH = libDirs,
106  AR = 'pic30-ar',
107  LINK = 'pic30-gcc', # Copied from SCons\Tools\link.py with mods
108  )
109  #
110  # add the bin2hex program to the environment as a new builder
111  #
112  b2h = Builder(action = 'pic30-bin2hex $SOURCE',
113  suffix = 'hex',
114  src_suffix = 'cof')
115  env.Append(BUILDERS = {'Hex' : b2h})
116 
117 # adjust our default environment based on user command-line requests
118 dict = env.Dictionary()
119 if dict['BOOTLDR'] == 'msu':
120  env.Replace(
121  LINKFLAGS = '-mcpu=${MCU} -Wl,--heap=100,$LINKERSCRIPT',
122  LINKERSCRIPT = '--script=lib/lkr' + os.sep + 'p${MCU}_bootldr.gld',
123  )
124 else:
125  env.Replace(
126  LINKFLAGS = '-mcpu=${MCU} -Wl,--heap=100,$LINKERSCRIPT',
127  LINKERSCRIPT = '--script=p${MCU}.gld',
128  )
129 
130 ## By default, run two jobs at once (assume a dual-core PC)
131 # For some reason I haven't yet determined, this causes build errors. Turn it off for now.
132 #env.SetOption('num_jobs', 2)
133 print "Running with -j", env.GetOption('num_jobs')
134 
135 # generate some command line help for our custom options
136 Help(opts.GenerateHelpText(env))
137 
138 #
139 # A DEBUG STATEMENT to see what the scons build envrionment (env) has defined
140 #
141 #print env.Dump()
142 
143 ## @}
144 
145 
146 
147 # Definition of targets
148 
149 
150 ## Define what parts of the source tree should be inclued in a
151 # .zip distribution.
152 archiveFiles = [
153  'Doxyfile',
154  'readme.txt',
155  'runAStyle.bat',
156  'SConstruct',
157  'SConstruct.py',
158  'SCons_build.py',
159  'standard_header.txt',
160  'bin',
161  'bootloader',
162  'docs',
163  'hex',
164  'lib/lkr',
165  'chap3',
166  'chap4',
167  'chap6',
168  'chap7',
169  'chap8',
170  'chap9',
171  'chap10',
172  'chap11',
173  'chap12',
174  'chap13',
175  'chap14',
176  'chap15',
177  'esos',
178  'lib/common',
179  'lib/include',
180  'explorer16_100p',
181  'templates',
182  'util' ]
183 
184 ## Select the file name for the .zip archive
185 archiveFileName = 'build/pic24_code_examples.zip'
186 
187 ## Call SConscript with a specific buildTargets value
188 def buildTargetsSConscript(buildTargets, env, variantDirName):
189  SConscript('SCons_build.py', exports='buildTargets env',
190  variant_dir='build/' + env['MCU'] + "_" + variantDirName)
191 
192 
193 # Inform SCons about the dependencies in the template-based files
194 SConscript('./templates/SConscript.py', 'env')
195 
196 env.Alias('template-build', ['lib/include/pic24_uart.h', 'lib/include/pic24_i2c.h',
197  'lib/include/pic24_ecan.h',
198  'lib/common/pic24_uart.c', 'lib/common/pic24_i2c.c',
199  'lib/common/pic24_spi.c', 'lib/common/pic24_ecan.c']);
200 
201 ## Create a target which zips up these files;
202 ## otherwise, create compilation targets.
203 if 'zipit' in COMMAND_LINE_TARGETS:
204  # Update docs
205  env.Command(Glob('docs/*'), Glob('lib/common/*.c'), "doxygen")
206  # Zip it!
207  zipNode = env.Zip(archiveFileName, archiveFiles)
208  env.Alias('zipit', zipNode)
209 else:
210  # Build the PIC24H32/FJ64Gxx02-compatible directories
211  #######################################################
212  # Build small, non-DMA on the PIC24HJ32GP202
213  buildTargetsSConscript(['chap8', 'chap9', 'chap10', 'chap11nodma', 'chap12',
214  'bootloader'],
215  env.Clone(MCU='24HJ32GP202'), 'default')
216 
217  # Build the large files on the PIC24HJ64GP202
218  buildTargetsSConscript( ['chap10large', ],
219  env.Clone(MCU='24HJ64GP202'), 'default')
220 
221  # Build everything on the PIC24FJ64GA002
222  buildTargetsSConscript(['chap8', 'chap9', 'chap10', 'chap10large', 'chap11nodma', 'chap12',
223  'chap15', 'bootloader'],
224  env.Clone(MCU='24FJ64GA002'), 'default')
225 
226  # Build small, non-DMA on the dsPIC33FJ32GP202
227  buildTargetsSConscript(['chap8', 'chap9', 'chap10', 'chap11nodma', 'chap12',
228  'bootloader'],
229  env.Clone(MCU='33FJ32GP202'), 'default')
230 
231  # Build the large files on the dsPIC33FJ64GP202
232  buildTargetsSConscript( ['chap10large'],
233  env.Clone(MCU='33FJ64GP202'), 'default')
234 
235  # Minimally test the 24F16KA102
236 # buildTargetsSConscript(['reset', 'echo', 'bootloader'],
237 # env.Clone(MCU='24F16KA102'), 'default')
238 
239  # Build the PIC24HJGP502-compatible directories
240  buildTargetsSConscript(['chap11dma', 'chap13', 'chap15', 'bootloader'],
241  env.Clone(MCU='24HJ64GP502'), 'default')
242 
243  # Same as above, but for the dsPIC
244  buildTargetsSConscript(['chap8', 'chap9', 'chap10', 'chap10stdio', 'chap11dma', 'chap12big','chap12',
245  'chap13', 'chap15', 'bootloader'],
246  env.Clone(MCU='33FJ128GP802'), 'default')
247 
248  # Build some for the PIC24E device
249  buildTargetsSConscript(['chap8', 'chap9', 'chap10', 'chap11_24E', 'chap12big','chap12_24E',
250  'bootloader'],
251  env.Clone(MCU='24EP64GP202'), 'default')
252 
253 
254  # Build for the explorer board
255  buildTargetsSConscript(['explorer', 'bootloader'],
256  env.Clone(MCU='24FJ128GA010', CPPDEFINES='HARDWARE_PLATFORM=EXPLORER16_100P'), 'default')
257  buildTargetsSConscript(['explorerh', 'bootloader'],
258  env.Clone(MCU='24HJ256GP610', CPPDEFINES='HARDWARE_PLATFORM=EXPLORER16_100P'), 'default')
259 
260  # Do a no-float build of reset
261  buildTargetsSConscript(['reset'],
262  env.Clone(MCU='24HJ32GP202', CPPDEFINES='_NOFLOAT'), 'nofloat')
263 
264  # Build reset on other supported platforms
265  buildTargetsSConscript(['reset'],
266  env.Clone(MCU='24FJ64GA002', CPPDEFINES='HARDWARE_PLATFORM=STARTER_BOARD_28P'), 'starter_board_28p')
267  buildTargetsSConscript(['reset'],
268  env.Clone(MCU='33FJ128GP204', CPPDEFINES='HARDWARE_PLATFORM=DANGEROUS_WEB'), 'dangerous_web')
269 
270  # Build reset with various clock options on all processors
271  for clock in ['SIM_CLOCK', 'FRCPLL_FCY16MHz', 'FRC_FCY4MHz',
272  'PRI_NO_PLL_7372KHzCrystal', 'PRIPLL_8MHzCrystal_16MHzFCY']:
273  buildTargetsSConscript(['reset'],
274  env.Clone(MCU='24FJ64GA002', CPPDEFINES='CLOCK_CONFIG=' + clock), clock)
275  buildTargetsSConscript(['reset'],
276  env.Clone(MCU='24FJ64GA102', CPPDEFINES='CLOCK_CONFIG=' + clock), clock)
277 # buildTargetsSConscript(['reset'],
278 # env.Clone(MCU='24F16KA102', CPPDEFINES='CLOCK_CONFIG=' + clock), clock)
279  for clock in ['SIM_CLOCK', 'PRI_NO_PLL_7372KHzCrystal', 'FRC_FCY3685KHz',
280  'FRCPLL_FCY40MHz', 'PRIPLL_7372KHzCrystal_40MHzFCY', 'PRIPLL_8MHzCrystal_40MHzFCY']:
281  buildTargetsSConscript(['reset'],
282  env.Clone(MCU='24HJ32GP202', CPPDEFINES='CLOCK_CONFIG=' + clock), clock)
283  buildTargetsSConscript(['reset'],
284  env.Clone(MCU='33FJ128GP802', CPPDEFINES='CLOCK_CONFIG=' + clock), clock)