1 Create New Project
After Install Modus IDE, the creating of new project becomes easy. Just press CRTL+7 to invode Project creater, select template, middleware and peripheral. Then new project can be created.
After customized the selection, new project can be created
Another way is to revise sample project, that would be more quick, but some functions are not included, there are still a lot work needed.
2 BSP
Becareful with BSP, there is device configurator for customized BSP, this is good for new design from scratch with electrical design. Once modified, each project shall be influeced, for this project with PSoC 62S2 Wi-Fi BT Pioneer Kit.
3 Build with FreeRTOS
With RTOS, the scaling of the project becomes easy. Just create new task, adding in thread, then all the task can run well, I have added several tasks it runs well.
Communication between task with Created Quene, the data structures need to be clear and robust, part of the code for LED pwm is listed below.
void task_led(void* param) { cyhal_pwm_t pwm_led; bool led_on = true; BaseType_t rtos_api_result = pdFAIL; led_command_data_t led_cmd_data; int freqled= PWM_LED_FREQ_HZ; /* Suppress warning for unused parameter */ (void)param; cyhal_gpio_init(CYBSP_USER_BTN, CYHAL_GPIO_DIR_INPUT, CYHAL_GPIO_DRIVE_PULLUP, CYBSP_BTN_OFF); printf("Raw Frequency==%d !\n",freqled); while(cyhal_gpio_read(CYBSP_USER_BTN) == CYBSP_BTN_PRESSED); /* Wait for SW2 to be released */ while(cyhal_gpio_read(CYBSP_USER_BTN) == CYBSP_BTN_OFF); /* Configure the TCPWM for driving led */ if(CY_RSLT_SUCCESS != cyhal_pwm_init(&pwm_led, CYBSP_D5, NULL)) { printf("CapSense interrupt initilization failed!"); } if(CY_RSLT_SUCCESS != cyhal_pwm_set_duty_cycle(&pwm_led, GET_DUTY_CYCLE(LED_MAX_BRIGHTNESS), freqled)) { printf("PWM failed to set dutycycle!"); } if(CY_RSLT_SUCCESS != cyhal_pwm_start(&pwm_led)) { printf("PWM failed to start!"); }
4 The Fun in PWM control
Connected with oscilloscope,here is the wave form.
So, go to BLE in next blog.