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.

BOOSTXL-CC3135: sl_Start() returns 1 and sl_Stop() stuck in a loop while other function like sl_WlanSetMode() works with wired response

Part Number: BOOSTXL-CC3135
Other Parts Discussed in Thread: CC3135, UNIFLASH, CC3100SDK, CC3100, CC3120

Hello. I am trying to use CC3135 using STM32f103 (Nucleo board) by porting SimpleLink CC3100SDK 1.3.0. I have uploaded the service pack 4.1.0.28_3.1.0.5_3.1.0.17 (most recent version) through Uniflash.

During porting the SDK, I replaced the SPI related function (spi_open, read, write, close) based on the pre-defined function like MX_SPI_Init(), MX_GPIO_Init() through CUBEmx. Furthermore, I have added needed event handlers and functions to deal with the interrupt signal from the IRQ pin from the CC3135.

Problems are the return value of sl_Start is always 1 (ROLE_UNKNOWN) and the program get stuck at the 'SL_DRV_SYNC_OBJ_WAIT_TIMEOUT' when I call sl_Stop(). In the case of sl_Stop, if I call the sl_Stop(0), then it does not get stuck.

The wired point is that, if I set the AP mode to the CC3135 using sl_WlanSetModeI(ROLE_AP), zero is returned and I can search the AP in my cell phone or laptop. This AP can be appeared and disappeared on my cell phone when I call sl_start and sl_Stop(0), repeatedly.

Also, if I called the sl_NetCFgGet to get the MAC address of the CC3135, it returns 0 which shows there is no problem during the command. However, the returned MAC address (macAddressVal[]) were 0x3, 0x34, 0x0, 0x6, 0x0, 0x0 which cannot be believed as the MAC address.

I doubt that my MCU (STM32F103) may not be able to read proper data through SPI, is it correct?

I wonder what I can solve these problems.

Source code: main.c

/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "simplelink.h"
#include "sl_common.h"
#include "user.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
SPI_HandleTypeDef hspi2;

TIM_HandleTypeDef htim1;

UART_HandleTypeDef huart2;

/* USER CODE BEGIN PV */

#define ASSERT_CS() (HAL_GPIO_WritePin(SPI2_CS_GPIO_Port, SPI2_CS_Pin, GPIO_PIN_RESET))
#define DEASSERT_CS() (HAL_GPIO_WritePin(SPI2_CS_GPIO_Port, SPI2_CS_Pin, GPIO_PIN_SET))

#define SPI_TIMEOUT_MAX 0x1000

#define SCAN_TABLE_SIZE 20
#define SCAN_INTERVAL 10


P_EVENT_HANDLER pIrqEventHandler = 0;
Sl_WlanNetworkEntry_t netEntries[SCAN_TABLE_SIZE];

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
static void MX_SPI2_Init(void);
static void MX_TIM1_Init(void);
/* USER CODE BEGIN PFP */
static _i32 initializeAppVariables();
static _i32 establishConnectionWithAP();
/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
_u32 g_Status = 0;
_u32 g_PingPacketsRecv = 0;
_u32 g_GatewayIP = 0;
/* USER CODE END 0 */

/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */
SystemClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_SPI2_Init();
MX_TIM1_Init();
/* USER CODE BEGIN 2 */

int retVal = 0;

retVal = sl_Start(0, 0, 0);
retVal = sl_WlanSetMode(ROLE_AP);
retVal = sl_Stop(0);

retVal = sl_Start(0, 0, 0);

_u8 macAddressVal[SL_MAC_ADDR_LEN];
_u8 macAddressLen = SL_MAC_ADDR_LEN;
sl_NetCfgGet(SL_MAC_ADDRESS_GET,NULL,&macAddressLen,(_u8 *)macAddressVal);


/* USER CODE END 2 */

/* Infinite loop */
/* USER CODE BEGIN WHILE */

while (1)
{
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}

/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
}

