Library 58- Dynamic strings on STM32F4xx

Have you ever been in position where you need to store some string informations just for a small amount of time? Did you reserve ram memory before you worked with strings?

If you did it like that, than this library might be a solution for you.

This library was designed directly for a purpose where you need to store your information for a few time. For example, getting some string informations from your sensor, USART, etc.

It uses malloc and free functions to allocate a memory inside HEAP section of RAM. So, if you have in plain to use a biiig array of strings, first make sure that your HEAP section is big enough where malloc and free functions can operate.

Library

Features

Dynamic string operation

Allocation size depends on string size only, no preallocations

Allows for dynamically search for new sections of memory if current preallocated memory is full

String deletion allowed one by one or all at a time

Dependencies

As I said above, library uses HEAP memory. If you use Keil uVision and startup files provided from ST or if you downloaded it from my Github or default Keil uVision project, then HEAP memory is by default set to 0x200 Bytes = 512kB which can be quite small for something like strings can be in size.

So, in case of Keil uVision, you can open .s (startup file) inside your project and edit variable “Heap_Size” to a value you want to reserve for HEAP.

Functions and enumerations

String functions and enumerations

C

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

/**

* @defgroup TM_STRING_Typedefs

* @brief Library Typedefs

* @{

*/

/**

* @brief Main string structure

*/

typedefstruct{

char**Strings;/*!< Pointer to pointers to strings */

uint32_t Count;/*!< Number of string elementsz */

uint32_t Size;/*!< Number of all allocated pointers for strings */

}TM_STRING_t;

/**

* @}

*/

/**

* @defgroup TM_STRING_Functions

* @brief Library Functions

* @{

*/

/**

* @brief Creates and allocated string structure and memory for pointers for desired number of strings