Skip to content

Commit 65ee0f6

Browse files
committed
ADDS flash read bytes 🔖
1 parent 81e9048 commit 65ee0f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+8483
-8303
lines changed

datasheets/winbond-flash.pdf

2.41 MB
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Basic structure of flash memory
2+
BYte - smallest adressable unit
3+
page - 256 bytes basic write unit
4+
sector - 4KB (16 pages x 246 bytes) basic erase unit
5+
block - 64KB (16 sectors) larger erase unit
6+
chip - whole capacity can be erased fully
7+
8+
THerefore each page is 256 bytes
9+
10+
Addressing
11+
The flash memory is byte addressable
12+
Code will express the address in terms of a page and an offset within that page
13+
14+
absolute_address = (page_number * page_size) + byte_offset
15+
16+
To avoid wrapping over on the same page

playground/stm32/blackpill-winbond-flash-memory/.mxproject

Lines changed: 25 additions & 25 deletions
Large diffs are not rendered by default.

playground/stm32/blackpill-winbond-flash-memory/.settings/language.settings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
66
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
77
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
8-
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1248333385293433819" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
8+
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1379047546566717012" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
99
<language-scope id="org.eclipse.cdt.core.gcc"/>
1010
<language-scope id="org.eclipse.cdt.core.g++"/>
1111
</provider>
@@ -16,7 +16,7 @@
1616
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
1717
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
1818
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
19-
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1248333385293433819" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
19+
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1379047546566717012" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
2020
<language-scope id="org.eclipse.cdt.core.gcc"/>
2121
<language-scope id="org.eclipse.cdt.core.g++"/>
2222
</provider>

playground/stm32/blackpill-winbond-flash-memory/Core/Inc/W25Qxx.h

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,71 @@
1010

1111
extern SPI_HandleTypeDef hspi3;
1212

13+
#define READ_DATA_3_BYTE_INSTR (0x03)
14+
#define READ_DATA_4_BYTE_INSTR (0x13)
15+
#define FAST_READ_DATA_3_BYTE_INSTR (0x0B)
16+
#define FAST_READ_DATA_4_BYTE_INSTR (0x0C)
17+
1318
#define W25Q_SPI hspi3
19+
#define NUM_BLOCKS (32)
20+
21+
/**
22+
* @brief This function creates a short delay
23+
* @param time length to delay (ms)
24+
*/
25+
void external_flash_delay(uint32_t time);
26+
27+
/**
28+
* @brief This function pulls the chip select pin LOW
29+
*/
30+
void cs_low(void);
31+
32+
/**
33+
* @brief This function pulls the chip select pin HIGH
34+
*/
35+
void cs_high(void);
36+
37+
/**
38+
* @brief This function sends a byte to the flash memory
39+
* @param data pointer to byte data to write
40+
* @param len the number of bytes to write
41+
*/
42+
void external_flash_spi_write(uint8_t* data, uint8_t len);
43+
44+
/**
45+
* @brief This function reads bytes from the flash memory
46+
* @param data pointer to byte data to read
47+
* @param len the number of bytes to read
48+
*/
49+
void external_flash_spi_read(uint8_t* data, uint8_t len);
50+
51+
/**
52+
* @brief This function performs a flash memory reset
53+
*/
54+
void external_flash_reset(void);
55+
56+
/**
57+
* @brief This function read the flash memory ID
58+
*/
59+
uint32_t external_flash_read_ID(void);
60+
61+
/**
62+
* @brief This function reads data from a given address
63+
* @param start_page page number where we want to read from
64+
* @param offset byte offset within that page (0 - 255)
65+
* @param the number of bytes we want to read
66+
* @param buffer pointer to the array where the data will be stored
67+
*/
68+
void external_flash_read(uint32_t start_page, uint8_t offset, uint32_t size, uint8_t *buffer);
69+
70+
/**
71+
* @brief This function performs a sequential read of bytes from the memory
72+
*
73+
*/
74+
void external_flash_fast_read(uint32_t start_page, uint8_t offset, uint32_t size, uint8_t *buffer);
75+
1476

15-
void W25Q_Delay(uint32_t time);
16-
void cs_LOW(void);
17-
void cs_HIGH(void);
18-
void SPI_Write(uint8_t* data, uint8_t len);
19-
void SPI_Read(uint8_t* data, uint8_t len);
20-
void W25Q_Reset(void);
21-
uint32_t W25Q_ReadID(void);
77+
uint8_t external_flash_test();
2278

2379

