4 Replies Latest reply on Feb 21, 2017 12:34 PM by azurkan

    Adding PUART functionality to mybeacon.c

    azurkan

      Hi there,

       

      I am trying to add PUART functionality to the mybeacon.c example without any luck.

      Hardware is a custom board equipped with a CYW20737S.

       

      My steps are as follows:

      • I started with the mybeacon-example as basic setup for my project. This compiles, downloads and works on my custom-hardware.
      • After this, I added devlpm_registerForLowPowerQueries and returning the associated callback with 0 to prevent the device going into sleep mode. This also works as I can see from the power consumption.
      • Next was to add UART functionality to the system. I implemented it the way describes in the Hardware-Interfaces-PDF provided with the SDK and adjusted the pins to my layout (RX = P2, TX = P32). Here the problems begin. I can´t receive and send anything using the UART, even if the device is awake.

       

      Am I missing somethhing? Is there more initialization to be done besides the steps outlined in the Hardware-Interfaces-PDF?

       

      My code is like this:

       

      //*****************************************************************************
      //
      //*****************************************************************************
      const BLE_PROFILE_PUART_CFG mybeacon_puart_cfg =
      {
          /*.baudrate   =*/ 115200,
          /*.txpin      =*/ 32,
          /*.rxpin      =*/ 2,
      };
      
      
      //*****************************************************************************
      //
      //*****************************************************************************
      void puart_rx_callback(void* unused)
      {
        //*****************************************************
        // There can be at most 16 bytes in the HW FIFO.
        //*****************************************************
        char readbytes[16];
        UINT8 number_of_bytes_read = 0;
      
      
        //*****************************************************
        // Empty the FIFO and ECHO received character
        //*****************************************************
        while(puart_rxFifoNotEmpty() && puart_read(&readbytes[number_of_bytes_read]))
        {
        puart_write(readbytes[number_of_bytes_read]);
        number_of_bytes_read++;
        }
      
      
        //*****************************************************
        // Clear the interrupt
        //*****************************************************
        P_UART_INT_CLEAR(P_UART_ISR_RX_AFF_MASK);
        P_UART_INT_ENABLE |= P_UART_ISR_RX_AFF_MASK;
      }
      
      
      //*****************************************************************************
      //
      //*****************************************************************************
      APPLICATION_INIT()
      {
          bleapp_set_cfg(NULL,
          0,
          NULL,
          (void *)&mybeacon_puart_cfg,
          NULL,
          mybeacon_create);
      }
      
      
      //*****************************************************************************
      //
      //*****************************************************************************
      UINT32 ask_for_sleep_cb(LowPowerModePollType type, UINT32 context)
      {
          return 0;
      }
      
      
      //*****************************************************************************
      //
      //*****************************************************************************
      void mybeacon_create(void)
      {
        //*****************************************************
        //
        //*****************************************************
          UINT16 interrupt_handler_mask[3] = {0, 0, 0};
          gpio_init();
      
        //*****************************************************
        //
        //*****************************************************
          bleprofile_Init(bleprofile_p_cfg);
          
          puart_config.baudrate = 115200;
          puart_selectUartPads(SERIAL_RX_PIN, SERIAL_TX_PIN, 0, 0);
          puart_init();
      
      
        puart_flowOff();
          puart_enableTx();
      
      
          P_UART_INT_CLEAR(P_UART_ISR_RX_AFF_MASK);
          P_UART_WATER_MARK_RX_LEVEL(1);
          P_UART_INT_ENABLE |= P_UART_ISR_RX_AFF_MASK;// | P_UART_ISR_TX_FF_MASK;
      
      
          puart_rxCb = puart_rx_callback;
          puart_enableInterrupt();
      
      
          puart_print("CYW: started\r\n");    
      
      
        //*****************************************************
        //
        //*****************************************************
          BLE_APP_DISABLE_TRACING();
          bleprofile_KillTimer();
      
      
        //*****************************************************
        //
        //*****************************************************
          devlpm_init();
          devlpm_registerForLowPowerQueries(ask_for_sleep_cb, 0);
      }