Merge pull request #3106 from kamtom480/sdcard

spresense: Add support for sdioio
This commit is contained in:
Scott Shawcroft 2020-07-02 11:28:24 -07:00 committed by GitHub
commit d901b056dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 228 additions and 3 deletions

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-07-01 10:33-0500\n"
"POT-Creation-Date: 2020-07-02 15:29+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -425,7 +425,8 @@ msgstr ""
msgid "Buffer length %d too big. It must be less than %d"
msgstr ""
#: ports/atmel-samd/common-hal/sdioio/SDCard.c shared-module/sdcardio/SDCard.c
#: ports/atmel-samd/common-hal/sdioio/SDCard.c
#: ports/cxd56/common-hal/sdioio/SDCard.c shared-module/sdcardio/SDCard.c
msgid "Buffer length must be a multiple of 512"
msgstr ""
@ -589,6 +590,10 @@ msgstr ""
msgid "Could not initialize GNSS"
msgstr ""
#: ports/cxd56/common-hal/sdioio/SDCard.c
msgid "Could not initialize SDCard"
msgstr ""
#: ports/atmel-samd/common-hal/busio/UART.c ports/cxd56/common-hal/busio/UART.c
msgid "Could not initialize UART"
msgstr ""
@ -982,7 +987,8 @@ msgstr ""
#: ports/atmel-samd/common-hal/busio/UART.c
#: ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral.c
#: ports/cxd56/common-hal/busio/I2C.c ports/cxd56/common-hal/busio/SPI.c
#: ports/cxd56/common-hal/busio/UART.c ports/mimxrt10xx/common-hal/busio/I2C.c
#: ports/cxd56/common-hal/busio/UART.c ports/cxd56/common-hal/sdioio/SDCard.c
#: ports/mimxrt10xx/common-hal/busio/I2C.c
#: ports/mimxrt10xx/common-hal/busio/SPI.c
#: ports/mimxrt10xx/common-hal/busio/UART.c ports/nrf/common-hal/busio/I2C.c
msgid "Invalid pins"

View File

@ -24,8 +24,21 @@
* THE SOFTWARE.
*/
#include "py/objtuple.h"
#include "shared-bindings/board/__init__.h"
STATIC const mp_rom_obj_tuple_t sdio_data_tuple = {
{&mp_type_tuple},
4,
{
MP_ROM_PTR(&pin_SDIO_DATA0),
MP_ROM_PTR(&pin_SDIO_DATA1),
MP_ROM_PTR(&pin_SDIO_DATA2),
MP_ROM_PTR(&pin_SDIO_DATA3),
}
};
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_UART2_RXD) },
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_UART2_TXD) },
@ -76,5 +89,8 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
{ MP_ROM_QSTR(MP_QSTR_SDIO_CLOCK), MP_ROM_PTR(&pin_SDIO_CLK) },
{ MP_ROM_QSTR(MP_QSTR_SDIO_COMMAND), MP_ROM_PTR(&pin_SDIO_CMD) },
{ MP_ROM_QSTR(MP_QSTR_SDIO_DATA), MP_ROM_PTR(&sdio_data_tuple) },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

View File

@ -72,6 +72,12 @@ const mcu_pin_obj_t pin_I2S1_BCK = PIN(PIN_I2S1_BCK, false);
const mcu_pin_obj_t pin_I2S1_LRCK = PIN(PIN_I2S1_LRCK, false);
const mcu_pin_obj_t pin_I2S1_DATA_IN = PIN(PIN_I2S1_DATA_IN, false);
const mcu_pin_obj_t pin_I2S1_DATA_OUT = PIN(PIN_I2S1_DATA_OUT, false);
const mcu_pin_obj_t pin_SDIO_CLK = PIN(PIN_SDIO_CLK, false);
const mcu_pin_obj_t pin_SDIO_CMD = PIN(PIN_SDIO_CMD, false);
const mcu_pin_obj_t pin_SDIO_DATA0 = PIN(PIN_SDIO_DATA0, false);
const mcu_pin_obj_t pin_SDIO_DATA1 = PIN(PIN_SDIO_DATA1, false);
const mcu_pin_obj_t pin_SDIO_DATA2 = PIN(PIN_SDIO_DATA2, false);
const mcu_pin_obj_t pin_SDIO_DATA3 = PIN(PIN_SDIO_DATA3, false);
const mcu_pin_obj_t pin_LPADC0 = PIN(0, true);
const mcu_pin_obj_t pin_LPADC1 = PIN(1, true);
const mcu_pin_obj_t pin_LPADC2 = PIN(2, true);

View File

@ -77,6 +77,12 @@ extern const mcu_pin_obj_t pin_I2S1_BCK;
extern const mcu_pin_obj_t pin_I2S1_LRCK;
extern const mcu_pin_obj_t pin_I2S1_DATA_IN;
extern const mcu_pin_obj_t pin_I2S1_DATA_OUT;
extern const mcu_pin_obj_t pin_SDIO_CLK;
extern const mcu_pin_obj_t pin_SDIO_CMD;
extern const mcu_pin_obj_t pin_SDIO_DATA0;
extern const mcu_pin_obj_t pin_SDIO_DATA1;
extern const mcu_pin_obj_t pin_SDIO_DATA2;
extern const mcu_pin_obj_t pin_SDIO_DATA3;
extern const mcu_pin_obj_t pin_LPADC0;
extern const mcu_pin_obj_t pin_LPADC1;
extern const mcu_pin_obj_t pin_LPADC2;

View File