/**
* @brief SPI2 Initialization Function
* @param None
* @retval None
*/
static void MX_SPI2_Init(void)
{

/* USER CODE BEGIN SPI2_Init 0 */

/* USER CODE END SPI2_Init 0 */

/* USER CODE BEGIN SPI2_Init 1 */

/* USER CODE END SPI2_Init 1 */
/* SPI2 parameter configuration*/
hspi2.Instance = SPI2;
hspi2.Init.Mode = SPI_MODE_MASTER;
hspi2.Init.Direction = SPI_DIRECTION_2LINES;
hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi2.Init.NSS = SPI_NSS_SOFT;
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi2.Init.CRCPolynomial = 10;
if (HAL_SPI_Init(&hspi2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI2_Init 2 */

/* USER CODE END SPI2_Init 2 */

}

/**
* @brief TIM1 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM1_Init(void)
{

/* USER CODE BEGIN TIM1_Init 0 */

/* USER CODE END TIM1_Init 0 */

TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_SlaveConfigTypeDef sSlaveConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};

/* USER CODE BEGIN TIM1_Init 1 */

/* USER CODE END TIM1_Init 1 */
htim1.Instance = TIM1;
htim1.Init.Prescaler = 64;
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
htim1.Init.Period = 0;
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.RepetitionCounter = 0;
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
sSlaveConfig.SlaveMode = TIM_SLAVEMODE_DISABLE;
sSlaveConfig.InputTrigger = TIM_TS_ITR0;
if (HAL_TIM_SlaveConfigSynchro(&htim1, &sSlaveConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM1_Init 2 */
/* USER CODE END TIM1_Init 2 */

}

/**
* @brief USART2 Initialization Function
* @param None
* @retval None
*/
static void MX_USART2_UART_Init(void)
{

/* USER CODE BEGIN USART2_Init 0 */

/* USER CODE END USART2_Init 0 */

/* USER CODE BEGIN USART2_Init 1 */

/* USER CODE END USART2_Init 1 */
huart2.Instance = USART2;
huart2.Init.BaudRate = 115200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART2_Init 2 */

/* USER CODE END USART2_Init 2 */

}

/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};

/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, CC_nHIB_Pin|SPI2_CS_Pin, GPIO_PIN_SET);

/*Configure GPIO pin : B1_Pin */
GPIO_InitStruct.Pin = B1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);

/*Configure GPIO pin : LD2_Pin */
GPIO_InitStruct.Pin = LD2_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);

/*Configure GPIO pin : CC_EXTI_Pin */
GPIO_InitStruct.Pin = CC_EXTI_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
HAL_GPIO_Init(CC_EXTI_GPIO_Port, &GPIO_InitStruct);

/*Configure GPIO pins : CC_nHIB_Pin SPI2_CS_Pin */
GPIO_InitStruct.Pin = CC_nHIB_Pin|SPI2_CS_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI2_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(EXTI2_IRQn);

HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);

}

/* USER CODE BEGIN 4 */

void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent)
{
/*
* Most of the general errors are not FATAL are are to be handled
* appropriately by the application
*/
}

void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *pHttpEvent,
SlHttpServerResponse_t *pHttpResponse)
{
/*
* This application doesn't work with HTTP server - Hence these
* events are not handled here
*/
}

void SimpleLinkSockEventHandler(SlSockEvent_t *pSock)
{
/*
* This application doesn't work w/ socket - Hence not handling these events
*/

}

void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent)
{
if(pNetAppEvent == NULL)
{

return;
}

switch(pNetAppEvent->Event)
{
case SL_NETAPP_IPV4_IPACQUIRED_EVENT:
{
SlIpV4AcquiredAsync_t *pEventData = NULL;

SET_STATUS_BIT(g_Status, STATUS_BIT_IP_ACQUIRED);

pEventData = &pNetAppEvent->EventData.ipAcquiredV4;
g_GatewayIP = pEventData->gateway;
}
break;

default:
{

}
break;
}
}

void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent)
{
if(pWlanEvent == NULL)
{

return;
}

switch(pWlanEvent->Event)
{
case SL_WLAN_CONNECT_EVENT:
{
SET_STATUS_BIT(g_Status, STATUS_BIT_CONNECTION);

/*
* Information about the connected AP (like name, MAC etc) will be
* available in 'slWlanConnectAsyncResponse_t' - Applications
* can use it if required
*
* slWlanConnectAsyncResponse_t *pEventData = NULL;
* pEventData = &pWlanEvent->EventData.STAandP2PModeWlanConnected;
*
*/
}
break;

case SL_WLAN_DISCONNECT_EVENT:
{
slWlanConnectAsyncResponse_t* pEventData = NULL;

CLR_STATUS_BIT(g_Status, STATUS_BIT_CONNECTION);
CLR_STATUS_BIT(g_Status, STATUS_BIT_IP_ACQUIRED);

pEventData = &pWlanEvent->EventData.STAandP2PModeDisconnected;

/* If the user has initiated 'Disconnect' request, 'reason_code' is SL_USER_INITIATED_DISCONNECTION */
if(SL_WLAN_DISCONNECT_USER_INITIATED_DISCONNECTION == pEventData->reason_code)
{

}
else
{

}
}
break;

default:
{

}
break;
}
}

