Malloc Error

mikroC, mikroBasic and mikroPascal PRO for Microchip’s 32-bit PIC MCUs
Post Reply
Author
Message
Sheshebens
Posts: 3
Joined: 01 Jul 2021 15:36

Malloc Error

#1 Post by Sheshebens » 02 Jul 2021 10:19

I used Charger 9 Click and it's code copy from Changer 9 Click website,

I will show code,

void applicationTask()
{
rx_dat = UART_Rdy_Ptr();

if (rx_dat != 0)
{
rx_dat = UART_Rd_Ptr();

switch (rx_dat)
{
case 'e' :
{
if (en_flag == _CHARGER9_DISABLE)
{
charger9_enable( _CHARGER9_ENABLE );
en_flag = _CHARGER9_ENABLE;

mikrobus_logWrite( "** Charger 9 is enabled **", _LOG_LINE );
alarmOn();
}
else
{
mikrobus_logWrite( "** Charger 9 is already enabled **", _LOG_LINE );
}
break;
}
case 'd' :
{
if (en_flag == _CHARGER9_ENABLE)
{
charger9_enable( _CHARGER9_DISABLE );
en_flag = _CHARGER9_DISABLE;

mikrobus_logWrite( "** Charger 9 is disabled **", _LOG_LINE );
alarmOff();
}
else
{
mikrobus_logWrite( "** Charger 9 is already disabled **", _LOG_LINE );
}
break;
}
case 's' :
{
charge_state = charger9_fullChargeInd();

if (charge_state == _CHARGER9_IND_ACTIVE)
{
mikrobus_logWrite( "** Full-Charge state **", _LOG_LINE );
}

charge_state = charger9_fastChargeInd();

if (charge_state == _CHARGER9_IND_ACTIVE)
{
mikrobus_logWrite( "** Fast-Charge state **", _LOG_LINE );
}
break;
}
case 'l' :
{
writeLegend();
break;
}
default :
{
mikrobus_logWrite( "** Invalid command **", _LOG_LINE );
writeLegend();
break;
}
}
}

charge_state = charger9_faultInd();

if (charge_state == _CHARGER9_IND_ACTIVE)
{
charger9_enable( _CHARGER9_DISABLE );
en_flag = _CHARGER9_DISABLE;

mikrobus_logWrite( "** Fault condition! **", _LOG_LINE );
mikrobus_logWrite( "** Charger 9 is disabled **", _LOG_LINE );
alarmFault();
}
}

When I used code I encountered error.

Error name:4622 393 'malloc' Identifier redefined __Lib_dlmalloc.c
How can I solve this problem.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Malloc Error

#2 Post by filip » 07 Jul 2021 07:52

Hi,

Can you please attach the entire example in ZIP or RAR archive so I can reproduce this issue ?

Regards,
Filip.

Sheshebens
Posts: 3
Joined: 01 Jul 2021 15:36

Re: Malloc Error

#3 Post by Sheshebens » 12 Jul 2021 09:03

I found full code in microC PRO for PIC32/Packages/Chargers 9 Click/Examples/PIC32 and,Charges code is;

/*
Example for Charger_9 Click

Date : Mar 2019.
Author : Nemanja Medakovic

Test configuration PIC32 :

MCU : P32MX795F512L
Dev. Board : EasyPIC Fusion v7
PIC32 Compiler ver : v4.0.0.0

---

Description :

The application is composed of three sections :

- System Initialization - Initializes peripherals and pins.
- Application Initialization - Initializes GPIO driver and turns OFF the charger as initial state.
- Application Task - (code snippet) - Checks which command was sent by user and performs the selected command.
Also checks the fault condition, and when fault condition is detected sends a report message to the uart terminal
and turns OFF the charger.
Note: When user sends a desired command to the charger, a report message will be sent to the uart terminal as
indication to the user.
The possible commands, for Charger 9 control, will be written to the uart terminal.
The alarm sound will be generated on the determined commands: enable, disable and fault condition detecting.

Additional Functions :

- alarmOn - Generates an alarm sound for charger power ON.
- alarmOff - Generates an alarm sound for charger power OFF.
- alarmFault - Generates an alarm sound for fault condition.
- writeLegend - Writes possible valid commands to the uart terminal.

*/

#include "Click_Charger_9_types.h"

char rx_dat;
T_CHARGER9_STATE en_flag;
T_CHARGER9_RETVAL charge_state;

void alarmOn()
{
Sound_Play( 800, 50 );
Delay_ms( 50 );
Sound_Play( 1000, 50 );
Delay_ms( 50 );
Sound_Play( 1200, 50 );
Delay_ms( 50 );
}

void alarmOff()
{
Sound_Play( 1200, 50 );
Delay_ms( 50 );
Sound_Play( 1000, 50 );
Delay_ms( 50 );
Sound_Play( 800, 50 );
Delay_ms( 50 );
}

