Add some chibios demos
[lwext4.git] / demos / chibios / boards / olimex_stm32_p107 / board.c
diff --git a/demos/chibios/boards/olimex_stm32_p107/board.c b/demos/chibios/boards/olimex_stm32_p107/board.c
new file mode 100644 (file)
index 0000000..996919c
--- /dev/null
@@ -0,0 +1,84 @@
+/*\r
+    ChibiOS/RT - Copyright (C) 2006-2014 Giovanni Di Sirio\r
+\r
+    Licensed under the Apache License, Version 2.0 (the "License");\r
+    you may not use this file except in compliance with the License.\r
+    You may obtain a copy of the License at\r
+\r
+        http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+    Unless required by applicable law or agreed to in writing, software\r
+    distributed under the License is distributed on an "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+    See the License for the specific language governing permissions and\r
+    limitations under the License.\r
+*/\r
+\r
+#include "hal.h"\r
+\r
+/**\r
+ * @brief   PAL setup.\r
+ * @details Digital I/O ports static configuration as defined in @p board.h.\r
+ *          This variable is used by the HAL when initializing the PAL driver.\r
+ */\r
+#if HAL_USE_PAL || defined(__DOXYGEN__)\r
+const PALConfig pal_default_config =\r
+{\r
+  {VAL_GPIOAODR, VAL_GPIOACRL, VAL_GPIOACRH},\r
+  {VAL_GPIOBODR, VAL_GPIOBCRL, VAL_GPIOBCRH},\r
+  {VAL_GPIOCODR, VAL_GPIOCCRL, VAL_GPIOCCRH},\r
+  {VAL_GPIODODR, VAL_GPIODCRL, VAL_GPIODCRH},\r
+  {VAL_GPIOEODR, VAL_GPIOECRL, VAL_GPIOECRH},\r
+};\r
+#endif\r
+\r
+/*\r
+ * Early initialization code.\r
+ * This initialization must be performed just after stack setup and before\r
+ * any other initialization.\r
+ */\r
+void __early_init(void) {\r
+\r
+  stm32_clock_init();\r
+}\r
+\r
+#if HAL_USE_MMC_SPI\r
+/*\r
+ * Card detection through the card internal pull-up on D3.\r
+ */\r
+bool mmc_lld_is_card_inserted(MMCDriver *mmcp) {\r
+  static bool last_status = FALSE;\r
+\r
+  (void)mmcp;\r
+  if ((palReadLatch(GPIOA) & PAL_PORT_BIT(GPIOA_SPI3_CS_MMC)) == 0)\r
+    return last_status;\r
+  return last_status = (bool)palReadPad(GPIOA, GPIOA_SPI3_CS_MMC);\r
+}\r
+\r
+/*\r
+ * Card write protection detection is not possible, the card is always\r
+ * reported as not protected.\r
+ */\r
+bool mmc_lld_is_write_protected(MMCDriver *mmcp) {\r
+\r
+  (void)mmcp;\r
+  return FALSE;\r
+}\r
+#endif\r
+\r
+/*\r
+ * Board-specific initialization code.\r
+ */\r
+void boardInit(void) {\r
+\r
+  /*\r
+   * Several I/O pins are re-mapped:\r
+   *   USART3 to the PD8/PD9 pins.\r
+   *   I2C1 to the PB8/PB9 pins.\r
+   *   SPI3 to the PC10/PC11/PC12 pins.\r
+   */\r
+  AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_FULLREMAP |\r
+                AFIO_MAPR_USART2_REMAP |\r
+                AFIO_MAPR_I2C1_REMAP |\r
+                AFIO_MAPR_SPI3_REMAP;\r
+}\r