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

SD Card Logger + Library #338

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open

SD Card Logger + Library #338

wants to merge 22 commits into from

Conversation

ikesicle
Copy link

sd_binary.c is the file which defines general-purpose methods for reading and writing to the SD card.
main.c is the smoke test file (need help writing this probably).

@ikesicle ikesicle self-assigned this Oct 30, 2024
@ikesicle ikesicle marked this pull request as draft October 30, 2024 23:19
@ikesicle ikesicle marked this pull request as ready for review January 16, 2025 00:30
Copy link
Collaborator

@Bafran Bafran left a comment

Choose a reason for hiding this comment

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

This is really cool! I think it just requires a bit of cleanup since there's some random files, but if this works and is tested the general structure seems solid.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think these should all be removed

*******************************************************************************
* @attention
*
* COPYRIGHT(c) 2016 STMicroelectronics
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this using something from the HAL?

Copy link
Author

Choose a reason for hiding this comment

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

Not sure what exactly the HAL is, could you clarify? Also, that line above seems to be added by scons format.

s = prv_read_byte(spi, &readvalue);
if (s != STATUS_CODE_OK) return s;
if (--timeout)
return status_msg(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry I might not be familiar with the source of some of this code - where is this status_msg type coming from? looks like this function is still supposed to be returning our StatusCode

Copy link
Author

Choose a reason for hiding this comment

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

Not sure either. The old SD card program which this was based off of seemed to use it, and it expanded into a macro which returned a Status Code as normal. Maybe it returns a status code and also logs a message at the same time?

frame[5] = (uint8_t)0x95; // CRC for a CMD0. We can hardcode this since the CRC is ignored from
// then on anyways.

spi_cs_set_state(spi, GPIO_STATE_LOW);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this not taken care of within spi_tx? If there is a reason this is here then leave a comment about it

Copy link
Author

Choose a reason for hiding this comment

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

Don't actually think there's a reason for that to be there, I remember spi_tx does pull down. I think I could remove it.


// Send CMD0 (SD_CMD_GO_IDLE_STATE) to put SD in SPI mode and
// wait for In Idle State Response (R1 Format) equal to 0x01
do {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Kind of an interesting setup you've got with the do while loops, did you reference this from somewhere or is it just a fitting solution given that you need to send once and continue on some condition?

Copy link
Author

Choose a reason for hiding this comment

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

It just seemed fitting since every step requires an initial try of the process, so I thought do-while would work for that

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is super cool! Looks like a fairly simple interface and great job getting this to work I know it's a tough driver. Only note for this is maybe remove the mallocs and statically allocate so someone could copy paste your code into their project to test.


// set spi CS state HIGH
gpio_set_state(&s_port[spi].cs, GPIO_STATE_HIGH);
StatusCode spi_cs_set_state(SpiPort spi, GpioState state) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh I see I left a comment below about this, I think a comment would still help though

@Bafran
Copy link
Collaborator

Bafran commented Jan 25, 2025

One more thing, for this project more than others please fill out the Readme with all the resources you used to write the driver. This one has some quirks so if there's no documentation it'll get out of date pretty quickly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants