Skip to content

cpu/atmega_common: make remaining RAM available as heap#10934

Merged
smlng merged 1 commit intoRIOT-OS:masterfrom
gschorcht:cpu_atmega_common_heap
Apr 15, 2019
Merged

cpu/atmega_common: make remaining RAM available as heap#10934
smlng merged 1 commit intoRIOT-OS:masterfrom
gschorcht:cpu_atmega_common_heap

Conversation

@gschorcht
Copy link
Copy Markdown
Contributor

@gschorcht gschorcht commented Feb 3, 2019

Contribution description

This PR make the remaining RAM of AVR MCUs available as heap for malloc/free functions of avr-libc.

__malloc_heap_end is set to 0 by default. Therefore, malloc checks __brkval against the SP instead of __malloc_heap_end.

	cp = __malloc_heap_end;
	if (cp == 0)
		cp = STACK_POINTER() - __malloc_margin;
	if (cp <= __brkval)

In thread mode, however, the SP is is always in .data section below __bss_end and thus below __malloc_heap_start. Since __brkval points at least to __malloc_heap_start, the check always fails.

This PR sets __malloc_heap_end to the current SP before switching to thread mode. Thus, malloc checks __brkval against __malloc_heap_end.

Testing procedure

Use tests/malloc to check malloc/free functions of avr-libc, for example:

make -C tests/malloc BOARD=arduino-mega2560 PORT=/dev/ttyUSB0 flash test

@gschorcht gschorcht added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Platform: AVR Platform: This PR/issue effects AVR-based platforms Area: cpu Area: CPU/MCU ports labels Feb 4, 2019
Fills __malloc_heap_end with the current SP before it enters thread mode to make the remaining RAM available as a heap.
Copy link
Copy Markdown
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested with #10953, works!

@smlng smlng added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines labels Apr 15, 2019
@smlng smlng merged commit d08a613 into RIOT-OS:master Apr 15, 2019
@gschorcht
Copy link
Copy Markdown
Contributor Author

@smlng Thanks

@gschorcht gschorcht deleted the cpu_atmega_common_heap branch April 15, 2019 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: cpu Area: CPU/MCU ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: AVR Platform: This PR/issue effects AVR-based platforms Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants