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

Report flash memory module capacity in Mebibytes #197

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

Conversation

vaibhavkpr
Copy link
Contributor

@vaibhavkpr vaibhavkpr commented Sep 24, 2024

Implements #150 - Reports memory module's sizes as a 'human-readable' string (as Mebibytes MiB). Also updates to utilize LOG_message instead of DEBUG_uart_print.

Success Output:

========================= UART Telecommand Received =========================
CTS1+flash_each_is_reachable()!
=========================
Parsed telecommand (len=31): 'CTS1+flash_each_is_reachable()!'
0000000000000+0000000930_N [TELECOMMAND:NORMAL]: Executing telecommand from agenda slot 0, sent at tssent=0, scheduled for tsexec=0.
========================= Executing telecommand 'flash_each_is_reachable'=========================
0000000000000+0000000951_N [FLASH:NORMAL]: SUCCESS: FLASH_is_reachable received IDs: 0x01 0x02 0x20 0x00 0x00    Capacity: 512 MiB
0000000000000+0000000964_N [FLASH:NORMAL]: SUCCESS: FLASH_is_reachable received IDs: 0x01 0x02 0x20 0x00 0x00    Capacity: 512 MiB
0000000000000+0000000977_N [FLASH:NORMAL]: SUCCESS: FLASH_is_reachable received IDs: 0x01 0x02 0x20 0x00 0x00    Capacity: 512 MiB
0000000000000+0000000989_N [FLASH:NORMAL]: SUCCESS: FLASH_is_reachable received IDs: 0x01 0x02 0x20 0x00 0x00    Capacity: 512 MiB
0000000000000+0000001002_N [FLASH:NORMAL]: SUCCESS: FLASH_is_reachable received IDs: 0x01 0x02 0x20 0x00 0x00    Capacity: 512 MiB
0000000000000+0000001015_N [FLASH:NORMAL]: SUCCESS: FLASH_is_reachable received IDs: 0x01 0x02 0x20 0x00 0x00    Capacity: 512 MiB
0000000000000+0000001028_N [FLASH:NORMAL]: SUCCESS: FLASH_is_reachable received IDs: 0x01 0x02 0x20 0x00 0x00    Capacity: 512 MiB
0000000000000+0000001040_N [FLASH:NORMAL]: SUCCESS: FLASH_is_reachable received IDs: 0x01 0x02 0x20 0x00 0x00    Capacity: 512 MiB
========================= Response (duration=102ms, err=0) =========================
Chip 0 is reachable.
Chip 1 is reachable.
Chip 2 is reachable.
Chip 3 is reachable.
Chip 4 is reachable.
Chip 5 is reachable.
Chip 6 is reachable.
Chip 7 is reachable.
All chips are reachable.

Failure Output:

========================= UART Telecommand Received =========================
CTS1+flash_each_is_reachable()!
=========================
Parsed telecommand (len=31): 'CTS1+flash_each_is_reachable()!'
0000000000000+0000002930_N [TELECOMMAND:NORMAL]: Executing telecommand from agenda slot 0, sent at tssent=0, scheduled for tsexec=0.
========================= Executing telecommand 'flash_each_is_reachable'=========================
0000000000000+0000002951_N [FLASH:NORMAL]: ERROR: FLASH_is_reachable received IDs: 0x00 0x00 0x00 0x00 0x00    Capacity: 0 MiB
0000000000000+0000002964_N [FLASH:NORMAL]: ERROR: FLASH_is_reachable received IDs: 0x00 0x00 0x00 0x00 0x00    Capacity: 0 MiB
0000000000000+0000002976_N [FLASH:NORMAL]: ERROR: FLASH_is_reachable received IDs: 0x00 0x00 0x00 0x00 0x00    Capacity: 0 MiB
0000000000000+0000002988_N [FLASH:NORMAL]: ERROR: FLASH_is_reachable received IDs: 0x00 0x00 0x00 0x00 0x00    Capacity: 0 MiB
0000000000000+0000003001_N [FLASH:NORMAL]: ERROR: FLASH_is_reachable received IDs: 0x00 0x00 0x00 0x00 0x00    Capacity: 0 MiB
0000000000000+0000003013_N [FLASH:NORMAL]: ERROR: FLASH_is_reachable received IDs: 0x00 0x00 0x00 0x00 0x00    Capacity: 0 MiB
0000000000000+0000003026_N [FLASH:NORMAL]: ERROR: FLASH_is_reachable received IDs: 0x00 0x00 0x00 0x00 0x00    Capacity: 0 MiB
0000000000000+0000003038_N [FLASH:NORMAL]: ERROR: FLASH_is_reachable received IDs: 0x00 0x00 0x00 0x00 0x00    Capacity: 0 MiB
========================= Response (duration=102ms, err=1 !!!!!! ERROR !!!!!!) =========================
Chip 0 is not reachable. Error code: 3
Chip 1 is not reachable. Error code: 3
Chip 2 is not reachable. Error code: 3
Chip 3 is not reachable. Error code: 3
Chip 4 is not reachable. Error code: 3
Chip 5 is not reachable. Error code: 3
Chip 6 is not reachable. Error code: 3
Chip 7 is not reachable. Error code: 3
8/8 chips are not reachable.

