1 |
582 |
jeremybenn |
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
2 |
|
|
* File Name : spi_flash.h
|
3 |
|
|
* Author : MCD Application Team
|
4 |
|
|
* Version : V2.0.0
|
5 |
|
|
* Date : 04/27/2009
|
6 |
|
|
* Description : Header for spi_flash.c file.
|
7 |
|
|
********************************************************************************
|
8 |
|
|
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
9 |
|
|
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
|
10 |
|
|
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
|
11 |
|
|
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
|
12 |
|
|
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
13 |
|
|
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
14 |
|
|
*******************************************************************************/
|
15 |
|
|
|
16 |
|
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
17 |
|
|
#ifndef __SPI_FLASH_H
|
18 |
|
|
#define __SPI_FLASH_H
|
19 |
|
|
|
20 |
|
|
/* Includes ------------------------------------------------------------------*/
|
21 |
|
|
#include "stm32f10x.h"
|
22 |
|
|
#include "stm32f10x_spi.h"
|
23 |
|
|
#include "stm32f10x_gpio.h"
|
24 |
|
|
#include "stm32f10x_rcc.h"
|
25 |
|
|
|
26 |
|
|
#define uint32_t unsigned long
|
27 |
|
|
#define uint8_t unsigned char
|
28 |
|
|
#define uint16_t unsigned short
|
29 |
|
|
|
30 |
|
|
/* Exported types ------------------------------------------------------------*/
|
31 |
|
|
/* Exported constants --------------------------------------------------------*/
|
32 |
|
|
/* Uncomment the line corresponding to the STMicroelectronics evaluation board
|
33 |
|
|
used to run the example */
|
34 |
|
|
#if !defined (USE_STM3210B_EVAL) && !defined (USE_STM3210E_EVAL)
|
35 |
|
|
//#define USE_STM3210B_EVAL
|
36 |
|
|
#define USE_STM3210E_EVAL
|
37 |
|
|
#endif
|
38 |
|
|
|
39 |
|
|
#ifdef USE_STM3210B_EVAL
|
40 |
|
|
#define GPIO_CS GPIOA
|
41 |
|
|
#define RCC_APB2Periph_GPIO_CS RCC_APB2Periph_GPIOA
|
42 |
|
|
#define GPIO_Pin_CS GPIO_Pin_4
|
43 |
|
|
#else /* USE_STM3210E_EVAL */
|
44 |
|
|
#define GPIO_CS GPIOB
|
45 |
|
|
#define RCC_APB2Periph_GPIO_CS RCC_APB2Periph_GPIOB
|
46 |
|
|
#define GPIO_Pin_CS GPIO_Pin_2
|
47 |
|
|
#endif
|
48 |
|
|
|
49 |
|
|
/* Exported macro ------------------------------------------------------------*/
|
50 |
|
|
/* Select SPI FLASH: Chip Select pin low */
|
51 |
|
|
#define SPI_FLASH_CS_LOW() __asm volatile( "NOP" );__asm volatile( "NOP" );__asm volatile( "NOP" );__asm volatile( "NOP" );GPIO_ResetBits(GPIO_CS, GPIO_Pin_CS);__asm volatile( "NOP" );__asm volatile( "NOP" );__asm volatile( "NOP" );__asm volatile( "NOP" )
|
52 |
|
|
/* Deselect SPI FLASH: Chip Select pin high */
|
53 |
|
|
#define SPI_FLASH_CS_HIGH() __asm volatile( "NOP" );__asm volatile( "NOP" );__asm volatile( "NOP" );__asm volatile( "NOP" );GPIO_SetBits(GPIO_CS, GPIO_Pin_CS);__asm volatile( "NOP" );__asm volatile( "NOP" );__asm volatile( "NOP" );__asm volatile( "NOP" )
|
54 |
|
|
|
55 |
|
|
/* Exported functions ------------------------------------------------------- */
|
56 |
|
|
/*----- High layer function -----*/
|
57 |
|
|
void SPI_FLASH_Init(void);
|
58 |
|
|
void SPI_FLASH_SectorErase(uint32_t SectorAddr);
|
59 |
|
|
void SPI_FLASH_BulkErase(void);
|
60 |
|
|
void SPI_FLASH_PageWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
|
61 |
|
|
void SPI_FLASH_BufferWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
|
62 |
|
|
void SPI_FLASH_BufferRead(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead);
|
63 |
|
|
uint32_t SPI_FLASH_ReadID(void);
|
64 |
|
|
void SPI_FLASH_StartReadSequence(uint32_t ReadAddr);
|
65 |
|
|
|
66 |
|
|
/*----- Low layer function -----*/
|
67 |
|
|
uint8_t SPI_FLASH_ReadByte(void);
|
68 |
|
|
uint8_t SPI_FLASH_SendByte(uint8_t byte);
|
69 |
|
|
uint16_t SPI_FLASH_SendHalfWord(uint16_t HalfWord);
|
70 |
|
|
void SPI_FLASH_WriteEnable(void);
|
71 |
|
|
void SPI_FLASH_WaitForWriteEnd(void);
|
72 |
|
|
|
73 |
|
|
#endif /* __SPI_FLASH_H */
|
74 |
|
|
|
75 |
|
|
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
|