Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typos in memory_management.md #1222

Merged
merged 1 commit into from
Feb 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions docs/development/memory_management.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ The RAM is a limiting resource and has to be managed to be used as efficiently a
## Static VS dynamic allocation

Static memory allocation is done at compile time and the build system checks that the amount of memory that is required
actually is available in the Crazyflie. Dynamic memory on the other hand, is requested and allocated in runtime using
actually is available in the Crazyflie. Dynamic memory, on the other hand, is requested and allocated in runtime using
the `malloc()` function. Dynamic memory allocation may fail (if there is not enough memory) and the error must be
handled in some way (currently by failing an assert which will reboot the Crazyflie).

In the Crazyflie firmware, we prefer static allocation over dynamic, mainly because it is checked at compile time and no
more error handling is required. Some calls to FreeRTOS do allocate a limited amount dynamic of RAM, but this is usually done
more error handling is required. Some calls to FreeRTOS do allocate a limited amount of dynamic RAM, but this is usually done
in the initialization phase and out of memory conditions should be detected quickly when booting the system.

## Static allocation

Static allocation of RAM memory happens when a variable is declared on a global scope (variables
Static allocation of RAM happens when a variable is declared on a global scope (variables
declared in a function will end up on the stack). The actual allocation is done by the linker by
reserving space in the memory map in the appropriate location.

Expand All @@ -35,7 +35,7 @@ void aFunction() {
Variables that are declared without an assignment will be set to zero at start up,
while variables with an assignment will be initialized to that value. The
values to use for initialized variables are stored in flash together with the
code and is copied to RAM at start up.
code and are copied to RAM at start up.

```
int zeroInitialized;
Expand All @@ -45,7 +45,7 @@ int initializedWithAValue = 17;
### RAM types

The MCU in the Crazyflie has two types of RAM, "normal" RAM and CCM (Core Coupled Memory).
The CCM and normal ram are attached to different buses internally which gives them
The CCM and normal RAM are attached to different buses internally which gives them
different properties. The most significant difference is that the CCM can not be
used for DMA transfers, since the DMA unit does not have access to the bus used by CCM. The
normal RAM can be used for all types of tasks and should be used for normal development,
Expand All @@ -67,8 +67,8 @@ zero initialization is supported for CCM.

```
int variableInNormalRam; // Initialized to 0
int alsoVariableInNormalRam = 17; // Initialize to 17
NO_DMA_CCM_SAFE_ZERO_INIT int variableInCcm; // Initialized ot 0
int alsoVariableInNormalRam = 17; // Initialized to 17
NO_DMA_CCM_SAFE_ZERO_INIT int variableInCcm; // Initialized to 0
NO_DMA_CCM_SAFE_ZERO_INIT int dontDoThisInCcm = 17; // WARNING! Will not work, will be initialized to 0! Will be silently accepted without warning.
````

Expand All @@ -81,6 +81,6 @@ to stack memory will be used for DMA transfers, it is possible to
also allocate the stack in CCM by using the `STATIC_MEM_TASK_ALLOC_STACK_NO_DMA_CCM_SAFE()`
macro instead.

Code that uses DMA through a public API should verify verify that pointers
Code that uses DMA through a public API should verify that pointers
passed in through the API do not point to CCM. Use `ASSERT_DMA_SAFE` for this
purpose to fail fast and indicate what the reason for the failed is.