Skip to content
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

BlockDevices: minor fixes to cleanup compile warnings #444

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libraries/BlockDevices/QSPIFlashBlockDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ int QSPIFlashBlockDevice::write(const void *buffer, bd_addr_t add, bd_size_t _si
R_QSPI_BankSet(&ctrl, bank);
rv = R_QSPI_Write(&ctrl, (uint8_t *)(buffer), (uint8_t*)address, chunk);
address += chunk;
buffer += chunk;
buffer = (uint8_t *)(buffer) + chunk;

if(rv == FSP_SUCCESS) {
rv = get_flash_status();
Expand Down Expand Up @@ -328,7 +328,7 @@ int QSPIFlashBlockDevice::erase(bd_addr_t add, bd_size_t _size) {

uint32_t num_of_blocks = (_size / erase_block_size);

for(int i = 0; i < num_of_blocks && rv == FSP_SUCCESS; i++) {
for(uint32_t i = 0; i < num_of_blocks && rv == FSP_SUCCESS; i++) {
/* set bank */
uint32_t bank = add / READ_PAGE_SIZE;
uint32_t address = base_address + ((add + i * erase_block_size) % READ_PAGE_SIZE);
Expand Down
18 changes: 10 additions & 8 deletions libraries/BlockDevices/QSPIFlashBlockDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,27 @@

class QSPIFlashBlockDevice : public BlockDevice {
private:
bool opened;


pin_t ck;
pin_t cs;
pin_t io0;
pin_t io1;
pin_t io2;
pin_t io3;

bd_addr_t base_address;
bd_size_t total_size;
bd_size_t read_block_size;
bd_size_t erase_block_size;
bd_size_t write_block_size;

bool opened;

bool is_address_correct(bd_addr_t add);

qspi_instance_ctrl_t ctrl;
spi_flash_cfg_t cfg;
qspi_extended_cfg_t ext_cfg;
pin_t ck;
pin_t cs;
pin_t io0;
pin_t io1;
pin_t io2;
pin_t io3;

fsp_err_t get_flash_status();

Expand Down
11 changes: 5 additions & 6 deletions libraries/BlockDevices/SDCardBlockDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ SDCardBlockDevice::~SDCardBlockDevice() {
/* CALLBACK */
/* -------------------------------------------------------------------------- */
void SDCardBlockDevice::SDCardBlockDeviceCbk(sdmmc_callback_args_t *arg) {
int open_status = -1;
if(arg != nullptr) {
sdmmc_event_t event = arg->event;

Expand Down Expand Up @@ -368,8 +367,8 @@ int SDCardBlockDevice::read(void *buffer, bd_addr_t add, bd_size_t _size) {
uint32_t num_of_blocks = (_size / read_block_size);
uint32_t start_add_of_block = (add / read_block_size);
rv = FSP_SUCCESS;
for(int i = 0; i < num_of_blocks && rv == FSP_SUCCESS; i++) {
rv = R_SDHI_Read (&ctrl, (uint8_t *)(buffer + (i * read_block_size)), start_add_of_block + i, 1);
for(uint32_t i = 0; i < num_of_blocks && rv == FSP_SUCCESS; i++) {
rv = R_SDHI_Read (&ctrl, (uint8_t *)((uint8_t *)buffer + (i * read_block_size)), start_add_of_block + i, 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is just a matter of personal taste but I would prefer this way without the double cast (to me is clearer)

Suggested change
rv = R_SDHI_Read (&ctrl, (uint8_t *)((uint8_t *)buffer + (i * read_block_size)), start_add_of_block + i, 1);
uint8_t *buf = (uint8_t *)buffer;
rv = R_SDHI_Read (&ctrl, buf + (i * read_block_size), start_add_of_block + i, 1);

if(rv == FSP_SUCCESS) {
rv = wait_for_completition();
}
Expand Down Expand Up @@ -404,8 +403,8 @@ int SDCardBlockDevice::write(const void *buffer, bd_addr_t add, bd_size_t _size)
uint32_t num_of_blocks = (_size / write_block_size);
uint32_t start_block_number = (add / write_block_size);
rv = FSP_SUCCESS;
for(int i = 0; i < num_of_blocks && rv == FSP_SUCCESS; i++) {
rv = R_SDHI_Write (&ctrl, (uint8_t *)(buffer + (i * write_block_size)), start_block_number + i, 1);
for(uint32_t i = 0; i < num_of_blocks && rv == FSP_SUCCESS; i++) {
rv = R_SDHI_Write (&ctrl, (uint8_t *)((uint8_t *)buffer + (i * write_block_size)), start_block_number + i, 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is just a matter of personal taste but I would prefer this way without the double cast (to me is clearer)

Suggested change
rv = R_SDHI_Write (&ctrl, (uint8_t *)((uint8_t *)buffer + (i * write_block_size)), start_block_number + i, 1);
uint8_t *buf = (uint8_t *)buffer;
rv = R_SDHI_Write (&ctrl, buf + (i * write_block_size), start_block_number + i, 1);

if(rv == FSP_SUCCESS) {
rv = wait_for_completition();
}
Expand Down Expand Up @@ -439,7 +438,7 @@ int SDCardBlockDevice::erase(bd_addr_t add, bd_size_t _size) {
uint32_t num_of_blocks = (_size / erase_block_size);
uint32_t start_block_number = (add / erase_block_size);
rv = FSP_SUCCESS;
for(int i = 0; i < num_of_blocks && rv == FSP_SUCCESS; i++) {
for(uint32_t i = 0; i < num_of_blocks && rv == FSP_SUCCESS; i++) {
rv = R_SDHI_Erase (&ctrl, start_block_number + i, 1);
if(rv == FSP_SUCCESS) {
rv = wait_for_completition();
Expand Down
22 changes: 12 additions & 10 deletions libraries/BlockDevices/SDCardBlockDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,22 @@ enum class CmdStatus {

class SDCardBlockDevice : public BlockDevice {
private:
sdmmc_device_t sd_card_info;
pin_t ck;
pin_t cmd;
pin_t d0;
pin_t d1;
pin_t d2;
pin_t d3;
pin_t cd;
pin_t wp;
bd_addr_t base_address;
bd_size_t total_size;
bd_size_t read_block_size;
bd_size_t erase_block_size;
bd_size_t write_block_size;
bool opened;
sdhi_instance_ctrl_t ctrl;
sdmmc_device_t sd_card_info;
sdmmc_cfg_t cfg;

#ifdef USE_DMAC
Expand All @@ -84,22 +93,15 @@ class SDCardBlockDevice : public BlockDevice {
transfer_cfg_t dtc_cfg;
transfer_instance_t dtc_instance;
#endif
pin_t ck;
pin_t cmd;
pin_t d0;
pin_t d1;
pin_t d2;
pin_t d3;
pin_t cd;
pin_t wp;

static volatile bool initialized;
static volatile bool card_inserted;
static volatile CmdStatus st;
static void SDCardBlockDeviceCbk(sdmmc_callback_args_t *);
virtual int write(const void *buffer, bd_addr_t addr, bd_size_t size) override;
virtual int open() override;
virtual int close() override;
bool opened;

fsp_err_t wait_for_completition();
public:

Expand Down
Loading