MCPcopy Create free account
hub / github.com/kiibohd/controller / flash_program_sector

Function flash_program_sector

Bootloader/flash.c:111–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109}
110
111int flash_program_sector( uintptr_t addr, size_t len )
112{
113 if ( len != USB_DFU_TRANSFER_SIZE )
114 return 1;
115
116#if defined(_mk20dx128vlf5_) || defined(_mk20dx128vlh7_)
117 // Check if this is the beginning of a sector
118 // Only erase if necessary
119 if ( (addr & (FLASH_SECTOR_SIZE - 1)) == 0
120 && flash_read_1s_sector( addr, FLASH_SECTOR_SIZE / 4 )
121 && flash_erase_sector( addr ) )
122 return 1;
123
124 // Program sector (longword)
125 return flash_program_section( addr, FLASH_SECTOR_SIZE / 4 );
126#elif defined(_mk20dx256vlh7_)
127 // Check if beginning of sector and erase if not empty
128 // Each sector is 2 kB in length, but we can only write to half a sector at a time
129 // We can only erase an entire sector at a time
130 if ( (addr & (FLASH_SECTOR_SIZE - 1)) == 0
131 && flash_read_1s_sector( addr, FLASH_SECTOR_SIZE / 8 )
132 && flash_erase_sector( addr ) )
133 return 1;
134
135 // Program half-sector (phrases)
136 return flash_program_section( addr, FLASH_SECTOR_SIZE / 16 );
137#elif defined(_mk22fx512avlh12_)
138 // Check if beginning of sector and erase if not empty
139 // Each sector is 4 kB in length, but we can only write to half a sector at a time
140 // We can only erase an entire sector at a time
141 if ( (addr & (FLASH_SECTOR_SIZE - 1)) == 0
142 && flash_read_1s_sector( addr, FLASH_SECTOR_SIZE / 16 )
143 && flash_erase_sector( addr ) )
144 return 1;
145
146 // Program half-sector (double phrases)
147 return flash_program_section( addr, FLASH_SECTOR_SIZE / 32 );
148#endif
149}
150
151int flash_prepare_reading()
152{

Callers 1

finish_writeFunction · 0.85

Calls 6

flash_read_1s_sectorFunction · 0.85
flash_program_sectionFunction · 0.85
flash_unlockFunction · 0.85
flash_erase_pageFunction · 0.85
flash_writeFunction · 0.85
flash_erase_sectorFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…