<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" 
  xmlns:content="http://purl.org/rss/1.0/modules/content/" 
  xmlns:dc="http://purl.org/dc/elements/1.1/" 
  xmlns:atom="http://www.w3.org/2005/Atom" 
  xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" 
  xmlns:media="http://search.yahoo.com/mrss/">
  <channel>
    <title>embedded on Ben&#39;s ideas and projects</title>
    <link>https://ben.the-collective.net/tags/embedded/</link>
    <description>Recent content in embedded on Ben&#39;s ideas and projects</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <managingEditor>locutus@the-collective.net (Ben Mason)</managingEditor>
    <webMaster>locutus@the-collective.net (Ben Mason)</webMaster>
    <copyright>©2022, All Rights Reserved</copyright>
    <lastBuildDate>Sun, 08 Jul 2018 12:05:28 -0400</lastBuildDate>
    <sy:updatePeriod>daily</sy:updatePeriod>
    
        <atom:link href="https://ben.the-collective.net/tags/embedded/index.xml" rel="self" type="application/rss+xml" />
    

      
      <item>
        <title>STM32 Development Notes</title>
        <link>https://ben.the-collective.net/my-notes/stm32-development-notes/</link>
        <pubDate>Sun, 08 Jul 2018 12:05:28 -0400</pubDate>
        <author>locutus@the-collective.net (Ben Mason)</author>
        <atom:modified>Sun, 08 Jul 2018 12:05:28 -0400</atom:modified>
        <guid>https://ben.the-collective.net/my-notes/stm32-development-notes/</guid>
        <description>STM32 Notes Embedded Wednesdays: Getting Started in Embedded Systems — Embedded
STM32F4 Discovery – Libraries and tutorials for STM32F4 series MCUs by Tilen Majerle. Working with STM32F4xx series and Standard peripheral drivers (STD, SPL) or with STM32F0xx, STM32F4xx or STM32F7xx using Hardware abstraction layer libraries (HAL) from STMicroelectronics. My libraries are built on these 2 packages and are highly optimized compared to them.
Code CubeMX may duplicate c files in C_SOURCES variable they must be removed of you will get multiple declaration errors in linking</description>
        <content:encoded>&lt;h1 id=&#34;stm32-notes&#34;&gt;STM32 Notes&lt;/h1&gt;
&lt;p&gt;&lt;a href=&#34;http://embedded.fm/blog/embedded-wednesdays&#34;&gt;Embedded Wednesdays: Getting Started in Embedded Systems — Embedded&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;http://stm32f4-discovery.net/&#34;&gt;STM32F4 Discovery – Libraries and tutorials for STM32F4 series MCUs by Tilen Majerle. Working with STM32F4xx series and Standard peripheral drivers (STD, SPL) or with STM32F0xx, STM32F4xx or STM32F7xx using Hardware abstraction layer libraries (HAL) from STMicroelectronics. My libraries are built on these 2 packages and are highly optimized compared to them.&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;code&#34;&gt;Code&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;CubeMX may duplicate c files in C_SOURCES variable they must be removed of you will get multiple declaration errors in linking&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;HAL – Hardware abstraction layer, abstracts hardware commands&lt;/p&gt;
&lt;p&gt;LL – TBD&lt;/p&gt;
&lt;p&gt;Delay – &lt;code&gt;HAL_Delay( 500);&lt;/code&gt; &lt;em&gt;* Stop for 1/2 second *&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&#34;gpio&#34;&gt;GPIO&lt;/h3&gt;
&lt;p&gt;Port initialization&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;  /* Struct options are defined in stm32f1xx_hal_gpio.h */
  GPIO_InitStruct.Pin = GPIO_PIN_13;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOC, &amp;amp;GPIO_InitStruct);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following functions are in format Port, Pin&lt;/p&gt;
