-
Notifications
You must be signed in to change notification settings - Fork 0
Add littlefs_shim.c #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
492d27b
add littlefs_shim.c
x-ximena 719386d
Add the header file
x-ximena 84694e6
fix code
x-ximena 64b9f2b
Added first_sector global variable
x-ximena 64c260a
Format code
x-ximena e9be571
Debug
x-ximena 9f2755f
Debug
x-ximena f584544
Edit
x-ximena 267c38e
Rename functions and files
x-ximena f10713d
Rename functions and files
x-ximena bbd99ac
lfsshim_write fixed
x-ximena 87004ea
Define timeout as a macro
x-ximena 15379fb
Code clean up
x-ximena 1b90bf8
lfsshim_hsd fixed
x-ximena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #ifndef ROCKETLIB_LITTLEFS_SHIM_H | ||
| #define ROCKETLIB_LITTLEFS_SHIM_H | ||
|
|
||
| #include "lfs.h" | ||
| #include "stm32h7xx_hal_sd.h" | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| // External SD handle used by the shim | ||
| extern SD_HandleTypeDef *lfsshim_hsd; | ||
|
|
||
| extern uint32_t lfsshim_first_block_offset; | ||
|
|
||
| // LittleFS-compatible SD card interface functions | ||
| int lfsshim_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, | ||
| lfs_size_t size); | ||
|
|
||
| int lfsshim_write(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, | ||
| lfs_size_t size); | ||
|
|
||
| int lfsshim_erase(const struct lfs_config *c, lfs_block_t block); | ||
|
|
||
| int lfsshim_sync(const struct lfs_config *c); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif // ROCKETLIB_LITTLEFS_SHIM_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| #include "stm32h7xx_hal.h" | ||
| #include "lfs.h" | ||
| #include "common.h" | ||
|
|
||
| SD_HandleTypeDef* lfsshim_hsd; | ||
| uint32_t lfsshim_first_block_offset = 0; | ||
|
|
||
| uint32_t SD_RW_TIMEOUT_MS = 50U; | ||
x-ximena marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| int lfsshim_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, | ||
| lfs_size_t size) { | ||
| uint32_t timeout_ms = SD_RW_TIMEOUT_MS; | ||
| uint32_t block_addr = block + lfsshim_first_block_offset; | ||
| //uint32_t num_blocks = (size + c->block_size - 1) / c->block_size; | ||
x-ximena marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| uint32_t num_blocks = size / c->block_size; | ||
x-ximena marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| w_assert((size % c->block_size) == 0); | ||
| w_assert(off == 0); | ||
| HAL_StatusTypeDef hal = | ||
| HAL_SD_ReadBlocks(lfsshim_hsd, (uint8_t *)buffer, block_addr, num_blocks, timeout_ms); | ||
| if (hal != HAL_OK) { | ||
| return -1; // LFS_ERR_IO | ||
| } | ||
|
|
||
| // Wait for card to be ready (polling) | ||
| uint32_t start = HAL_GetTick(); | ||
| while (HAL_SD_GetCardState(lfsshim_hsd) != HAL_SD_CARD_TRANSFER) { | ||
| if ((HAL_GetTick() - start) > timeout_ms) { | ||
| return -1; // timeout -> LFS_ERR_IO | ||
| } | ||
| } | ||
|
|
||
| return 0; // success | ||
| } | ||
|
|
||
| int lfsshim_write(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, | ||
| lfs_size_t size) { | ||
| uint32_t timeout_ms = SD_RW_TIMEOUT_MS; | ||
| uint32_t block_addr = block + lfsshim_first_block_offset; | ||
| //uint32_t num_blocks = (size + c->block_size - 1) / c->block_size; | ||
x-ximena marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| uint32_t num_blocks = 1; | ||
| if(size != 512){ | ||
| for(;;){} | ||
| } | ||
| if(off != 0){ | ||
| for(;;){} | ||
| } | ||
|
|
||
| HAL_StatusTypeDef hal = | ||
| HAL_SD_WriteBlocks(lfsshim_hsd, (uint8_t *)buffer, block_addr, num_blocks, timeout_ms); | ||
| if (hal != HAL_OK) { | ||
| return -1; // LFS_ERR_IO | ||
| } | ||
|
|
||
| // Wait for card to be ready (polling) | ||
| uint32_t start = HAL_GetTick(); | ||
| while (HAL_SD_GetCardState(lfsshim_hsd) != HAL_SD_CARD_TRANSFER) { | ||
| if ((HAL_GetTick() - start) > timeout_ms) { | ||
| return -1; // timeout -> LFS_ERR_IO | ||
| } | ||
| } | ||
|
|
||
| return 0; // success | ||
| } | ||
|
|
||
| int lfsshim_erase(const struct lfs_config *c, lfs_block_t block) { | ||
| return 0; // SD does not require explicit erase | ||
| } | ||
|
|
||
| int lfsshim_sync(const struct lfs_config *c) { | ||
| return 0; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.