1

In a arm-gcc program (precisely a Atmel Studio 7 Project on a ATSAMC20E18A), I have a weird behavior where a local variable in a function (uint8_t tmp_buffer[ROWS][COLUMNS]) is placed at the beginning of the RAM (0x20000000), overwritting static variables in the .data section.

I would assume that all local variables be placed in the stack. I am running FreeRTOS 10 on the chip with heap_4.c, and there is plenty of heap available.

void _flash_write(struct _flash_device *const device, const uint32_t dst_addr, uint8_t *buffer, uint32_t length)
{
    uint8_t  tmp_buffer[NVMCTRL_ROW_PAGES][NVMCTRL_PAGE_SIZE];
    uint32_t row_start_addr, row_end_addr;
    uint32_t i, j, k;
    uint32_t wr_start_addr = dst_addr;
...

the tmp_buffer gets filled up before the flash is written, which directly overwrittes the variables at the start of the RAM. There is no warning, no crash, not even a HardFault or SegFault.

  • I have found the issue to this bug, the stack size for the task was insufficient to allow the creation of the `tmp_buffer`. I still don't understand why it would not generate a fault and simply bleed back to the start of ram, as the heap is located after the .data section... – Charles Gervais Jun 25 '20 at 19:17

0 Answers0