{"id":267,"date":"2020-06-30T10:10:29","date_gmt":"2020-06-30T10:10:29","guid":{"rendered":"https:\/\/www.vu2ese.com\/?p=267"},"modified":"2020-07-01T19:23:10","modified_gmt":"2020-07-01T19:23:10","slug":"bluepill-setup-on-arduino-with-ubuntu-linux","status":"publish","type":"post","link":"https:\/\/www.vu2ese.com\/index.php\/2020\/06\/30\/bluepill-setup-on-arduino-with-ubuntu-linux\/","title":{"rendered":"Bluepill setup on Arduino on Ubuntu linux"},"content":{"rendered":"<p>This is a work in progress.<\/p>\n<ol>\n<li>STlinkV2 adapter&#8217;s pinout on the plastic case is WRONG. the actual pin details are printed on the PCB.<\/li>\n<li>\u00a0I installed the stlink (the stlink should be added to a special group that allows access to the &#8216;modem&#8217;\/&#8217;usb&#8217;)\n<pre><code>git clone https:\/\/github.com\/texane\/stlink.git\r\ncd stlink\/build\r\ncmake ..\r\nmake &amp;&amp; sudo make install<\/code><\/pre>\n<\/li>\n<li>\u00a0We run lsusb. It didn&#8217;t work on USB 3.0 port.\u00a0 The ST-Link shows up now when plugged into a different USB port as:\n<pre>farhan@Farhan:~\/Documents\/ham\/stlink$ lsusb\r\nBus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub\r\nBus 001 Device 005: ID 06cb:00a2 Synaptics, Inc. \r\nBus 001 Device 004: ID 04f2:b604 Chicony Electronics Co., Ltd \r\nBus 001 Device 002: ID 046d:c534 Logitech, Inc. Unifying Receiver\r\nBus 001 Device 020: ID 0483:3748 STMicroelectronics ST-LINK\/V2\r\nBus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub<\/pre>\n<\/li>\n<li>Started to install Arduino support for the blue pill :\n<pre>https:\/\/github.com\/rogerclarkmelbourne\/Arduino_STM32\/wiki\/Installation<\/pre>\n<\/li>\n<li>I tried running st-link from command line. It failed to enable it to find the libstlink,\n<pre>export LD_LIBRARY_PATH=\/usr\/local\/lib\r\nsudo ldconfig<\/pre>\n<\/li>\n<li>Now, sudo stlink works!<\/li>\n<li>\u00a0Downloaded the bootloader from\u00a0https:\/\/github.com\/rogerclarkmelbourne\/STM32duino- bootloader\/blob\/master\/binaries\/generic_boot20_pc13.bin as this has the LED on PC13.<\/li>\n<li>Next, we plug in the stlinkV2 adapter and probe for the chip ,then flash the progam into it.\n<pre>farhan@Farhan:~\/Documents\/ham\/stm32$ sudo st-info --probe\r\nFound 1 stlink programmers\r\n serial: 2d0c02012612344d314b4e00\r\n hla-serial: \"\\x2d\\x0c\\x02\\x01\\x26\\x12\\x34\\x4d\\x31\\x4b\\x4e\\x00\"\r\n flash: 131072 (pagesize: 1024)\r\n sram: 20480\r\n chipid: 0x0410\r\n descr: F1xx Medium-density\r\nfarhan@Farhan:~\/Documents\/ham\/stm32$ st-flash --reset write generic_boot20_pc13.bin 0x8000000\r\nst-flash 1.6.0-392-g31b1fa1\r\n2020-06-30T15:42:38 INFO common.c: F1xx Medium-density: 20 KiB SRAM, 128 KiB flash in at least 1 KiB pages.\r\nfile generic_boot20_pc13.bin md5 checksum: f6d7639c776ddc06d62a1b612ef7876, stlink checksum: 0x00192077\r\n2020-06-30T15:42:38 INFO common.c: Attempting to write 22268 (0x56fc) bytes to stm32 address: 134217728 (0x8000000)\r\n2020-06-30T15:42:38 INFO common.c: Flash page at addr: 0x08000000 erased\r\n2020-06-30T15:42:38 INFO common.c: Flash page at addr: 0x08000400 erased\r\n2020-06-30T15:42:38 INFO common.c: Flash page at addr: 0x08000800 erased\r\n2020-06-30T15:42:38 INFO common.c: Flash page at addr: 0x08000c00 erased\r\n2020-06-30T15:42:38 INFO common.c: Flash page at addr: 0x08001000 erased\r\n2020-06-30T15:42:38 INFO common.c: Flash page at addr: 0x08001400 erased\r\n2020-06-30T15:42:38 INFO common.c: Flash page at addr: 0x08001800 erased\r\n2020-06-30T15:42:38 INFO common.c: Flash page at addr: 0x08001c00 erased\r\n2020-06-30T15:42:38 INFO common.c: Flash page at addr: 0x08002000 erased\r\n2020-06-30T15:42:38 INFO common.c: Flash page at addr: 0x08002400 erased\r\n2020-06-30T15:42:38 INFO common.c: Flash page at addr: 0x08002800 erased\r\n2020-06-30T15:42:38 INFO common.c: Flash page at addr: 0x08002c00 erased\r\n2020-06-30T15:42:39 INFO common.c: Flash page at addr: 0x08003000 erased\r\n2020-06-30T15:42:39 INFO common.c: Flash page at addr: 0x08003400 erased\r\n2020-06-30T15:42:39 INFO common.c: Flash page at addr: 0x08003800 erased\r\n2020-06-30T15:42:39 INFO common.c: Flash page at addr: 0x08003c00 erased\r\n2020-06-30T15:42:39 INFO common.c: Flash page at addr: 0x08004000 erased\r\n2020-06-30T15:42:39 INFO common.c: Flash page at addr: 0x08004400 erased\r\n2020-06-30T15:42:39 INFO common.c: Flash page at addr: 0x08004800 erased\r\n2020-06-30T15:42:39 INFO common.c: Flash page at addr: 0x08004c00 erased\r\n2020-06-30T15:42:39 INFO common.c: Flash page at addr: 0x08005000 erased\r\n2020-06-30T15:42:39 INFO common.c: Flash page at addr: 0x08005400 erased\r\n2020-06-30T15:42:39 INFO common.c: Finished erasing 22 pages of 1024 (0x400) bytes\r\n2020-06-30T15:42:39 INFO common.c: Starting Flash write for VL\/F0\/F3\/F1_XL core id\r\n2020-06-30T15:42:39 INFO flash_loader.c: Successfully loaded flash loader in sram\r\n 22\/22 pages written<\/pre>\n<\/li>\n<li>This concludes installation of the bootloader and any other program into the Blue pill if we already have a .BIN file. Whew!<\/li>\n<\/ol>\n<h2>Part 2 Setting up the Arduino IDE<\/h2>\n<p>Here, we will figure out how to compile our blink with an output to the USB&#8217;s serial port.<\/p>\n<ol>\n<li>The\u00a0Arduino_STM32 folder has to be copied into a newly created &#8216;hardware&#8217; folder inside the &#8216;Arduino&#8217; folder in the home directory.<\/li>\n<li>We checked that lsusb lists the port as\n<pre>farhan@Farhan:~\/Documents\/ham\/stm32$ lsusb\r\nBus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub\r\nBus 001 Device 005: ID 06cb:00a2 Synaptics, Inc. \r\nBus 001 Device 004: ID 04f2:b604 Chicony Electronics Co., Ltd \r\nBus 001 Device 002: ID 046d:c534 Logitech, Inc. Unifying Receiver\r\nBus 001 Device 026: ID 1eaf:0004 \r\nBus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub<\/pre>\n<\/li>\n<li>\u00a0Under tools &gt; port, the Bluepill appears as \/dev\/ttyACM0 (Maple Mini)<\/li>\n<li>The blink was compiled, and uploaded through &#8220;STM32duino Bootloader&#8221; . The board had to be reset for it to be recognized, then it uploaded properly.<\/li>\n<li>Here is the test sketch (the potentiometer was connected to A7 and between GND and 3.3V).\n<pre>const int analogInPin = PA7; \/\/ Analog input pin that the potentiometer\r\n \/\/ is attached to\r\n\r\nconst int pwmOutPin = 9; \/\/ PWM pin that the LED is attached to\r\n\r\n\/\/ These variables will change:\r\nint sensorValue = 0; \/\/ value read from the pot\r\nint outputValue = 0; \/\/ value output to the PWM\r\n\r\nvoid setup() {\r\n \/\/ Configure the ADC pin\r\n pinMode(analogInPin, INPUT_ANALOG);\r\n \/\/ Configure LED pin\r\n pinMode(pwmOutPin, PWM);\r\n Serial.begin(115200); \/\/ Ignored by Maple. But needed by boards using Hardware serial via a USB to Serial Adaptor\r\n}\r\n\r\nvoid loop() {\r\n \/\/ read the analog in value:\r\n sensorValue = analogRead(analogInPin);\r\n \/\/ map it to the range of the analog out:\r\n outputValue = map(sensorValue, 0, 1023, 0, 65535);\r\n \/\/ change the analog out value:\r\n pwmWrite(pwmOutPin, outputValue);\r\n\r\n\/\/ print the results to the serial monitor:\r\n Serial.print(\"sensor = \" );\r\n Serial.print(sensorValue);\r\n Serial.print(\"\\t output = \");\r\n Serial.println(outputValue);\r\n}<\/pre>\n<\/li>\n<li>The output came out on the serial port alright.<\/li>\n<li>While uploading be sure to press the RESET button the bluepill simultaneously with the upload button on the Arduino IDE, this will catch the bootstrap loader before the serial port opens itself up for debug messaging.<\/li>\n<\/ol>\n<h2>Step 3 &#8211; Measure the analog conversion rate<\/h2>\n<ol>\n<li>The ADC example is on\u00a0https:\/\/github.com\/rogerclarkmelbourne\/Arduino_STM32\/blob\/master\/STM32F1\/libraries\/STM32ADC\/examples\/MultiChannelContinuousConversion\/MultiChannelContinuousConversion.ino<\/li>\n<li>It needs to kickstart the conversion with a startConversion call:\n<pre>uint8_t pins[] = {PA7, PA6};\r\nconst int MAX_SAMPLES = 8;\r\nuint16_t data_points[MAX_SAMPLES];\r\n\r\nvoid setup() {\r\n \/\/ put your setup code here, to run once:\r\n my_adc.calibrate();\r\n\r\nfor (unsigned int j = 0; j &lt;8; j++) \r\n pinMode(pins[j], INPUT_ANALOG);\r\n \r\n my_adc.setSampleRate(ADC_SMPR_1_5);\/\/set the Sample Rate\r\n my_adc.setScanMode(); \/\/set the ADC in Scan mode. \r\n my_adc.setPins(pins, 2); \/\/set how many and which pins to convert.\r\n my_adc.setContinuous(); \/\/set the ADC in continuous mode.\r\n\r\n\/\/set the DMA transfer for the ADC. \r\n\/\/in this case we want to increment the memory side and run it in circular mode\r\n\/\/By doing this, we can read the last value sampled from the channels by reading the dataPoints array\r\n my_adc.setDMA(data_points, 2, (DMA_MINC_MODE | DMA_CIRC_MODE), NULL);\r\n my_adc.startConversion();\r\n\r\nSerial.begin(115200); \/\/ Ignored by Maple. But needed by boards using Hardware serial via a USB to S\r\n}<\/pre>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This is a work in progress. STlinkV2 adapter&#8217;s pinout on the plastic case is WRONG. the actual pin details are printed on the PCB. \u00a0I installed the stlink (the stlink should be added to a special group that allows access to the &#8216;modem&#8217;\/&#8217;usb&#8217;) git clone https:\/\/github.com\/texane\/stlink.git cd stlink\/build cmake .. make &amp;&amp; sudo make install [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-267","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.vu2ese.com\/index.php\/wp-json\/wp\/v2\/posts\/267","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vu2ese.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vu2ese.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vu2ese.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vu2ese.com\/index.php\/wp-json\/wp\/v2\/comments?post=267"}],"version-history":[{"count":6,"href":"https:\/\/www.vu2ese.com\/index.php\/wp-json\/wp\/v2\/posts\/267\/revisions"}],"predecessor-version":[{"id":273,"href":"https:\/\/www.vu2ese.com\/index.php\/wp-json\/wp\/v2\/posts\/267\/revisions\/273"}],"wp:attachment":[{"href":"https:\/\/www.vu2ese.com\/index.php\/wp-json\/wp\/v2\/media?parent=267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vu2ese.com\/index.php\/wp-json\/wp\/v2\/categories?post=267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vu2ese.com\/index.php\/wp-json\/wp\/v2\/tags?post=267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}