Merge pull request #3806 from AndrzejKurek/baremetal-refactor-variable-buffers

Refactor the buffer resize feature to reduce codesize