我正在尝试使用printf半主机(JTAG上的printf)在STM32F746NG Discovery开发板上工作,并且在调用printf时遇到麻烦。我对如何继续调试这个问题感到茫然。
这是症状。 HardFault_Handler是从_malloc_r调用的,由printf调用。这是输入HardFault_Handler时的堆栈:
#0 0x08000424 in HardFault_Handler () at startup.c:155
#1 <signal handler called>
#2 0x08000d28 in _malloc_r ()
#3 0x0800215c in __smakebuf_r ()
#4 0x08002066 in __swsetup_r ()
#5 0x08001972 in __sfvwrite_r ()
#6 0x080018b2 in _puts_r ()
#7 0x0800036a in main () at main.c:41
_malloc_r + 96处的指令导致硬故障。如果我在_malloc_r + 96设置断点并继续3次,则第三次跳过_malloc_r + 96后处理器出现硬故障。以下是GDB输出的寄存器信息。
GNU gdb (GNU Tools for ARM Embedded Processors 6-2017-q1-update) 7.12.1.20170215
-git
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-w64-mingw32 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Resetting target
Select auto target interface speed (2000 kHz)
Selecting device: STM32F746NG
Semi-hosting enabled (Handle on BKPT)
Semihosting I/O set to TELNET and GDB Client
Loading section .vectors, size 0x1c8 lma 0x8000000
Loading section .text, size 0x1fe4 lma 0x8000200
Loading section .rodata, size 0x1c lma 0x80021e4
Loading section .init_array, size 0x8 lma 0x8002200
Loading section .fini_array, size 0x4 lma 0x8002208
Loading section .data, size 0x848 lma 0x800220c
Start address 0x8000384, load size 10780
Transfer rate: 1315 KB/sec, 1796 bytes/write.
Resetting target
(gdb) b *_malloc_r+96
Breakpoint 1 at 0x8000ce8
(gdb) display/i $pc
1: x/i $pc
=> 0x8000384 <Reset_Handler>: push {r7, lr}
(gdb) c
Continuing.
Breakpoint 1, 0x08000ce8 in _malloc_r ()
1: x/i $pc
=> 0x8000ce8 <_malloc_r+96>: ldr r3, [r4, #4]
(gdb) i r
r0 0x49 73
r1 0x20000678 536872568
r2 0x1 1
r3 0x20000680 536872576
r4 0x84882528 2223514920
r5 0x20000008 536870920
r6 0x408 1032
r7 0x20000438 536871992
r8 0x0 0
r9 0x0 0
r10 0x0 0
r11 0x0 0
r12 0xffffffff 4294967295
sp 0x2004fb28 0x2004fb28
lr 0x48 72
pc 0x8000ce8 0x8000ce8 <_malloc_r+96>
xpsr 0x91090000 2433286144
msp 0x2004fb28 537197352
psp 0x0 0
primask 0x0 0
basepri 0x0 0
faultmask 0x0 0
control 0x0 0
(gdb) c
Continuing.
Breakpoint 1, 0x08000ce8 in _malloc_r ()
1: x/i $pc
=> 0x8000ce8 <_malloc_r+96>: ldr r3, [r4, #4]
(gdb) i r
r0 0x49 73
r1 0x20000678 536872568
r2 0xfffffbf8 4294966264
r3 0x0 0
r4 0x0 0
r5 0x20000008 536870920
r6 0x408 1032
r7 0x20000438 536871992
r8 0x0 0
r9 0x0 0
r10 0x0 0
r11 0x0 0
r12 0xffffffff 4294967295
sp 0x2004fb28 0x2004fb28
lr 0x48 72
pc 0x8000ce8 0x8000ce8 <_malloc_r+96>
xpsr 0x21090000 554237952
msp 0x2004fb28 537197352
psp 0x0 0
primask 0x0 0
basepri 0x0 0
faultmask 0x0 0
control 0x0 0
(gdb) c
Continuing.
Breakpoint 1, 0x08000ce8 in _malloc_r ()
1: x/i $pc
=> 0x8000ce8 <_malloc_r+96>: ldr r3, [r4, #4]
(gdb) i r
r0 0x49 73
r1 0x20000678 536872568
r2 0xbbc234f0 3150066928
r3 0xbbc238f8 3150067960
r4 0x77f2eed6 2012409558
r5 0x20000008 536870920
r6 0x408 1032
r7 0x20000438 536871992
r8 0x0 0
r9 0x0 0
r10 0x0 0
r11 0x0 0
r12 0xffffffff 4294967295
sp 0x2004fb28 0x2004fb28
lr 0x48 72
pc 0x8000ce8 0x8000ce8 <_malloc_r+96>
xpsr 0x81090000 2164850688
msp 0x2004fb28 537197352
psp 0x0 0
primask 0x0 0
basepri 0x0 0
faultmask 0x0 0
control 0x0 0
(gdb) si
0x080003ec in HardFault_Handler () at startup.c:149
149 void HardFault_Handler(void) { while(1) { } }
1: x/i $pc
=> 0x80003ec <HardFault_Handler+4>:
b.n 0x80003ec <HardFault_Handler+4>
(gdb) i r
r0 0x49 73
r1 0x20000678 536872568
r2 0xbbc234f0 3150066928
r3 0xbbc238f8 3150067960
r4 0x77f2eed6 2012409558
r5 0x20000008 536870920
r6 0x408 1032
r7 0x2004fb04 537197316
r8 0x0 0
r9 0x0 0
r10 0x0 0
r11 0x0 0
r12 0xffffffff 4294967295
sp 0x2004fb04 0x2004fb04
lr 0xfffffff9 4294967289
pc 0x80003ec 0x80003ec <HardFault_Handler+4>
xpsr 0x81090003 2164850691
msp 0x2004fb04 537197316
psp 0x0 0
primask 0x0 0
basepri 0x0 0
faultmask 0x0 0
control 0x0 0
(gdb)
看起来$ r4正在被破坏。关于如何调试和修复此问题,我完全失败了。我没有在startup.c中正确初始化C环境?我没有在链接器中正确定义某些内容吗?如果我需要添加更多信息,澄清某些内容或尝试某些测试,请告诉我。
其他一些细节:
#include <stdint.h>
#include <string.h>
void Reset_Handler(void);
// __attribute__((weak, alias("Default_Handler"))) void NMI_Handler(void);
// __attribute__((weak, alias("Default_Handler"))) void HardFault_Handler(void);
// __attribute__((weak, alias("Default_Handler"))) void MemManage_Handler(void);
// __attribute__((weak, alias("Default_Handler"))) void BusFault_Handler(void);
// __attribute__((weak, alias("Default_Handler"))) void UsageFault_Handler(void);
// __attribute__((weak, alias("Default_Handler"))) void SVC_Handler(void);
// __attribute__((weak, alias("Default_Handler"))) void DebugMon_Handler(void);
// __attribute__((weak, alias("Default_Handler"))) void PendSV_Handler(void);
// __attribute__((weak, alias("Default_Handler"))) void SysTick_Handler(void);
__attribute__((weak, alias("Default_Handler"))) void WWDG_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void PVD_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void TAMP_STAMP_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void RTC_WKUP_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void FLASH_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void RCC_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void EXTI0_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void EXTI1_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void EXTI2_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void EXTI3_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void EXTI4_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void DMA1_Stream0_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void DMA1_Stream1_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void DMA1_Stream2_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void DMA1_Stream3_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void DMA1_Stream4_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void DMA1_Stream5_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void DMA1_Stream6_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void ADC_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void CAN1_TX_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void CAN1_RX0_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void CAN1_RX1_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void CAN1_SCE_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void EXTI9_5_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void TIM1_BRK_TIM9_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void TIM1_UP_TIM10_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void TIM1_TRG_COM_TIM11_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void TIM1_CC_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void TIM2_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void TIM3_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void TIM4_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void I2C1_EV_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void I2C1_ER_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void I2C2_EV_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void I2C2_ER_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void SPI1_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void SPI2_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void USART1_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void USART2_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void USART3_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void EXTI15_10_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void RTC_Alarm_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void OTG_FS_WKUP_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void TIM8_BRK_TIM12_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void TIM8_UP_TIM13_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void TIM8_TRG_COM_TIM14_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void TIM8_CC_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void DMA1_Stream7_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void FMC_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void SDMMC1_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void TIM5_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void SPI3_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void UART4_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void UART5_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void TIM6_DAC_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void TIM7_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void DMA2_Stream0_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void DMA2_Stream1_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void DMA2_Stream2_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void DMA2_Stream3_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void DMA2_Stream4_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void ETH_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void ETH_WKUP_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void CAN2_TX_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void CAN2_RX0_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void CAN2_RX1_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void CAN2_SCE_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void OTG_FS_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void DMA2_Stream5_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void DMA2_Stream6_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void DMA2_Stream7_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void USART6_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void I2C3_EV_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void I2C3_ER_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void OTG_HS_EP1_OUT_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void OTG_HS_EP1_IN_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void OTG_HS_WKUP_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void OTG_HS_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void DCMI_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void RNG_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void FPU_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void UART7_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void UART8_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void SPI4_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void SPI5_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void SPI6_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void SAI1_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void LTDC_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void LTDC_ER_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void DMA2D_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void SAI2_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void QUADSPI_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void LPTIM1_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void CEC_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void I2C4_EV_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void I2C4_ER_IRQHandler(void);
__attribute__((weak, alias("Default_Handler"))) void SPDIF_RX_IRQHandler(void);
extern int main(void);
extern void SystemInit(void);
extern void __stack(void);
extern unsigned _sidata;
extern unsigned _sdata;
extern unsigned _edata;
extern unsigned _sbss;
extern unsigned _ebss;
void Reset_Handler(void)
{
SystemInit();
memcpy(&_sdata, &_sidata, &_edata - &_sdata);
memset(&_sbss, 0, &_ebss - &_sbss);
main();
}
void Default_Handler(void)
{
/* Spin forever */
while(1) { }
}
void NMI_Handler(void) { while(1) { } }
void HardFault_Handler(void) { while(1) { } }
void MemManage_Handler(void) { while(1) { } }
void BusFault_Handler(void) { while(1) { } }
void UsageFault_Handler(void) { while(1) { } }
void SVC_Handler(void) { while(1) { } }
void DebugMon_Handler(void) { while(1) { } }
void PendSV_Handler(void) { while(1) { } }
void SysTick_Handler(void) { while(1) { } }
void __attribute__ ((section(".vectors"))) (*const vector_table[])(void) =
{
&__stack,
Reset_Handler,
NMI_Handler,
HardFault_Handler,
MemManage_Handler,
BusFault_Handler,
UsageFault_Handler,
0,
0,
0,
0,
SVC_Handler,
DebugMon_Handler,
0,
PendSV_Handler,
SysTick_Handler,
/* External Interrupts */
WWDG_IRQHandler,
PVD_IRQHandler,
TAMP_STAMP_IRQHandler,
RTC_WKUP_IRQHandler,
FLASH_IRQHandler,
RCC_IRQHandler,
EXTI0_IRQHandler,
EXTI1_IRQHandler,
EXTI2_IRQHandler,
EXTI3_IRQHandler,
EXTI4_IRQHandler,
DMA1_Stream0_IRQHandler,
DMA1_Stream1_IRQHandler,
DMA1_Stream2_IRQHandler,
DMA1_Stream3_IRQHandler,
DMA1_Stream4_IRQHandler,
DMA1_Stream5_IRQHandler,
DMA1_Stream6_IRQHandler,
ADC_IRQHandler,
CAN1_TX_IRQHandler,
CAN1_RX0_IRQHandler,
CAN1_RX1_IRQHandler,
CAN1_SCE_IRQHandler,
EXTI9_5_IRQHandler,
TIM1_BRK_TIM9_IRQHandler,
TIM1_UP_TIM10_IRQHandler,
TIM1_TRG_COM_TIM11_IRQHandler,
TIM1_CC_IRQHandler,
TIM2_IRQHandler,
TIM3_IRQHandler,
TIM4_IRQHandler,
I2C1_EV_IRQHandler,
I2C1_ER_IRQHandler,
I2C2_EV_IRQHandler,
I2C2_ER_IRQHandler,
SPI1_IRQHandler,
SPI2_IRQHandler,
USART1_IRQHandler,
USART2_IRQHandler,
USART3_IRQHandler,
EXTI15_10_IRQHandler,
RTC_Alarm_IRQHandler,
OTG_FS_WKUP_IRQHandler,
TIM8_BRK_TIM12_IRQHandler,
TIM8_UP_TIM13_IRQHandler,
TIM8_TRG_COM_TIM14_IRQHandler,
TIM8_CC_IRQHandler,
DMA1_Stream7_IRQHandler,
FMC_IRQHandler,
SDMMC1_IRQHandler,
TIM5_IRQHandler,
SPI3_IRQHandler,
UART4_IRQHandler,
UART5_IRQHandler,
TIM6_DAC_IRQHandler,
TIM7_IRQHandler,
DMA2_Stream0_IRQHandler,
DMA2_Stream1_IRQHandler,
DMA2_Stream2_IRQHandler,
DMA2_Stream3_IRQHandler,
DMA2_Stream4_IRQHandler,
ETH_IRQHandler,
ETH_WKUP_IRQHandler,
CAN2_TX_IRQHandler,
CAN2_RX0_IRQHandler,
CAN2_RX1_IRQHandler,
CAN2_SCE_IRQHandler,
OTG_FS_IRQHandler,
DMA2_Stream5_IRQHandler,
DMA2_Stream6_IRQHandler,
DMA2_Stream7_IRQHandler,
USART6_IRQHandler,
I2C3_EV_IRQHandler,
I2C3_ER_IRQHandler,
OTG_HS_EP1_OUT_IRQHandler,
OTG_HS_EP1_IN_IRQHandler,
OTG_HS_WKUP_IRQHandler,
OTG_HS_IRQHandler,
DCMI_IRQHandler,
0,
RNG_IRQHandler,
FPU_IRQHandler,
UART7_IRQHandler,
UART8_IRQHandler,
SPI4_IRQHandler,
SPI5_IRQHandler,
SPI6_IRQHandler,
SAI1_IRQHandler,
LTDC_IRQHandler,
LTDC_ER_IRQHandler,
DMA2D_IRQHandler,
SAI2_IRQHandler,
QUADSPI_IRQHandler,
LPTIM1_IRQHandler,
CEC_IRQHandler,
I2C4_EV_IRQHandler,
I2C4_ER_IRQHandler,
SPDIF_RX_IRQHandler,
};
#include <stdlib.h>
#include <stdio.h>
extern void initialise_monitor_handles(void);
int main(void)
{
initialise_monitor_handles();
printf("Hello world!\n");
return 0;
}
void SystemInit(void)
{
}
ENTRY(Reset_Handler)
__heap_size = 0x200;
__stack_size = 0x400;
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 320K
}
GROUP(
libgcc.a
libg.a
libc.a
libm.a
libnosys.a
librdimon.a
)
SECTIONS
{
/***********************************************************************************************/
/* VECTOR TABLE */
/***********************************************************************************************/
.vectors :
{
. = ALIGN(4);
KEEP(*(.vectors))
. = ALIGN(4);
} > FLASH
/***********************************************************************************************/
/* PROGRAM CODE */
/***********************************************************************************************/
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} > FLASH
/***********************************************************************************************/
/* CONSTANT DATA */
/***********************************************************************************************/
.rodata :
{
. = ALIGN(4);
__rodata_start__ = .;
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
__rodata_end__ = .;
} > FLASH
.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > FLASH
.ARM.exidx :
{
__exidx_start = .;
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
__exidx_end = .;
} > FLASH
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} > FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} > FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} > FLASH
_etext = .;
/***********************************************************************************************/
/* INITIALIZED DATA */
/***********************************************************************************************/
.data : ALIGN(4)
{
. = ALIGN(4);
_sidata = LOADADDR(.data);
_sdata = .;
__data_start__ = .;
*(.data)
*(.data*)
. = ALIGN(4);
_edata = .;
__data_end__ = .;
} > RAM AT > FLASH
/***********************************************************************************************/
/* UNINITIALIZED DATA */
/***********************************************************************************************/
.bss (NOLOAD) : ALIGN(4)
{
. = ALIGN(4);
PROVIDE(_sbss = .);
__bss_start__ = .;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
PROVIDE(_ebss = .); /* define a global symbol at bss end */
__bss_end__ = .;
} > RAM
/***********************************************************************************************/
/* USER HEAP */
/***********************************************************************************************/
.heap (NOLOAD) : ALIGN(4)
{
. = ALIGN(4);
PROVIDE(end = .);
__heap_start = .;
__heap_base__ = .;
. = . + __heap_size;
__heap_end = .;
__HeapLimit = .;
} > RAM
/***********************************************************************************************/
/* USER STACK */
/***********************************************************************************************/
.stack ORIGIN(RAM) + LENGTH(RAM) - __stack_size (NOLOAD) :
{
__stack_start = .;
__stack = .;
*(.stack)
. = . + __stack_size;
__stack_end = .;
__StackLimit = .;
} > RAM
/* Remove information from the standard libraries */
/*/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}*/
.ARM.attributes 0 : { *(.ARM.attributes) }
}
CC = arm-none-eabi-gcc
LD = arm-none-eabi-gcc
SIZE = arm-none-eabi-size
ARCHFLAGS = -mcpu=cortex-m7 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard
CFLAGS = -g -c -Wall -Werror -pedantic
LDFLAGS = --specs=rdimon.specs -lc -lrdimon -Wl,--gc-sections,-Map,main.map,-Tmemory.ld
SOURCES = main.c startup.c
OBJECTS = $(SOURCES:%.c=%.o)
main.elf: $(OBJECTS)
$(LD) $(ARCHFLAGS) $(LDFLAGS) -o $@ $(OBJECTS)
$(SIZE) --format=sysv -x $@
%.o: %.c
$(CC) $(ARCHFLAGS) $(CFLAGS) $< -o $@
clean:
rm -rf main.elf
rm -rf $(OBJECTS)
rm -rf main.map
file main.elf
target remote :2331
monitor reset
monitor halt
monitor speed auto
monitor flash device STM32F746NG
monitor semihosting enable
monitor semihosting IOclient 3
load
monitor reset