Mercurial > public > ostc4
comparison Discovery/Src/externLogbookFlash.c @ 981:c6c781a2e85b default
Merge into default
| author | heinrichsweikamp |
|---|---|
| date | Tue, 11 Feb 2025 18:12:00 +0100 |
| parents | bc6c90e20d9e |
| children | 158100a84ebd |
comparison
equal
deleted
inserted
replaced
| 871:f7318457df4d | 981:c6c781a2e85b |
|---|---|
| 113 | 113 |
| 114 | 114 |
| 115 /* Exported variables --------------------------------------------------------*/ | 115 /* Exported variables --------------------------------------------------------*/ |
| 116 | 116 |
| 117 /* Private variables ---------------------------------------------------------*/ | 117 /* Private variables ---------------------------------------------------------*/ |
| 118 | |
| 119 #ifndef BOOTLOADER_STANDALONE | |
| 120 static uint32_t entryPoint = 0; | |
| 121 static uint32_t LengthLeftSampleRead = 0; | |
| 122 static uint32_t actualPointerDevicedata_Read = DDSTART; | |
| 123 #endif | |
| 124 | |
| 118 static uint32_t actualAddress = 0; | 125 static uint32_t actualAddress = 0; |
| 119 static uint32_t preparedPageAddress = 0; | 126 static uint32_t preparedPageAddress = 0; |
| 120 static uint32_t closeSectorAddress = 0; | 127 static uint32_t closeSectorAddress = 0; |
| 121 static uint32_t entryPoint = 0; | |
| 122 | |
| 123 static uint32_t actualPointerHeader = 0; | 128 static uint32_t actualPointerHeader = 0; |
| 124 static uint32_t actualPointerSample = 0; | 129 static uint32_t actualPointerSample = 0; |
| 125 static uint32_t LengthLeftSampleRead = 0; | |
| 126 static uint32_t actualPointerDevicedata = DDSTART; | 130 static uint32_t actualPointerDevicedata = DDSTART; |
| 127 static uint32_t actualPointerDevicedata_Read = DDSTART; | |
| 128 static uint32_t actualPointerVPM = 0; | 131 static uint32_t actualPointerVPM = 0; |
| 129 static uint32_t actualPointerSettings = SETTINGSSTART; | 132 static uint32_t actualPointerSettings = SETTINGSSTART; |
| 130 static uint32_t actualPointerFirmware = 0; | 133 static uint32_t actualPointerFirmware = 0; |
| 131 static uint32_t actualPointerFirmware2 = 0; | 134 static uint32_t actualPointerFirmware2 = 0; |
| 132 | 135 |
| 133 /* Private function prototypes -----------------------------------------------*/ | 136 /* Private function prototypes -----------------------------------------------*/ |
| 134 static void chip_unselect(void); | 137 static void chip_unselect(void); |
| 135 static void chip_select(void); | 138 static void chip_select(void); |
| 139 #ifndef BOOTLOADER_STANDALONE | |
| 136 static void error_led_on(void); | 140 static void error_led_on(void); |
| 137 static void error_led_off(void); | 141 static void error_led_off(void); |
| 138 | 142 static void ext_flash_decf_address_ring(uint8_t type); |
| 143 static void ext_flash_disable_protection(void); | |
| 144 static _Bool ext_flash_test_remaining_space_of_page_empty(uint32_t pointer, uint16_t length); | |
| 145 static void ext_flash_set_to_begin_of_next_page(uint32_t *pointer, uint8_t type); | |
| 146 #endif | |
| 139 static void write_spi(uint8_t data, uint8_t unselect_CS_afterwards); | 147 static void write_spi(uint8_t data, uint8_t unselect_CS_afterwards); |
| 140 static uint8_t read_spi(uint8_t unselect_CS_afterwards); | 148 static uint8_t read_spi(uint8_t unselect_CS_afterwards); |
| 141 static void write_address(uint8_t unselect_CS_afterwards); | 149 static void write_address(uint8_t unselect_CS_afterwards); |
| 142 static void Error_Handler_extflash(void); | 150 static void Error_Handler_extflash(void); |
| 143 static void wait_chip_not_busy(void); | 151 static void wait_chip_not_busy(void); |
| 144 static void ext_flash_incf_address(uint8_t type); | 152 static void ext_flash_incf_address(uint8_t type); |
| 145 //void ext_flash_incf_address_ring(void); | 153 //void ext_flash_incf_address_ring(void); |
| 146 static void ext_flash_decf_address_ring(uint8_t type); | |
| 147 | 154 |
| 148 static void ext_flash_erase4kB(void); | 155 static void ext_flash_erase4kB(void); |
| 149 static void ext_flash_erase32kB(void); | 156 static void ext_flash_erase32kB(void); |
| 150 static void ext_flash_erase64kB(void); | 157 static void ext_flash_erase64kB(void); |
| 151 static uint8_t ext_flash_erase_if_on_page_start(void); | 158 static uint8_t ext_flash_erase_if_on_page_start(void); |
| 157 static void ext_flash_read_block_stop(void); | 164 static void ext_flash_read_block_stop(void); |
| 158 | 165 |
| 159 static void ef_hw_rough_delay_us(uint32_t delayUs); | 166 static void ef_hw_rough_delay_us(uint32_t delayUs); |
| 160 static void ef_erase_64K(uint32_t blocks); | 167 static void ef_erase_64K(uint32_t blocks); |
| 161 | 168 |
| 169 #ifndef BOOTLOADER_STANDALONE | |
| 162 static void ext_flash_overwrite_sample_without_erase(uint8_t *pSample, uint16_t length); | 170 static void ext_flash_overwrite_sample_without_erase(uint8_t *pSample, uint16_t length); |
| 163 | |
| 164 static void ext_flash_disable_protection(void); | |
| 165 | |
| 166 static _Bool ext_flash_test_remaining_space_of_page_empty(uint32_t pointer, uint16_t length); | |
| 167 static void ext_flash_set_to_begin_of_next_page(uint32_t *pointer, uint8_t type); | |
| 168 static void ext_flash_find_start(void); | 171 static void ext_flash_find_start(void); |
| 172 #endif | |
| 173 | |
| 169 | 174 |
| 170 | 175 |
| 171 /* Exported functions --------------------------------------------------------*/ | 176 /* Exported functions --------------------------------------------------------*/ |
| 172 | 177 |
| 173 void ext_flash_write_firmware(uint8_t *pSample1, uint32_t length1)//, uint8_t *pSample2, uint32_t length2) | 178 void ext_flash_write_firmware(uint8_t *pSample1, uint32_t length1)//, uint8_t *pSample2, uint32_t length2) |
| 1579 settings->logFlashNextSampleStartAddress = SAMPLESTART; | 1584 settings->logFlashNextSampleStartAddress = SAMPLESTART; |
| 1580 } | 1585 } |
| 1581 } | 1586 } |
| 1582 | 1587 |
| 1583 | 1588 |
| 1584 #endif | 1589 |
| 1585 | 1590 |
| 1586 static void ext_flash_disable_protection(void) | 1591 static void ext_flash_disable_protection(void) |
| 1587 { | 1592 { |
| 1588 /* | 1593 /* |
| 1589 extFlashStatusBit8_Type status; | 1594 extFlashStatusBit8_Type status; |
| 1594 write_spi(0x50,RELEASE); // EWSR | 1599 write_spi(0x50,RELEASE); // EWSR |
| 1595 write_spi(0x01,HOLDCS); // WRSR | 1600 write_spi(0x01,HOLDCS); // WRSR |
| 1596 write_spi(status.uw,RELEASE); // new status | 1601 write_spi(status.uw,RELEASE); // new status |
| 1597 */ | 1602 */ |
| 1598 } | 1603 } |
| 1599 | 1604 #endif |
| 1600 | 1605 |
| 1601 void ext_flash_disable_protection_for_logbook(void) | 1606 void ext_flash_disable_protection_for_logbook(void) |
| 1602 { | 1607 { |
| 1603 /* | 1608 /* |
| 1604 extFlashStatusBit8_Type status; | 1609 extFlashStatusBit8_Type status; |
| 1930 default: | 1935 default: |
| 1931 break; | 1936 break; |
| 1932 } | 1937 } |
| 1933 } | 1938 } |
| 1934 | 1939 |
| 1935 | 1940 #ifndef BOOTLOADER_STANDALONE |
| 1936 static _Bool ext_flash_test_remaining_space_of_page_empty(uint32_t pointer, uint16_t length) | 1941 static _Bool ext_flash_test_remaining_space_of_page_empty(uint32_t pointer, uint16_t length) |
| 1937 { | 1942 { |
| 1938 if((pointer & 0xFFF) == 0) | 1943 if((pointer & 0xFFF) == 0) |
| 1939 return 1; | 1944 return 1; |
| 1940 | 1945 |
| 2000 *pointer = (*pointer & 0xFFF) + 0x1000; | 2005 *pointer = (*pointer & 0xFFF) + 0x1000; |
| 2001 | 2006 |
| 2002 if((*pointer < ringStart) || (*pointer >= ringStop)) | 2007 if((*pointer < ringStart) || (*pointer >= ringStop)) |
| 2003 *pointer = ringStart; | 2008 *pointer = ringStart; |
| 2004 } | 2009 } |
| 2005 | 2010 #endif |
| 2006 | 2011 |
| 2007 static void ef_erase_64K(uint32_t blocks) | 2012 static void ef_erase_64K(uint32_t blocks) |
| 2008 { | 2013 { |
| 2009 for(uint32_t i = 0; i < blocks; i++) | 2014 for(uint32_t i = 0; i < blocks; i++) |
| 2010 { | 2015 { |
| 2025 | 2030 |
| 2026 static void chip_select(void) | 2031 static void chip_select(void) |
| 2027 { | 2032 { |
| 2028 HAL_GPIO_WritePin(EXTFLASH_CSB_GPIO_PORT,EXTFLASH_CSB_PIN,GPIO_PIN_RESET); // chip select | 2033 HAL_GPIO_WritePin(EXTFLASH_CSB_GPIO_PORT,EXTFLASH_CSB_PIN,GPIO_PIN_RESET); // chip select |
| 2029 } | 2034 } |
| 2030 | 2035 #ifndef BOOTLOADER_STANDALONE |
| 2031 static void error_led_on(void) | 2036 static void error_led_on(void) |
| 2032 { | 2037 { |
| 2033 HAL_GPIO_WritePin(OSCILLOSCOPE_GPIO_PORT,OSCILLOSCOPE_PIN,GPIO_PIN_SET); | 2038 HAL_GPIO_WritePin(OSCILLOSCOPE_GPIO_PORT,OSCILLOSCOPE_PIN,GPIO_PIN_SET); |
| 2034 } | 2039 } |
| 2035 | 2040 |
| 2036 static void error_led_off(void) | 2041 static void error_led_off(void) |
| 2037 { | 2042 { |
| 2038 HAL_GPIO_WritePin(OSCILLOSCOPE_GPIO_PORT,OSCILLOSCOPE_PIN,GPIO_PIN_RESET); | 2043 HAL_GPIO_WritePin(OSCILLOSCOPE_GPIO_PORT,OSCILLOSCOPE_PIN,GPIO_PIN_RESET); |
| 2039 } | 2044 } |
| 2040 | 2045 #endif |
| 2041 | 2046 |
| 2042 static uint8_t read_spi(uint8_t unselect_CS_afterwards) | 2047 static uint8_t read_spi(uint8_t unselect_CS_afterwards) |
| 2043 { | 2048 { |
| 2044 uint8_t byte; | 2049 uint8_t byte; |
| 2045 | 2050 |
| 2148 | 2153 |
| 2149 if((actualAddress < ringStart) || (actualAddress > ringStop)) | 2154 if((actualAddress < ringStart) || (actualAddress > ringStop)) |
| 2150 actualAddress = ringStart; | 2155 actualAddress = ringStart; |
| 2151 } | 2156 } |
| 2152 | 2157 |
| 2153 | 2158 #ifndef BOOTLOADER_STANDALONE |
| 2154 static void ext_flash_decf_address_ring(uint8_t type) | 2159 static void ext_flash_decf_address_ring(uint8_t type) |
| 2155 { | 2160 { |
| 2156 uint32_t ringStart, ringStop; | 2161 uint32_t ringStart, ringStop; |
| 2157 | 2162 |
| 2158 switch(type) | 2163 switch(type) |
| 2194 if((actualAddress <= ringStart) || (actualAddress > ringStop)) | 2199 if((actualAddress <= ringStart) || (actualAddress > ringStop)) |
| 2195 actualAddress = ringStop; | 2200 actualAddress = ringStop; |
| 2196 else | 2201 else |
| 2197 actualAddress -= 1; | 2202 actualAddress -= 1; |
| 2198 } | 2203 } |
| 2199 | 2204 #endif |
| 2200 | 2205 |
| 2201 static void ef_hw_rough_delay_us(uint32_t delayUs) | 2206 static void ef_hw_rough_delay_us(uint32_t delayUs) |
| 2202 { | 2207 { |
| 2203 if(!delayUs) | 2208 if(!delayUs) |
| 2204 return; | 2209 return; |
| 2378 ext_flash_close_read_sample(); | 2383 ext_flash_close_read_sample(); |
| 2379 return profileLength; | 2384 return profileLength; |
| 2380 } | 2385 } |
| 2381 | 2386 |
| 2382 | 2387 |
| 2383 /* | 2388 |
| 2384 uint8_t ext_flash_erase_firmware_if_not_empty(void) | 2389 uint8_t ext_flash_erase_firmware_if_not_empty(void) |
| 2385 { | 2390 { |
| 2386 const uint8_t TESTSIZE_FW = 4; | 2391 const uint8_t TESTSIZE_FW = 4; |
| 2387 | 2392 |
| 2388 uint8_t data[TESTSIZE_FW]; | 2393 uint8_t data[TESTSIZE_FW]; |
| 2429 ext_flash_erase_firmware2(); | 2434 ext_flash_erase_firmware2(); |
| 2430 return 1; | 2435 return 1; |
| 2431 } | 2436 } |
| 2432 else | 2437 else |
| 2433 return 0; | 2438 return 0; |
| 2434 }*/ | 2439 } |