2480
#endif /* INC_W25QXX_H_ */
Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,73 @@
1-
/* USER CODE BEGIN Header */
2-
/**
3-
******************************************************************************
4-
* @file : main.h
5-
* @brief : Header for main.c file.
6-
* This file contains the common defines of the application.
7-
******************************************************************************
8-
* @attention
9-
*
10-
* Copyright (c) 2025 STMicroelectronics.
11-
* All rights reserved.
12-
*
13-
* This software is licensed under terms that can be found in the LICENSE file
14-
* in the root directory of this software component.
15-
* If no LICENSE file comes with this software, it is provided AS-IS.
16-
*
17-
******************************************************************************
18-
*/
19-
/* USER CODE END Header */
20-
21-
/* Define to prevent recursive inclusion -------------------------------------*/
22-
#ifndef __MAIN_H
23-
#define __MAIN_H
24-
25-
#ifdef __cplusplus
26-
extern "C" {
27-
#endif
28-
29-
/* Includes ------------------------------------------------------------------*/
30-
#include "stm32f4xx_hal.h"
31-
32-
/* Private includes ----------------------------------------------------------*/
33-
/* USER CODE BEGIN Includes */
34-
35-
/* USER CODE END Includes */
36-
37-
/* Exported types ------------------------------------------------------------*/
38-
/* USER CODE BEGIN ET */
39-
40-
/* USER CODE END ET */
41-
42-
/* Exported constants --------------------------------------------------------*/
43-
/* USER CODE BEGIN EC */
44-
45-
/* USER CODE END EC */
46-
47-
/* Exported macro ------------------------------------------------------------*/
48-
/* USER CODE BEGIN EM */
49-
50-
/* USER CODE END EM */
51-
52-
/* Exported functions prototypes ---------------------------------------------*/
53-
void Error_Handler(void);
54-
55-
/* USER CODE BEGIN EFP */
56-
57-
/* USER CODE END EFP */
58-
59-
/* Private defines -----------------------------------------------------------*/
60-
#define LED1_Pin GPIO_PIN_13
61-
#define LED1_GPIO_Port GPIOC
62-
#define FLASH_CS_Pin GPIO_PIN_14
63-
#define FLASH_CS_GPIO_Port GPIOB
64-
65-
/* USER CODE BEGIN Private defines */
66-
67-
/* USER CODE END Private defines */
68-
69-
#ifdef __cplusplus
70-
}
71-
#endif
72-
73-
#endif /* __MAIN_H */
1+
/* USER CODE BEGIN Header */
2+
/**
3+
******************************************************************************
4+
* @file : main.h
5+
* @brief : Header for main.c file.
6+
* This file contains the common defines of the application.
7+
******************************************************************************
8+
* @attention
9+
*
10+
* Copyright (c) 2025 STMicroelectronics.
11+
* All rights reserved.
12+
*
13+
* This software is licensed under terms that can be found in the LICENSE file
14+
* in the root directory of this software component.
15+
* If no LICENSE file comes with this software, it is provided AS-IS.
16+
*
17+
******************************************************************************
18+
*/
19+
/* USER CODE END Header */
20+
21+
/* Define to prevent recursive inclusion -------------------------------------*/
22+
#ifndef __MAIN_H
23+
#define __MAIN_H
24+
25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
29+
/* Includes ------------------------------------------------------------------*/
30+
#include "stm32f4xx_hal.h"
31+
32+
/* Private includes ----------------------------------------------------------*/
33+
/* USER CODE BEGIN Includes */
34+
35+
/* USER CODE END Includes */
36+
37+
/* Exported types ------------------------------------------------------------*/
38+
/* USER CODE BEGIN ET */
39+
40+
/* USER CODE END ET */
41+
42+
/* Exported constants --------------------------------------------------------*/
43+
/* USER CODE BEGIN EC */
44+
45+
/* USER CODE END EC */
46+
47+
/* Exported macro ------------------------------------------------------------*/
48+
/* USER CODE BEGIN EM */
49+
50+
/* USER CODE END EM */
51+
52+
/* Exported functions prototypes ---------------------------------------------*/
53+
void Error_Handler(void);
54+
55+
/* USER CODE BEGIN EFP */
56+
57+
/* USER CODE END EFP */
58+
59+
/* Private defines -----------------------------------------------------------*/
60+
#define LED1_Pin GPIO_PIN_13
61+
#define LED1_GPIO_Port GPIOC
62+
#define FLASH_CS_Pin GPIO_PIN_14
63+
#define FLASH_CS_GPIO_Port GPIOB
64+
65+
/* USER CODE BEGIN Private defines */
66+
67+
/* USER CODE END Private defines */
68+
69+
#ifdef __cplusplus
70+
}
71+
#endif
72+
73+
#endif /* __MAIN_H */

0 commit comments

Comments
 (0)