Other Parts Discussed in Thread: CC2540, CC2541, CC2640
Hello everyone.
I am currently developing on CC2540. I have a custom board with a serial port peripheral and an SDCard reader peripheral. I have successfully developed serial port communication and BLE relay on my main project, and have a lot of logic there that is not easily portable.
Separately, on another project based on SimpleBLEPeripheral example, I have enabled SD-SPI communication using bit-banging (I enable SPI Master mode, initialize the card, and then set SPI to faster speeds). It's important to mention that I have commented out "SimpleBLEPeripheral_Init(uint8 task_id)" and "SimpleBLEPeripheral_ProcessEvent" for my tests, since I didnt need the functionality provided by the examples, just the testbench they provided. I then managed to get Chan's FatFS library working with this SD-SPI implementation (interfacing with mmc.h, more details here: http://elm-chan.org/fsw/ff/en/appnote.html).
I can do everything FatFS related, opens, reads, writes, seeks, etc, with the standard configurations and tiny option _disabled_, but I have limited the use of FatFS lib for my necessary constraints (I needed f_readdir and "above"). I can even format (f_mkfs) but I have disabled it since I don't need it. The card gets written, and everyhting works OK.
Now the problems arise when I uncomment SimpleBLEPeripheral_Init and associated event - when debugging, it passes the example's initialization (SimpleBLEPeripheral_Init), initializes SD-SPI with disk-initialize, but as soon as it reaches code that uses FatFS, specifically a global variable of type FATFS (a struct) essential for chan's lib, I'm getting XSTACK-IDATA overflows in the debugger. Sometimes the stacks just fill and cc2540 hangs, sometimes it goes into HAL_SYSTEM_RESET and keeps throwing me back to start of main(), sometimes I don't even know what's happening (although I always get debugger xdata full warnings after I break the debugger). To the best of my knowledge, it has something to do with the big 512 BYTE array in the FATFS-struct type global - "BYTE win[_MAX_SS]" (the sector map). The struct size amounts to a 560 bytes total instance, and I believe this is too much for the IDATA/XSTACK/RAM...
When I tried porting the code that initially worked to my main project, which also uses BLE functionalities like SimpleBLEPeripheral, I get similar results since it also works with my BLE code commented out, doesn't work with it uncommented.
So, what I don't get is why the device allows all related fatfs methods to work perfectly when not enabling BLE stuff, and does not allow it with the features on. I am 99% sure it's memory allocation issues (heap, stack, code size...), but maybe it has something to do with UART "collisions" as SimpleBLEPeripheral supposedly uses it for a peripheral not present in my board configuration. But I can't really debug anything after the stacks fill .
Can anyone shed a light on this issue?