![]() Here, we create a simple string and call a USB CDC function to send out that string over the USB lines. ![]() Under /* USER CODE BEGIN 3 */ (but still inside the while loop), enter the following: uint8_t buffer = "Hello, World!\r\n" Scroll down to our while(1) loop in main. This will let us call functions from the CDC library. At the top, under /* USER CODE BEGIN Includes */ , enter the following line: #include "usbd_cdc_if.h" usbd_cdc_if.c contains the functions that allow us to send and receive serial data using the USB Communication Device Class. Notice that you have several USB-related files that have been added. In your project files, navigate to the Src directory. You’ll be asked if you want to generate Code. ld linker script and look for the _Min_Heap_Size and _Min_Stack_Size settings there (just know that this file will be overwritten if you make changes in the graphical Device Configuration Tool).Ĭlick File > Save to save the changes to the CubeMX configuration. ioc file) and adjust the stack and heap settings as described above. You will need to go into the Device Configuration Tool (the. If you get an error message like `._user_heap_stack’ will not fit in region `RAM’ or region `RAM’ overflowed by 64 bytes when you compile, it means you are running out of RAM in your application. I chose heap, as it seems less likely we’ll be using dynamically allocated memory for this application. We need to lower one of them in order to accommodate the USB functions. By setting 0x200 and 0x400, we’ve told the processor to reserve 1 kB of RAM for the heap and stack, respectively. These parameters essentially reserve sections of data memory for the heap and stack. We can free up some space by adjusting the minimum heap and stack sizes. USB functionality takes up probably 2-3 kB worth of that memory, so we need to be careful about how we use the rest. The STM32F042K6 comes with 6 kB of RAM, which isn’t a whole lot. In the Project Manager tab, change the Minimum Heap Size to 0x100. This should automatically change all of the necessary clocks to 48 MHz. Luckily, you can just click Yes on the pop-up when asked to run the automatic clock issues solver. We need to bump those up to 48 MHz for USB to work. By default, the Nucleo-F042K6 board is configured for 8 MHz clocks for almost everything. The software will tell you that your clocks have issues. This tells the USB stack that we want to enumerate as a CDC device, which will allow us to send serial data to and from our computer across the USB lines.Ĭlick on the Clock Configuration tab. Change Class For FS IP to Communication Device Class (CDC). Under Categories > Middleware, select USB_DEVICE. You should see PA11 and PA12 be automatically configured for USB_DM and USB_DP. In the Pinout & Configuration tab, go to Categories > Connectivity and click USB. In the CubeMX configuration perspective, you’ll need to enable a few options to initialize the USB as a Virtual COM Port.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |