STM32GENERIC, my arduino implementation

Cores are the underlying magic that make the Arduino API possible
ChrisMicro
Posts: 276
Joined: Fri Mar 24, 2017 4:51 pm
Location: Germany

Re: STM32GENERIC, my arduino implementation

Post by ChrisMicro » Thu May 04, 2017 4:42 pm

Here seems like you copied the F411 clock settings, but F411 runs on 100Mhz, F401 only 84Mhz (and there might be other small differences)
Oh, hmm... yes ... I thought they are the same except some differences in peripherals and Memory ...
Do you have STM32CubeMX?
I have, but I didn't use it. This is what it produces when I select the Nucleo F401 without any modifications:

Code: Select all

void SystemCoreClockUpdate(void)
{
  uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
  
  /* Get SYSCLK source -------------------------------------------------------*/
  tmp = RCC->CFGR & RCC_CFGR_SWS;

  switch (tmp)
  {
    case 0x00:  /* HSI used as system clock source */
      SystemCoreClock = HSI_VALUE;
      break;
    case 0x04:  /* HSE used as system clock source */
      SystemCoreClock = HSE_VALUE;
      break;
    case 0x08:  /* PLL used as system clock source */

      /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N
         SYSCLK = PLL_VCO / PLL_P
         */    
      pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
      pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
      
      if (pllsource != 0)
      {
        /* HSE used as PLL clock source */
        pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
      }
      else
      {
        /* HSI used as PLL clock source */
        pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
      }

      pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;
      SystemCoreClock = pllvco/pllp;
      break;
    default:
      SystemCoreClock = HSI_VALUE;
      break;
  }
So, what is the way? Reading the values and translating them into the STM32GENERIC?

One remark: It blinks when flashing it with ST-LINK. It blnks not when using "Mass Storage". So at least the clock settings seem to work somehow.

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: STM32GENERIC, my arduino implementation

Post by danieleff » Thu May 04, 2017 4:46 pm

SystemClock_Config() should be in main.c

victor_pv
Posts: 1605
Joined: Mon Apr 27, 2015 12:12 pm

Re: STM32GENERIC, my arduino implementation

Post by victor_pv » Thu May 04, 2017 10:49 pm

Getting this error compiling for a 103RFT6, and indeed I can not find that symbol defined anywhere:

/STM32/system/STM32F1/stm32_chip/stm32_STM32F103RF.h:128: undefined reference to `__HAL_AFIO_REMAP_SPI3_ENABLE'

ChrisMicro
Posts: 276
Joined: Fri Mar 24, 2017 4:51 pm
Location: Germany

Re: STM32GENERIC, my arduino implementation

Post by ChrisMicro » Fri May 05, 2017 6:23 am

@Daniel

For the NUCLEO_F476RG I have the linker script corrected according to

http://www.openstm32.org/forumthread2359

Now the Board is working as expected. Download via ST-Link and Mass storage works.

For the F401 I have corrected the clock settings copying the ones from STMCube.
The Board behaves as before: Blink runs only after download with ST-Link.

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: STM32GENERIC, my arduino implementation

Post by danieleff » Fri May 05, 2017 7:18 am

I will look into 103RFT6 later.

L476RG ah then RAM LENGTH = 128K is wrong also.

michael_l
Posts: 336
Joined: Mon Aug 24, 2015 6:11 pm

Re: STM32GENERIC, my arduino implementation

Post by michael_l » Fri May 05, 2017 12:48 pm

Daniel: I've been working with platformio integration for your STM32GENERIC implementation and I've almost finished. Do you think it would be possible for you to add package.json to root folder of your github repository ? I would appreciate that. That would make using your repo in platformio much more easier with automatic downloading and integration. Thanks. Attached is the package.json file with some initial texts and description - feel free to change them. Other possibility is that I use my own fork but then I would have to merge it once a while to be at same level with your repository.
Attachments
package.zip
(308 Bytes) Downloaded 10 times

ChrisMicro
Posts: 276
Joined: Fri Mar 24, 2017 4:51 pm
Location: Germany

Re: STM32GENERIC, my arduino implementation

Post by ChrisMicro » Fri May 05, 2017 12:55 pm

L476RG ah then RAM LENGTH = 128K is wrong also.
I have reduced the ram length now to 96K even if they sell it as 128K.

Both Nucleo 64 boards ( F401RE and L476RG ) are working now as they are expected ( from my side ;) )
The problem of the F401RE with the "mass storage download" was an on-board ST-LINK V2 proplem: I had to update it with the "STM32 ST-LINK Utility" then it was working correct.

So .. if you want .. you can merge.

@michael
Did you try my STM32F4 Discovery examples the microphone is working a little bit ...

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: STM32GENERIC, my arduino implementation

Post by danieleff » Fri May 05, 2017 1:07 pm

@ChrisMicro I merged your changes.
@michael_l I can add package.json, is there somewhere a documentation of it?

victor_pv
Posts: 1605
Joined: Mon Apr 27, 2015 12:12 pm

Re: STM32GENERIC, my arduino implementation

Post by victor_pv » Fri May 05, 2017 1:14 pm

danieleff wrote:I will look into 103RFT6 later.

L476RG ah then RAM LENGTH = 128K is wrong also.
I have corrected the 103RFT6 errors commenting/changing some lines in files specific to that MCU. Looks like they included stuff for SPI3 remapping, which I do not see it as possible in cubemx, so I changed that.
I'll send a PR with that when I have time, but don't worry about it in the meanwhile since I can compile.

I'm having the same problems as Pito with the SPI DMA low speeds, but can't find what causes it so far.

michael_l
Posts: 336
Joined: Mon Aug 24, 2015 6:11 pm

Re: STM32GENERIC, my arduino implementation

Post by michael_l » Fri May 05, 2017 7:14 pm

danieleff wrote: @michael_l I can add package.json, is there somewhere a documentation of it?
I couldn't find any documentation but it is really simple. Check the attachment. Important is framework name and URL. https://community.platformio.org/t/addi ... rmio/297/2 Here some info on how to add a new framework to platformio. But I add only new package and it is much more simple. I'm not adding a new framework but only a new package. The actual script that does the build will detect based on platformio.ini which one user wants to use. Basically I could add a new framework but I think it is not necessary because framework is 'arduino'. My script will work both with stm32duino and this new STM32GENERIC. It's pretty cool you can build all variants including stm32duino with one command.. and much more. So it is good to verify builds after code change. Maybe it is better to add new topic about this platformio?

But before you add this package.json I will check a few things and get back to you later.

Post Reply