Bug in MikroBasic for ARM? [SOLVED]

General discussion on mikroBasic PRO for ARM.
Post Reply
Author
Message
Darklakebridge78
Posts: 136
Joined: 12 May 2007 14:04
Location: Italy
Contact:

Bug in MikroBasic for ARM? [SOLVED]

#1 Post by Darklakebridge78 » 03 Aug 2021 08:50

Hello everybody!
I am trying in vain to translate the MikroC example for Mikromedia 4 into MikroBasic (https://libstock.mikroe.com/projects/vi ... capacitive). It seems I have managed to translate most of the code, but the lines of code intended to pull up pins PD2, PC8 and PC9 fail, which, on the other hand, does not happen with the MikroC ... Am I doing something wrong or is there an error in the program descriptors?

Part written in C without problems:

Code: Select all

void Init_Ext_Mem() {
  char FAT_cnt = 0;
  char Fat_Init_Flag = 0;  
  rfStartSect = 0;
  rfName      = "Mikromed.RES";

  // adjust this code to suite hw configuration
  GPIO_Digital_Output(&GPIOD_BASE, _GPIO_PINMASK_2);
  Mmc_Chip_Select = 1;

    // Initialize SDIO
    SDIO_Reset();

    SDIO_Init(_SDIO_CFG_POWER_SAVE_DISABLE | _SDIO_CFG_4_WIDE_BUS_MODE | _SDIO_CFG_CLOCK_BYPASS_DISABLE
            | _SDIO_CFG_CLOCK_RISING_EDGE | _SDIO_CFG_HW_FLOW_DISABLE, 125, &_GPIO_MODULE_SDIO_D0_D3);

    // Set pull-ups on SDIO lines
    GPIOD_PUPDRbits.PUPDR2 = 1;
    GPIOC_PUPDRbits.PUPDR8 = 1;
    GPIOC_PUPDRbits.PUPDR9 = 1;
    GPIOC_PUPDRbits.PUPDR10 = 1;
    GPIOC_PUPDRbits.PUPDR11 = 1;

    Mmc_Set_Interface(_MMC_INTERFACE_SDIO);

      if (Fat_Init_Flag == 0){
        while ((FAT32_Init() != 0) && (FAT_cnt < 5))
          FAT_cnt ++;
        if (FAT_cnt < 5){
          SDIO_Init(_SDIO_CFG_POWER_SAVE_DISABLE | _SDIO_CFG_4_WIDE_BUS_MODE | _SDIO_CFG_CLOCK_BYPASS_DISABLE
                    | _SDIO_CFG_CLOCK_RISING_EDGE | _SDIO_CFG_HW_FLOW_DISABLE, 1, &_GPIO_MODULE_SDIO_D0_D3);
          Fat_Init_Flag = 1;
        }
      }
    // Open resource file for read
    rfHandle    = FAT32_Open(rfName, 0x01);
    rfStartSect = FAT32_ClustToSect(fat32_fdesc[rfHandle]._1stClust);
}
Part written in Basic with syntax problems for the pull-up ...

Code: Select all

sub procedure Init_Ext_Mem()
  dim FAT_cnt as byte
  dim Fat_Init_Flag as byte
  
  FAT_cnt = 0
  Fat_Init_Flag = 0
  
  rfStartSect = 0
  rfName = "Mikromed.RES"
  Mmc_Chip_Select = 1

  SDIO_Reset()

  SDIO_Init(_SDIO_CFG_POWER_SAVE_DISABLE or _SDIO_CFG_4_WIDE_BUS_MODE or _SDIO_CFG_CLOCK_BYPASS_DISABLE
            or _SDIO_CFG_CLOCK_RISING_EDGE or _SDIO_CFG_HW_FLOW_DISABLE, 125, @_GPIO_MODULE_SDIO_D0_D3)

    'Set pull-ups on SDIO lines
    GPIOD_PUPDR.PUPDR2 = 1  'ERROR!
    GPIOC_PUPDR.PUPDR8 = 1  'ERROR!
    GPIOC_PUPDR.PUPDR9 = 1  'ERROR!
    GPIOC_PUPDR.PUPDR10 = 1 'OK!
    GPIOC_PUPDR.PUPDR11 = 1 'OK!

    Mmc_Set_Interface(_MMC_INTERFACE_SDIO)

      if (Fat_Init_Flag = 0) then
         while ((FAT32_Init() <> 0) and (FAT_cnt < 5))
               inc(FAT_cnt)
            if (FAT_cnt < 5) then
                SDIO_Init(_SDIO_CFG_POWER_SAVE_DISABLE or _SDIO_CFG_4_WIDE_BUS_MODE or _SDIO_CFG_CLOCK_BYPASS_DISABLE
                or _SDIO_CFG_CLOCK_RISING_EDGE or _SDIO_CFG_HW_FLOW_DISABLE, 1, @_GPIO_MODULE_SDIO_D0_D3)
                Fat_Init_Flag = 1
            end if
         wend
      end if
    ' Open resource file for read
    rfHandle    = FAT32_Open(@rfName, 0x01)
    rfStartSect = FAT32_ClustToSect(fat32_fdesc[rfHandle]._1stClust)
end sub
Last edited by Darklakebridge78 on 03 Aug 2021 14:57, edited 2 times in total.
MikroC PRO for PIC, MikroC PRO for dsPIC, MikroC PRO for PIC32, MikroC PRO for ARM, Visual TFT, Visual GLCD,
http://www.teolab.it

Darklakebridge78
Posts: 136
Joined: 12 May 2007 14:04
Location: Italy
Contact:

Re: Bug in MikroBasic for ARM? [SOLVED]

#2 Post by Darklakebridge78 » 03 Aug 2021 10:42

I found the error: in Mikrobasic the pull-up directives must be expressed like this:

GPIOD_PUPDR.B2 = 1
GPIOC_PUPDR.B8 = 1
GPIOC_PUPDR.B9 = 1
GPIOC_PUPDR.B10 = 1
GPIOC_PUPDR.B11 = 1

that becomes ...

GPIOD_PUPDR = GPIOD_PUPDR or 0x10
GPIOC_PUPDR = GPIOC_PUPDR or 0x550000

View the Defs file for STM32F746ZG to: C:\Users\Public\Documents\Mikroelektronika\mikroBasic PRO for ARM\Defs\STM32F746ZG.mbas

The correct routine, therefore, is this:

Code: Select all

sub procedure Init_Ext_Mem()
  dim FAT_cnt as byte
  dim Fat_Init_Flag as byte
  
  FAT_cnt = 0
  Fat_Init_Flag = 0
  
  rfStartSect = 0
  rfName = "Mikromed.RES"
  Mmc_Chip_Select = 1

  SDIO_Reset()
  SDIO_Init(_SDIO_CFG_POWER_SAVE_DISABLE or _SDIO_CFG_4_WIDE_BUS_MODE or _SDIO_CFG_CLOCK_BYPASS_DISABLE
  or _SDIO_CFG_CLOCK_RISING_EDGE or _SDIO_CFG_HW_FLOW_DISABLE, 125, @_GPIO_MODULE_SDIO_D0_D3)

  'Set pull-ups on SDIO lines
  GPIOD_PUPDR = GPIOD_PUPDR or 0x10
  GPIOC_PUPDR = GPIOC_PUPDR or 0x550000
  
  Mmc_Set_Interface(_MMC_INTERFACE_SDIO)

  if (Fat_Init_Flag = 0) then
      while ((FAT32_Init() <> 0) and (FAT_cnt < 5))
          inc(FAT_cnt)
          if (FAT_cnt < 5) then
              SDIO_Init(_SDIO_CFG_POWER_SAVE_DISABLE or _SDIO_CFG_4_WIDE_BUS_MODE or _SDIO_CFG_CLOCK_BYPASS_DISABLE
              or _SDIO_CFG_CLOCK_RISING_EDGE or _SDIO_CFG_HW_FLOW_DISABLE, 1, @_GPIO_MODULE_SDIO_D0_D3)
              Fat_Init_Flag = 1
          end if
      wend
  end if
  
  'Open resource file for read
  rfHandle    = FAT32_Open(@rfName, 0x01)
  rfStartSect = FAT32_ClustToSect(fat32_fdesc[rfHandle]._1stClust)
end sub
MikroC PRO for PIC, MikroC PRO for dsPIC, MikroC PRO for PIC32, MikroC PRO for ARM, Visual TFT, Visual GLCD,
http://www.teolab.it

Post Reply

Return to “mikroBasic PRO for ARM General”