@@ -304,7 +304,9 @@ Then answer a few questions about the driver:
304304Other global information (author name, email, organization) should be retrieved
305305automatically from your git configuration.
306306
307- ## Using Common Code
307+ ## Common Board Directories
308+
309+ ### Using Common Code
308310
309311To avoid code duplication, common code across boards has been grouped in
310312` boards/common ` . e.g. ` BOARD ` s based on the same cpu (` boards/common/nrf52 ` ) or
@@ -336,6 +338,125 @@ static const timer_conf_t timer_config[] = {
336338/* * @} */
337339```
338340
341+ #### New Style Common Code
342+
343+ The common board definitions of RIOT are currently being reworked to make the
344+ usage of common code easier and less error prone. For example, if you want
345+ to use the common code for the Adafruit nRF52 Bootloader that is used
346+ by many of the nRF52 based boards from Adafruit, you simply have to add the
347+ following line to the ` Makefile.dep ` of your board. Everything else
348+ will be automatically included by the build system.
349+
350+ ``` makefile
351+ USEMODULE += boards_common_adafruit-nrf52-bootloader
352+ ```
353+
354+ Not all common code is migrated to the new style yet, so if you are unsure
355+ whether it is or not, you can check if the ` boards/Makefile ` already
356+ includes a reference to the common code you want to use. If you are still
357+ unsure, you can still use the Old Style Common Code or ask the
358+ community.
359+
360+ #### Old Style Common Code
361+
362+ If you want to use common makefiles, include them at the end of the specific
363+ ` Makefile ` , e.g. for a ` Makefile.features ` :
364+
365+ ``` makefile
366+ CPU = foo
367+ CPU_MODEL = foobar
368+ # Put defined MCU peripherals here (in alphabetical order)
369+ FEATURES_PROVIDED += periph_i2c
370+ FEATURES_PROVIDED += periph_spi
371+ FEATURES_PROVIDED += periph_uart
372+ include $(RIOTBOARD ) /common/foo_common/Makefile.features
373+ ```
374+
375+ If the common code includes source files, it might be necessary
376+ to explicitly include the directory in your `Makefile` so the Make system
377+ finds all the necessary files :
378+
379+ ```makefile
380+ MODULE = board
381+
382+ DIRS += $(RIOTBOARD ) /common/myCommonFolder
383+
384+ include $(RIOTBASE ) /Makefile.base
385+ ```
386+
387+ If possible, you should use the New Style Common Code though.
388+
389+ # ## Moving Common Code to a Dedicated Folder
390+
391+ If you port a board that is very similar to an already existing board, it might
392+ make sense to move the shared code to a common directory located in
393+ `boards/common` to use it as described in the previous section.
394+
395+ The directory structure of a common folder is very similar to the board
396+ folder structure and not all files and folders have to be present except for
397+ the main `Makefile`.
398+
399+ ```
400+ RIOT
401+ └── boards
402+ └── common
403+ └── adafruit-nrf52-bootloader
404+ ├── board.c
405+ ├── doc.md
406+ ├── include
407+ │ ├── periph_conf.h
408+ │ ├── board.h
409+ │ └── gpio_params.h
410+ ├── Makefile
411+ ├── Makefile.dep
412+ ├── Makefile.features
413+ └── Makefile.include
414+ ```
415+
416+ The main `Makefile` defines the module name for the common board module and
417+ should follow the general naming scheme of `boards_common_awesome-common-stuff`.
418+
419+ ```makefile
420+ MODULE = boards_common_adafruit-nrf52-bootloader
421+
422+ include $(RIOTBASE)/Makefile.base
423+ ```
424+
425+ The ` Makefile.dep ` , ` Makefile.features ` and ` Makefile.include ` are optional
426+ and work the same way as their normal board pendants.
427+
428+ To inform the build system about the common folders and Makefiles, the
429+ ` boards/Makefile ` , ` boards/Makefile.dep ` , ` boards/Makefile.features ` and
430+ ` boards/Makefile.include ` files have to be modified.
431+
432+ The ` boards/Makefile ` contains the directory entries for the common files.
433+ The entries should check if the common module is used and conditionally add
434+ the directory to the ` DIRS ` variable.
435+ Please note that the entries should be sorted alphabetically.
436+ ``` makefile
437+ # SORT THIS ALPHABETICALLY BY COMMON BOARD NAME!
438+ ...
439+ ifneq (,$(filter boards_common_adafruit-nrf52-bootloader,$(USEMODULE ) ) )
440+ DIRS += $(RIOTBOARD ) /common/adafruit-nrf52-bootloader
441+ endif
442+ ...
443+ ```
444+
445+ The ` boards/Makefile.dep ` , ` boards/Makefile.features ` and
446+ ` boards/Makefile.include ` just include their common counterparts. As an
447+ example, an entry of the ` boards/Makefile.dep ` is shown:
448+ ``` makefile
449+ # SORT THIS ALPHABETICALLY BY COMMON BOARD NAME!
450+ ...
451+ ifneq (,$(filter boards_common_adafruit-nrf52-bootloader,$(USEMODULE ) ) )
452+ include $(RIOTBOARD ) /common/adafruit-nrf52-bootloader/Makefile.dep
453+ endif
454+ ...
455+ ```
456+
457+ You only have to add entries to the ` board/Makefile ` s if your common code
458+ actually has the regarding Makefile-type.
459+
339460## Boards Outside of RIOTBASE
340461
341462All ` BOARD ` s in RIOT reside in ` RIOTBOARD ` (` RIOTBOARD ` being a make variable
@@ -433,5 +554,5 @@ Some scripts and tools available to ease `BOARD` porting and testing:
433554- [ In her blog] ( https://blog.martine-lenders.eu/riot-board-en.html ) , Martine Lenders documented her approach of
434555 porting the [ Adafruit Feather nRF52840 Express] ( https://doc.riot-os.org/group__boards__adafruit-feather-nrf52840-express.html )
435556 in February 2020.
436- - [ Over at HackMD] [ https://hackmd.io/njFHwQ33SNS3sQKAkLkNtQ ] , Akshai M documented his approach of
557+ - [ Over at HackMD] ( https://hackmd.io/njFHwQ33SNS3sQKAkLkNtQ ) , Akshai M documented his approach of
437558 porting the [ Silicon Labs SLSTK3400A starter kit] ( https://doc.riot-os.org/group__boards__slstk3400a.html ) in July 2020.
0 commit comments