&lt;p&gt;&lt;code&gt;HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);&lt;/code&gt; – Toggle Pin state&lt;/p&gt;
&lt;p&gt;&lt;code&gt;GPIO_PIN_SET == HAL_GPIO_ReadPin(GPIOA, BUTTINPIN)&lt;/code&gt; – Read Pin status&lt;/p&gt;
&lt;p&gt;&lt;code&gt;HAL_GPIO_WritePin(GPIO_TypeDef * GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState )&lt;/code&gt; – Write Specific state to Pin&lt;/p&gt;
&lt;p&gt;PinState = GPIO_PIN_RESET, GPIO_PIN_SET&lt;/p&gt;
&lt;h3 id=&#34;uart&#34;&gt;UART&lt;/h3&gt;
&lt;p&gt;both functions should be added un “USER CODE BEGIN 4”&lt;/p&gt;
&lt;p&gt;Add following code to allow printf() to print out UART&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt; _write( file, *outgoing, len) {
   HAL_UART_Transmit(&amp;amp;huart3, outgoing, len, 100);
  return len;
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This code allows &lt;code&gt;ch = getchar();&lt;/code&gt; to work,&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt; _read( file, *result, size_t len) {
    HAL_StatusTypeDef status;
     retcode = 0;

   if (len != 0) {
        status = HAL_UART_Receive( &amp;amp;huart3, (uint8_t *) result, len, HAL_MAX_DELAY);

       if (status == HAL_OK) {
            retcode = len;
        }else {
            retcode = -1;
        }
    }
   return( retcode);
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;also add &lt;code&gt;setvbuf(stdin, NULL, _IONBF, 0);&lt;/code&gt; before while loop to tune off 1k buffer&lt;/p&gt;
&lt;h3 id=&#34;i2c&#34;&gt;i2c&lt;/h3&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;I2C_HandleTypeDef *hi2c
uint8_t data[6];
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Shift Address by 1 leaving room for read / write bit&lt;/p&gt;
&lt;p&gt;&lt;code&gt;status = HAL_I2C_Master_Receive(hi2c, HMC5883LADDRESS&amp;lt;&amp;lt;1, &amp;amp;data, 6, HMC5883LTIMEOUT);&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;status = HAL_I2C_Master_Transmit(hi2c, HMC5883LADDRESS&amp;lt;&amp;lt;1, &amp;amp;returntofirstvalue, 1, HMC5883LTIMEOUT);&lt;/code&gt;&lt;/p&gt;
&lt;h2 id=&#34;programer-and-debug&#34;&gt;Programer and Debug&lt;/h2&gt;
&lt;h3 id=&#34;memory-locations&#34;&gt;Memory locations&lt;/h3&gt;
&lt;p&gt;0x2000000 – RAM&lt;/p&gt;
&lt;p&gt;0x8000000 – Flash&lt;/p&gt;
&lt;h3 id=&#34;bluepill-programing&#34;&gt;Bluepill programing&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Set the ‘boot 0′ pin/jumper high (1), and keep ‘boot 1’ low (0)&lt;/li&gt;
&lt;li&gt;Upload code&lt;/li&gt;
&lt;li&gt;For normal use, set both boot pins low (0)&lt;/li&gt;
&lt;li&gt;Reset board&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;st-link-utility&#34;&gt;st-link utility&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/texane/stlink&#34;&gt;GitHub – texane/stlink: stm32 discovery line linux programmer&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://startingelectronics.org/tutorials/STM32-microcontrollers/programming-STM32-flash-in-Linux/&#34;&gt;Programming STM32 Microcontroller Flash in Linux&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;st-flash write myflash.bin 0x8000000&lt;/code&gt; – write code to flash&lt;/p&gt;
&lt;p&gt;&lt;code&gt;st-util&lt;/code&gt; – start debugging&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;./st-util - usage:

  -h, --help		Print this help
  -vXX, --verbose=XX	Specify a specific verbosity level (0..99)
  -v, --verbose		Specify generally verbose logging
  -s X, --stlink_version=X
			Choose what version of stlink to use, (defaults to 2)
  -1, --stlinkv1	Force stlink version 1
  -p 4242, --listen_port=1234
			Set the gdb server listen port. (default port: 4242)
  -m, --multi
			Set gdb server to extended mode.
			st-util will continue listening for connections after disconnect.
  -n, --no-reset
			Do not reset board on connection.
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;openocd&#34;&gt;OpenOCD&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;telnet localhost 4444&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://gojimmypi.blogspot.com/2017/05/using-openocd-and-gdb.html&#34;&gt;GoJimmyPi: Using OpenOCD and GDB&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/rogerclarkmelbourne/Arduino_STM32/wiki/Programming-an-STM32F103XXX-with-a-generic-%22ST-Link-V2%22-programmer-from-Linux&#34;&gt;Programming an STM32F103XXX with a generic “ST Link V2” programmer from Linux · rogerclarkmelbourne/Arduino_STM32 Wiki · GitHub&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;simulation&#34;&gt;Simulation&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;https://beckus.github.io/qemu_stm32/&#34;&gt;Qemu STM32&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;ides&#34;&gt;IDEs&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;http://www.st.com/en/development-tools/stm32cubemx.html&#34;&gt;STM32CubeMX – STM32Cube initialization code generator – STMicroelectronics&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;http://www.st.com/en/development-tools/sw4stm32.html&#34;&gt;SW4STM32 – System Workbench for STM32: free IDE on Windows, Linux and OS X – STMicroelectronics&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The System Workbench toolchain, called SW4STM32, is a free multi-OS software development environment based on Eclipse, which supports the full range of STM32 microcontrollers and associated boards.&lt;/p&gt;
&lt;h3 id=&#34;eclipse&#34;&gt;Eclipse&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;https://www.carminenoviello.com/2015/06/04/stm32-applications-eclipse-gcc-stcube/&#34;&gt;Build STM32 applications with Eclipse, GCC and STM32Cube&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.carminenoviello.com/2014/12/28/setting-gcceclipse-toolchain-stm32nucleo-part-1/&#34;&gt;Setting up a GCC/Eclipse toolchain for STM32Nucleo – Part I | Carmine Noviello – A blog about programming and electronics&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.carminenoviello.com/2015/01/07/setting-gcceclipse-toolchain-stm32nucleo-part-2/&#34;&gt;Setting up a GCC/Eclipse toolchain for STM32Nucleo – Part II | Carmine Noviello – A blog about programming and electronics&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.carminenoviello.com/2015/01/16/setting-gcceclipse-toolchain-stm32nucleo-part-iii/&#34;&gt;Setting up a GCC/Eclipse toolchain for STM32Nucleo – Part III | Carmine Noviello – A blog about programming and electronics&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://hackaday.io/page/3033-6-ides-to-debug-the-2-stm32-bluepill&#34;&gt;6+ IDEs to debug the $2 STM32 BluePill | Wassim | Hackaday.io&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;http://erika.tuxfamily.org/wiki/index.php?title=Tutorial:_STM32_-_Integrated_Debugging_in_Eclipse_using_GNU_toolchain&#34;&gt;Tutorial: STM32 – Integrated Debugging in Eclipse using GNU toolchain – ErikaWiki&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://simonmartin.ch/resources/stm32/&#34;&gt;Simon Burkhardt | STM32&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;hashtag&#34;&gt;#microcontroller/stm32 &lt;span class=&#34;hashtag&#34;&gt;#7-notes&lt;/p&gt;
</content:encoded>
        <dc:creator>Ben Mason</dc:creator>
        
        
        
        
          
            
              <category>stm32</category>
            
          
            
              <category>electronics</category>
            
          
            
              <category>embedded</category>
            
          
            
              <category>c</category>
            
          
            
              <category>notes</category>
            
          
        
        
        
      </item>
      

    
  </channel>
</rss>
