This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/CC2640R2F: CC2640R2F

Part Number: CC2640R2F


Tool/software: TI C/C++ Compiler

Hello!

I have 2 problems and asks for help.

The first problem i have - is a problem with a malloc function in my project based on simple peripheral.

This screenshot contains memory allocation of project. So i have about 7k ram

But when i try to allocate a 2048 bytes buffer using malloc - cc2640r2 just hangs. 

So i think that the heap size is small - is it possible to make it bigger? in app_ble_m3 file defines heap function 0x80.

And the second problem is the spi problem -

 

This is how i define hardware pins, and then i do 

volatile static PIN_Id chipselect_main;

bool ll_spi_init( PIN_Id chipselect, spi_device_e device_type )
{
bool result = false;
SPI_Params params = { 0 };

SPI_init();

switch (device_type)
{

case SPI_DAC:

SPI_Params_init(&params);
params.bitRate = 400000;
params.dataSize = 16;
params.frameFormat = SPI_POL0_PHA1;
params.mode = SPI_MASTER;

break;

case SPI_FLASH:

SPI_Params_init(&params);
params.bitRate = 100000;
params.dataSize = 8;
params.frameFormat = SPI_POL1_PHA1;//SPI_POL1_PHA1;
params.mode = SPI_MASTER;

break;

default:

break;

}

spiHandle = SPI_open(SPI_BUS_NUM, &params);

if (spiHandle != NULL) {
result = true;
}
chipselect_main = chipselect;
SPI_control(spiHandle, SPICC26XXDMA_SET_CSN_PIN, &chipselect_main);

return result;
}

If i do this instantly after i2c init

bool ll_i2c_init( void )
{
bool result = false;
I2C_Params params = {0};

I2C_init();
I2C_Params_init( &params );
params.bitRate = I2C_100kHz;

i2cHandle = I2C_open( I2C_BUS_NUM, &params );
if (i2cHandle != NULL) {
result = true;
}

return result;
}

then i sometimes have problems - cc2640r2 hangs too:(

and not instantly after spi open.

Best regards, Dmitrity.

  • Hi,

    Assigning this to an expert.

  • Hi Dmitriy,

    1) Regarding the Heap:

    - RAM is used for the heap and also various stacks. Since you are using auto-heap size (heap function 0x80.) the heap size is set by the linker, so the heap will not show up as an object in memory view. You can check you heap size using the instructions here:

     

    - The API for using the heap is ICall_malloc(). (Please double-check yo are not using ICall_mallocMsg or other APIs.)

    - Always check that the malloc is successful 

     // Allocate Memory
      uint32_t *myPtr = ICall_malloc(500);
    
      // Check that the malloc was successful
      if( NULL != myPtr)
      {
        *myPtr = 42;
      }

    2) Can you post some more info about what happens when the device hangs? 

    - How does the call stack look?

    - What SPI mode are you in?

    - Did you check ROV for exceptions?

  • Hello Marie!

    Thank you for your answer and sorry for my long time reply:)

    1) About heap - i've already changed all my malloc cals in programm to static buffers and it works, but i tryied to test ICall and there is what i get:

    when i use ical_malloc(2000) it returns zero, but if i compile and start programm with initialized uint8_t buffer[2000] it even doesn't start now. ROV don't say anything about heap "no data to disply". So i think i really have a little free RAM, is it? 

    If i change size from 2000 to 50 - it would work with static buffer and would not work with malloced buffer( the result of ICall_malloc would not be zero ), i mean it hangs in case of malloc.

    2) This is very strange thing.. If i initialize and open spi for work with flash, do some operations and then some time later start constructed clock - the programm just hangs, if i do nothing with flash at the beging and operate with it some time later and after that start earlier constructed clock - all is ok.

    Spi mode is blocking, transfer timeout is 10000.

    ROV is very intersting thing, thank you - haven't use it before.

    ROV says that stack of my SimplePeripheral_taskFxn is full.

    Blocked  SimplePeripheral_taskFxn 0x0 0x0 640 640
    And exception is stackpeak overrun. So as i understand - i have to change stack size of app task ? Where can i do that?

    And i have a questions about spi - is it ok to call SPI_init at the beging of my task(my task is inside simple_peripheral, called by SBP_PERIODIC_EVT_PERIOD ) and then do spi_open and spi_close many times, switching spi options between dac case and flash case? Becouse i have to work with them two on one physical SPI with different chip selects and different spi options.

    And the last question - i can't restart programm while in debug mode, so i need to stop debugging and then start again, flashing the whole programm inside chip - is it ok?

    Thank you very much for help - it's really great!

    Best regards, Dmitriy.

  • I've changed the stack size to 1024 and now there is no strange problem with hanging after clock starting i spoke aboute in previous reply. Thanks with this part!

    As i can see through ROV BIOS_raw the actual heap size is 4096 bytes

    And this is what heap says . Do i have any heap problems?

    If i try to create another buffer of 2000 bytes - the programm doesnt start and there is no exceptions. ICall_malloc can't allocate such amounts too..

    oh, Marie, do you know how many free heap\ram simple-peripheral example has?

  • Hi Dmitriy,

    That's good to hear!

    You can read all about the ICall heap and how to debug and determine the size here:

     

  • Hello!

    Thank you, but now i have a real big problem - after i increase stack size from 644 to 1000 - i can't anymore use bluetooth, it even doesn't connect... I mean that when i tap connect through ble scanner app, or from windows desktop app  -  nothing happens, ble applications waits forever. 

    If i change in SDK icall stack size from 1000 to 822 and my application stack size from 644 to 822 ( so 1644 is the sum of stack size for both of them ) - ble works and application works, but only with ble 5. I use ble 4.2 stack - and if i try to connect from phone with 4.2 ble - it can't connect like i write upper. Yearlier all my devices with ble 4.2 and 5 could connect, with that fix only 5 can..

    What may i do with it? Why if i increase application stack size and don't decrease icall stack size bluetooth stopping to work properly? 

    Best regards, Dmitriy.

  • Hi Dmitry,

    Sorry for the late answer.

    Are you using auto heap? In this case, any time you increase the task stack sizes, the heap will decrease... I would guess this means you run out of heap. If your problem is that you are running out of SRAM, you can take a look at this app note:

  • Thank you! The problem was in ram, so i give cache to ram and it works.


    Best regards, Dmitriy.