Lines Matching +full:row +full:- +full:offset
4 * SPDX-License-Identifier: Apache-2.0
61 * Fetch word using sys_get_le32, which performs byte-sized in read_mem_u32()
62 * reads instead of word-sized. This is important as ptr may in read_mem_u32()
64 * stored in little-endian inside the flash. in read_mem_u32()
76 READ_BIT(FLASH->SIZE, FLASH_FLASH_SIZE_FLASH_SIZE) + 1; in get_flash_size_in_bytes()
90 * - illegal command in error_from_irq_flags()
91 * - command error in error_from_irq_flags()
94 return -EINVAL; in error_from_irq_flags()
98 return -EIO; in error_from_irq_flags()
102 * Unexpected error flag -> "out of domain" in error_from_irq_flags()
105 return -EDOM; in error_from_irq_flags()
109 off_t offset, uint32_t len) in is_valid_flash_range() argument
111 const struct flash_wb0x_data *data = dev->data; in is_valid_flash_range()
114 /* (offset + len) must not overflow */ in is_valid_flash_range()
115 return !u32_add_overflow(offset, len, &offset_plus_len) in is_valid_flash_range()
116 /* offset must be a valid offset in flash */ in is_valid_flash_range()
117 && IN_RANGE(offset, 0, data->flash_size - 1) in is_valid_flash_range()
118 /* (offset + len) must be in [0; flash size] in is_valid_flash_range()
121 * bytes starting at `offset` touches bytes in is_valid_flash_range()
122 * `offset` to `offset + len` EXCLUDED) in is_valid_flash_range()
124 && IN_RANGE(offset_plus_len, 0, data->flash_size); in is_valid_flash_range()
128 off_t offset, uint32_t len) in is_writeable_flash_range() argument
130 if ((offset % WRITE_BLOCK_SIZE) != 0 in is_writeable_flash_range()
135 return is_valid_flash_range(dev, offset, len); in is_writeable_flash_range()
139 off_t offset, uint32_t len) in is_erasable_flash_range() argument
141 if ((offset % ERASE_BLOCK_SIZE) != 0 in is_erasable_flash_range()
146 return is_valid_flash_range(dev, offset, len); in is_erasable_flash_range()
159 flags = FLASH->IRQRAW; in poll_flash_controller()
163 FLASH->IRQRAW = flags; in poll_flash_controller()
173 FLASH->IRQRAW = FLASH->IRQRAW; in execute_flash_command()
176 FLASH->COMMAND = cmd; in execute_flash_command()
207 __ASSERT_NO_MSG((start_page + page_count - 1) < PAGES_IN_FLASH); in erase_page_range()
213 * ADDRESS[8:0] = 0 (row & word address, must be 0) in erase_page_range()
215 FLASH->ADDRESS = (i << 9); in erase_page_range()
236 * Note that @p buf may not be aligned to 32-bit boundary. in write_word_range()
246 * - write single words using WRITE commands until the write in write_word_range()
249 * - after write address is aligned to quadword, we can use in write_word_range()
252 * - once less than 4 words remain to write, a last BURSTWRITE in write_word_range()
259 FLASH->ADDRESS = dst_addr; in write_word_range()
260 FLASH->DATA0 = read_mem_u32(src_ptr); in write_word_range()
269 remaining--; in write_word_range()
276 FLASH->ADDRESS = dst_addr; in write_word_range()
277 FLASH->DATA0 = read_mem_u32(src_ptr + 0); in write_word_range()
278 FLASH->DATA1 = read_mem_u32(src_ptr + 1); in write_word_range()
279 FLASH->DATA2 = read_mem_u32(src_ptr + 2); in write_word_range()
280 FLASH->DATA3 = read_mem_u32(src_ptr + 3); in write_word_range()
289 remaining -= WORDS_IN_BURST; in write_word_range()
297 FLASH->ADDRESS = dst_addr; in write_word_range()
298 FLASH->DATA0 = read_mem_u32(src_ptr + 0); in write_word_range()
300 FLASH->DATA1 = (remaining >= 2) in write_word_range()
304 FLASH->DATA2 = (remaining == 3) in write_word_range()
308 FLASH->DATA3 = BURST_IGNORE_VALUE; in write_word_range()
321 int flash_wb0x_read(const struct device *dev, off_t offset, in flash_wb0x_read() argument
328 if (!is_valid_flash_range(dev, offset, len)) { in flash_wb0x_read()
329 return -EINVAL; in flash_wb0x_read()
334 memcpy(buffer, flash_base + (uint32_t)offset, len); in flash_wb0x_read()
339 int flash_wb0x_write(const struct device *dev, off_t offset, in flash_wb0x_write() argument
342 struct flash_wb0x_data *data = dev->data; in flash_wb0x_write()
349 if (!is_writeable_flash_range(dev, offset, len)) { in flash_wb0x_write()
350 return -EINVAL; in flash_wb0x_write()
354 res = k_sem_take(&data->write_lock, K_NO_WAIT); in flash_wb0x_write()
359 const uint32_t start_word = (uint32_t)offset / WORD_SIZE; in flash_wb0x_write()
365 k_sem_give(&data->write_lock); in flash_wb0x_write()
370 int flash_wb0x_erase(const struct device *dev, off_t offset, size_t size) in flash_wb0x_erase() argument
372 struct flash_wb0x_data *data = dev->data; in flash_wb0x_erase()
379 if (!is_erasable_flash_range(dev, offset, size)) { in flash_wb0x_erase()
380 return -EINVAL; in flash_wb0x_erase()
384 res = k_sem_take(&data->write_lock, K_NO_WAIT); in flash_wb0x_erase()
389 const uint32_t start_page = (uint32_t)offset / ERASE_BLOCK_SIZE; in flash_wb0x_erase()
395 k_sem_give(&data->write_lock); in flash_wb0x_erase()
443 struct flash_wb0x_data *data = dev->data; in stm32wb0x_flash_init()
445 k_sem_init(&data->write_lock, 1, 1); in stm32wb0x_flash_init()
447 data->flash_size = get_flash_size_in_bytes(); in stm32wb0x_flash_init()