Skip to content

Commit 13cb4aa

Browse files
committed
atmel-samd: Add support for a second flash chip so either may be used.
1 parent 8f3c5eb commit 13cb4aa

File tree

6 files changed

+84
-20
lines changed

6 files changed

+84
-20
lines changed

atmel-samd/boards/circuitplayground_express/mpconfigboard.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,12 @@
99
// On-board flash
1010
#define SPI_FLASH_MUX_SETTING SPI_SIGNAL_MUX_SETTING_E
1111
// Use default pinmux for the chip select since we manage it ourselves.
12-
13-
// Rev B:
14-
// #define SPI_FLASH_PAD0_PINMUX PINMUX_PA12D_SERCOM4_PAD0 // MISO
15-
// #define SPI_FLASH_PAD1_PINMUX PINMUX_UNUSED // CS
16-
// #define SPI_FLASH_PAD2_PINMUX PINMUX_PB10D_SERCOM4_PAD2 // MOSI
17-
// #define SPI_FLASH_PAD3_PINMUX PINMUX_PB11D_SERCOM4_PAD3 // SCK
18-
19-
// Rev C:
2012
#define SPI_FLASH_PAD0_PINMUX PINMUX_PA16D_SERCOM3_PAD0 // MISO
2113
#define SPI_FLASH_PAD1_PINMUX PINMUX_UNUSED // CS
2214
#define SPI_FLASH_PAD2_PINMUX PINMUX_PA20D_SERCOM3_PAD2 // MOSI
2315
#define SPI_FLASH_PAD3_PINMUX PINMUX_PA21D_SERCOM3_PAD3 // SCK
2416

2517
#define SPI_FLASH_CS PIN_PB22
26-
// rev B: #define SPI_FLASH_SERCOM SERCOM4
2718
#define SPI_FLASH_SERCOM SERCOM3
2819

2920
// PA24 and PA25 are USB.
@@ -37,6 +28,7 @@
3728
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000)
3829

3930
#include "flash_S25FL216K.h"
31+
#include "flash_GD25Q16C.h"
4032

4133
#define CALIBRATE_CRYSTALLESS 1
4234

atmel-samd/boards/feather_m0_express/mpconfigboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@
2626
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000)
2727

2828
#include "flash_S25FL216K.h"
29+
#include "flash_GD25Q16C.h"

atmel-samd/boards/flash_GD25Q16C.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* This file is part of the Micro Python project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_GD25Q16C_H__
28+
#define __MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_GD25Q16C_H__
29+
30+
// Settings for the Gigadevice GD25Q16C 2MiB SPI flash.
31+
// Datasheet: http://www.gigadevice.com/product/download/410.html?locale=en_US
32+
33+
// The total flash size in bytes.
34+
#define SPI_FLASH_TOTAL_SIZE (1 << 21) // 2 MiB
35+
36+
// The size of the smallest erase unit thats erased with command 0x20.
37+
#define SPI_FLASH_ERASE_SIZE (1 << 12) // 4 KiB
38+
39+
// The size of a page that is programmed with page program command 0x02.
40+
#define SPI_FLASH_PAGE_SIZE (256) // 256 bytes
41+
42+
#ifndef SPI_FLASH_JEDEC_MANUFACTURER
43+
// These are the first three response bytes to the JEDEC ID command 0x9f that is
44+
// used to confirm we're talking to the flash we expect.
45+
#define SPI_FLASH_JEDEC_MANUFACTURER 0xc8
46+
#define SPI_FLASH_SECTOR_PROTECTION true
47+
#else
48+
#define SPI_FLASH_JEDEC_MANUFACTURER_2 0xc8
49+
#define SPI_FLASH_SECTOR_PROTECTION_2 true
50+
#endif
51+
#define SPI_FLASH_JEDEC_MEMORY_TYPE 0x40
52+
#define SPI_FLASH_JEDEC_CAPACITY 0x15
53+
54+
55+
#endif // __MICROPY_INCLUDED_ATMEL_SAMD_BOARD_FLASH_GD25Q16C_H__

atmel-samd/boards/flash_S25FL216K.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@
4141

4242
// These are the first three response bytes to the JEDEC ID command 0x9f that is
4343
// used to confirm we're talking to the flash we expect.
44+
#ifndef SPI_FLASH_JEDEC_MANUFACTURER
4445
#define SPI_FLASH_JEDEC_MANUFACTURER 0x01
46+
#define SPI_FLASH_SECTOR_PROTECTION false
47+
#else
48+
#define SPI_FLASH_JEDEC_MANUFACTURER_2 0x01
49+
#define SPI_FLASH_SECTOR_PROTECTION_2 false
50+
#endif
4551
#define SPI_FLASH_JEDEC_MEMORY_TYPE 0x40
4652
#define SPI_FLASH_JEDEC_CAPACITY 0x15
4753

atmel-samd/boards/metro_m0_express/mpconfigboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@
2828
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000)
2929

3030
#include "flash_S25FL216K.h"
31+
#include "flash_GD25Q16C.h"

atmel-samd/spi_flash.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,12 @@ void spi_flash_init(void) {
275275
flash_enable();
276276
spi_transceive_buffer_wait(&spi_flash_instance, jedec_id_request, response, 4);
277277
flash_disable();
278-
if (response[1] == SPI_FLASH_JEDEC_MANUFACTURER &&
278+
uint8_t manufacturer = response[1];
279+
if ((response[1] == SPI_FLASH_JEDEC_MANUFACTURER
280+
#ifdef SPI_FLASH_JEDEC_MANUFACTURER_2
281+
|| response[1] == SPI_FLASH_JEDEC_MANUFACTURER_2
282+
#endif
283+
) &&
279284
response[2] == SPI_FLASH_JEDEC_MEMORY_TYPE &&
280285
response[3] == SPI_FLASH_JEDEC_CAPACITY) {
281286
spi_flash_is_initialised = true;
@@ -285,16 +290,20 @@ void spi_flash_init(void) {
285290
return;
286291
}
287292

288-
#ifdef SPI_FLASH_SECTOR_PROTECTION
289-
write_enable();
290-
291-
// Turn off sector protection
292-
uint8_t disable_protect_request[2] = {CMD_WRITE_STATUS_BYTE1, 0x00};
293-
uint8_t disable_protect_response[2] = {0x00, 0x00};
294-
flash_enable();
295-
spi_transceive_buffer_wait(&spi_flash_instance, disable_protect_request, disable_protect_response, 2);
296-
flash_disable();
297-
#endif
293+
if ((manufacturer == SPI_FLASH_JEDEC_MANUFACTURER && SPI_FLASH_SECTOR_PROTECTION)
294+
#ifdef SPI_FLASH_JEDEC_MANUFACTURER_2
295+
|| (manufacturer == SPI_FLASH_JEDEC_MANUFACTURER_2 && SPI_FLASH_SECTOR_PROTECTION_2)
296+
#endif
297+
) {
298+
write_enable();
299+
300+
// Turn off sector protection
301+
uint8_t disable_protect_request[2] = {CMD_WRITE_STATUS_BYTE1, 0x00};
302+
uint8_t disable_protect_response[2] = {0x00, 0x00};
303+
flash_enable();
304+
spi_transceive_buffer_wait(&spi_flash_instance, disable_protect_request, disable_protect_response, 2);
305+
flash_disable();
306+
}
298307

299308
// Turn off writes in case this is a microcontroller only reset.
300309
uint8_t disable_write_request[1] = {CMD_DISABLE_WRITE};

0 commit comments

Comments
 (0)