qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

flash_spi.h (3150B)


      1 /*
      2 Copyright (C) 2021 Westberry Technology (ChangZhou) Corp., Ltd
      3 
      4 This program is free software: you can redistribute it and/or modify
      5 it under the terms of the GNU General Public License as published by
      6 the Free Software Foundation, either version 2 of the License, or
      7 (at your option) any later version.
      8 
      9 This program is distributed in the hope that it will be useful,
     10 but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 GNU General Public License for more details.
     13 
     14 You should have received a copy of the GNU General Public License
     15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
     16 */
     17 
     18 #pragma once
     19 
     20 #include "flash.h"
     21 
     22 /* All the following default configurations are based on MX25L4006E Nor FLASH. */
     23 
     24 /*
     25     The slave select pin of the FLASH.
     26     This needs to be a normal GPIO pin_t value, such as B14.
     27 */
     28 #ifndef EXTERNAL_FLASH_SPI_SLAVE_SELECT_PIN
     29 #    error "No chip select pin defined -- missing EXTERNAL_FLASH_SPI_SLAVE_SELECT_PIN"
     30 #endif
     31 
     32 /*
     33     The clock divisor for SPI to ensure that the MCU is within the
     34     specifications of the FLASH chip. Generally this will be PCLK divided by
     35     the intended divisor -- check your clock settings and the datasheet of
     36     your FLASH.
     37 */
     38 #ifndef EXTERNAL_FLASH_SPI_CLOCK_DIVISOR
     39 #    ifdef __AVR__
     40 #        define EXTERNAL_FLASH_SPI_CLOCK_DIVISOR 4
     41 #    else
     42 #        define EXTERNAL_FLASH_SPI_CLOCK_DIVISOR 8
     43 #    endif
     44 #endif
     45 
     46 /*
     47     The SPI mode to communicate with the FLASH.
     48 */
     49 #ifndef EXTERNAL_FLASH_SPI_MODE
     50 #    define EXTERNAL_FLASH_SPI_MODE 0
     51 #endif
     52 
     53 /*
     54     Whether or not the SPI communication between the MCU and FLASH should be
     55     LSB-first.
     56 */
     57 #ifndef EXTERNAL_FLASH_SPI_LSBFIRST
     58 #    define EXTERNAL_FLASH_SPI_LSBFIRST false
     59 #endif
     60 
     61 /*
     62     The Flash address size in bytes, as specified in datasheet.
     63 */
     64 #ifndef EXTERNAL_FLASH_ADDRESS_SIZE
     65 #    define EXTERNAL_FLASH_ADDRESS_SIZE 3
     66 #endif
     67 
     68 /*
     69     The page size of the FLASH in bytes, as specified in the datasheet.
     70 */
     71 #ifndef EXTERNAL_FLASH_PAGE_SIZE
     72 #    define EXTERNAL_FLASH_PAGE_SIZE 256
     73 #endif
     74 
     75 /*
     76     The sector size of the FLASH in bytes, as specified in the datasheet.
     77 */
     78 #ifndef EXTERNAL_FLASH_SECTOR_SIZE
     79 #    define EXTERNAL_FLASH_SECTOR_SIZE (4 * 1024L)
     80 #endif
     81 
     82 /*
     83     The block size of the FLASH in bytes, as specified in the datasheet.
     84 */
     85 #ifndef EXTERNAL_FLASH_BLOCK_SIZE
     86 #    define EXTERNAL_FLASH_BLOCK_SIZE (64 * 1024L)
     87 #endif
     88 
     89 /*
     90     The total size of the FLASH in bytes, as specified in the datasheet.
     91 */
     92 #ifndef EXTERNAL_FLASH_SIZE
     93 #    define EXTERNAL_FLASH_SIZE (512 * 1024L)
     94 #endif
     95 
     96 /*
     97     The block count of the FLASH, calculated by total FLASH size and block size.
     98 */
     99 #define EXTERNAL_FLASH_BLOCK_COUNT ((EXTERNAL_FLASH_SIZE) / (EXTERNAL_FLASH_BLOCK_SIZE))
    100 
    101 /*
    102     The sector count of the FLASH, calculated by total FLASH size and sector size.
    103 */
    104 #define EXTERNAL_FLASH_SECTOR_COUNT ((EXTERNAL_FLASH_SIZE) / (EXTERNAL_FLASH_SECTOR_SIZE))
    105 
    106 /*
    107     The page count of the FLASH, calculated by total FLASH size and page size.
    108 */
    109 #define EXTERNAL_FLASH_PAGE_COUNT ((EXTERNAL_FLASH_SIZE) / (EXTERNAL_FLASH_PAGE_SIZE))