Skip to content

Commit 314721f

Browse files
committed
save
1 parent b06f0a1 commit 314721f

File tree

11 files changed

+416
-5
lines changed

11 files changed

+416
-5
lines changed

Bootloader/Adapters/Inc/flash_adapter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,8 @@ bool FlashAdapter_setReadProtection(bool enable);
9292
/* proprietary code readout protection */
9393
bool FlashAdapter_setPCROP(bool enable, uint32_t protect_address_start, uint32_t protect_address_end);
9494

95+
#ifdef EXTERNAL_FLASH
96+
void FlashAdapter_initXSPI(void);
97+
#endif
9598

9699
#endif /* BOOTLOADER_INC_FLASH_ADAPTER_H_ */

Bootloader/Adapters/Src/flash_adapter.c

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ HAL_StatusTypeDef ActivateProtection(FLASH_OBProgramInitTypeDef* ob_struct, uint
5858
#endif
5959

6060
#ifdef EXTERNAL_FLASH
61+
62+
XSPI_HandleTypeDef hxspi2;
63+
6164
bool
6265
FlashAdapter_erase(uint32_t firmware_size, uint32_t flash_address) {
6366
//return W25q_dynamicErase(firmware_size, flash_address);
@@ -66,19 +69,16 @@ FlashAdapter_erase(uint32_t firmware_size, uint32_t flash_address) {
6669

6770
bool
6871
FlashAdapter_blockErase(uint32_t address) {
69-
//return W25q_blockErase64k(address);
7072
return true;
7173
}
7274

7375
bool
7476
FlashAdapter_program(uint32_t address, uint8_t* buffer, uint32_t length) {
75-
//return W25q_quadPageProgram(address, buffer, length);
7677
return true;
7778
}
7879

7980
bool
8081
FlashAdapter_readBytes(uint32_t address, uint8_t* buffer, uint32_t length) {
81-
//return W25q_readBytes(address, buffer, length);
8282
return true;
8383
}
8484

@@ -87,6 +87,38 @@ FlashAdapter_finish(void) {
8787
return true;
8888
}
8989

90+
void
91+
FlashAdapter_initXSPI(void) {
92+
XSPIM_CfgTypeDef sXspiManagerCfg = {0};
93+
94+
/* XSPI2 parameter configuration*/
95+
hxspi2.Instance = XSPI2;
96+
hxspi2.Init.FifoThresholdByte = 4;
97+
hxspi2.Init.MemoryMode = HAL_XSPI_SINGLE_MEM;
98+
hxspi2.Init.MemoryType = HAL_XSPI_MEMTYPE_MACRONIX;
99+
hxspi2.Init.MemorySize = HAL_XSPI_SIZE_1GB;
100+
hxspi2.Init.ChipSelectHighTimeCycle = 1;
101+
hxspi2.Init.FreeRunningClock = HAL_XSPI_FREERUNCLK_DISABLE;
102+
hxspi2.Init.ClockMode = HAL_XSPI_CLOCK_MODE_0;
103+
hxspi2.Init.WrapSize = HAL_XSPI_WRAP_NOT_SUPPORTED;
104+
hxspi2.Init.ClockPrescaler = 0;
105+
hxspi2.Init.SampleShifting = HAL_XSPI_SAMPLE_SHIFT_NONE;
106+
hxspi2.Init.DelayHoldQuarterCycle = HAL_XSPI_DHQC_ENABLE;
107+
hxspi2.Init.ChipSelectBoundary = HAL_XSPI_BONDARYOF_NONE;
108+
hxspi2.Init.MaxTran = 0;
109+
hxspi2.Init.Refresh = 0;
110+
hxspi2.Init.MemorySelect = HAL_XSPI_CSSEL_NCS1;
111+
if (HAL_XSPI_Init(&hxspi2) != HAL_OK) {
112+
Error_Handler();
113+
}
114+
sXspiManagerCfg.nCSOverride = HAL_XSPI_CSSEL_OVR_NCS1;
115+
sXspiManagerCfg.IOPort = HAL_XSPIM_IOPORT_2;
116+
sXspiManagerCfg.Req2AckTime = 1;
117+
if (HAL_XSPIM_Config(&hxspi2, &sXspiManagerCfg, HAL_XSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
118+
Error_Handler();
119+
}
120+
}
121+
90122
#else
91123
bool
92124
FlashAdapter_erase(uint32_t firmware_size, uint32_t flash_address) {

Bootloader/Adapters/Src/gpio_adapter.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ GpioAdapter_init(void) {
4747
__HAL_RCC_GPIOF_CLK_ENABLE();
4848
#if defined(STM32N657xx)
4949
__HAL_RCC_GPIOG_CLK_ENABLE();
50+
__HAL_RCC_GPION_CLK_ENABLE();
5051
#endif
5152

5253
#if defined(LED1_Pin) && defined(LED1_Port) && defined(LED_OFF)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* USER CODE BEGIN Header */
2+
/**
3+
******************************************************************************
4+
* @file : extmem_manager.c
5+
* @version : 1.0.0
6+
* @brief : This file implements the extmem configuration
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+
/* Includes ------------------------------------------------------------------*/
22+
#include "extmem_manager.h"
23+
#include <string.h>
24+
25+
/* USER CODE BEGIN Includes */
26+
27+
/* USER CODE END Includes */
28+
29+
/* USER CODE BEGIN PV */
30+
/* Private variables ---------------------------------------------------------*/
31+
32+
/* USER CODE END PV */
33+
34+
/* USER CODE BEGIN PFP */
35+
/* Private function prototypes -----------------------------------------------*/
36+
37+
/* USER CODE END PFP */
38+
39+
/*
40+
* -- Insert your variables declaration here --
41+
*/
42+
/* USER CODE BEGIN 0 */
43+
44+
/* USER CODE END 0 */
45+
46+
/*
47+
* -- Insert your external function declaration here --
48+
*/
49+
/* USER CODE BEGIN 1 */
50+
51+
/* USER CODE END 1 */
52+
53+
/**
54+
* Init External memory manager
55+
* @retval None
56+
*/
57+
void
58+
MX_EXTMEM_MANAGER_Init(void) {
59+
60+
/* USER CODE BEGIN MX_EXTMEM_Init_PreTreatment */
61+
62+
/* USER CODE END MX_EXTMEM_Init_PreTreatment */
63+
64+
/* Initialization of the memory parameters */
65+
memset(extmem_list_config, 0x0, sizeof(extmem_list_config));
66+
67+
/* EXTMEMORY_1 */
68+
extmem_list_config[0].MemType = EXTMEM_NOR_SFDP;
69+
extmem_list_config[0].Handle = (void*)&hxspi2;
70+
extmem_list_config[0].ConfigType = EXTMEM_LINK_CONFIG_8LINES;
71+
72+
EXTMEM_Init(EXTMEMORY_1, HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_XSPI2));
73+
74+
/* USER CODE BEGIN MX_EXTMEM_Init_PostTreatment */
75+
76+
/* USER CODE END MX_EXTMEM_Init_PostTreatment */
77+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* USER CODE BEGIN Header */
2+
/**
3+
******************************************************************************
4+
* @file : extmem_manager.h
5+
* @version : 1.0.0
6+
* @brief : Header for secure_manager_api.c file.
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 __MX_EXTMEM__H__
23+
#define __MX_EXTMEM__H__
24+
25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
29+
/* Includes ------------------------------------------------------------------*/
30+
#include "stm32_extmem_conf.h"
31+
32+
/* USER CODE BEGIN INCLUDE */
33+
34+
/* USER CODE END INCLUDE */
35+
36+
/* Private variables ---------------------------------------------------------*/
37+
/* USER CODE BEGIN PV */
38+
39+
/* USER CODE END PV */
40+
41+
/* Private function prototypes -----------------------------------------------*/
42+
/* USER CODE BEGIN PFP */
43+
44+
/* USER CODE END PFP */
45+
46+
/*
47+
* -- Insert your variables declaration here --
48+
*/
49+
/* USER CODE BEGIN VARIABLES */
50+
51+
/* USER CODE END VARIABLES */
52+
53+
void MX_EXTMEM_MANAGER_Init(void);
54+
55+
/*
56+
* -- Insert functions declaration here --
57+
*/
58+
/* USER CODE BEGIN FD */
59+
60+
/* USER CODE END FD */
61+
62+
#ifdef __cplusplus
63+
}
64+
#endif
65+
66+
#endif /* __MX_EXTMEM__H__ */
67+
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/* USER CODE BEGIN Header */
2+
/**
3+
******************************************************************************
4+
* @file : stm32_extmem_conf.h
5+
* @version : 1.0.0
6+
* @brief : Header for extmem.c file.
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 __STM32_EXTMEM_CONF__H__
23+
#define __STM32_EXTMEM_CONF__H__
24+
25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
29+
/* Includes ------------------------------------------------------------------*/
30+
31+
/*
32+
@brief management of the driver layer enable
33+
*/
34+
35+
#define EXTMEM_DRIVER_NOR_SFDP 1
36+
#define EXTMEM_DRIVER_PSRAM 0
37+
#define EXTMEM_DRIVER_SDCARD 0
38+
#define EXTMEM_DRIVER_USER 0
39+
40+
/*
41+
@brief management of the sal layer enable
42+
*/
43+
#define EXTMEM_SAL_XSPI 1
44+
#define EXTMEM_SAL_SD 0
45+
46+
/* Includes ------------------------------------------------------------------*/
47+
#include "stm32n6xx_hal.h"
48+
49+
#include "stm32_extmem_type.h"
50+
#include "boot/stm32_boot_lrun.h"
51+
52+
/* USER CODE BEGIN INCLUDE */
53+
54+
/* USER CODE END INCLUDE */
55+
/* Private variables ---------------------------------------------------------*/
56+
extern XSPI_HandleTypeDef hxspi2;
57+
58+
/* USER CODE BEGIN PV */
59+
60+
/* USER CODE END PV */
61+
62+
/* Exported constants --------------------------------------------------------*/
63+
/** @defgroup EXTMEM_CONF_Exported_constants EXTMEM_CONF exported constants
64+
* @{
65+
*/
66+
enum {
67+
EXTMEMORY_1 = 0 /*!< ID=0 for the first memory */
68+
};
69+
70+
/*
71+
@brief management of the boot layer
72+
*/
73+
74+
#define EXTMEM_LRUN_SOURCE EXTMEMORY_1
75+
#define EXTMEM_LRUN_SOURCE_ADDRESS 0x00100000u
76+
#define EXTMEM_LRUN_SOURCE_SIZE 0x10000u
77+
#define EXTMEM_LRUN_DESTINATION_INTERNAL 1
78+
#define EXTMEM_LRUN_DESTINATION_ADDRESS 0x34000000u
79+
80+
/* USER CODE BEGIN PV */
81+
82+
/* USER CODE END PV */
83+
84+
/* Exported configuration --------------------------------------------------------*/
85+
/** @defgroup EXTMEM_CONF_Exported_configuration EXTMEM_CONF exported configuration definition
86+
* @{
87+
*/
88+
89+
extern EXTMEM_DefinitionTypeDef extmem_list_config[1];
90+
#if defined(EXTMEM_C)
91+
EXTMEM_DefinitionTypeDef extmem_list_config[1];
92+
#endif /* EXTMEM_C */
93+
94+
/**
95+
* @}
96+
*/
97+
98+
/* Private function prototypes -----------------------------------------------*/
99+
/* USER CODE BEGIN PFP */
100+
101+
/* USER CODE END PFP */
102+
103+
/*
104+
* -- Insert your variables declaration here --
105+
*/
106+
/* USER CODE BEGIN VARIABLES */
107+
108+
/* USER CODE END VARIABLES */
109+
110+
/*
111+
* -- Insert functions declaration here --
112+
*/
113+
/* USER CODE BEGIN FD */
114+
115+
/* USER CODE END FD */
116+
117+
#ifdef __cplusplus
118+
}
119+
#endif
120+
121+
#endif /* __STM32_EXTMEM_CONF__H__ */

Bootloader/STM32/Inc/stm32n6xx_hal_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ extern "C" {
8080
#define HAL_UART_MODULE_ENABLED
8181
/*#define HAL_USART_MODULE_ENABLED */
8282
/*#define HAL_WWDG_MODULE_ENABLED */
83-
/*#define HAL_XSPI_MODULE_ENABLED */
83+
#define HAL_XSPI_MODULE_ENABLED
8484
/*#define HAL_CACHEAXI_MODULE_ENABLED */
8585
/*#define HAL_MDIOS_MODULE_ENABLED */
8686
/*#define HAL_GPU2D_MODULE_ENABLED */

0 commit comments

Comments
 (0)