summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--cc3200/application.lds42
-rw-r--r--cc3200/application.mk1
-rw-r--r--cc3200/boards/LAUNCHXL/mpconfigboard.h3
-rw-r--r--cc3200/bootmgr/bootmgr.lds62
-rw-r--r--cc3200/fatfs/src/ffconf.c6
-rw-r--r--cc3200/fatfs/src/ffconf.h2
-rw-r--r--cc3200/hal/cc3200_hal.c32
-rw-r--r--cc3200/mods/modpyb.c5
-rw-r--r--cc3200/mods/pybextint.c2
-rw-r--r--cc3200/mods/pybpin.c8
-rw-r--r--cc3200/mods/pybpin.h1
-rw-r--r--cc3200/mods/pybsd.c189
-rw-r--r--cc3200/mods/pybsd.h36
-rw-r--r--cc3200/mptask.c24
-rw-r--r--cc3200/qstrdefsport.h6
15 files changed, 285 insertions, 134 deletions
diff --git a/cc3200/application.lds b/cc3200/application.lds
index 46b29e99ee..147941f4cf 100644
--- a/cc3200/application.lds
+++ b/cc3200/application.lds
@@ -1,41 +1,3 @@
-/*****************************************************************************
-* cc3200.lds
-*
-* GCC Linker script for the CC3200
-*
-* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
-*
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-*
-* Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-*
-* Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the
-* distribution.
-*
-* Neither the name of Texas Instruments Incorporated nor the names of
-* its contributors may be used to endorse or promote products derived
-* from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*
-******************************************************************************/
-
/*
* This file is part of the Micro Python project, http://micropython.org/
*
@@ -62,8 +24,8 @@
* THE SOFTWARE.
*/
-__stack_size__ = 1K; /* interrupts are handled using this stack */
-__min_heap_size__ = 6K;
+__stack_size__ = 1K; /* interrupts are handled within this stack */
+__min_heap_size__ = 8K;
__rtos_heap_size = 16K;
MEMORY
diff --git a/cc3200/application.mk b/cc3200/application.mk
index f0f041a75a..1762d1f6a7 100644
--- a/cc3200/application.mk
+++ b/cc3200/application.mk
@@ -94,6 +94,7 @@ APP_MODS_SRC_C = $(addprefix mods/,\
pybi2c.c \
pybpin.c \
pybrtc.c \
+ pybsd.c \
pybsystick.c \
pybuart.c \
)
diff --git a/cc3200/boards/LAUNCHXL/mpconfigboard.h b/cc3200/boards/LAUNCHXL/mpconfigboard.h
index 1741c2df19..c4472c77bd 100644
--- a/cc3200/boards/LAUNCHXL/mpconfigboard.h
+++ b/cc3200/boards/LAUNCHXL/mpconfigboard.h
@@ -30,9 +30,10 @@
#define MICROPY_HW_BOARD_NAME "LaunchPad"
#define MICROPY_HW_MCU_NAME "CC3200"
-#define MICROPY_HW_HAS_SDCARD (1)
+#define MICROPY_HW_HAS_SDCARD (0)
#define MICROPY_HW_ENABLE_RNG (1)
#define MICROPY_HW_ENABLE_RTC (1)
#define MICROPY_STDIO_UART PYB_UART_0
#define MICROPY_STDIO_UART_BAUD 115200
+
diff --git a/cc3200/bootmgr/bootmgr.lds b/cc3200/bootmgr/bootmgr.lds
index 456f424905..e9d44d3c96 100644
--- a/cc3200/bootmgr/bootmgr.lds
+++ b/cc3200/bootmgr/bootmgr.lds
@@ -1,40 +1,28 @@
-/*****************************************************************************
-* bootmgr.lds
-*
-* GCC Linker script for get_time application.
-*
-* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
-*
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-*
-* Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-*
-* Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the
-* distribution.
-*
-* Neither the name of Texas Instruments Incorporated nor the names of
-* its contributors may be used to endorse or promote products derived
-* from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*
-******************************************************************************/
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2015 Daniel Campora
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
__stack_size__ = 1024;
diff --git a/cc3200/fatfs/src/ffconf.c b/cc3200/fatfs/src/ffconf.c
index a52eed55ac..f23d241285 100644
--- a/cc3200/fatfs/src/ffconf.c
+++ b/cc3200/fatfs/src/ffconf.c
@@ -61,11 +61,11 @@ int ff_get_ldnumber (const TCHAR **path) {
}
if (**path != '/') {
- #if _FS_RPATH
+ #if _FS_RPATH
return ff_CurrVol;
- #else
+ #else
return -1;
- #endif
+ #endif
}
if (check_path(path, "/SFLASH", 7)) {
diff --git a/cc3200/fatfs/src/ffconf.h b/cc3200/fatfs/src/ffconf.h
index d2d123e2ef..f4b56f3de6 100644
--- a/cc3200/fatfs/src/ffconf.h
+++ b/cc3200/fatfs/src/ffconf.h
@@ -232,7 +232,7 @@
#define _FS_REENTRANT 1
-#define _FS_TIMEOUT 2000
+#define _FS_TIMEOUT 2500 // milliseconds
#define _SYNC_t SemaphoreHandle_t
/* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs
/ module itself. Note that regardless of this option, file access to different
diff --git a/cc3200/hal/cc3200_hal.c b/cc3200/hal/cc3200_hal.c
index 7932d9e06f..e1ae0eafcb 100644
--- a/cc3200/hal/cc3200_hal.c
+++ b/cc3200/hal/cc3200_hal.c
@@ -41,7 +41,6 @@
#include "interrupt.h"
#include "systick.h"
#include "prcm.h"
-#include "sdhost.h"
#include "pin.h"
#include "mpexception.h"
#include "telnet.h"
@@ -55,19 +54,11 @@
/******************************************************************************
- DECLARE CONSTANTS
- ******************************************************************************/
-#define HAL_SDCARD_FREQUENCY_HZ 15000000 // 15MHz
-
-/******************************************************************************
DECLARE PRIVATE FUNCTIONS
******************************************************************************/
#ifndef USE_FREERTOS
static void hal_TickInit (void);
#endif
-#if MICROPY_HW_HAS_SDCARD
-static void hal_EnableSdCard (void);
-#endif
/******************************************************************************
DECLARE LOCAL DATA
@@ -101,9 +92,6 @@ void HAL_SystemInit (void) {
#ifndef USE_FREERTOS
hal_TickInit();
#endif
-#if MICROPY_HW_HAS_SDCARD
- hal_EnableSdCard();
-#endif
}
void HAL_SystemDeInit (void) {
@@ -189,23 +177,3 @@ static void hal_TickInit (void) {
}
#endif
-#if MICROPY_HW_HAS_SDCARD
-static void hal_EnableSdCard (void) {
- // Configure PIN_06 for SDHOST0 SDHost_D0
- MAP_PinTypeSDHost(PIN_06, PIN_MODE_8);
- // Configure PIN_07 for SDHOST0 SDHost_CLK
- MAP_PinTypeSDHost(PIN_07, PIN_MODE_8);
- // Configure PIN_08 for SDHOST0 SDHost_CMD
- MAP_PinTypeSDHost(PIN_08, PIN_MODE_8);
- // Set the SD card clock as an output pin
- MAP_PinDirModeSet(PIN_07, PIN_DIR_MODE_OUT);
- // Enable SD peripheral clock
- MAP_PRCMPeripheralClkEnable(PRCM_SDHOST, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
- // Reset MMCHS
- MAP_PRCMPeripheralReset(PRCM_SDHOST);
- // Configure MMCHS
- MAP_SDHostInit(SDHOST_BASE);
- // Configure the card clock
- MAP_SDHostSetExpClk(SDHOST_BASE, MAP_PRCMPeripheralClockGet(PRCM_SDHOST), HAL_SDCARD_FREQUENCY_HZ);
-}
-#endif
diff --git a/cc3200/mods/modpyb.c b/cc3200/mods/modpyb.c
index 1045817993..976c2bb337 100644
--- a/cc3200/mods/modpyb.c
+++ b/cc3200/mods/modpyb.c
@@ -64,6 +64,7 @@
#include "pybextint.h"
#include "pybadc.h"
#include "pybi2c.h"
+#include "pybsd.h"
#include "utils.h"
@@ -317,6 +318,10 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_ADC), (mp_obj_t)&pyb_adc_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_I2C), (mp_obj_t)&pyb_i2c_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_UART), (mp_obj_t)&pyb_uart_type },
+
+#if MICROPY_HW_HAS_SDCARD
+ { MP_OBJ_NEW_QSTR(MP_QSTR_SD), (mp_obj_t)&pyb_sdcard_obj },
+#endif
};
STATIC MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table);
diff --git a/cc3200/mods/pybextint.c b/cc3200/mods/pybextint.c
index bc4f5a82b8..ca0d3de739 100644
--- a/cc3200/mods/pybextint.c
+++ b/cc3200/mods/pybextint.c
@@ -271,7 +271,7 @@ void extint_init0(void) {
}
extint_obj_t* extint_register(mp_obj_t pin_obj, uint32_t intmode, uint32_t pull, mp_obj_t callback) {
- const pin_obj_t *pin = NULL;
+ const pin_obj_t *pin;
extint_obj_t* self;
void *handler;
uint32_t intnum;
diff --git a/cc3200/mods/pybpin.c b/cc3200/mods/pybpin.c
index f1f7eaa924..ee71ffb8d8 100644
--- a/cc3200/mods/pybpin.c
+++ b/cc3200/mods/pybpin.c
@@ -113,6 +113,12 @@ const pin_obj_t *pin_find(mp_obj_t user_obj) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
}
+void pin_verify_af (uint af) {
+ if (af > PIN_MODE_15) {
+ nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
+ }
+}
+
void pin_config(const pin_obj_t *self, uint af, uint mode, uint type, uint strength) {
// Skip all this if the pin is to be used in analog mode
if (type != PIN_TYPE_ANALOG) {
@@ -138,6 +144,8 @@ void pin_config(const pin_obj_t *self, uint af, uint mode, uint type, uint stren
// configure the direction
MAP_GPIODirModeSet(self->port, self->bit, mode);
}
+ // verify the alternate function
+ pin_verify_af (af);
// now set the alternate function, strenght and type
MAP_PinModeSet (self->pin_num, af);
}
diff --git a/cc3200/mods/pybpin.h b/cc3200/mods/pybpin.h
index 2ab7a507db..7a407d7bf1 100644
--- a/cc3200/mods/pybpin.h
+++ b/cc3200/mods/pybpin.h
@@ -57,6 +57,7 @@ extern const mp_obj_dict_t pin_cpu_pins_locals_dict;
MP_DECLARE_CONST_FUN_OBJ(pin_init_obj);
void pin_init0(void);
+void pin_verify_af (uint af);
void pin_config(const pin_obj_t *self, uint af, uint mode, uint type, uint strength);
const pin_obj_t *pin_find(mp_obj_t user_obj);
const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name);
diff --git a/cc3200/mods/pybsd.c b/cc3200/mods/pybsd.c
new file mode 100644
index 0000000000..5862cd79ca
--- /dev/null
+++ b/cc3200/mods/pybsd.c
@@ -0,0 +1,189 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2013, 2014 Damien P. George
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "mpconfig.h"
+#include MICROPY_HAL_H
+#include "nlr.h"
+#include "misc.h"
+#include "qstr.h"
+#include "obj.h"
+#include "runtime.h"
+#include "inc/hw_types.h"
+#include "inc/hw_gpio.h"
+#include "inc/hw_ints.h"
+#include "inc/hw_memmap.h"
+#include "rom_map.h"
+#include "pin.h"
+#include "prcm.h"
+#include "gpio.h"
+#include "sdhost.h"
+#include "pybpin.h"
+#include "pybsd.h"
+#include "ff.h"
+#include "osi.h"
+#include "debug.h"
+#include "mpexception.h"
+
+
+#if MICROPY_HW_HAS_SDCARD
+
+#define PYBSD_FREQUENCY_HZ 15000000 // 15MHz
+
+static byte pybsd_pin_d0, pybsd_pin_clk, pybsd_pin_cmd;
+static byte pybsd_af_d0, pybsd_af_clk, pybsd_af_cmd;
+static const pin_obj_t *pybsd_pin_sd_detect;
+static bool pybsd_pin_config_set;
+static bool pybsd_is_enabled;
+static FATFS *sd_fatfs;
+
+
+void pybsd_init0 (void) {
+ // Allocate memory for the sd file system
+ ASSERT ((sd_fatfs = mem_Malloc(sizeof(FATFS))) != NULL);
+}
+
+
+bool pybsd_is_present(void) {
+ if (pybsd_pin_sd_detect) {
+ return pybsd_is_enabled && MAP_GPIOPinRead(pybsd_pin_sd_detect->port, pybsd_pin_sd_detect->bit);
+ }
+ return true;
+}
+
+/******************************************************************************/
+// Micro Python bindings
+//
+// Note: these function are a bit ad-hoc at the moment and are mainly intended
+// for testing purposes. In the future SD should be a proper class with a
+// consistent interface and methods to mount/unmount it.
+
+/// \method sd_config([value])
+/// Configure the pins used for the sd card.
+/// May receive 6 or 7 arguments. The 7th optional argument is the card detect pin.
+/// this pin needs no external pull-up and must be low when the sdcard is inserted.
+///
+/// Usage:
+///
+/// pyb.SDcard.config_pins (d0_pin, d0_af, clk_pin, clk_af, cmd_pin, cmd_af)
+///
+/// or:
+///
+/// pyb.SDcard.sd_config_pins (d0_pin, d0_af, clk_pin, clk_af, cmd_pin, cmd_af, card_detect_pin)
+///
+STATIC mp_obj_t pybsd_config (mp_uint_t n_args, const mp_obj_t *args) {
+ const pin_obj_t *pin = NULL;
+
+ pin = pin_find(args[0]);
+ pybsd_pin_d0 = pin->pin_num;
+ pybsd_af_d0 = mp_obj_get_int(args[1]);
+ pin_verify_af (pybsd_af_d0);
+ pin = pin_find(args[2]);
+ pybsd_pin_clk = pin->pin_num;
+ pybsd_af_clk = mp_obj_get_int(args[3]);
+ pin_verify_af (pybsd_af_clk);
+ pin = pin_find(args[4]);
+ pybsd_pin_cmd = pin->pin_num;
+ pybsd_af_cmd = mp_obj_get_int(args[5]);
+ pin_verify_af (pybsd_af_cmd);
+ if (n_args == 7) {
+ pybsd_pin_sd_detect = pin_find(args[6]);
+ }
+ pybsd_pin_config_set = true;
+
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pybsd_config_obj, 6, 7, pybsd_config);
+
+STATIC mp_obj_t pybsd_enable(mp_obj_t self) {
+ if (pybsd_pin_config_set) {
+ // Configure the D0 pin
+ MAP_PinTypeSDHost(pybsd_pin_d0, pybsd_af_d0);
+ // Configure the CLK pin
+ MAP_PinTypeSDHost(pybsd_pin_clk, pybsd_af_clk);
+ // Configure the CMD pin
+ MAP_PinTypeSDHost(pybsd_pin_cmd, pybsd_af_cmd);
+ // Set the SD card clock as an output pin
+ MAP_PinDirModeSet(pybsd_pin_clk, PIN_DIR_MODE_OUT);
+ // Enable SD peripheral clock
+ MAP_PRCMPeripheralClkEnable(PRCM_SDHOST, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
+ // Reset MMCHS
+ MAP_PRCMPeripheralReset(PRCM_SDHOST);
+ // Initialize MMCHS
+ MAP_SDHostInit(SDHOST_BASE);
+ // Configure the card clock
+ MAP_SDHostSetExpClk(SDHOST_BASE, MAP_PRCMPeripheralClockGet(PRCM_SDHOST), PYBSD_FREQUENCY_HZ);
+
+ // Configure the card detect pin (if available)
+ if (pybsd_pin_sd_detect) {
+ pin_config(pybsd_pin_sd_detect, PIN_MODE_0, GPIO_DIR_MODE_IN, PIN_TYPE_STD_PU, PIN_STRENGTH_4MA);
+ }
+ }
+ else {
+ nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_resource_not_avaliable));
+ }
+
+ // try to mount the sd card on /SD
+ if (FR_OK == f_mount(sd_fatfs, "/SD", 1)) {
+ mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SD));
+ mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SD_slash_LIB));
+ }
+
+ pybsd_is_enabled = true;
+
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(pybsd_enable_obj, pybsd_enable);
+
+STATIC mp_obj_t pybsd_disable(mp_obj_t self) {
+ if (pybsd_is_enabled) {
+ pybsd_is_enabled = false;
+ // unmount the sd card
+ f_mount (NULL, "/SD", 1);
+ // disable the peripheral
+ MAP_PRCMPeripheralClkDisable(PRCM_SDHOST, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
+ }
+
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(pybsd_disable_obj, pybsd_disable);
+
+STATIC const mp_map_elem_t pybsd_locals_dict_table[] = {
+ { MP_OBJ_NEW_QSTR(MP_QSTR_config), (mp_obj_t)&pybsd_config_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_enable), (mp_obj_t)&pybsd_enable_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_disable), (mp_obj_t)&pybsd_disable_obj },
+};
+
+STATIC MP_DEFINE_CONST_DICT(pybsd_locals_dict, pybsd_locals_dict_table);
+
+static const mp_obj_type_t sdcard_type = {
+ { &mp_type_type },
+ .name = MP_QSTR_SD,
+ .locals_dict = (mp_obj_t)&pybsd_locals_dict,
+};
+
+const mp_obj_base_t pyb_sdcard_obj = {&sdcard_type};
+
+#endif // MICROPY_HW_HAS_SDCARD
diff --git a/cc3200/mods/pybsd.h b/cc3200/mods/pybsd.h
new file mode 100644
index 0000000000..b2efdb01e9
--- /dev/null
+++ b/cc3200/mods/pybsd.h
@@ -0,0 +1,36 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2013, 2014 Damien P. George
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef PYBSD_H_
+#define PYBSD_H_
+
+#if MICROPY_HW_HAS_SDCARD
+void pybsd_init0 (void);
+bool pybsd_is_present(void);
+
+extern const struct _mp_obj_base_t pyb_sdcard_obj;
+#endif
+
+#endif // PYBSD_H_
diff --git a/cc3200/mptask.c b/cc3200/mptask.c
index 3dd1231228..39e6e9ecf4 100644
--- a/cc3200/mptask.c
+++ b/cc3200/mptask.c
@@ -67,6 +67,7 @@
#include "random.h"
#include "pybextint.h"
#include "pybi2c.h"
+#include "pybsd.h"
#include "pins.h"
/******************************************************************************
@@ -91,9 +92,6 @@ OsiTaskHandle svTaskHandle;
DECLARE PRIVATE DATA
******************************************************************************/
static FATFS *sflash_fatfs;
-#if MICROPY_HW_HAS_SDCARD
-static FATFS *sd_fatfs;
-#endif
static const char fresh_main_py[] = "# main.py -- put your code here!\r\n";
static const char fresh_boot_py[] = "# boot.py -- run on boot-up\r\n"
@@ -119,8 +117,7 @@ void TASK_Micropython (void *pvParameters) {
// Allocate memory for the flash file system
ASSERT ((sflash_fatfs = mem_Malloc(sizeof(FATFS))) != NULL);
#if MICROPY_HW_HAS_SDCARD
- // Allocate memory for the sd file system
- ASSERT ((sd_fatfs = mem_Malloc(sizeof(FATFS))) != NULL);
+ pybsd_init0();
#endif
#ifdef DEBUG
@@ -175,17 +172,6 @@ soft_reset:
// initialize the serial flash file system
main_init_sflash_filesystem();
-#if MICROPY_HW_HAS_SDCARD
- // try to mount the sd card on /SD
- res = f_mount(sd_fatfs, "/SD", 1);
- if (res == FR_OK) {
- // use the SD card as the current directory
- f_chdrive("/SD");
- mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SD));
- mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SD_slash_LIB));
- }
-#endif
-
// append the SFLASH paths to the system path
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SFLASH));
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SFLASH_slash_LIB));
@@ -252,13 +238,13 @@ soft_reset_exit:
sflash_disk_flush();
- printf("PYB: soft rebooting...\n");
+ printf("PYB: soft reboot\n");
- // Disable wlan services
+ // disable wlan services
wlan_servers_stop();
wlan_sl_disable();
- // Wait for all bus transfers to complete
+ // wait for all bus transfers to complete
HAL_Delay(50);
uart_deinit();
diff --git a/cc3200/qstrdefsport.h b/cc3200/qstrdefsport.h
index b4d647a33a..9c5c6eafdf 100644
--- a/cc3200/qstrdefsport.h
+++ b/cc3200/qstrdefsport.h
@@ -160,6 +160,12 @@ Q(read)
Q(enable)
Q(disable)
+// for SD class
+Q(SD)
+Q(config)
+Q(enable)
+Q(disable)
+
// for RTC class
Q(RTC)
Q(datetime)