Skip to content

Commit a249054

Browse files
committed
Cleanup and documentation of target_{board,config,family}.h.
1 parent 89e0623 commit a249054

File tree

3 files changed

+109
-48
lines changed

3 files changed

+109
-48
lines changed

source/target/target_board.h

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,44 +34,77 @@ enum _board_info_version {
3434
kBoardInfoVersion = 1, //!< The current board info version.
3535
};
3636

37-
// Flags for board_info
38-
enum {
39-
kEnablePageErase = 1, /*!< Enable page programming and sector erase for drag and drop */
40-
kEnableUnderResetConnect = 1<<1, /*!< Enable under reset connection when enabling debug mode */
37+
//! @brief Flags for board_info
38+
enum _board_info_flags {
39+
kEnablePageErase = (1 << 0), /*!< Enable page programming and sector erase for drag and drop */
40+
kEnableUnderResetConnect = (1 << 1), /*!< Enable under reset connection when enabling debug mode */
4141
};
4242

43+
/*!
44+
* @brief Board customization info.
45+
*
46+
* Each board must have a unique 4-character Board ID. For Mbed OS targets, the Board ID is the same
47+
* as the Mbed Platform ID. These IDs are nominally allocated by Arm in order to guarantee there are
48+
* no conflicts between boards. Please see the DAPLink documentation for more.
49+
*
50+
* The family_id member tells DAPLink which device family the on-board target belongs to. This then
51+
* determines certain behaviours, such as how to reset the target. Family IDs are defined in the
52+
* #family_id_t enumeration.
53+
*
54+
* The board initialization function pointers allow the board to override the routines defined
55+
* by the device family.
56+
*/
4357
typedef struct __attribute__((__packed__)) board_info {
4458
uint16_t info_version; /*!< Version number of the board info */
45-
uint16_t family_id; /*!< Use to select or identify target family from defined target family or custom ones */
59+
uint16_t family_id; /*!< Use to select or identify target family from defined target family or custom ones */
4660
char board_id[5]; /*!< 4-char board ID plus null terminator */
4761
uint8_t _padding[3];
48-
uint32_t flags; /*!< Combination of kEnablePageErase and kEnableUnderResetConnect */
62+
uint32_t flags; /*!< Flags from #_board_info_flags */
4963
target_cfg_t *target_cfg; /*!< Specific chip configuration for the target and enables MSD when non-NULL */
5064

51-
// fields used by MSD
65+
//! @name MSD customization
66+
//@{
5267
vfs_filename_t daplink_url_name; /*!< Customize the URL file name */
5368
vfs_filename_t daplink_drive_name; /*!< Customize the MSD DAPLink drive name */
5469
char daplink_target_url[64]; /*!< Customize the target url in DETAILS.TXT */
70+
//@}
5571

56-
// some specific board initilization
72+
//! @name Board initialization customization
73+
//@{
5774
void (*prerun_board_config)(void); /*!< Specific board debug/ID related initialization */
5875
void (*swd_set_target_reset)(uint8_t asserted); /*!< Boards can customize how to send reset to the target precedence over target family */
5976
uint8_t (*target_set_state)(TARGET_RESET_STATE state); /*!< Boards can customize target debug states in target_reset.h precedence over target family */
6077
uint32_t soft_reset_type; /*!< Boards can override software reset type to VECTRESET or SYSRESETREQ */
78+
//@}
6179
} board_info_t;
6280

81+
//! @brief Information describing the board on which DAPLink is running.
6382
extern const board_info_t g_board_info;
6483

6584
#ifdef __cplusplus
6685
extern "C" {
6786
#endif
6887

88+
//! @brief Returns the 4-char ID of the board used by the running firmware.
89+
//!
90+
//! For firmware with no board, the board ID is "0000".
6991
const char * get_board_id(void);
92+
93+
//! @brief Returns the family ID for the target associated with the board.
94+
//!
95+
//! The family ID will be 0 if there is no board.
7096
uint16_t get_family_id(void);
97+
98+
//! @brief Whether the board has a valid flash algo.
7199
uint8_t flash_algo_valid(void);
72100

101+
//! @brief Returns the MSD HTML help filename or a default.
73102
static inline const char * get_daplink_url_name ( void ) { return ((g_board_info.daplink_url_name[0] != 0) ? g_board_info.daplink_url_name : "MBED HTM"); }
103+
104+
//! @brief Returns the MSD volume name or a default.
74105
static inline const char * get_daplink_drive_name ( void ) { return ((g_board_info.daplink_drive_name[0] != 0) ? g_board_info.daplink_drive_name : "DAPLINK "); }
106+
107+
//! @brief Returns the target information URL or a default.
75108
static inline const char * get_daplink_target_url ( void ) { return ((g_board_info.daplink_target_url[0] != 0) ? g_board_info.daplink_target_url : "https://mbed.org/device/?code=@U?version=@V?target_id=@T"); }
76109

77110
#ifdef __cplusplus

source/target/target_config.h

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,57 +28,45 @@
2828
#include "flash_blob.h"
2929
#include "macro.h"
3030

31-
#ifdef __cplusplus
32-
extern "C" {
33-
#endif
34-
35-
/**
36-
@addtogroup
37-
@{
38-
*/
39-
40-
// This can vary from target to target and should be in the structure or flash blob
31+
//! This can vary from target to target and should be in the structure or flash blob
4132
#define TARGET_AUTO_INCREMENT_PAGE_SIZE (1024)
4233

43-
//Additional flash and ram regions
44-
#define MAX_EXTRA_FLASH_REGION 10
45-
#define MAX_EXTRA_RAM_REGION 10
34+
//! Additional flash and ram regions
35+
#define MAX_REGIONS (10)
4636

37+
//! @brief Option flags for memory regions.
4738
enum _region_flags {
48-
kRegionIsDefault = (1 << 0), //out of bounds regions will use the same flash algo if this is set
49-
kRegionIsSecure = (1 << 1)
39+
kRegionIsDefault = (1 << 0), /*!< Out of bounds regions will use the same flash algo if this is set */
40+
kRegionIsSecure = (1 << 1), /*!< The region can only be accessed from the secure world. Only applies for TrustZone-enabled targets. */
5041
};
5142

52-
43+
/*!
44+
* @brief Details of a target flash or RAM memory region.
45+
*/
5346
typedef struct __attribute__((__packed__)) region_info {
54-
uint32_t start;
55-
uint32_t end;
56-
uint32_t flags;
57-
uint32_t alias_index; /*!<use with flags; will point to a different index if there is an alias region */
47+
uint32_t start; /*!< Region start address. */
48+
uint32_t end; /*!< Region end address. */
49+
uint32_t flags; /*!< Flags for this region from the #_region_flags enumeration. */
50+
uint32_t alias_index; /*!< Use with flags; will point to a different index if there is an alias region */
5851
program_target_t *flash_algo; /*!< A pointer to the flash algorithm structure */
5952
} region_info_t;
6053

61-
/**
62-
@struct target_cfg_t
63-
@brief The firmware configuration struct has unique about the chip its running on.
54+
/*!
55+
* @brief Information required to program target flash.
6456
*/
6557
typedef struct __attribute__((__packed__)) target_cfg {
66-
uint32_t version; /*!< Target configuration version */
67-
const sector_info_t* sectors_info; /*!< Sector start and length list */
68-
uint32_t sector_info_length; /*!< Sector start and length list total */
69-
region_info_t flash_regions[MAX_EXTRA_FLASH_REGION]; /*!< Flash regions */
70-
region_info_t ram_regions[MAX_EXTRA_RAM_REGION]; /*!< RAM regions */
71-
const char *rt_board_id; /*!< If assigned, this is a flexible board ID */
72-
uint16_t rt_family_id; /*!< If assigned, this is a flexible board ID */
73-
uint8_t erase_reset; /*!< Reset after performing an erase */
58+
uint32_t version; /*!< Target configuration version */
59+
const sector_info_t* sectors_info; /*!< Sector start and length list */
60+
uint32_t sector_info_length; /*!< Number of entries in the sectors_info array */
61+
region_info_t flash_regions[MAX_REGIONS]; /*!< Flash regions */
62+
region_info_t ram_regions[MAX_REGIONS]; /*!< RAM regions */
63+
const char *rt_board_id; /*!< If assigned, this is a flexible board ID */
64+
uint16_t rt_family_id; /*!< If assigned, this is a flexible family ID */
65+
uint8_t erase_reset; /*!< Reset after performing an erase */
7466
uint8_t pad;
7567
} target_cfg_t;
7668

7769
extern target_cfg_t target_device;
7870

7971

80-
#ifdef __cplusplus
81-
}
82-
#endif
83-
8472
#endif

source/target/target_family.h

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,21 @@
2626
#include <string.h>
2727
#include "target_reset.h"
2828

29-
#define VENDOR_TO_FAMILY(x, y) (x<<8 | y)
29+
//! @brief Creates a family ID from a vendor ID and family index within that vendor.
30+
#define VENDOR_TO_FAMILY(vendor, family) ((vendor) << 8 | (family))
3031

32+
//! @brief Options for reset.
3133
typedef enum _reset_type {
3234
kHardwareReset = 1,
3335
kSoftwareReset,
3436
} reset_type_t;
3537

38+
//! @brief Unique IDs for vendors.
39+
//!
40+
//! The vendor IDs are the same as those used for the _DeviceVendorEnum_ defined for the PDSC file
41+
//! format from CMSIS-Packs. See the [DeviceVendorEnum
42+
//! documentation](https://arm-software.github.io/CMSIS_5/Pack/html/pdsc_family_pg.html#DeviceVendorEnum)
43+
//! for the list of ID values.
3644
enum _vendor_ids {
3745
kStub_VendorID = 0,
3846
kNXP_VendorID = 11,
@@ -44,6 +52,24 @@ enum _vendor_ids {
4452
kRealtek_VendorID = 124,
4553
};
4654

55+
//! @brief Unique IDs for device families supported by DAPLink.
56+
//!
57+
//! The values of these enums are created with the VENDOR_TO_FAMILY() macro. Vendor IDs come from
58+
//! the #_vendor_ids enumeration. The family index for each ID is simply an integer that is unique
59+
//! within the family.
60+
//!
61+
//! There are several "stub" families defined with a stub vendor. These families are meant to be
62+
//! used for devices that do not require any customized behaviour in order to be successfully
63+
//! controlled by DAPLink. The individual stub families provide some options for what reset type
64+
//! should be used, either hardware or software.
65+
//!
66+
//! To add a new family, first determine if you can simply use one of the stub families. For many
67+
//! devices, the stub families are sufficient and using them reduces complexity.
68+
//!
69+
//! If you do need a new family ID, first check if the vendor is present in #_vendor_ids. If not,
70+
//! add the vendor ID to that enum (see its documentation for the source of vendor ID values).
71+
//! Then pick a unique family index by adding 1 to the highest existing family index within that
72+
//! vendor. For a family with a new vendor, the family index should be 1.
4773
typedef enum _family_id {
4874
kStub_HWReset_FamilyID = VENDOR_TO_FAMILY(kStub_VendorID, 1),
4975
kStub_SWVectReset_FamilyID = VENDOR_TO_FAMILY(kStub_VendorID, 2),
@@ -62,6 +88,7 @@ typedef enum _family_id {
6288
kRenesas_FamilyID = VENDOR_TO_FAMILY(kRenesas_VendorID, 1),
6389
} family_id_t;
6490

91+
//! @brief Defines all characteristics of a device family.
6592
typedef struct target_family_descriptor {
6693
uint16_t family_id; /*!< Use to select or identify target family from defined target family or custom ones */
6794
reset_type_t default_reset_type; /*!< Target family can select predefined reset from kHardwareReset and kSoftwareReset */
@@ -70,22 +97,35 @@ typedef struct target_family_descriptor {
7097
void (*prerun_target_config)(void); /*!< Target specific initialization */
7198
uint8_t (*target_unlock_sequence)(void); /*!< Unlock targets that can enter lock state */
7299
uint8_t (*security_bits_set)(uint32_t addr, uint8_t *data, uint32_t size); /*!< Check security bits in the programmable flash region */
73-
uint8_t (*target_set_state)(TARGET_RESET_STATE state); /*!< Families can customize target debug states in target_reset.h */
74-
void (*swd_set_target_reset)(uint8_t asserted); /*!< Families can customize how to send reset to the target */
75-
uint8_t (*validate_bin_nvic)(const uint8_t *buf); /*!< Validate a bin file to be flash by drag and drop */
76-
uint8_t (*validate_hexfile)(const uint8_t *buf); /*!< Validate a hex file to be flash by drag and drop */
100+
uint8_t (*target_set_state)(TARGET_RESET_STATE state); /*!< Families can customize target debug states */
101+
void (*swd_set_target_reset)(uint8_t asserted); /*!< Families can customize how to send reset to the target */
102+
uint8_t (*validate_bin_nvic)(const uint8_t *buf); /*!< Validate a bin file to be flash by drag and drop */
103+
uint8_t (*validate_hexfile)(const uint8_t *buf); /*!< Validate a hex file to be flash by drag and drop */
77104
uint32_t apsel; /*!< APSEL for the family */
78105
} target_family_descriptor_t;
79106

107+
//! @brief The active family used by the board.
108+
//!
109+
//! This global is initialized by init_family() just after DAPLink boots. Normally it matches
110+
//! the family specified by the #board_info_t::family_id field of #g_board_info.
80111
extern const target_family_descriptor_t *g_target_family;
81112

82113
#ifdef __cplusplus
83114
extern "C" {
84115
#endif
85116

117+
//! @brief Initialize g_target_family.
86118
void init_family(void);
119+
120+
//! @brief Reset the target into a new state.
121+
//!
122+
//! Used to prepare the target for some operation, or release it for user control.
87123
uint8_t target_set_state(TARGET_RESET_STATE state);
124+
125+
//! @brief Controls reset of the target.
88126
void swd_set_target_reset(uint8_t asserted);
127+
128+
//! @brief Get the APSEL for the AHB-AP to use for controlling the target.
89129
uint32_t target_get_apsel(void);
90130

91131
#ifdef __cplusplus

0 commit comments

Comments
 (0)