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

Memory #7

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,16 @@
"stopAtEntry": true,
"preLaunchTask": "RunQemu_3_task_scheduling_challenge"
},
{
"name": "Launch_QEMU_4_memory",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/4_memory/build/demo",
"cwd": "${workspaceFolder}",
"miDebuggerPath": "${env:GCC_ARM_NONE_EABI_BIN_PATH}/arm-none-eabi-gdb-py",
"miDebuggerServerAddress": "localhost:1234",
"stopAtEntry": true,
"preLaunchTask": "RunQemu_4_memory"
},
]
}
24 changes: 24 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,29 @@
}
]
}
,
{
"label": "RunQemu_4_memory",
"type": "shell",
"command": "${workspaceFolder}/misc/shell/build_run_qemu.sh ${workspaceFolder}/4_memory debug",
"isBackground": true,
"problemMatcher": [
{
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": ".",
"endsPattern": "QEMU_started",
}
}
]
}
]
}
1 change: 1 addition & 0 deletions 0_base/misc/cmake/arm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ set(CMAKE_C_FLAGS "-ffreestanding \
set(CMAKE_EXE_LINKER_FLAGS "-T ${CMAKE_SOURCE_DIR}/0_base/misc/mps2_m3.ld \
-Xlinker -Map=${prj}.map \
-Xlinker --gc-sections \
-Xlinker --print-memory-usage \
-nostartfiles \
-specs=nano.specs -specs=nosys.specs")
19 changes: 19 additions & 0 deletions 4_memory/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch_QEMU",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/demo",
"cwd": "${workspaceFolder}",
"miDebuggerPath": "${env:GCC_ARM_NONE_EABI_BIN_PATH}/arm-none-eabi-gdb-py",
"miDebuggerServerAddress": "localhost:1234",
"stopAtEntry": true,
"preLaunchTask": "Run_QEMU",
},
]
}
303 changes: 303 additions & 0 deletions 4_memory/.vscode/settings.json

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions 4_memory/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Clean_Build",
"type": "shell",
"command": "${workspaceFolder}/../misc/shell/rebuild.sh ${workspaceFolder}"
},
{
"label": "Run_QEMU",
"type": "shell",
"command": "${workspaceFolder}/../misc/shell/build_run_qemu.sh ${workspaceFolder} debug",
"isBackground": true,
"problemMatcher": [
{
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": ".",
"endsPattern": "QEMU_started",
}
}
]
},
]
}
1 change: 1 addition & 0 deletions 4_memory/0_base
31 changes: 31 additions & 0 deletions 4_memory/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 3.10)

set(prj demo)

include("${CMAKE_CURRENT_SOURCE_DIR}/0_base/misc/cmake/arm.cmake")
set(freertos_root "${CMAKE_CURRENT_SOURCE_DIR}/0_base/misc/FreeRTOS")
include("${CMAKE_CURRENT_SOURCE_DIR}/0_base/misc/cmake/common_demo.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/0_base/misc/cmake/freertos.cmake")

# Set the project name
project(${prj})

if(APP_DEMO)
message(STATUS "APP_DEMO is set to ${APP_DEMO}")
add_compile_definitions(APP_DEMO=${APP_DEMO})
endif()

add_subdirectory(0_base)

# Add all source files in the current directory
file(GLOB app_src "${CMAKE_CURRENT_SOURCE_DIR}/*.c")

set(src ${src} ${app_src})
set(inc ${inc} ${CMAKE_CURRENT_SOURCE_DIR})

# Add the executable
add_executable(${prj} ${src})
# Include directories
target_include_directories(${prj} PUBLIC ${inc})

include("${CMAKE_CURRENT_SOURCE_DIR}/0_base/misc/cmake/log.cmake")
41 changes: 41 additions & 0 deletions 4_memory/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 4_memory

Implementation in [app.c](./app.c).

[Introduction to RTOS Part 4 - Memory Management ](https://www.youtube.com/watch?v=Qske3yZRW5I&list=PLEBQazB0HUyQ4hAPU1cJED6t3DU0h34bz&index=4)

This file demonstrates memory management in FreeRTOS
Explanation of demos:
```
// demo 1 : overflow stack by recursive call
#define APP_DEMO_1 1
// demo 2 : allocating huge array in stack to ovf
#define APP_DEMO_2 2
// demo 3 : ovf heap u32 at a time
#define APP_DEMO_3 3
// demo 4 : ovf heap in single shot
#define APP_DEMO_4 4
// demo 5 : properly malloc and free. this should be fine
#define APP_DEMO_5 5
// demo 6 : overflow of static stack by recursive call
#define APP_DEMO_6 6

#ifndef APP_DEMO
#define APP_DEMO APP_DEMO_1
#endif
```

## Terminal Output
Terminal output of APP_DEMO_1:
```
rem: 0 tec: 574
rem: 0 tec: 575
re

Stack overflow in A
```

## Notes
Use app_init function in app.c to implement your demo application.
Run in debug console to dump the trace
-exec dump binary value trace.bin *RecorderDataPtr
Loading
Loading