pico-ice
RaspberryPi Pico with an iCE40 FPGA
Loading...
Searching...
No Matches
ice_flash.h
1/*
2 * MIT License
3 *
4 * Copyright (c) 2023 tinyVision.ai
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
34#pragma once
35#include <stdint.h>
36#include <stddef.h>
37
41#define ICE_FLASH_PAGE_SIZE 256
42#define ICE_FLASH_SECTOR_SIZE 4096
43#define ICE_FLASH_BLOCK_SIZE 65536
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
52void ice_flash_init(void);
53
61void ice_flash_read(uint32_t addr, uint8_t *buf, size_t sz);
62
67void ice_flash_erase_sector(uint32_t addr);
68
75void ice_flash_program_page(uint32_t addr, uint8_t const page[ICE_FLASH_PAGE_SIZE]);
76
81void ice_flash_erase_block(uint32_t addr);
82
87
92
96void ice_flash_sleep(void);
97
98#ifdef __cplusplus
99}
100#endif
101
void ice_flash_read(uint32_t addr, uint8_t *buf, size_t sz)
Communicate to the chip over SPI and read multiple bytes at chosen address onto onto a buffer.
void ice_flash_program_page(uint32_t addr, uint8_t const page[ICE_FLASH_PAGE_SIZE])
Program a page of the flash chip at the given address.
#define ICE_FLASH_PAGE_SIZE
The size of the flash.
Definition ice_flash.h:41
void ice_flash_erase_sector(uint32_t addr)
Erase a sector of the flash chip at the given address.
void ice_flash_erase_block(uint32_t addr)
Send a command to erase a whole block.
void ice_flash_init(void)
Initialise the SPI1 peripheral, dedicated to flashing the FPGA.
void ice_flash_wakeup(void)
Send a command to wakeup the chip.
void ice_flash_sleep(void)
Send a command to put the chip to sleep.
void ice_flash_erase_chip(void)
Send a command to erase the whole chip.