@ -0,0 +1,141 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright 2020 Sony Semiconductor Solutions Corporation
*
* 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 <fcntl.h>
#include <unistd.h>
#include <arch/chip/pin.h>
#include "py/mperrno.h"
#include "py/runtime.h"
#include "shared-bindings/sdioio/SDCard.h"
#include "shared-bindings/util.h"
#define DATA_PINS_NUM 4
void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self,
const mcu_pin_obj_t *clock, const mcu_pin_obj_t *command,
uint8_t num_data, mcu_pin_obj_t **data, uint32_t frequency) {
struct geometry geo;
if (clock->number != PIN_SDIO_CLK || command->number != PIN_SDIO_CMD) {
mp_raise_ValueError(translate("Invalid pins"));
}
uint8_t data_pins_num = 0;
for (uint8_t i = 0; i < DATA_PINS_NUM; i++) {
if (data[i]->number != PIN_SDIO_DATA0 || data[i]->number != PIN_SDIO_DATA1 ||
data[i]->number != PIN_SDIO_DATA2 || data[i]->number != PIN_SDIO_DATA3) {
data_pins_num++;
}
}
if (data_pins_num != DATA_PINS_NUM) {
mp_raise_ValueError(translate("Invalid pins"));
}
if (open_blockdriver("/dev/mmcsd0", 0, &self->inode) < 0) {
mp_raise_ValueError(translate("Could not initialize SDCard"));
}
self->inode->u.i_bops->geometry(self->inode, &geo);
claim_pin(clock);
claim_pin(command);
self->clock_pin = clock;
self->command_pin = command;
for (uint8_t i = 0; i < DATA_PINS_NUM; i++) {
claim_pin(data[i]);
self->data_pins[i] = data[i];
}
self->count = geo.geo_nsectors;
self->frequency = frequency;
self->width = num_data;
}
void common_hal_sdioio_sdcard_deinit(sdioio_sdcard_obj_t *self) {
close_blockdriver(self->inode);
self->inode = NULL;
reset_pin_number(self->clock_pin->number);
reset_pin_number(self->command_pin->number);
for (uint8_t i = 0; i < DATA_PINS_NUM; i++) {
reset_pin_number(self->data_pins[i]->number);
}
}
bool common_hal_sdioio_sdcard_deinited(sdioio_sdcard_obj_t *self) {
return self->inode == NULL;
}
bool common_hal_sdioio_sdcard_configure(sdioio_sdcard_obj_t *self, uint32_t baudrate, uint8_t width) {
return true;
}
uint32_t common_hal_sdioio_sdcard_get_frequency(sdioio_sdcard_obj_t* self) {
return self->frequency;
}
uint8_t common_hal_sdioio_sdcard_get_width(sdioio_sdcard_obj_t* self) {
return self->width;
}
uint32_t common_hal_sdioio_sdcard_get_count(sdioio_sdcard_obj_t* self) {
return self->count;
}
STATIC void check_whole_block(mp_buffer_info_t *bufinfo) {
if (bufinfo->len % 512) {
mp_raise_ValueError(translate("Buffer length must be a multiple of 512"));
}
}
int common_hal_sdioio_sdcard_readblocks(sdioio_sdcard_obj_t* self, uint32_t start_block, mp_buffer_info_t *bufinfo) {
if (common_hal_sdioio_sdcard_deinited(self)) {
raise_deinited_error();
}
check_whole_block(bufinfo);
return self->inode->u.i_bops->read(self->inode, bufinfo->buf, start_block, bufinfo->len / 512);
}
int common_hal_sdioio_sdcard_writeblocks(sdioio_sdcard_obj_t* self, uint32_t start_block, mp_buffer_info_t *bufinfo) {
if (common_hal_sdioio_sdcard_deinited(self)) {
raise_deinited_error();
}
check_whole_block(bufinfo);
return self->inode->u.i_bops->write(self->inode, bufinfo->buf, start_block, bufinfo->len / 512);;
}
void common_hal_sdioio_sdcard_never_reset(sdioio_sdcard_obj_t *self) {
never_reset_pin_number(self->clock_pin->number);
never_reset_pin_number(self->command_pin->number);
for (uint8_t i = 0; i < DATA_PINS_NUM; i++) {
never_reset_pin_number(self->data_pins[i]->number);
}
}

View File

@ -0,0 +1,47 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright 2020 Sony Semiconductor Solutions Corporation
*
* 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 MICROPY_INCLUDED_CXD56_SDIOIO_SDCARD_H
#define MICROPY_INCLUDED_CXD56_SDIOIO_SDCARD_H
#include <nuttx/fs/fs.h>
#include "py/obj.h"
#include "common-hal/microcontroller/Pin.h"
typedef struct {
mp_obj_base_t base;
struct inode* inode;
uint32_t frequency;
uint32_t count;
uint8_t width;
const mcu_pin_obj_t *command_pin;
const mcu_pin_obj_t *clock_pin;
const mcu_pin_obj_t *data_pins[4];
} sdioio_sdcard_obj_t;
#endif // MICROPY_INCLUDED_CXD56_SDIOIO_SDCARD_H

View File

View File

@ -7,6 +7,8 @@ USB_CDC_EP_NUM_DATA_IN = 1
USB_MSC_EP_NUM_OUT = 5
USB_MSC_EP_NUM_IN = 4
MPY_TOOL_LONGINT_IMPL = -mlongint-impl=mpz
CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_AUDIOIO = 0
CIRCUITPY_COUNTIO = 0
@ -18,6 +20,7 @@ CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_NVM = 0
CIRCUITPY_ROTARYIO = 0
CIRCUITPY_SDIOIO = 1
CIRCUITPY_TOUCHIO = 0
CIRCUITPY_USB_HID = 0
CIRCUITPY_USB_MIDI = 0