Skip to content

Commit

Permalink
lib: stm32wba: hci: Add flash_manager when building controller library
Browse files Browse the repository at this point in the history
Flash manager is used to driver flash access coexistence between RF and
user accesses.

Signed-off-by: Erwan Gouriou <[email protected]>
  • Loading branch information
erwango committed Dec 20, 2023
1 parent 3fe2e32 commit 2292590
Show file tree
Hide file tree
Showing 10 changed files with 1,345 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ if(CONFIG_HAS_STM32LIB)
zephyr_sources(stm32wba/hci/bpka.c)
zephyr_sources(stm32wba/hci/power_table.c)
zephyr_sources(stm32wba/hci/scm.c)
zephyr_sources(stm32wba/hci/log_module.c)
if(CONFIG_FLASH)
zephyr_sources(stm32wba/hci/flash_manager.c)
zephyr_sources(stm32wba/hci/flash_driver.c)
zephyr_sources(stm32wba/hci/stm_list.c)
zephyr_sources(stm32wba/hci/rf_timing_synchro.c)
endif()

set(STM32WBA_BLE_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../zephyr/blobs/stm32wba/lib)
set(STM32WBA_BLE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/stm32wba/hci)
Expand Down
8 changes: 8 additions & 0 deletions lib/stm32wba/hci/README
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,20 @@ Description:
Projects/NUCLEO-WBA52CG/Applications/BLE/BLE_HeartRate/Core/Inc/app_entry.h
Projects/NUCLEO-WBA52CG/Applications/BLE/BLE_HeartRate/Core/Inc/utilities_conf.h
Projects/NUCLEO-WBA52CG/Applications/BLE/BLE_HeartRate/Core/Inc/main.h
Projects/NUCLEO-WBA52CG/Applications/BLE/BLE_HeartRate/System/Modules/Flash/rf_timing_synchro.c
Projects/NUCLEO-WBA52CG/Applications/BLE/BLE_HeartRate/System/Modules/Flash/rf_timing_synchro.h
Projects/NUCLEO-WBA52CG/Applications/BLE/BLE_HeartRate/System/Modules/Flash/flash_driver.c
Projects/NUCLEO-WBA52CG/Applications/BLE/BLE_HeartRate/System/Modules/Flash/flash_driver.h
Projects/NUCLEO-WBA52CG/Applications/BLE/BLE_HeartRate/System/Modules/Flash/flash_manager.c
Projects/NUCLEO-WBA52CG/Applications/BLE/BLE_HeartRate/System/Modules/Flash/flash_manager.h
Projects/NUCLEO-WBA52CG/Applications/BLE/BLE_HeartRate/System/Modules/RTDebug/debug_signals.h
Projects/NUCLEO-WBA55CG/Applications/BLE/BLE_HeartRate/System/Modules/RTDebug/RTDebug.c
Projects/NUCLEO-WBA52CG/Applications/BLE/BLE_HeartRate/System/Modules/RTDebug/RTDebug.h
Projects/NUCLEO-WBA52CG/Applications/BLE/BLE_HeartRate/System/Modules/RTDebug/local_debug_tables.h
Projects/NUCLEO-WBA52CG/Applications/BLE/BLE_HeartRate/System/Modules/scm.c
Projects/NUCLEO-WBA52CG/Applications/BLE/BLE_HeartRate/System/Modules/scm.h
Projects/NUCLEO-WBA52CG/Applications/BLE/BLE_HeartRate/System/Modules/stm_list.c
Projects/NUCLEO-WBA52CG/Applications/BLE/BLE_HeartRate/System/Modules/stm_list.h
Projects/NUCLEO-WBA52CG/Applications/BLE/BLE_HeartRate/System/Modules/utilities_common.h
Projects/NUCLEO-WBA52CG/Applications/BLE/BLE_HeartRate/System/Interfaces/hw.h
Projects/NUCLEO-WBA52CG/Applications/BLE/BLE_HeartRate/System/Interfaces/hw_aes.c
Expand Down
132 changes: 132 additions & 0 deletions lib/stm32wba/hci/flash_driver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file flash_driver.c
* @author MCD Application Team
* @brief The Flash Driver module is the interface layer between Flash
* management modules and HAL Flash drivers
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "flash_driver.h"
#include "utilities_conf.h"

/* Global variables ----------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private defines -----------------------------------------------------------*/

#define FD_CTRL_NO_BIT_SET (0UL) /* value used to reset the Flash Control status */

/* Private macros ------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/

/**
* @brief variable used to represent the Flash Control status
*/
static volatile FD_Flash_ctrl_bm_t FD_Flash_Control_status = FD_CTRL_NO_BIT_SET;

/* Private function prototypes -----------------------------------------------*/
/* Functions Definition ------------------------------------------------------*/

/**
* @brief Update Flash Control status
* @param Flags_bm: Bit mask identifying the caller (1 bit per user)
* @param Status: Action requested (enable or disable flash access)
* @retval None
*/
void FD_SetStatus(FD_Flash_ctrl_bm_t Flags_bm, FD_FLASH_Status_t Status)
{
UTILS_ENTER_CRITICAL_SECTION();

switch (Status)
{
case LL_FLASH_DISABLE:
{
FD_Flash_Control_status |= (1u << Flags_bm);
break;
}
case LL_FLASH_ENABLE:
{
FD_Flash_Control_status &= ~(1u << Flags_bm);
break;
}
default :
{
break;
}
}

UTILS_EXIT_CRITICAL_SECTION();
}

