LPCOPEN compilation error

cancel
Showing results for 
Search instead for 
Did you mean: 

LPCOPEN compilation error

402 Views
Contributor I

Good Morning!

I am migrating my project from CMSIS to LPCOPEN and I am having compilation problems with function "caddr_t _sbrk(int incr)". I am using LPC1768FBD100 chip.

Follow function:

#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>

caddr_t _sbrk(int incr)
{

extern char _pvHeapStart; /* Defined by the linker */
static char *heap_end;
char *prev_heap_end;
register char *stack_ptr __asm ("sp");

if (heap_end == 0)
{
heap_end = &_pvHeapStart;
}

prev_heap_end = heap_end;

if (heap_end + incr > stack_ptr)
{
errno = ENOMEM;

return (caddr_t)-1;
}

heap_end += incr;

return (caddr_t)prev_heap_end;

}

When I compile the project using CMSIS everything is ok,

Invoking: MCU C Compiler
arm-none-eabi-gcc -D__USE_CMSIS -D__CODE_RED -D__NEWLIB__ -I"../inc" -I"C:\Alvaro\thyssen\Workspace_alopes_MFG040029\depot\Drivers\LPC17xx\CMSIS_LPC17xx\inc" -I"C:\Alvaro\thyssen\Workspace_alopes_MFG040029\depot\Drivers\LPC17xx\Drivers_LPC17xx\inc" -O0 -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -mcpu=cortex-m3 -mthumb -D__NEWLIB__ -MMD -MP -MF"src/system.d" -MT"src/system.o" -MT"src/system.d" -o"src/system.o" "../src/system.c"
Finished building: ../src/system.c

but when I compile using lpcopen I have the follow compilation error:

Invoking: MCU C Compiler
arm-none-eabi-gcc -std=gnu99 -D__REDLIB__ -DDEBUG -D__CODE_RED -D__USE_LPCOPEN -D__LPC175X_6X__ -DUSB_HOST_ONLY -DCORE_M3 -I"C:\Alvaro\thyssen\Workspace_alopes_MFG040029\depot\Modulos\lpc_chip_175x_6x\inc" -I"C:\nxp\LPCXpresso_8.0.0_526\lpcxpresso\tools\lib\gcc\arm-none-eabi\4.9.3\include-fixed" -I"C:\nxp\LPCXpresso_8.0.0_526\lpcxpresso\tools\arm-none-eabi\include" -I"C:\nxp\LPCXpresso_8.0.0_526\lpcxpresso\tools\lib\gcc\arm-none-eabi\4.9.3\include" -I"C:\Alvaro\thyssen\Workspace_alopes_MFG040029\depot\Modulos\lpc_board_nxp_lpcxpresso_1769\inc" -I"C:\Alvaro\thyssen\Workspace_alopes_MFG040029\depot\Modulos\VOX5\VOX5\code\inc" -I"C:\Alvaro\thyssen\Workspace_alopes_MFG040029\depot\Modulos\VOX5\VOX5\lpcusblib\Drivers\USB" -I"C:\Alvaro\thyssen\Workspace_alopes_MFG040029\depot\Modulos\VOX5\VOX5\fatfs\inc" -O0 -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -mcpu=cortex-m3 -mthumb -specs=redlib.specs -MMD -MP -MF"code/src/main.d" -MT"code/src/main.o" -MT"code/src/main.d" -o "code/src/main.o" "../code/src/main.c"
../code/src/main.c:154:1: error: function '__errno' is initialized like a variable
int errno=0;
^
../code/src/main.c: In function '_sbrk':
../code/src/main.c:1080:8: error: 'errno' undeclared (first use in this function)
errno = ENOMEM;

In my file .c there is other functions that are using errno and not generate compilation erros.

Regards!

0 Kudos
2 Replies

1 View
NXP Employee
NXP Employee

The IDE"s built in libraries provide the _sbrk() function. You generally should not need to provide your own.

Aside : you may find this FAQ useful : https://community.nxp.com/message/630622 

Regards,

LPCXpresso Support

0 Kudos

1 View
Contributor I

Good Morning!

Where can I find the prototype of this function (_sbrk)?

When I search in my workspace project for this function, there is 0 results for this.

I am trying migrating other funcions (system calls) :

int _close(int file)
void _exit(int status)
int _fstat(int file, struct stat *st)
int _getpid(void)
int _isatty(int file)
int _kill(int pid, int sig)
int _lseek(int file, int ptr, int dir)
int _open(char *name, int flags, int mode)
int _read(int file, char *ptr, int len)
int _stat(char *file, struct stat *st)
int _unlink(char *name)
int _write(int file, char *ptr, int len)

I am doing this because, for example, when I use fopen, I need that this function, open a file from External Flash(using SPI) that have your own functions like write, read, status, etc.

How do I direct all these file handling functions to the SPI interface?

For make this happen I create a function _open that provide this action.

Regards!

0 Kudos