atmel-samd: Add support for a second flash chip so either may be used.

This commit is contained in:
Scott Shawcroft 2017-08-03 13:44:04 -07:00
parent 8f3c5ebdc8
commit 13cb4aa89d
6 changed files with 83 additions and 19 deletions

View File

@ -9,21 +9,12 @@
// On-board flash
#define SPI_FLASH_MUX_SETTING SPI_SIGNAL_MUX_SETTING_E
// Use default pinmux for the chip select since we manage it ourselves.
// Rev B:
// #define SPI_FLASH_PAD0_PINMUX PINMUX_PA12D_SERCOM4_PAD0 // MISO
// #define SPI_FLASH_PAD1_PINMUX PINMUX_UNUSED // CS
// #define SPI_FLASH_PAD2_PINMUX PINMUX_PB10D_SERCOM4_PAD2 // MOSI
// #define SPI_FLASH_PAD3_PINMUX PINMUX_PB11D_SERCOM4_PAD3 // SCK
// Rev C:
#define SPI_FLASH_PAD0_PINMUX PINMUX_PA16D_SERCOM3_PAD0 // MISO
#define SPI_FLASH_PAD1_PINMUX PINMUX_UNUSED // CS
#define SPI_FLASH_PAD2_PINMUX PINMUX_PA20D_SERCOM3_PAD2 // MOSI
#define SPI_FLASH_PAD3_PINMUX PINMUX_PA21D_SERCOM3_PAD3 // SCK
#define SPI_FLASH_CS PIN_PB22
// rev B: #define SPI_FLASH_SERCOM SERCOM4
#define SPI_FLASH_SERCOM SERCOM3
// PA24 and PA25 are USB.
@ -37,6 +28,7 @@
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000)
#include "flash_S25FL216K.h"
#include "flash_GD25Q16C.h"
#define CALIBRATE_CRYSTALLESS 1

View File

@ -26,3 +26,4 @@
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000)
#include "flash_S25FL216K.h"
#include "flash_GD25Q16C.h"

View File

@ -0,0 +1,55 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_GD25Q16C_H__
#define __MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_GD25Q16C_H__
// Settings for the Gigadevice GD25Q16C 2MiB SPI flash.
// Datasheet: http://www.gigadevice.com/product/download/410.html?locale=en_US
// The total flash size in bytes.
#define SPI_FLASH_TOTAL_SIZE (1 << 21) // 2 MiB
// The size of the smallest erase unit thats erased with command 0x20.
#define SPI_FLASH_ERASE_SIZE (1 << 12) // 4 KiB
// The size of a page that is programmed with page program command 0x02.
#define SPI_FLASH_PAGE_SIZE (256) // 256 bytes
#ifndef SPI_FLASH_JEDEC_MANUFACTURER
// These are the first three response bytes to the JEDEC ID command 0x9f that is
// used to confirm we're talking to the flash we expect.
#define SPI_FLASH_JEDEC_MANUFACTURER 0xc8
#define SPI_FLASH_SECTOR_PROTECTION true
#else
#define SPI_FLASH_JEDEC_MANUFACTURER_2 0xc8
#define SPI_FLASH_SECTOR_PROTECTION_2 true
#endif
#define SPI_FLASH_JEDEC_MEMORY_TYPE 0x40
#define SPI_FLASH_JEDEC_CAPACITY 0x15
#endif // __MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_GD25Q16C_H__

View File

@ -41,7 +41,13 @@
// These are the first three response bytes to the JEDEC ID command 0x9f that is
// used to confirm we're talking to the flash we expect.
#ifndef SPI_FLASH_JEDEC_MANUFACTURER
#define SPI_FLASH_JEDEC_MANUFACTURER 0x01
#define SPI_FLASH_SECTOR_PROTECTION false
#else
#define SPI_FLASH_JEDEC_MANUFACTURER_2 0x01
#define SPI_FLASH_SECTOR_PROTECTION_2 false
#endif
#define SPI_FLASH_JEDEC_MEMORY_TYPE 0x40
#define SPI_FLASH_JEDEC_CAPACITY 0x15

View File

@ -28,3 +28,4 @@
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000)
#include "flash_S25FL216K.h"
#include "flash_GD25Q16C.h"

View File

@ -275,7 +275,12 @@ void spi_flash_init(void) {
flash_enable();
spi_transceive_buffer_wait(&spi_flash_instance, jedec_id_request, response, 4);
flash_disable();
if (response[1] == SPI_FLASH_JEDEC_MANUFACTURER &&
uint8_t manufacturer = response[1];
if ((response[1] == SPI_FLASH_JEDEC_MANUFACTURER
#ifdef SPI_FLASH_JEDEC_MANUFACTURER_2
|| response[1] == SPI_FLASH_JEDEC_MANUFACTURER_2
#endif
) &&
response[2] == SPI_FLASH_JEDEC_MEMORY_TYPE &&
response[3] == SPI_FLASH_JEDEC_CAPACITY) {
spi_flash_is_initialised = true;
@ -285,16 +290,20 @@ void spi_flash_init(void) {
return;
}
#ifdef SPI_FLASH_SECTOR_PROTECTION
write_enable();
if ((manufacturer == SPI_FLASH_JEDEC_MANUFACTURER && SPI_FLASH_SECTOR_PROTECTION)
#ifdef SPI_FLASH_JEDEC_MANUFACTURER_2
|| (manufacturer == SPI_FLASH_JEDEC_MANUFACTURER_2 && SPI_FLASH_SECTOR_PROTECTION_2)
#endif
) {
write_enable();
// Turn off sector protection
uint8_t disable_protect_request[2] = {CMD_WRITE_STATUS_BYTE1, 0x00};
uint8_t disable_protect_response[2] = {0x00, 0x00};
flash_enable();
spi_transceive_buffer_wait(&spi_flash_instance, disable_protect_request, disable_protect_response, 2);
flash_disable();
#endif
// Turn off sector protection
uint8_t disable_protect_request[2] = {CMD_WRITE_STATUS_BYTE1, 0x00};
uint8_t disable_protect_response[2] = {0x00, 0x00};
flash_enable();
spi_transceive_buffer_wait(&spi_flash_instance, disable_protect_request, disable_protect_response, 2);
flash_disable();
}
// Turn off writes in case this is a microcontroller only reset.
uint8_t disable_write_request[1] = {CMD_DISABLE_WRITE};