Hi everyone,
I am developing a remote control using nRF52832 chip. My prototype is currently developed in PC10040 board. The IDE is Eclipse Oxygen, and the SDK is S132 v5.0.0.
I am trying to create an application using BLE which running on the freertos. My problem now is that when the program start running, it seems to be locked at the beginning because of lack of memory.
Below is the main function code:
int main(void)
{
/*
* Config hardware peripherals
*/
ConfigSystem();
UARTFlush();
/*
* Config FreeRTOS
*/
xTaskCreate(TaskTest1, "Test Task 1", 100, NULL, 1, NULL);
xTaskCreate(TaskTest2, "Test Task 2", 100, NULL, 1, NULL);
xTaskCreate(TaskLog, "Log Task", 100, NULL, 1, NULL);
// Start FreeRTOS scheduler.
vTaskStartScheduler();
while(1)
{
}
}
void TaskLog(void * pvParameter)
{
while(1)
{
PrintDebug("Task log");
UARTFlush();
vTaskDelay(1);
}
}
void TaskTest1(void * pvParameter)
{
while(1)
{
PrintDebug("Task test 1");
UARTFlush();
vTaskDelay(1);
}
}
void TaskTest2(void * pvParameter)
{
while(1)
{
PrintDebug("Task test 2");
UARTFlush();
vTaskDelay(1);
}
}
And the following is the code for configuring the hardware periperals
void ConfigSystem()
{
// Config Log
ConfigLog(TX_PIN_NUMBER, RX_PIN_NUMBER, CTS_PIN_NUMBER, RTS_PIN_NUMBER, HWFC, UART_BAUDRATE_230400);
Print("\n\n\n");
PrintInfo("Headset for people with low vision project");
PrintAppInfo("Log Initialized!");
// Config SPI
// USE_SPI have to be defined if SPI is used
#ifdef USE_SPI
SPIConfig.SPIBase = SPI_BASE;
SPIConfig.pinCSN = CSN_PIN_NUMBER;
SPIConfig.pinSCK = SCK_PIN_NUMBER;
SPIConfig.pinMOSI = MOSI_PIN_NUMBER;
SPIConfig.pinMISO = MISO_PIN_NUMBER;
SPIConfig.role = SPI_ROLE;
SPIConfig.mode = SPI_MODE;
SPIConfig.order = SPI_BIT_ORDER;
SPIConfig.freq = SPI_MASTER_SPEED;
ConfigSPI(SPIConfig);
PrintAppInfo("SPI Master Initialized!");
#endif
// Config I2C
// USE_I2C have to be defined if I2C is used
#ifdef USE_I2C
I2CConfig.I2CBase = I2C_BASE;
I2CConfig.pinSCL = SCL_PIN_NUMBER;
I2CConfig.pinSDA = SDA_PIN_NUMBER;
I2CConfig.role = I2C_ROLE;
I2CConfig.frequency = I2C_MASTER_SPEED;
ConfigI2C(I2CConfig);
PrintAppInfo("I2C Master Initialized!");
#endif
//Config ADC
ADC_Channel_Configuration_t ADCChannelConfig;
ADCChannelConfig.ADCPosPin = ADC_PSELP_PIN;
ADCChannelConfig.ADCNegPin = ADC_PSELN_PIN;
ADCChannelConfig.resPinPos = ADC_RESISTOR_DISABLED;
ADCChannelConfig.resPinNeg = ADC_RESISTOR_PULLDOWN;
ADCChannelConfig.acqTime = ADC_ACQTIME_3US;
ADCChannelConfig.burst = ADC_BURST_DISABLED;
ADCChannelConfig.gain = ADC_GAIN_1_6;
ADCChannelConfig.mode = ADC_MODE_DIFF;
ADCChannelConfig.reference = ADC_REFERENCE_INTERNAL;
ConfigADCChannel(ADC_CHANNEL, ADCChannelConfig);
ADC_Configuration_t ADCConfig;
ADCConfig.resolution = ADC_RESOLUTION;
ADCConfig.samplerateMode = ADC_SAMPLERATE_MODE_TASK;
ADCConfig.oversample = ADC_OVERSAMPLE_DISABLED;
ADCConfig.buffer = &ADCBuffer;
ADCConfig.bufferAmount = 1;
ConfigADC(ADCConfig);
PrintAppInfo("ADC Initialized!");
// Config BLE and start advertising
ConfigBLE();
PrintAppInfo("BLE Initialized!");
// BLEStartAdvertising(BLE_ADV_MODE_FAST);
// PrintAppInfo("Start advertising");
BLEStartScanning();
PrintAppInfo("Start scanning");
UARTFlush();
// Config Power
ConfigPOWER();
PrintAppInfo("POWER Initialized!");
// Config CLOCK
ConfigCLOCK();
PrintAppInfo("CLOCK Initialized!");
// Config indicators (GPIO pins used for controlling LEDs and buttons)
ConfigIndicator();
PrintAppInfo("Indicator Initialized!");
// Get reset reason
uint32_t resetReason = POWERGetResetReason();
switch (resetReason) {
case POWER_RESETREAS_RESETPIN:
PrintAppInfo("Reset reason: Reset from pin-reset");
break;
case POWER_RESETREAS_DOG:
PrintAppInfo("Reset reason: Reset from watchdog");
break;
case POWER_RESETREAS_SREQ:
PrintAppInfo("Reset reason: Reset from soft reset");
break;
case POWER_RESETREAS_LOCKUP:
PrintAppInfo("Reset reason: Reset from from CPU lock-up");
break;
case POWER_RESETREAS_OFF:
PrintAppInfo("Reset reason:Reset due to wake up from System OFF mode when wakeup is triggered from DETECT signal from GPIO");
break;
case POWER_RESETREAS_LPCOMP:
PrintAppInfo("Reset reason: Reset due to wake up from System OFF mode when wakeup is triggered from ANADETECT signal from LPCOMP ");
break;
case POWER_RESETREAS_DIF:
PrintAppInfo("Reset reason: Reset due to wake up from System OFF mode when wakeup is triggered from entering into debug interface mode");
break;
case POWER_RESETREAS_NFC:
PrintAppInfo("Reset reason: Reset due to wake up from System OFF mode by NFC field detect");
break;
case POWER_RESETREAS_ONCHIP:
PrintAppInfo("Reset reason: power-on-reset or a brownout reset");
default:
break;
}
sd_power_reset_reason_clr(resetReason);
// delay a while for system to be ready
int i;
for(i = 0; i < 1000; i++)
;
PrintAppInfo("System initialization done!");
}
And the last is the piece of code for configuring the BLE
BLE_ERR_CODE_t ConfigBLE()
{
// Initialize.
db_discovery_init();
ble_stack_init();
services_init();
gatt_init();
return BLE_ERR_SUCCESS;
}
Thanks for reading.