{"componentChunkName":"component---src-templates-blog-post-js","path":"/posts/stm32discovery_1/","result":{"data":{"markdownRemark":{"html":"<p>Reader's note: These instructions are specifically for Mac OSX (I was running Catalina). I'm currently trying to port over everything onto my linux computer, but I am running into compile issues there.</p>\n<p>Since I've decided it was time to actually learn how to write embedded code, I decided the best thing to do was to start with this free STM32 Discovery kit, which I got for free after attending a conference. It's neat because this board is packed to the brim with sensors, and also includes a WiFi and BLE chip. I only which it had a cell module too, but nothing's perfect.</p>\n<p>It's easy to get started with this board because STM32 provides the STM32CubeMX application, which generates code for you automatically. The first thing I wanted to do was to get the USB port working so that I could write serial logs. This was pretty easy to do by following this setup here: <a href=\"https://www.youtube.com/watch?v=AYICE0gU-Sg\">https://www.youtube.com/watch?v=AYICE0gU-Sg</a>. Of course, there were some minor differences because the board from that video was different from this one. You can see exactly what by opening the .ioc file in my repo <a href=\"https://github.com/simjxu/stm32_discovery\">https://github.com/simjxu/stm32_discovery</a> (as of commit hash 1798e96db2c7153ad87412712790d49240252aee). </p>\n<p>From there, code was generated. I opted to use the VS Code plugin called \"PlatformIO\" to help build and read from terminal. The code generated from CubeMX actually had some compile errors when I tried to follow the tutorial. Turns out, it didn't like that a couple of the functions had a mismatched type in the last argument. It was expecting uint16<em>t, but you can see a uint32</em>t.</p>\n<pre><code class=\"language-cpp\">USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr,\n                                    uint8_t *pbuf, uint32_t size);\n\nUSBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr,\n                                          uint8_t *pbuf, uint32_t size);\n</code></pre>\n<p>I edited to say uint16<em>t, and compilations ended up happening successfully, but for some reason this switched back to uint32</em>t, but with no issues compiling after that point... So I'm not sure what's happening here. Nevertheless, I was able to start printing my helloworld over serial. Note that both USB connectors need to be connected in order to read off of that port (see picture).</p>\n<p>Results:\n<img src=\"https://raw.githubusercontent.com/simjxu/simjxu.github.io/gh-pages/img/BL475E_usb.jpg\" alt=\"board_2xusb\"></p>\n<p>As a side note, you are also able to compile in C++ code, no problemo. I tried adding in a class, and was able to get it working and printing out (see classtest.h and classtest.cpp).</p>\n<pre><code class=\"language-cpp\">class FatherProperty {\nprivate:\n    static uint8_t propValue[];        // I need to declare this as static, why?\n    // static means that there is only one copy of propValue, no matter how many times the class is instantiated\n\npublic:\n    void getProperty();\n};\n\nuint8_t FatherProperty::propValue[]=\"asdf\\n\";\nvoid FatherProperty::getProperty() \n{\n    int len = sizeof(this->propValue);\n    CDC_Transmit_FS(this->propValue,len-1);         // subtract 1 so that it does not include the extra character\n}\n</code></pre>","frontmatter":{"title":"Getting started iwth the B-L475E-IOT01A STM32 Discovery kit (IoT Node)"}}},"pageContext":{"slug":"/posts/stm32discovery_1/"}},"staticQueryHashes":["3649515864"]}