Im using the following code to evaluate the CC3135 on a STM32L4 controller.
auto result = sl_Start(nullptr, nullptr, nullptr);
int ctr = 0;
while (true) {
printf("%d\r\n", ctr++);
const auto sockid = sl_Socket(SL_AF_INET, SL_SOCK_STREAM, 0);
constexpr SlTimeval_t timeVal{ 20, 0 };
auto sockOptSetResult = sl_SetSockOpt(sockid, SL_SOL_SOCKET, SL_SO_RCVTIMEO, &timeVal, sizeof(timeVal));
if (sockOptSetResult != 0) {
printf("Failed to set timeout\r\n");
sl_Close(sockid);
sl_Stop(0xFFFF);
sl_Start(nullptr, nullptr, nullptr);
ThisThread::sleep_for(1000);
continue;
}
constexpr SlSockNonblocking_t enableOption{ 1 };
sockOptSetResult = sl_SetSockOpt(sockid, SL_SOL_SOCKET, SL_SO_NONBLOCKING, (_u8 *)&enableOption, sizeof(enableOption));
if (sockOptSetResult != 0) {
printf("Failed to set nonblocking\r\n");
ThisThread::sleep_for(1000);
NVIC_SystemReset();
}
SlSockAddrIn_t addr;
addr.sin_family = SL_AF_INET;
addr.sin_port = sl_Htons(8888);
addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(192, 168, 42, 130));
result = SLNETERR_BSD_EALREADY;
constexpr auto POLL_INTERVAL = 10;
constexpr auto MAX_POLL = 1000;
for (int i = 0; i < MAX_POLL && result == SLNETERR_BSD_EALREADY; i++) {
result = sl_Connect(sockid, reinterpret_cast<SlSockAddr_t *>(&addr), sizeof(SlSockAddrIn_t));
ThisThread::yield();
if (result < 0) {
ThisThread::sleep_for(POLL_INTERVAL);
}
}
if (result < 0) {
printf("Failed to connect %d\n", result);
sl_Close(sockid);
continue;
}
constexpr auto BUFFER_SIZE = 1460;
static char buffer[BUFFER_SIZE];
std::transform(std::begin(buffer), std::end(buffer), std::begin(buffer),
[](char) -> char { return static_cast<char>(std::rand()); });
for (int i = 0; i < 1000; i++) {
result = SLNETERR_BSD_EAGAIN;
for (int k = 0; k < MAX_POLL && result == SLNETERR_BSD_EAGAIN; k++) {
result = sl_Send(sockid, buffer, sizeof(buffer), 0);
ThisThread::yield();
if (result != sizeof(buffer)) {
ThisThread::sleep_for(POLL_INTERVAL);
}
}
if (result < 0) {
printf("Failed to send%d\n", result);
NVIC_SystemReset();
}
}
result = sl_Close(sockid);
if (result != 0) {
printf("Close failed %d\r\n", result);
}
printf("done\r\n");
}
It usually runs for a few iterations and then throws a "FATAL ERROR: No Cmd Ack detected [cmd opcode = 0x9401]" and stops working. sl_SetSockOpt() would fail in the next iteration which would restart the module, by calling sl_Stop and sl_Start. According to the documentation this should fix the issue, but it does not. In the next iteration it would connect to AP and get IP via DHCP but again fail with the same error. In most of these cases sl_Close does return 0, but in a few rare cases it returns -2005. I only encounter this error when i try to close the socket, if i were to continuously send data it works fine.
