sprintf problem in GCC RX MCU
sprintf problem in GCC RX MCU
We are trying to use sprintf function in our code but are facing problems.
In certain cases, the program execution goes into Undefined Exception or Reserved Exception.
System Conditions:
Toolchain: GCC for Renesas RX 4.8.4.201902-SP1-GNURX-ELF
MCU: RX1115 – R5F51115ADFN
IDE: e2Studio v7.6.0
Library Settings:
The following code Executes properly without any issues.
char A[50] = {};
sprintf(A,”%s”,”HelloBoyos!!!”);
The following code throws an Undefined Exception when executed
char A[50] = {};
sprintf(A,”%s%s”,”Hello”,”Boyos!!!”);
The following code, when executed goes to the following non-existent address
char A[50] = {};
sprintf(A,”%d”,12);
Are we doing something wrong or is this a bug?
Any assistance will be really useful and greatly appreciated.
Thanks in Advance.
Vikram.
Thanks NoMaY, a larger stack solved the problem!
I wonder why the wizard selected such a small stack although this MCU has 96 kB RAM.
So the _ustack goes from 0x7FF down to 0x400 and the _istack from 0x3ff to 0x00? Is this right?
Another question: Is there any ‘best practice’ to implement a heap with gcc? I read in the wiki a special _sbrk function for RX (newlib), but it references the undefined function __set_heaptop.
I think it’s really hard to make the MCU work with gcc, heap and stack. So I really would apprecriate a walkthrough what I have to modify for the GCC-RX toolchain to get it work.
Bye,
Oliver
Hi,
unfortunately, I have the same problem here, but with a different MCU and compiler. Using sprintf fires the “INT_Excep_UndefinedInst” exception handler when the code enters the line with sprintf. The array acces before works without problem and the array seems to be in the RAM section of the MCU.
MCU: RX62N on a YRDKRX62N with Segger jlink lite on board.
e2studio version: 7.8.0
GCC toolchain 8.3.0.202002-GNURX Windows
Everything compiles fine, the code skeleton is unmodified and created by the project wizard for this kind of MCU:
Pretty simple code:
#include <iodefine.h>
#include <stdio.h>
//Initialize global constructors
int main(void) {
char z[40];
z[0]=1;
z[1]=2;
z[2]=3;
sprintf(z,”%s”,”Hello Hello?”);
while(1)
{
// TODO: add application code here
}
return 0;
}
Linker script:
MEMORY
{
RAM : ORIGIN = 0x0, LENGTH = 98304
ROM : ORIGIN = 0xFFF80000, LENGTH = 524288
}
SECTIONS
{
.fvectors 0xFFFFFF80: AT(0xFFFFFF80)
{
KEEP(*(.fvectors))
} > ROM
.text 0xFFF80000: AT(0xFFF80000)
{
*(.text)
*(.text.*)
*(P)
etext = .;
} > ROM
.rvectors ALIGN(4):
{
_rvectors_start = .;
KEEP(*(.rvectors))
_rvectors_end = .;
} > ROM
.init :
{
KEEP(*(.init))
__preinit_array_start = .;
KEEP(*(.preinit_array))
__preinit_array_end = .;
__init_array_start = (. + 3) & ~ 3;
KEEP(*(.init_array))
KEEP(*(SORT(.init_array.*)))
__init_array_end = .;
__fini_array_start = .;
KEEP(*(.fini_array))
KEEP(*(SORT(.fini_array.*)))
__fini_array_end = .;
} > ROM
.fini :
{
KEEP(*(.fini))
} > ROM
.got :
{
*(.got)
*(.got.plt)
} > ROM
.rodata :
{
*(.rodata)
*(.rodata.*)
*(C_1)
*(C_2)
*(C)
_erodata = .;
} > ROM
.eh_frame_hdr :
{
*(.eh_frame_hdr)
} > ROM
.eh_frame :
{
*(.eh_frame)
} > ROM
.jcr :
{
*(.jcr)
} > ROM
.tors :
{
__CTOR_LIST__ = .;
. = ALIGN(2);
___ctors = .;
*(.ctors)
___ctors_end = .;
__CTOR_END__ = .;
__DTOR_LIST__ = .;
___dtors = .;
*(.dtors)
___dtors_end = .;
__DTOR_END__ = .;
. = ALIGN(2);
_mdata = .;
} > ROM
.ustack 0x200: AT(0x200)
{
_ustack = .;
} > RAM
.istack 0x100: AT(0x100)
{
_istack = .;
} > RAM
.data 0x204: AT(_mdata)
{
_data = .;
*(.data)
*(.data.*)
*(D)
*(D_1)
*(D_2)
_edata = .;
} > RAM
.gcc_exc :
{
*(.gcc_exc)
} > RAM
.bss :
{
_bss = .;
*(.bss)
*(.bss.**)
*(COMMON)
*(B)
*(B_1)
*(B_2)
_ebss = .;
_end = .;
} > RAM
}
Hi Vikram_FE, we’re looking into your issue and will reply as soon as we have an update.
Hello,
Thank you for reaching out to us!
Unfortunately, we were unable to reproduce the issue with a basic sample testcase.
Could you please send us a sample project in which the issue is reproducible in order to investigate? We encourage you to please open a private support ticket where you could attach the project.
__
Best regards,
The GNU Tools Team