Macros | Functions | Variables
drv_m25p16.c File Reference
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include "stm32f10x_conf.h"
#include "stm32f10x_gpio.h"
#include "core_cm3.h"
#include "drv_m25p16.h"
#include <drv_spi.h>
#include <drv_system.h>
Include dependency graph for drv_m25p16.c:

Go to the source code of this file.

Macros

#define BULK_ERASE_TIMEOUT_MILLIS   21000
 
#define DEFAULT_TIMEOUT_MILLIS   6
 
#define DISABLE_M25P16   GPIO_SetBits(M25P16_CS_GPIO, M25P16_CS_PIN)
 
#define ENABLE_M25P16   GPIO_ResetBits(M25P16_CS_GPIO, M25P16_CS_PIN)
 
#define JEDEC_ID_MICRON_M25P16   0x202015
 
#define JEDEC_ID_MICRON_N25Q064   0x20BA17
 
#define JEDEC_ID_MICRON_N25Q128   0x20ba18
 
#define JEDEC_ID_WINBOND_W25Q128   0xEF4018
 
#define JEDEC_ID_WINBOND_W25Q64   0xEF4017
 
#define M25P16_CS_GPIO   NAZE_SPI_CS_GPIO
 
#define M25P16_CS_PIN   NAZE_SPI_CS_PIN
 
#define M25P16_INSTRUCTION_BULK_ERASE   0xC7
 
#define M25P16_INSTRUCTION_PAGE_PROGRAM   0x02
 
#define M25P16_INSTRUCTION_RDID   0x9F
 
#define M25P16_INSTRUCTION_READ_BYTES   0x03
 
#define M25P16_INSTRUCTION_READ_STATUS_REG   0x05
 
#define M25P16_INSTRUCTION_SECTOR_ERASE   0xD8
 
#define M25P16_INSTRUCTION_WRITE_DISABLE   0x04
 
#define M25P16_INSTRUCTION_WRITE_ENABLE   0x06
 
#define M25P16_INSTRUCTION_WRITE_STATUS_REG   0x01
 
#define M25P16_SPI_INSTANCE   NAZE_SPI_INSTANCE
 
#define M25P16_STATUS_FLAG_WRITE_ENABLED   0x02
 
#define M25P16_STATUS_FLAG_WRITE_IN_PROGRESS   0x01
 
#define NAZE_CS_GPIO_CLK_PERIPHERAL   RCC_APB2Periph_GPIOB
 
#define NAZE_SPI_CS_GPIO   GPIOB
 
#define NAZE_SPI_CS_PIN   GPIO_Pin_12
 
#define NAZE_SPI_INSTANCE   SPI2
 
#define SECTOR_ERASE_TIMEOUT_MILLIS   5000
 
#define U_ID_0   (*(uint32_t*)0x1FFFF7E8)
 
#define U_ID_1   (*(uint32_t*)0x1FFFF7EC)
 
#define U_ID_2   (*(uint32_t*)0x1FFFF7F0)
 

Functions

void m25p16_eraseCompletely ()
 
void m25p16_eraseSector (uint32_t address)
 
const flashGeometry_tm25p16_getGeometry ()
 
bool m25p16_init ()
 
bool m25p16_isReady ()
 
void m25p16_pageProgram (uint32_t address, const uint8_t *data, int length)
 
void m25p16_pageProgramBegin (uint32_t address)
 
void m25p16_pageProgramContinue (const uint8_t *data, int length)
 
void m25p16_pageProgramFinish ()
 
static void m25p16_performOneByteCommand (uint8_t command)
 
int m25p16_readBytes (uint32_t address, uint8_t *buffer, int length)
 
static bool m25p16_readIdentification ()
 
static uint8_t m25p16_readStatus ()
 
bool m25p16_waitForReady (uint32_t timeoutMillis)
 
static void m25p16_writeEnable ()
 

Variables

static bool couldBeBusy = false
 
static flashGeometry_t geometry = {.pageSize = M25P16_PAGESIZE}
 

Macro Definition Documentation

#define BULK_ERASE_TIMEOUT_MILLIS   21000

Definition at line 79 of file drv_m25p16.c.

#define DEFAULT_TIMEOUT_MILLIS   6

Definition at line 75 of file drv_m25p16.c.

#define DISABLE_M25P16   GPIO_SetBits(M25P16_CS_GPIO, M25P16_CS_PIN)

Definition at line 71 of file drv_m25p16.c.

#define ENABLE_M25P16   GPIO_ResetBits(M25P16_CS_GPIO, M25P16_CS_PIN)

Definition at line 72 of file drv_m25p16.c.

#define JEDEC_ID_MICRON_M25P16   0x202015

Definition at line 65 of file drv_m25p16.c.

#define JEDEC_ID_MICRON_N25Q064   0x20BA17

Definition at line 66 of file drv_m25p16.c.

#define JEDEC_ID_MICRON_N25Q128   0x20ba18

Definition at line 68 of file drv_m25p16.c.

#define JEDEC_ID_WINBOND_W25Q128   0xEF4018

Definition at line 69 of file drv_m25p16.c.

#define JEDEC_ID_WINBOND_W25Q64   0xEF4017

Definition at line 67 of file drv_m25p16.c.

#define M25P16_CS_GPIO   NAZE_SPI_CS_GPIO

Definition at line 41 of file drv_m25p16.c.

#define M25P16_CS_PIN   NAZE_SPI_CS_PIN

Definition at line 42 of file drv_m25p16.c.

#define M25P16_INSTRUCTION_BULK_ERASE   0xC7

Definition at line 59 of file drv_m25p16.c.

#define M25P16_INSTRUCTION_PAGE_PROGRAM   0x02

Definition at line 57 of file drv_m25p16.c.

