-
Notifications
You must be signed in to change notification settings - Fork 4
Initial Rev 3 flash driver #261
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
Changes from all commits
76be24e
3f6e0ab
a54fd57
96bb98c
47dbb51
4faf9ae
713979d
8dba673
d899744
19ae58a
0eedc4a
6a4fa9a
b4f6a28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| /** | ||
| ****************************************************************************** | ||
| * @file : hardware_validation.c | ||
| * @brief : Routines to validate components on the FC. | ||
| ****************************************************************************** | ||
| * @attention | ||
| * | ||
| * Copyright (c) 2026 Sun Devil Rocketry. | ||
| * All rights reserved. | ||
| * | ||
| * This software is licensed under terms that can be found in the LICENSE file | ||
| * in the root directory of this software component. | ||
| * If no LICENSE file comes with this software, it is covered under the | ||
| * BSD-3-Clause. | ||
| * | ||
| * https://opensource.org/license/bsd-3-clause | ||
| * | ||
| ****************************************************************************** | ||
| */ | ||
|
|
||
| /* Includes ------------------------------------------------------------------*/ | ||
| #include "main.h" | ||
| #include "usb_device.h" | ||
| #include "led.h" | ||
| #include "flash.h" | ||
| #include "error_sdr.h" | ||
|
|
||
| /* Global Variables ----------------------------------------------------------*/ | ||
|
|
||
|
|
||
|
|
||
| /* Private function prototypes -----------------------------------------------*/ | ||
|
|
||
|
|
||
|
|
||
| /* Procedures ----------------------------------------------------------------*/ | ||
|
|
||
| static void flash_validation_routine | ||
| ( | ||
| void | ||
| ) | ||
| { | ||
| /* Flash */ | ||
| // Begin Performance Timer | ||
| volatile uint32_t start_time = HAL_GetTick(); | ||
|
|
||
| // Init | ||
| HFLASH_BUFFER flash_handle; | ||
| memset(&flash_handle, 0, sizeof(HFLASH_BUFFER)); | ||
| FLASH_STATUS flash_status = flash_init(&flash_handle); | ||
| uint8_t flash_buf[FLASH_PAGE_SIZE]; | ||
| memset(flash_buf, 0, FLASH_PAGE_SIZE); | ||
| flash_handle.pbuffer = flash_buf; | ||
|
|
||
| assert_fail_fast( flash_status == FLASH_OK, ERROR_FLASH_INIT_ERROR ); | ||
|
|
||
| // Set up HW validation routine | ||
| flash_status = flash_erase(&flash_handle); | ||
|
|
||
| assert_fail_fast( flash_status == FLASH_OK, ERROR_FLASH_CMD_ERROR ); | ||
|
|
||
| // Run write sequence (once per page) | ||
| flash_buf[0] = 127; | ||
| for ( uint32_t i = 0; i < FLASH_MAX_ADDR; i+=FLASH_PAGE_SIZE ) { | ||
| flash_handle.address = i; | ||
| flash_status = flash_write(&flash_handle); | ||
| assert_fail_fast( flash_status == FLASH_OK, ERROR_FLASH_CMD_ERROR ); | ||
| } | ||
|
|
||
| // Run read sequence and verify (once per page) | ||
| memset(flash_buf, 0, FLASH_PAGE_SIZE); | ||
| for ( uint32_t i = 0; i < FLASH_MAX_ADDR; i+=FLASH_PAGE_SIZE ) { | ||
| flash_handle.address = i; | ||
| flash_status = flash_read(&flash_handle, 2); | ||
| assert_fail_fast( flash_status == FLASH_OK, ERROR_FLASH_CMD_ERROR ); | ||
| assert_fail_fast( flash_buf[0] == 127, ERROR_FLASH_CMD_ERROR ); | ||
| assert_fail_fast( flash_buf[1] == 0xFF, ERROR_FLASH_CMD_ERROR ); | ||
| } | ||
|
|
||
| // Test Block Erasures | ||
| // 4K | ||
| flash_status = flash_block_erase(0, FLASH_BLOCK_4K); | ||
| assert_fail_fast( flash_status == FLASH_OK, ERROR_FLASH_CMD_ERROR ); | ||
| for ( uint32_t i = 0; i < 0x1000 - 1; i+=FLASH_PAGE_SIZE ) { | ||
| flash_handle.address = i; | ||
| flash_status = flash_read(&flash_handle, 2); | ||
| assert_fail_fast( flash_status == FLASH_OK, ERROR_FLASH_CMD_ERROR ); | ||
| assert_fail_fast( flash_buf[0] == 0xFF, ERROR_FLASH_CMD_ERROR ); | ||
| } | ||
|
|
||
| // 32K | ||
| flash_status = flash_block_erase(0, FLASH_BLOCK_32K); | ||
| assert_fail_fast( flash_status == FLASH_OK, ERROR_FLASH_CMD_ERROR ); | ||
| for (uint32_t i = 0; i < 0x8000 - 1; i+=FLASH_PAGE_SIZE ) { | ||
| flash_handle.address = i; | ||
| flash_status = flash_read(&flash_handle, 2); | ||
| assert_fail_fast( flash_status == FLASH_OK, ERROR_FLASH_CMD_ERROR ); | ||
| assert_fail_fast( flash_buf[0] == 0xFF, ERROR_FLASH_CMD_ERROR ); | ||
| } | ||
|
|
||
| // 64K | ||
| flash_status = flash_block_erase(0, FLASH_BLOCK_64K); | ||
| assert_fail_fast( flash_status == FLASH_OK, ERROR_FLASH_CMD_ERROR ); | ||
| for ( uint32_t i = 0; i < 0x10000 - 1; i+=FLASH_PAGE_SIZE ) { | ||
| flash_handle.address = i; | ||
| flash_status = flash_read(&flash_handle, 2); | ||
| assert_fail_fast( flash_status == FLASH_OK, ERROR_FLASH_CMD_ERROR ); | ||
| assert_fail_fast( flash_buf[0] == 0xFF, ERROR_FLASH_CMD_ERROR ); | ||
| } | ||
|
|
||
| // End Performance Timer | ||
| volatile uint32_t tdelta = HAL_GetTick() - start_time; | ||
| (void)tdelta; // suppress unused | ||
|
|
||
| } /* flash_validation_routine */ | ||
|
|
||
|
|
||
| void run_hardware_validation | ||
| ( | ||
| void | ||
| ) | ||
| { | ||
| /* LED */ | ||
| led_set_color(LED_WHITE); | ||
| HAL_Delay(1000); | ||
| led_set_color(LED_RED); | ||
| HAL_Delay(1000); | ||
| led_set_color(LED_BLUE); | ||
| HAL_Delay(1000); | ||
| led_set_color(LED_GREEN); | ||
| HAL_Delay(1000); | ||
|
|
||
| /* flash */ | ||
| flash_validation_routine(); | ||
|
|
||
| led_set_color(LED_WHITE); | ||
| //buzzer_num_beeps(/*2 beeps when buzzer is implemented to signal the end*/); | ||
| led_set_color(LED_GREEN); | ||
|
|
||
|
|
||
| } /* run_hardware_validation */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ | |
|
|
||
| /* Private includes ----------------------------------------------------------*/ | ||
| /* USER CODE BEGIN Includes */ | ||
|
|
||
| #include "flash.h" | ||
| /* USER CODE END Includes */ | ||
|
|
||
| /* Private typedef -----------------------------------------------------------*/ | ||
|
|
@@ -78,7 +78,6 @@ static void MX_USART3_UART_Init(void); | |
|
|
||
| /* Private user code ---------------------------------------------------------*/ | ||
| /* USER CODE BEGIN 0 */ | ||
|
|
||
| /* USER CODE END 0 */ | ||
|
|
||
| /** | ||
|
|
@@ -125,8 +124,17 @@ int main(void) | |
| MX_SPI4_Init(); | ||
| MX_USART3_UART_Init(); | ||
| MX_USB_DEVICE_Init(); | ||
|
|
||
| /* USER CODE BEGIN 2 */ | ||
|
|
||
| #ifdef DO_HARDWARE_VALIDATION | ||
| run_hardware_validation(); | ||
| while (1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like there's a good chance that I feel like we need some warning for this; at the very least, we could have a well-documented LED sequence to signal that it's a hardware validation build, and I also wonder if we could do something to tell SDEC and have it warn a user that they're on a hardware validation build.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is temporary. If we keep these routines after the initial HW bring up, they'll live in test and need a different way to be compiled into the FW. Right now, this is the only way we'll be running rev 3 until we port the app. Gonna go NAT. Also, I intend to have our debug logging indicate the results of HW validation once implemented for rev 3. |
||
| #endif | ||
|
|
||
| /* Flash */ | ||
| HFLASH_BUFFER flash_handle; | ||
| memset(&flash_handle, 0, sizeof(HFLASH_BUFFER)); | ||
| FLASH_STATUS flash_status = flash_init(&flash_handle); | ||
| /* USER CODE END 2 */ | ||
|
|
||
| /* Infinite loop */ | ||
|
|
||
| +658 −0 | flash/MX25L51245GZ2I-08G.c | |
| +6 −1 | flash/flash.c | |
| +125 −67 | flash/flash.h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add some indication that the routine is finished
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intention is to eventually set this up to use the uart debug interface for driver development, which should come soon.