From 14e64fdd5099ad82882664798caebbdc189803e3 Mon Sep 17 00:00:00 2001 From: Hiroyuki OYAMA Date: Thu, 13 Jun 2024 15:35:21 +0900 Subject: [PATCH] Assertion to incorrect initial values, Fix #37 --- include/blockdevice/flash.h | 2 +- include/filesystem/vfs.h | 10 +++++----- src/blockdevice/flash.c | 4 ++++ src/blockdevice/sd.c | 15 +++++++++++++++ tests/integration/test_vfs.c | 4 ++-- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/include/blockdevice/flash.h b/include/blockdevice/flash.h index 144e8d0..384e659 100644 --- a/include/blockdevice/flash.h +++ b/include/blockdevice/flash.h @@ -13,7 +13,7 @@ extern "C" { /** Create Raspberry Pi Pico On-board Flash block device * - * Create a block device object that uses the Raspberry Pi Pico onboard flash memory. The start position of the flash memory to be allocated to the block device is specified by start and the length by length. + * Create a block device object that uses the Raspberry Pi Pico onboard flash memory. The start position of the flash memory to be allocated to the block device is specified by start and the length by length. start and length must be aligned to a flash sector of 4096 bytes. * * @param start Specifies the starting position of the flash memory to be allocated to the block device in bytes. * @param length Size in bytes to be allocated to the block device. If zero is specified, all remaining space is used. diff --git a/include/filesystem/vfs.h b/include/filesystem/vfs.h index 990ee97..a6048e2 100644 --- a/include/filesystem/vfs.h +++ b/include/filesystem/vfs.h @@ -35,7 +35,7 @@ bool fs_init(void); * @param fs File system object. Format the block device according to the specified file system. * @param device Block device used in the file system. * @retval 0 Format succeeded. - * @retval <0 Format failed. Negative integer value indicates an error code. + * @retval -1 Format failed. Error codes are indicated by errno. */ int fs_format(filesystem_t *fs, blockdevice_t *device); @@ -47,7 +47,7 @@ int fs_format(filesystem_t *fs, blockdevice_t *device); * @param fs File system object. * @param device Block device used in the file system. Block devices must be formatted with a file system. * @retval 0 Mount succeeded. - * @retval <0 Mount failed. Negative integer value indicates an error code. + * @retval -1 Mount failed. Error codes are indicated by errno. */ int fs_mount(const char *path, filesystem_t *fs, blockdevice_t *device); @@ -57,7 +57,7 @@ int fs_mount(const char *path, filesystem_t *fs, blockdevice_t *device); * * @param path Directory path of the mount point. Must be the same as the path specified for the mount. * @retval 0 Dismount succeeded. - * @retval <0 Dismount failed. Negative integer value indicates an error code. + * @retval -1 Dismount failed. Error codes are indicated by errno. */ int fs_unmount(const char *path); @@ -67,7 +67,7 @@ int fs_unmount(const char *path); * * @param path Directory path of the mount point. Must be the same as the path specified for the mount. * @retval 0 Reformat suceeded. - * @retval <0 Reformat failed. Negative integer value indicates an error code. + * @retval -1 Reformat failed. Error codes are indicated by errno. */ int fs_reformat(const char *path); @@ -77,7 +77,7 @@ int fs_reformat(const char *path); * @param fs Pointer references to filesystem objects * @param device Pinter references to blockdevice objects * @retval 0 Lookup succeeded - * @retval <0 Lookup failed. Negative integer value indicates an error code. + * @retval -1 Lookup failed. Error codes are indicated by errno. */ int fs_info(const char *path, filesystem_t **fs, blockdevice_t **device); diff --git a/src/blockdevice/flash.c b/src/blockdevice/flash.c index 50ebbb8..44c48fb 100644 --- a/src/blockdevice/flash.c +++ b/src/blockdevice/flash.c @@ -2,6 +2,7 @@ * Copyright 2024, Hiroyuki OYAMA. All rights reserved. * SPDX-License-Identifier: BSD-3-Clause */ +#include #include #include #include @@ -87,6 +88,9 @@ static size_t size(blockdevice_t *device) { } blockdevice_t *blockdevice_flash_create(uint32_t start, size_t length) { + assert(start % FLASH_SECTOR_SIZE == 0); + assert(length % FLASH_SECTOR_SIZE == 0); + blockdevice_t *device = calloc(1, sizeof(blockdevice_t)); if (device == NULL) { fprintf(stderr, "blockdevice_flash_create: Out of memory\n"); diff --git a/src/blockdevice/sd.c b/src/blockdevice/sd.c index 1789d66..052bfcd 100644 --- a/src/blockdevice/sd.c +++ b/src/blockdevice/sd.c @@ -7,6 +7,7 @@ * [ARM Mbed OS](https://github.com/ARMmbed/mbed-os/blob/master/storage/blockdevice/COMPONENT_SD/source/SDBlockDevice.cpp); * ARM Embed OS is licensed under the Apache 2.0 licence. */ +#include #include #include #include @@ -1036,6 +1037,20 @@ blockdevice_t *blockdevice_sd_create(spi_inst_t *spi_inst, uint32_t hz, bool enable_crc) { + if (spi_inst == spi0) { + assert(mosi == 3 || mosi == 7 || mosi == 19 || mosi == 23); + assert(miso == 0 || miso == 4 || miso == 16 || miso == 20); + assert(sclk == 2 || sclk == 6 || sclk == 18 || sclk == 22); + // assert(cs == 1 || cs == 5 || cs == 17 || cs == 21); + } else if (spi_inst == spi1) { + assert(mosi == 11 || mosi == 15 || mosi == 27); + assert(miso == 8 || miso == 12 || mosi == 24 || mosi == 28); + assert(sclk == 10 || sclk == 14 || sclk == 26); + // assert(cs == 9 || cs == 13 || cs == 25 || cs == 29); + } else { + assert(spi_inst == spi0 || spi_inst == spi1); + } + blockdevice_t *device = calloc(1, sizeof(blockdevice_t)); if (device == NULL) { fprintf(stderr, "blockdevice_sd_create: Out of memory\n"); diff --git a/tests/integration/test_vfs.c b/tests/integration/test_vfs.c index 54eece2..5cb4842 100644 --- a/tests/integration/test_vfs.c +++ b/tests/integration/test_vfs.c @@ -25,8 +25,8 @@ #define PICO_SPI1_TX_PIN 15 #define PICO_SPI1_RX_PIN 12 -#define PICO_SPI1_SCK_PIN 19 -#define PICO_SPI1_CSN_PIN 17 +#define PICO_SPI1_SCK_PIN 14 +#define PICO_SPI1_CSN_PIN 13 static void test_printf(const char *format, ...) { va_list args;