pico2-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
38#include "ice_fpga_data.h"
39
43#define ICE_FLASH_PAGE_SIZE 256
44#define ICE_FLASH_SECTOR_SIZE 4096
45#define ICE_FLASH_BLOCK_SIZE 65536
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
54int ice_flash_init(const ice_spibus spibus, int baudrate);
55
63int ice_flash_read(const ice_spibus spibus, uint32_t addr, uint8_t *buf, size_t sz);
64
69int ice_flash_erase_sector(const ice_spibus spibus, uint32_t addr);
70
77int ice_flash_program_page(const ice_spibus spibus, uint32_t addr, uint8_t const page[ICE_FLASH_PAGE_SIZE]);
78
83int ice_flash_erase_block(const ice_spibus spibus, uint32_t addr);
84
89
93int ice_flash_wakeup(const ice_spibus spibus);
94
98int ice_flash_sleep(const ice_spibus spibus);
99
103int ice_flash_deinit(const ice_spibus spibus);
104
105#ifdef __cplusplus
106}
107#endif
108
int ice_flash_init(const ice_spibus spibus, int baudrate)
Initialise the SPI1 peripheral, dedicated to flashing the FPGA.
int ice_flash_erase_block(const ice_spibus spibus, uint32_t addr)
Send a command to erase a whole block.
int ice_flash_sleep(const ice_spibus spibus)
Send a command to put the chip to sleep.
int ice_flash_deinit(const ice_spibus spibus)
Free SPI bus.
int ice_flash_program_page(const ice_spibus spibus, 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:43
int ice_flash_erase_chip(const ice_spibus spibus)
Send a command to erase the whole chip.
int ice_flash_wakeup(const ice_spibus spibus)
Send a command to wakeup the chip.
int ice_flash_read(const ice_spibus spibus, 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.
int ice_flash_erase_sector(const ice_spibus spibus, uint32_t addr)
Erase a sector of the flash chip at the given address.
Definition ice_fpga_data.h:30