From 2625a86450fdb127bbc49ea4af223b67865933e8 Mon Sep 17 00:00:00 2001
From: Leandro Lanzieri <leandro.lanzieri@haw-hamburg.de>
Date: Thu, 17 Jan 2019 13:55:27 +0100
Subject: [PATCH] boards/sensebox_samd21: Add MTD definitions

---
 boards/sensebox_samd21/board.c         | 21 +++++++++++++++++++
 boards/sensebox_samd21/include/board.h | 28 ++++++++++++++++++++++++++
 tests/pkg_fatfs/Makefile               |  9 +++++----
 tests/pkg_fatfs_vfs/Makefile           |  8 ++++----
 4 files changed, 58 insertions(+), 8 deletions(-)

diff --git a/boards/sensebox_samd21/board.c b/boards/sensebox_samd21/board.c
index 890ffb32c2..c8c10d42e2 100644
--- a/boards/sensebox_samd21/board.c
+++ b/boards/sensebox_samd21/board.c
@@ -21,6 +21,27 @@
 #include "cpu.h"
 #include "board.h"
 #include "periph/gpio.h"
+#include "sdcard_spi_params.h"
+#include "mtd_sdcard.h"
+
+#if defined(MODULE_MTD_SDCARD) || defined(DOXYGEN)
+ /* this is provided by the sdcard_spi driver
+ * see sys/auto_init/storage/auto_init_sdcard_spi.c */
+extern sdcard_spi_t sdcard_spi_devs[sizeof(sdcard_spi_params) /
+                                    sizeof(sdcard_spi_params[0])];
+mtd_sdcard_t sensebox_sd_dev = {
+    .base = {
+        .driver = &mtd_sdcard_driver,
+        .page_size = MTD_SD_CARD_PAGE_SIZE,
+        .pages_per_sector = MTD_SD_CARD_PAGES_PER_SECTOR,
+        .sector_count = MTD_SD_CARD_SECTOR_COUNT
+    },
+    .sd_card = &sdcard_spi_devs[0],
+    .params = &sdcard_spi_params[0]
+};
+
+mtd_dev_t *mtd0 = (mtd_dev_t *)&sensebox_sd_dev;
+#endif /* MODULE_MTD_SDCARD || DOXYGEN */
 
 void board_init(void)
 {
diff --git a/boards/sensebox_samd21/include/board.h b/boards/sensebox_samd21/include/board.h
index 72eaf46fce..e4e65bbc3d 100644
--- a/boards/sensebox_samd21/include/board.h
+++ b/boards/sensebox_samd21/include/board.h
@@ -25,6 +25,7 @@
 #include "cpu.h"
 #include "periph_conf.h"
 #include "periph_cpu.h"
+#include "mtd_sdcard.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -162,6 +163,33 @@ extern "C" {
  */
 #define BMX280_PARAM_I2C_ADDR        (0x76)
 
+#if defined(MODULE_MTD_SDCARD) || defined(DOXYGEN)
+/**
+ * @brief MTD device 0 (SD Card) definition. mtd0 is defined in board.c
+ * @{
+ */
+extern mtd_dev_t *mtd0;
+#define MTD_0 mtd0
+/** @} */
+
+/**
+ * @brief Attributes for the mtd_sdcard driver
+ * @{
+ */
+#ifndef MTD_SD_CARD_PAGE_SIZE
+#define MTD_SD_CARD_PAGE_SIZE           (512)
+#endif
+
+#ifndef MTD_SD_CARD_PAGES_PER_SECTOR
+#define MTD_SD_CARD_PAGES_PER_SECTOR    (128)
+#endif
+
+#ifndef MTD_SD_CARD_SECTOR_COUNT
+#define MTD_SD_CARD_SECTOR_COUNT        (3921920UL)
+#endif
+/** @} */
+#endif /* MODULE_MTD_SDCARD || DOXYGEN */
+
 /**
  * @brief   Initialize board specific hardware, including clock, LEDs and std-IO
  */
diff --git a/tests/pkg_fatfs/Makefile b/tests/pkg_fatfs/Makefile
index ba471515e5..3b7fcd2605 100644
--- a/tests/pkg_fatfs/Makefile
+++ b/tests/pkg_fatfs/Makefile
@@ -19,10 +19,11 @@ BOARD_WHITELIST := airfy-beacon arduino-due arduino-duemilanove arduino-mega2560
                    nucleo-f303re nucleo-f334r8 nucleo-f401re nucleo-f410rb nucleo-f411re \
                    nucleo-f446re nucleo-l053r8 nucleo-l073rz nucleo-l152re nucleo-l476rg \
                    nz32-sc151 openmote-cc2538 pba-d-01-kw2x remote-pa remote-reva \
-                   remote-revb samd21-xpro saml21-xpro samr21-xpro sltb001a \
-                   sodaq-autonomo sodaq-explorer spark-core stm32f0discovery \
-                   stm32f3discovery stm32f4discovery telosb udoo waspmote-pro \
-                   wsn430-v1_3b wsn430-v1_4 yunjia-nrf51822 z1 native
+                   remote-revb samd21-xpro saml21-xpro samr21-xpro \
+                   sensebox_samd21 sltb001a sodaq-autonomo \
+                   sodaq-explorer spark-core stm32f0discovery stm32f3discovery \
+                   stm32f4discovery telosb udoo waspmote-pro wsn430-v1_3b \
+                   wsn430-v1_4 yunjia-nrf51822 z1 native
 
 USEMODULE += shell
 USEMODULE += fatfs_diskio_mtd
diff --git a/tests/pkg_fatfs_vfs/Makefile b/tests/pkg_fatfs_vfs/Makefile
index b9ca238f2c..066f3d3994 100644
--- a/tests/pkg_fatfs_vfs/Makefile
+++ b/tests/pkg_fatfs_vfs/Makefile
@@ -42,10 +42,10 @@ BOARD_WHITELIST := airfy-beacon arduino-due arduino-duemilanove arduino-mega2560
                    nucleo-f303re nucleo-f334r8 nucleo-f401re nucleo-f410rb nucleo-f411re \
                    nucleo-f446re nucleo-l053r8 nucleo-l073rz nucleo-l152re nucleo-l476rg \
                    nz32-sc151 openmote-cc2538 pba-d-01-kw2x remote-pa remote-reva \
-                   remote-revb samd21-xpro saml21-xpro samr21-xpro sltb001a \
-                   sodaq-autonomo sodaq-explorer spark-core stm32f0discovery \
-                   stm32f3discovery stm32f4discovery udoo waspmote-pro \
-                   yunjia-nrf51822 native
+                   remote-revb samd21-xpro saml21-xpro samr21-xpro \
+                   sensebox_samd21 sltb001a sodaq-autonomo sodaq-explorer \
+                   spark-core stm32f0discovery stm32f3discovery \
+                   stm32f4discovery udoo waspmote-pro yunjia-nrf51822 native
 
 TEST_DEPS += image
 
-- 
GitLab