@DeflateAwning
Copy link
Contributor

DeflateAwning commented Sep 24, 2024

Implements #150

Would you mind adding example outputs of success and failure in this PR as a code block? Or I can if I get to it before you. Would just be helpful to have a record of what it looks like!

Copy link
Contributor

@DeflateAwning DeflateAwning 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 great, thanks for doing this! Tiny tweaks.

Take a look at the relevant docs/ file to see how to use LOG_message. Would be best to start using it as much as possible for new code

@@ -506,8 +509,18 @@ FLASH_error_enum_t FLASH_is_reachable(SPI_HandleTypeDef *hspi, uint8_t chip_numb
are_bytes_correct = 0;
}

// Extract memory capacity
uint32_t capacity_mib = (rx_buffer[2] * 512) / 32; // Convert to Mebibytes (MiB)
Copy link
Contributor

@DeflateAwning DeflateAwning Sep 24, 2024

Choose a reason for hiding this comment

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

Use const keyword. Avoid unnecessary math (multiply-then-divide). Use bitshifts for power-of-2 operations.

Ideally, include where you got this conversion math from.

Recommend making the variable name include MiB, as Mib/mib means mebibits (one eigth of a mebibyte)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, initially I had it simpler but just so the logic was clear I left the conversion math there, can simplify it and move it over to the comment!

DEBUG_uart_print_array_hex(rx_buffer, 5);
DEBUG_uart_print_str("\n");
DEBUG_uart_print_str("\t");
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, use the LOG_message function. Avoid using \t control character; not certain how it's going to behave with the ground station software.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Quick Question! Did we want this log to be part of LOG_SEVERITY_DEBUG or LOG_SEVERITY_NORMAL, since these messages were not setup to be part of the telecommand response buffer? Currently the is_reachable telecommand only prints the chip# availability and error codes if any. If the capacities are important we can have them printed part of the response itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably NORMAL

Copy link
Contributor

@DeflateAwning DeflateAwning left a comment

Choose a reason for hiding this comment

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

Looks solid! Just a tiny detail with the logs severity (log level) first though

@@ -290,7 +301,10 @@ FLASH_error_enum_t FLASH_erase(SPI_HandleTypeDef *hspi, uint8_t chip_number, lfs

if ((status_reg_buffer[0] & FLASH_SR1_ERASE_ERROR_MASK) > 0) {
// Flash module returned "erase error" via the status register.
DEBUG_uart_print_str("Flash erase error\n");
LOG_message(
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't errors be reported as a LOG_SEVERITY_WARNING or ERROR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good Catch! Must have missed it!

vaibhavkpr and others added 2 commits September 24, 2024 23:26
…being logged

* timeout logs set to LOG_SEVERITY_WARNING
* error logs respectively assigned LOG_SEVERITY_ERROR
@DeflateAwning
Copy link
Contributor

DeflateAwning commented Sep 25, 2024

Are you sure the output is right? You're showing a size of 512 MiB (512 mebibytes). I thought these devices were way smaller than that (maybe 512 Mib [mebibits])?

I also see this comment in the code: // rx_buffer[2] is 0x20=512 for 512 Mib (mebibits), which reinforces my quandry.

I just tacked on a small commit; make sure you pull it if you make more changes.

* New chip only returns two bytes: Manufacturer ID & Device ID
@NuclearTea
Copy link
Contributor

@vaibhavkpr Update on this PR? Been open for a while.

@vaibhavkpr
Copy link
Contributor Author

@NuclearTea I took a break off this issue as I didn't have a memory module to test this with, but I was able to pick one up last week. Once the other PR is complete, I was going to try testing the new memory module and see what we can do to find the capacity off it.

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

Successfully merging this pull request may close these issues.

3 participants