Skip to content

Commit

Permalink
trying more cs pins
Browse files Browse the repository at this point in the history
  • Loading branch information
FT9R committed Mar 26, 2024
1 parent fe96f49 commit 26f328d
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 5 deletions.
Binary file added Doc/TraceOutput_ChipErase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions Examples/STM32F401CDU6/w25qxx_Interface/w25qxx_Interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,57 @@ void w25qxx_SPI1_CS0_Set(w25qxx_CS_State_t newState)
}
}

void w25qxx_SPI1_CS1_Set(w25qxx_CS_State_t newState)
{
switch (newState)
{
case W25QXX_CS_HIGH:
HAL_GPIO_WritePin(SPI1_CS1_PORT, SPI1_CS1_PIN, GPIO_PIN_SET);
break;

case W25QXX_CS_LOW:
HAL_GPIO_WritePin(SPI1_CS1_PORT, SPI1_CS1_PIN, GPIO_PIN_RESET);
break;

default:
break;
}
}

void w25qxx_SPI1_CS2_Set(w25qxx_CS_State_t newState)
{
switch (newState)
{
case W25QXX_CS_HIGH:
HAL_GPIO_WritePin(SPI1_CS2_PORT, SPI1_CS2_PIN, GPIO_PIN_SET);
break;

case W25QXX_CS_LOW:
HAL_GPIO_WritePin(SPI1_CS2_PORT, SPI1_CS2_PIN, GPIO_PIN_RESET);
break;

default:
break;
}
}

void w25qxx_SPI1_CS3_Set(w25qxx_CS_State_t newState)
{
switch (newState)
{
case W25QXX_CS_HIGH:
HAL_GPIO_WritePin(SPI1_CS3_PORT, SPI1_CS3_PIN, GPIO_PIN_SET);
break;

case W25QXX_CS_LOW:
HAL_GPIO_WritePin(SPI1_CS3_PORT, SPI1_CS3_PIN, GPIO_PIN_RESET);
break;

default:
break;
}
}

void w25qxx_Delay(uint32_t ms)
{
extern volatile uint32_t uwTick;
Expand Down
26 changes: 25 additions & 1 deletion Examples/STM32F401CDU6/w25qxx_Interface/w25qxx_Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ extern "C" {
#define UART_TRANSMIT_TIMEOUT 1000
#define SPI1_CS0_PIN SPI1_CS0_Pin
#define SPI1_CS0_PORT SPI1_CS0_GPIO_Port
#define SPI1_CS1_PIN SPI1_CS1_Pin
#define SPI1_CS1_PORT SPI1_CS1_GPIO_Port
#define SPI1_CS2_PIN SPI1_CS2_Pin
#define SPI1_CS2_PORT SPI1_CS2_GPIO_Port
#define SPI1_CS3_PIN SPI1_CS3_Pin
#define SPI1_CS3_PORT SPI1_CS3_GPIO_Port

/* Macro */
#define TOGGLE_BIT(REG, BIT) ((REG) ^= (BIT))
Expand Down Expand Up @@ -55,11 +61,29 @@ w25qxx_Transfer_Status_t w25qxx_SPI1_Receive(uint8_t *pDataRx, uint16_t size, ui
w25qxx_Transfer_Status_t w25qxx_SPI1_Transmit(uint8_t *pDataTx, uint16_t size, uint32_t timeout);

/**
* @brief The one of chip select function templates
* @brief 1st device chip select function template
* @param newState: new CS pin state
*/
void w25qxx_SPI1_CS0_Set(w25qxx_CS_State_t newState);

/**
* @brief 2nd device chip select function template
* @param newState: new CS pin state
*/
void w25qxx_SPI1_CS1_Set(w25qxx_CS_State_t newState);

/**
* @brief 3rd device chip select function template
* @param newState: new CS pin state
*/
void w25qxx_SPI1_CS2_Set(w25qxx_CS_State_t newState);

/**
* @brief 4th device chip select function template
* @param newState: new CS pin state
*/
void w25qxx_SPI1_CS3_Set(w25qxx_CS_State_t newState);

/**
* @brief Provides minimum delay (in milliseconds) based on incremented variable
* @param ms: specifies the delay time length, in milliseconds
Expand Down
6 changes: 3 additions & 3 deletions w25qxx/w25qxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ enum w25qxx_ChipEraseTime {
/* Device constants */
#define W25QXX_MANUFACTURER_ID 0xEF
#define W25QXX_PAGE_SIZE 256
#define W25QXX_SECTOR_SIZE_4KB ((W25QXX_PAGE_SIZE) * 16)
#define W25QXX_BLOCK_SIZE_32KB ((W25QXX_PAGE_SIZE) * 128)
#define W25QXX_BLOCK_SIZE_64KB ((W25QXX_PAGE_SIZE) * 256)
#define W25QXX_SECTOR_SIZE_4KB (W25QXX_KB_TO_BYTE(4))
#define W25QXX_BLOCK_SIZE_32KB (W25QXX_KB_TO_BYTE(32))
#define W25QXX_BLOCK_SIZE_64KB (W25QXX_KB_TO_BYTE(64))

enum w25qxx_Device_e { W25Q80 = 0x13, W25Q16, W25Q32, W25Q64, W25Q128 };

Expand Down
2 changes: 1 addition & 1 deletion w25qxx/w25qxx_Demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ uint8_t w25qxx_Demo(void (*fpPrint)(const uint8_t *message))
return 1;

fpPrint("\nInterface link\n");
w25qxx_Link(&w25qxx_Handle, w25qxx_SPI1_Receive, w25qxx_SPI1_Transmit, w25qxx_SPI1_CS0_Set);
w25qxx_Link(&w25qxx_Handle, w25qxx_SPI1_Receive, w25qxx_SPI1_Transmit, w25qxx_SPI1_CS1_Set);

fpPrint("Device initialization\n");
w25qxx_Init(&w25qxx_Handle);
Expand Down

0 comments on commit 26f328d

Please sign in to comment.