Skip to content

Initial Rev 3 flash driver#30

Merged
ETSells merged 9 commits into
mainfrom
feature/ES/r3-flash
Jun 2, 2026
Merged

Initial Rev 3 flash driver#30
ETSells merged 9 commits into
mainfrom
feature/ES/r3-flash

Conversation

@ETSells

@ETSells ETSells commented May 5, 2026

Copy link
Copy Markdown
Member

Description

Implements the critical APIs needed to operate flash on Rev. 3.

Issue Link

Closes #5.

Child: SunDevilRocketry/Flight-Computer-Firmware#261

Depends on: SunDevilRocketry/mod#127 (can be reviewed separately though, just make sure this branch is checked out if you run any tests)

Testing

  • Passes existing unit tests
  • Unit tests modified
  • Integration test performed

N/A -- no testing possible until rev3 initial integration.

Other

N/A

Reviewer Checklist

Standards

  • Follows FCF Architectural Standards
  • Follows SDR Coding Standards
  • Code complexity/function Size is minimized
  • Code is testable
  • Code is readable and commented properly
  • License terms are respected

Error Handling

  • Potentially unsafe functions return a status code
  • Error returns properly handled

Memory

  • Stack allocated memory is scoped correctly
  • Heap allocated memory is avoided
  • Globally allocated memory is minimized except when necessary
  • Pointers are used correctly
  • Concurrency has been considered

Performance

  • Rate limiters are respected
  • Busy waiting is avoided
  • "Delay" calls are not used in performance sensitive code

@ETSells

ETSells commented May 23, 2026

Copy link
Copy Markdown
Member Author

@NArmistead adding you for review bc this has stalled. if you're uncomfortable reviewing a driver lmk

@NArmistead NArmistead left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Only thing from me is that there are a couple functions that would need a null check on the flash handle to be consistent with the other functions that have it. If it isn't necessary I'll approve.

Comment thread flash/flash.h Outdated
FLASH_BLOCK_13 ,
FLASH_BLOCK_14 ,
FLASH_BLOCK_15
FLASH_BLOCK_15 ,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: unnecessary comma

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Can fix. If youre curious, this arose because I was originally going to extend the enum to support the number of blocks on the new chip, but theres hundreds of pages & the smallest block size.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have to say: these kinds of inits made me wish C (and more languages in general) just had a way to create these kinds of types that are basically just ranges without crazy enums or (in the case of OOP languages like C++) a janky setup of operator overloading.

Is it time for SDR to contribute to the ISO C specification?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think C2y (expected to be C29) will do something like this for switch statements! Syntax like:

case 1 ... case 99:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

also inb4 the preprocessor lets you do for loops lol. turing complete c preprocessor when?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sometimes I kinda wish C had the C++ constexpr stuff

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, guaranteed compile time evaluation would go hard asf.

Comment thread flash/MX25L51245GZ2I-08G.c Outdated
Comment on lines +412 to +417
FLASH_STATUS flash_is_flash_busy
(
HFLASH_BUFFER* pflash_handle
)
{
if ( flash_get_status( pflash_handle ) != FLASH_OK )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should there be a check that pflash_handle is not NULL?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We can. There was a colton-era assumption that the flash handle would always be non-null, but we practice defensive programming and should null-check on new drivers.

Comment on lines +75 to +79
FLASH_STATUS flash_init
(
HFLASH_BUFFER* pflash_handle
)
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should there be a check that pflash_handle is not NULL?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Null check in place.

Comment thread flash/MX25L51245GZ2I-08G.c Outdated
Comment on lines +650 to +652
if ( timeout_ms != 0xFFFFFFFFu )
{
if ( ( HAL_GetTick() - start ) > timeout_ms )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think these two if statements can be consolidated into one

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yeah why did i do that lol

Comment thread flash/MX25L51245GZ2I-08G.c Outdated
* @file : MX25L51245GZ2I-08G.c
* @brief : Driver for the flash chip on FC rev 3.
******************************************************************************
* @attention

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we be using @copyright?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I believe I inherited this from STM, but will revisit this when I get home. Either way @copyright is probably the correct tag for doxygen generation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed

}

/* Validate addresses */
if( end_addr > FLASH_MAX_ADDR )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: space before parenthesis

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

will fix

@266-750Balloons 266-750Balloons left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Again, flash isn't my area of expertise, but I don't see anything problematic here.

Comment thread flash/flash.h Outdated
FLASH_BLOCK_13 ,
FLASH_BLOCK_14 ,
FLASH_BLOCK_15
FLASH_BLOCK_15 ,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have to say: these kinds of inits made me wish C (and more languages in general) just had a way to create these kinds of types that are basically just ranges without crazy enums or (in the case of OOP languages like C++) a janky setup of operator overloading.

Is it time for SDR to contribute to the ISO C specification?

@ETSells ETSells requested a review from NArmistead June 1, 2026 00:09

@NArmistead NArmistead left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@ETSells ETSells merged commit e1bbfee into main Jun 2, 2026
6 checks passed
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.

Flash: Initial R3 Driver Implementation

3 participants