-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pbdrv/block_device: Implement async program load and save.
This replaces the polling SPI implementation (deactivated in the previous commit) with asynchronous DMA driven SPI transfers. This fixes motors going out of sync when starting programs. Fixes pybricks/support#679 This also avoids touching file systems used by other known firmwares, so that Pybricks can operate entirely stand alone. This reduces the complexity of firmware installation and troubleshooting, because there are no dependencies on prior firmwares or hub state. It also lays the groundwork for saving and storing program data on Powered Up hubs, but this isn't fully implemented in order to preserve compatibility with Pybricks Code and the existing tutorial videos.
- Loading branch information
1 parent
aabdd5f
commit 2d8a2ee
Showing
23 changed files
with
1,137 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,23 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) 2022 The Pybricks Authors | ||
|
||
#ifndef _INTERNAL_PBDRV_BLOCK_DEVICE_H_ | ||
#define _INTERNAL_PBDRV_BLOCK_DEVICE_H_ | ||
|
||
#include <stdint.h> | ||
|
||
#include <pbdrv/config.h> | ||
#include <pbio/error.h> | ||
|
||
#if PBDRV_CONFIG_BLOCK_DEVICE | ||
|
||
void pbdrv_block_device_init(void); | ||
|
||
#else // PBDRV_CONFIG_BLOCK_DEVICE | ||
|
||
static inline void pbdrv_block_device_init(void) { | ||
} | ||
|
||
#endif // PBDRV_CONFIG_BLOCK_DEVICE | ||
|
||
#endif // _INTERNAL_PBDRV_BLOCK_DEVICE_H_ |
56 changes: 56 additions & 0 deletions
56
lib/pbio/drv/block_device/block_device_internal_flash_stm32.c
This file contains 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,56 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) 2022 The Pybricks Authors | ||
|
||
// Block device driver for Internal_flash. | ||
|
||
#include <pbdrv/config.h> | ||
|
||
#if PBDRV_CONFIG_BLOCK_DEVICE_INTERNAL_FLASH_STM32 | ||
|
||
#include <stdint.h> | ||
#include <string.h> | ||
|
||
#include <contiki.h> | ||
|
||
#include "../core.h" | ||
|
||
#include <pbdrv/block_device.h> | ||
|
||
#include <pbio/error.h> | ||
#include <pbio/util.h> | ||
|
||
void pbdrv_block_device_init(void) { | ||
} | ||
|
||
void pbdrv_block_device_set_callback(void (*callback)(void)) { | ||
} | ||
|
||
PT_THREAD(block_device_read(struct pt *pt, uint32_t offset, uint8_t *buffer, uint32_t size, pbio_error_t *err)) { | ||
|
||
PT_BEGIN(pt); | ||
|
||
// TODO: Read from user flash. For now this just loads | ||
// the mpy file appended to the firmware to keep Pybricks Code working. | ||
extern uint32_t _pb_user_mpy_size; | ||
if (_pb_user_mpy_size + 8 > pbdrv_block_device_get_size()) { | ||
*err = PBIO_ERROR_FAILED; | ||
PT_EXIT(pt); | ||
} | ||
extern uint8_t _pb_user_mpy_data[]; | ||
pbio_set_uint32_le(buffer, _pb_user_mpy_size + 8); | ||
pbio_set_uint32_le(&buffer[4], _pb_user_mpy_size); | ||
memcpy(&buffer[8], _pb_user_mpy_data, _pb_user_mpy_size); | ||
*err = PBIO_SUCCESS; | ||
|
||
PT_END(pt); | ||
} | ||
|
||
PT_THREAD(block_device_store(struct pt *pt, uint8_t *buffer, uint32_t size, pbio_error_t *err)) { | ||
|
||
PT_BEGIN(pt); | ||
// TODO: Implement saving to user flash. | ||
*err = PBIO_ERROR_NOT_IMPLEMENTED; | ||
PT_END(pt); | ||
} | ||
|
||
#endif // PBDRV_CONFIG_BLOCK_DEVICE_INTERNAL_FLASH_STM32 |
Oops, something went wrong.