반응형
IAR 경우 tools -> options 가서 Message 에서 ALL을 선택해야 용량이 보입니다.
일단 code 용량 체크부터 해봐야합니다.
이 코드의 용량은 29238+8193 =37431 (0x9237)byte입니다.
그러므로 sector2 까지는 쓰네요
저는 비어있는 sector3 에 eeprom을 써봅시다.
아래에 stm32f427 memory를 보니 0x08009236 까지 쓰는걸 볼수 있습니다.
STM32Cube 설정
#ifndef __MAIN_H
#define __MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
#define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */
#define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */
#define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */
#define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */
#define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */
#define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */
#define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */
#define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */
#define ADDR_FLASH_SECTOR_8 ((uint32_t)0x08080000) /* Base @ of Sector 8, 128 Kbytes */
#define ADDR_FLASH_SECTOR_9 ((uint32_t)0x080A0000) /* Base @ of Sector 9, 128 Kbytes */
#define ADDR_FLASH_SECTOR_10 ((uint32_t)0x080C0000) /* Base @ of Sector 10, 128 Kbytes */
#define ADDR_FLASH_SECTOR_11 ((uint32_t)0x080E0000) /* Base @ of Sector 11, 128 Kbytes */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
#ifdef __cplusplus
}
#endif
#endif /* __MAIN_H */
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef huart1;
static FLASH_EraseInitTypeDef EraseInitStruct;
uint32_t SectorError = 0;
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
int fputc(int ch, FILE *f)
{
uint8_t temp[1]={ch};
HAL_UART_Transmit(&huart1, temp, 1, 2);
return(ch);
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
uint32_t rom_data=1;
uint32_t user_address=0;
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
/*
HAL_FLASH_Unlock();
EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
EraseInitStruct.Sector = 3;
EraseInitStruct.NbSectors = 3;
HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError);
HAL_FLASH_Lock();
*/
printf("eep_test\r\n");
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
user_address=ADDR_FLASH_SECTOR_3;
while (1)
{
/* USER CODE END WHILE */
if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0)==1){
printf("check\r\n");
HAL_FLASH_Unlock();
printf("Addr=%x,Data=%d\r\n",user_address,(*(uint32_t*)user_address));
if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, user_address, rom_data) == HAL_OK){
printf("Success\r\n");
printf("Addr=%x,Data=%d,%d\r\n",user_address,(*(uint32_t*)user_address),rom_data);
rom_data++;
user_address+=4;
}
else{
Error_Handler();
}
HAL_FLASH_Lock();
while(!(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0)==0));
}
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
주석 부분은 메모리 초기화 코드입니다.
결과 화면
USER 스위치를 누를때 마다 메모리를 +4byte(32bit) 증가시키면서 1씩 증가된 값을 씁니다.
반응형
'공부 > STM32F4' 카테고리의 다른 글
[TouchGFX]STM32F4 와 TouchGFX 시작 (0) | 2019.08.08 |
---|---|
15.[STM32F429] Timer CH1N CH2N CH3N 사용하기 (0) | 2019.08.02 |
12.[STM32F429] Usart1 (0) | 2019.07.16 |
11.[STM32F429] 터치 스크린 STMPE811QTR (1) | 2019.07.10 |
10.[STM32F429] LCD (0) | 2019.07.10 |