#define M25P16_INSTRUCTION_RDID   0x9F

Definition at line 51 of file drv_m25p16.c.

#define M25P16_INSTRUCTION_READ_BYTES   0x03

Definition at line 52 of file drv_m25p16.c.

#define M25P16_INSTRUCTION_READ_STATUS_REG   0x05

Definition at line 53 of file drv_m25p16.c.

#define M25P16_INSTRUCTION_SECTOR_ERASE   0xD8

Definition at line 58 of file drv_m25p16.c.

#define M25P16_INSTRUCTION_WRITE_DISABLE   0x04

Definition at line 56 of file drv_m25p16.c.

#define M25P16_INSTRUCTION_WRITE_ENABLE   0x06

Definition at line 55 of file drv_m25p16.c.

#define M25P16_INSTRUCTION_WRITE_STATUS_REG   0x01

Definition at line 54 of file drv_m25p16.c.

#define M25P16_SPI_INSTANCE   NAZE_SPI_INSTANCE

Definition at line 43 of file drv_m25p16.c.

#define M25P16_STATUS_FLAG_WRITE_ENABLED   0x02

Definition at line 62 of file drv_m25p16.c.

#define M25P16_STATUS_FLAG_WRITE_IN_PROGRESS   0x01

Definition at line 61 of file drv_m25p16.c.

#define NAZE_CS_GPIO_CLK_PERIPHERAL   RCC_APB2Periph_GPIOB

Definition at line 38 of file drv_m25p16.c.

#define NAZE_SPI_CS_GPIO   GPIOB

Definition at line 36 of file drv_m25p16.c.

#define NAZE_SPI_CS_PIN   GPIO_Pin_12

Definition at line 37 of file drv_m25p16.c.

#define NAZE_SPI_INSTANCE   SPI2

Definition at line 35 of file drv_m25p16.c.

#define SECTOR_ERASE_TIMEOUT_MILLIS   5000

Definition at line 78 of file drv_m25p16.c.

#define U_ID_0   (*(uint32_t*)0x1FFFF7E8)

Definition at line 31 of file drv_m25p16.c.

#define U_ID_1   (*(uint32_t*)0x1FFFF7EC)

Definition at line 32 of file drv_m25p16.c.

#define U_ID_2   (*(uint32_t*)0x1FFFF7F0)

Definition at line 33 of file drv_m25p16.c.

Function Documentation

void m25p16_eraseCompletely ( )

Definition at line 243 of file drv_m25p16.c.

void m25p16_eraseSector ( uint32_t  address)

Erase a sector full of bytes to all 1's at the given byte offset in the flash chip.

Definition at line 228 of file drv_m25p16.c.

const flashGeometry_t* m25p16_getGeometry ( )

Fetch information about the detected flash chip layout.

Can be called before calling m25p16_init() (the result would have totalSize = 0).

Definition at line 330 of file drv_m25p16.c.

bool m25p16_init ( )

Initialize the driver, must be called before any other routines.

Attempts to detect a connected m25p16. If found, true is returned and device capacity can be fetched with m25p16_getGeometry().

Definition at line 217 of file drv_m25p16.c.

bool m25p16_isReady ( )

Definition at line 128 of file drv_m25p16.c.

void m25p16_pageProgram ( uint32_t  address,
const uint8_t *  data,
int  length 
)

Write bytes to a flash page. Address must not cross a page boundary.

Bits can only be set to zero, not from zero back to one again. In order to set bits to 1, use the erase command.

Length must be smaller than the page size.

This will wait for the flash to become ready before writing begins.

Datasheet indicates typical programming time is 0.8ms for 256 bytes, 0.2ms for 64 bytes, 0.05ms for 16 bytes. (Although the maximum possible write time is noted as 5ms).

If you want to write multiple buffers (whose sum of sizes is still not more than the page size) then you can break this operation up into one beginProgram call, one or more continueProgram calls, and one finishProgram call.

Definition at line 290 of file drv_m25p16.c.

void m25p16_pageProgramBegin ( uint32_t  address)

Definition at line 252 of file drv_m25p16.c.

void m25p16_pageProgramContinue ( const uint8_t *  data,
int  length 
)

Definition at line 265 of file drv_m25p16.c.

void m25p16_pageProgramFinish ( )

Definition at line 270 of file drv_m25p16.c.

static void m25p16_performOneByteCommand ( uint8_t  command)
static

Send the given command byte to the device.

Definition at line 93 of file drv_m25p16.c.

int m25p16_readBytes ( uint32_t  address,
uint8_t *  buffer,
int  length 
)

Read length bytes into the provided buffer from the flash starting from the given address (which need not lie on a page boundary).

Waits up to DEFAULT_TIMEOUT_MILLIS milliseconds for the flash to become ready before reading.

The number of bytes actually read is returned, which can be zero if an error or timeout occurred.

Definition at line 307 of file drv_m25p16.c.

static bool m25p16_readIdentification ( )
static

Read chip identification and geometry information (into global geometry).

Returns true if we get valid ident, false if something bad happened like there is no M25P16.

Definition at line 153 of file drv_m25p16.c.

static uint8_t m25p16_readStatus ( )
static

Definition at line 114 of file drv_m25p16.c.

bool m25p16_waitForReady ( uint32_t  timeoutMillis)

Definition at line 136 of file drv_m25p16.c.

static void m25p16_writeEnable ( )
static

The flash requires this write enable command to be sent before commands that would cause a write like program and erase.

Definition at line 106 of file drv_m25p16.c.

Variable Documentation

bool couldBeBusy = false
static

Definition at line 88 of file drv_m25p16.c.

flashGeometry_t geometry = {.pageSize = M25P16_PAGESIZE}
static

Definition at line 81 of file drv_m25p16.c.



rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Wed Jul 3 2019 19:59:26