void alarmFault()
{
Sound_Play( 900, 50 );
Delay_ms( 50 );
Sound_Play( 900, 50 );
Delay_ms( 50 );
Sound_Play( 900, 50 );
Delay_ms( 50 );
}

void writeLegend()
{ /*
mikrobus_logWrite( "***********************************", _LOG_LINE );
mikrobus_logWrite( "** Commands Legend **", _LOG_LINE );
mikrobus_logWrite( "***********************************", _LOG_LINE );
mikrobus_logWrite( "e - to enable Charger 9", _LOG_LINE );
mikrobus_logWrite( "d - to disable Charger 9", _LOG_LINE );
mikrobus_logWrite( "s - to check charging state", _LOG_LINE );
mikrobus_logWrite( "l - to see commands legend", _LOG_LINE );
mikrobus_logWrite( "***********************************", _LOG_LINE ); */
}

void systemInit()
{
mikrobus_gpioInit( _MIKROBUS1, _MIKROBUS_INT_PIN, _GPIO_INPUT );
mikrobus_gpioInit( _MIKROBUS1, _MIKROBUS_PWM_PIN, _GPIO_INPUT );
mikrobus_gpioInit( _MIKROBUS1, _MIKROBUS_AN_PIN, _GPIO_INPUT );
mikrobus_gpioInit( _MIKROBUS1, _MIKROBUS_RST_PIN, _GPIO_OUTPUT );

mikrobus_logInit( _LOG_USBUART_A, 57600 );
mikrobus_logWrite( "*** Initializing... ***", _LOG_LINE );

Delay_ms( 100 );
}

void applicationInit()
{
charger9_gpioDriverInit( (T_CHARGER9_P)&_MIKROBUS1_GPIO );
Sound_Init( &PORTD, 3 );

charger9_enable( _CHARGER9_DISABLE );
en_flag = _CHARGER9_DISABLE;
Delay_ms( 100 );

mikrobus_logWrite( "** Charger 9 initialization done **", _LOG_LINE );
writeLegend();
}

void applicationTask()
{
rx_dat = UART_Rdy_Ptr();

if (rx_dat != 0)
{
rx_dat = UART_Rd_Ptr();

switch (rx_dat)
{
case 'e' :
{
if (en_flag == _CHARGER9_DISABLE)
{
charger9_enable( _CHARGER9_ENABLE );
en_flag = _CHARGER9_ENABLE;

mikrobus_logWrite( "** Charger 9 is enabled **", _LOG_LINE );
alarmOn();
}
else
{
mikrobus_logWrite( "** Charger 9 is already enabled **", _LOG_LINE );
}
break;
}
case 'd' :
{
if (en_flag == _CHARGER9_ENABLE)
{
charger9_enable( _CHARGER9_DISABLE );
en_flag = _CHARGER9_DISABLE;

mikrobus_logWrite( "** Charger 9 is disabled **", _LOG_LINE );
alarmOff();
}
else
{
mikrobus_logWrite( "** Charger 9 is already disabled **", _LOG_LINE );
}
break;
}
case 's' :
{
charge_state = charger9_fullChargeInd();

if (charge_state == _CHARGER9_IND_ACTIVE)
{
mikrobus_logWrite( "** Full-Charge state **", _LOG_LINE );
}

charge_state = charger9_fastChargeInd();

if (charge_state == _CHARGER9_IND_ACTIVE)
{
mikrobus_logWrite( "** Fast-Charge state **", _LOG_LINE );
}
break;
}
case 'l' :
{
writeLegend();
break;
}
default :
{
mikrobus_logWrite( "** Invalid command **", _LOG_LINE );
writeLegend();
break;
}
}
}

charge_state = charger9_faultInd();

if (charge_state == _CHARGER9_IND_ACTIVE)
{
charger9_enable( _CHARGER9_DISABLE );
en_flag = _CHARGER9_DISABLE;

mikrobus_logWrite( "** Fault condition! **", _LOG_LINE );
mikrobus_logWrite( "** Charger 9 is disabled **", _LOG_LINE );
alarmFault();
}
}

void main()
{
systemInit();
applicationInit();

while (1)
{
applicationTask();
}
}

When I write logs,I have three problem,

1-microbus_gpioinit=88 324 Undeclared identifier 'mikrobus_gpioInit' in expression Click_Charger_9_PIC32.c
2-microbus_logInit=93 324 Undeclared identifier 'mikrobus_logInit' in expression Click_Charger_9_PIC32.c
3-microbus_logWrite=94 324 Undeclared identifier 'mikrobus_logWrite' in expression Click_Charger_9_PIC32.c

These are problems,so how can ı solve these problems,and mikrobus_logWrite( "** Charger 9 is disabled **", _LOG_LINE ); How can I write logs input or output can you give me examples,for examp;

mikrobus_logWrite( "** Charger 9 is disabled **", _LOG_LINE );-----what if my code look like mikrobus_logWrite( 21, _LOG_LINE ); 21 is pin number.What will happened.Is it wrong description

Post Reply

Return to “PIC32 PRO Compilers”