Fd_t spi_Open(char *ifName, unsigned long flags)
{
MX_SPI2_Init();

/* Initialize and disable the nHIB line */
CC3100_nHIB_init();
CC3100_disable();

Delay(50);
return 0;
}

int spi_Write (Fd_t fd, unsigned char *pBuff, int len)
{
ASSERT_CS();
HAL_SPI_Transmit(&hspi2, pBuff, len, SPI_TIMEOUT_MAX);
DEASSERT_CS();

return len;
}

int spi_Read(Fd_t fd, unsigned char *pBuff, int len)
{
ASSERT_CS();
HAL_SPI_Receive(&hspi2, pBuff, len, SPI_TIMEOUT_MAX);
DEASSERT_CS();

return len;
}

int spi_Close(Fd_t fd)
{
/* Disable Interrupt in GPIOA module... */
// CC3100_InterruptDisable();
HAL_Delay(100);
/* Deinitialize SPI */
HAL_SPI_DeInit(&hspi2);
HAL_Delay(100);
return 0;
}

void CC3100_nHIB_init()
{
MX_GPIO_Init();
}

void CC3100_disable()
{
HAL_GPIO_WritePin(CC_nHIB_GPIO_Port, CC_nHIB_Pin, 0);
}

void Delay(unsigned long delay)
{
HAL_Delay(delay);
}

int registerInterruptHandler(P_EVENT_HANDLER InterruptHdl , void* pValue)
{
pIrqEventHandler = InterruptHdl;
return 0;
}

void CC3100_enable()
{
HAL_GPIO_WritePin(CC_nHIB_GPIO_Port, CC_nHIB_Pin, 1);
}

unsigned long timer_GetCurrentTimestamp()
{
unsigned long timer_value = 0;

//Verify timer has been started by checking that the control register was set
if((TIM_CR1_CEN) != (((&htim1)->Instance->CR1) & (TIM_CR1_CEN)))
{
MX_TIM1_Init();
}

timer_value = __HAL_TIM_GET_COUNTER(&htim1);
return timer_value;
}

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(GPIO_Pin);
/* NOTE: This function Should not be modified, when the callback is needed,
the HAL_GPIO_EXTI_Callback could be implemented in the user file
*/

if((GPIO_Pin == CC_EXTI_Pin) &&
(NULL != pIrqEventHandler) )
{
pIrqEventHandler(0);
}


}


/* USER CODE END 4 */

/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */

/* USER CODE END Error_Handler_Debug */
}

#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

  • Hello,

    Now, I am debugging the program and let me leave what I found here.

    The read first 8 bytes from CC3135 in sl_Start() was 0xbc181400abcddcbc which includes the Sync word (Device to Host) as described in the wiki page. Therefore I may conclude that SPI communication between the host device (STM32F103) and the CC3135 works correctly. If I continue to debug, the value of AsyncRsp.Status was returned to 0x0, therefore, the role of CC3135 is shown as ROLE_UNKNOWN. 

  • Hi,

    What wiki page are you using?

    The issue you are reporting is very basic (sl_Start is the first command) so I'm still suspecting the host interface.

    I don't think the sl_Start command was changed between CC3100 and CC3135.

    Please try to compare the SPI data between a working CC3135 Plugin (ported to the STM) to your CC3100 porting.

    The SP you use is quite old (although this probably is not the problem). You can check the latest (SP_4.4.1.3... ) in the CC32XX SDK 3.30.

    Which version of Uniflash are you using to program the flash? 

     It is very recommended that you use to the CC3120/CC3135 plugin.

    Br,

    Kobi

  • Dear Kobi Leibovitch,

    I appreciate your kind help with my problem. The wiki page was about the CC3100 host interface (http://processors.wiki.ti.com/index.php/CC3100_Host_Interface)

    I got the solution and the 4 bytes of data right after 'header pattern (Sync + Opcode + Len)' was the problem.

    I suspect those patterns because only 2 bytes of returned MAC address were correct. Therefore, the problem was solved by adding the SPI_read for additional 4 bytes after reading the header pattern.

    Thank you!