/**
* @brief Write a block of 128 bits (4 32-bit words) in Flash
* @param Dest: Address where to write in Flash (128-bit aligned)
* @param Payload: Address of data to be written in Flash (32-bit aligned)
* @retval FD_FlashOp_Status_t: Success or failure of Flash write operation
*/
FD_FlashOp_Status_t FD_WriteData(uint32_t Dest, uint32_t Payload)
{
FD_FlashOp_Status_t status = FD_FLASHOP_FAILURE;

/* Check if RFTS OR Application allow flash access */
if ((FD_Flash_Control_status & (1u << FD_FLASHACCESS_RFTS)) &&
(FD_Flash_Control_status & (1u << FD_FLASHACCESS_RFTS_BYPASS)))
{ /* Access not allowed */
return status;
}

/* Wait for system to allow flash access */
while (FD_Flash_Control_status & (1u << FD_FLASHACCESS_SYSTEM));

if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_QUADWORD, Dest, Payload) == HAL_OK)
{
status = FD_FLASHOP_SUCCESS;
}
return status;
}

/**
* @brief Erase one sector of Flash
* @param Sect: Identifier of the sector to erase
* @retval FD_FlashOp_Status_t: Success or failure of Flash erase operation
*/
FD_FlashOp_Status_t FD_EraseSectors(uint32_t Sect)
{
FD_FlashOp_Status_t status = FD_FLASHOP_FAILURE;
uint32_t page_error;
FLASH_EraseInitTypeDef p_erase_init;

/* Check if LL allows flash access */
if ((FD_Flash_Control_status & (1u << FD_FLASHACCESS_RFTS)) &&
(FD_Flash_Control_status & (1u << FD_FLASHACCESS_RFTS_BYPASS)))
{ /* Access not allowed */
return status;
}

/* Wait for system to allow flash access */
while (FD_Flash_Control_status & (1u << FD_FLASHACCESS_SYSTEM));

p_erase_init.TypeErase = FLASH_TYPEERASE_PAGES;
p_erase_init.Page = Sect;
p_erase_init.NbPages = 1;

if (HAL_FLASHEx_Erase(&p_erase_init, &page_error) == HAL_OK)
{
status = FD_FLASHOP_SUCCESS;
}

return status;
}
90 changes: 90 additions & 0 deletions lib/stm32wba/hci/flash_driver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file flash_driver.h
* @author MCD Application Team
* @brief Header for flash_driver.c module
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef FLASH_DRIVER_H
#define FLASH_DRIVER_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "utilities_common.h"

/* Exported types ------------------------------------------------------------*/

/* Bit mask to modify Flash Control status */
typedef uint32_t FD_Flash_ctrl_bm_t;

/* Flash operation status */
typedef enum
{
FD_FLASHOP_SUCCESS,
FD_FLASHOP_FAILURE
} FD_FlashOp_Status_t;

/* Flash Driver commands to enable or disable flash access */
typedef enum
{
LL_FLASH_ENABLE,
LL_FLASH_DISABLE,
} FD_FLASH_Status_t;

/**
* @brief Bit mask to modify Flash Control status
*
* @details Those bitmasks are used to enable/disable access to the flash:
* - System:
* -# FD_FLASHACCESS_SYSTEM: Determine whether or not the flash access is allowed from a system POV.
* This bit has a predominance over all the other bit masks, ie: No flash operation can
* be achieved without this to be set to 0, ie: LL_FLASH_ENABLE.
* - RFTS:
* -# FD_FLASHACCESS_RFTS: Determine whether or not the RF Timing Synchro allows flash access. This bit is set
* once a window has been allowed by the BLE LL, ie: set to 0.
* This bit has no impact when FD_FLASHACCESS_RFTS_BYPASS is set, ie: set to 0.
* -# FD_FLASHACCESS_RFTS_BYPASS: Nullify the impact of FD_FLASHACCESS_RFTS when enabled, ie: set to 0. Its role is
* to allow flash operation without the need to request a timing window to the RFTS,
* ie: Executing flash operation without the BLE LL.
*
*/
typedef enum FD_FlashAccess_bm
{
/* System flash access bitfield */
FD_FLASHACCESS_SYSTEM,
/* RF Timing Synchro flash access bitfield */
FD_FLASHACCESS_RFTS,
/* Bypass of RF Timing Synchro flash access bitfield */
FD_FLASHACCESS_RFTS_BYPASS,
}FD_FlashAccess_bm_t;

/* Exported constants --------------------------------------------------------*/
/* Exported variables --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void FD_SetStatus(FD_Flash_ctrl_bm_t Flags_bm, FD_FLASH_Status_t Status);
FD_FlashOp_Status_t FD_WriteData(uint32_t Dest, uint32_t Payload);
FD_FlashOp_Status_t FD_EraseSectors(uint32_t Sect);

#ifdef __cplusplus
}
#endif

#endif /*FLASH_DRIVER_H */
Loading

0 comments on commit 2292590

Please sign in to comment.