How To Solve these errors: error: "initializer element is not constant (void (*)(void))​((uint32_t​)&__STACK_​TOP)" and "error: (near initialization for 'g_pfnVectors[0]')"

8 views (last 30 days)
Hello;
I made a modification in a serial transmitt program in C and it works very well when I send to my Tiva C target from TI, but this program will be a part of a simulink program, so I need to insert the C code with a function block to simulink.
When I debug the code in Simulink I receive these errors:
Building with 'MinGW64 Compiler (C)'.
C:\Users\Alberto\Desktop\ENVIOS~1\startup_ccs.c:43:20: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
(void (*)(void))((uint32_t)&__STACK_TOP),
^
C:\Users\Alberto\Desktop\ENVIOS~1\startup_ccs.c:43:3: error: initializer element is not constant
(void (*)(void))((uint32_t)&__STACK_TOP),
^
C:\Users\Alberto\Desktop\ENVIOS~1\startup_ccs.c:43:3: error: (near initialization for 'g_pfnVectors[0]')
gmake: *** [startup_ccs.obj] Error -1
I don't understan the problem, because the code in C directly installed in the target works fine, but I was searching for days and I can't find the problem.
This is the C code:
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
#include "hw_ints.h"
#include "hw_memmap.h"
#include "debug.h"
#include "fpu.h"
#include "gpio.h"
#include "interrupt.h"
#include "pin_map.h"
#include "rom.h"
#include "sysctl.h"
#include "uart.h"
char car[2000];
double u;
void UARTSend2(const uint8_t *pui8Buffer, uint32_t ui32Count);
//*****************************************************************************
// Send a string to the UART.
void UARTSend2(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
ROM_FPUEnable(); // Enable lazy stacking for interrupt handlers. This allows floating-point
ROM_FPULazyStackingEnable(); // instructions to be used within interrupt handlers, but at the expense of extra stack usage.
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // Set the clocking to run directly from the crystal.
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Enable the GPIO port that is used for the on-board LED.
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); // Enable the GPIO pins for the LED (PF2).
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // Enable the peripherals used by this example.
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
ROM_IntMasterEnable(); // Enable processor interrupts.
GPIOPinConfigure(GPIO_PA0_U0RX); // Set GPIO A0 and A1 as UART pins.
GPIOPinConfigure(GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200, // Configure the UART for 115,200, 8-N-1 operation.
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
while(ui32Count--) // Loop while there are more characters to send.
{
ROM_UARTCharPutNonBlocking(UART0_BASE, *pui8Buffer++); // Write the next character to the UART.
}
}
//*****************************************************************************
// This example demonstrates how to send a string of data to the UART.
int
main(double u)
{
u=1234;
int cont=(log10(u))+6;
sprintf (car,"%.2f\r\n",u);
UARTSend2((uint8_t *) car,cont); // Prompt for text to be entered.
}
And this is the block of the code where Simulink notify the error in the file startup_ccs.c:
//*****************************************************************************
//
// External declaration for the interrupt handler used by the application.
//
//*****************************************************************************
//extern void UARTIntHandler(void);
//*****************************************************************************
//
// The vector table. Note that the proper constructs must be placed on this to
// ensure that it ends up at physical address 0x0000.0000 or at the start of
// the program if located at a start address other than 0.
//
//*****************************************************************************
#pragma DATA_SECTION(g_pfnVectors, ".intvecs")
void (* const g_pfnVectors[])(void) =
{
(void (*)(void))((uint32_t)&__STACK_TOP),
// The initial stack pointer
ResetISR, // The reset handler
NmiSR, // The NMI handler
FaultISR, // The hard fault handler
IntDefaultHandler, // The MPU fault handler
IntDefaultHandler, // The bus fault handler
IntDefaultHandler, // The usage fault handler
0, // Reserved
0, // Reserved
The code of this file it's very large so I only insert the part of the error.
Can you help me to solve it?
Thanks a lot
Regards Alberto

Answers (1)

Venkatachala Sarma
Venkatachala Sarma on 6 May 2016
Hi Alberto,
Are you using a MATLAB Function block to evaluate your c-code? Could you paste your MATLAB coder here?

Categories

Find more on Simulink Functions in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!