ATMEL Start SAMB11 GPIO_MS1 pins programming

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all,

I started the project and trying to use MS1/MS2 pins as GPIOs(documentations says it is possible). In code I set one HIGH, another LOW (see code below).

My tests showed that I can set any normal GPIOs to whatever levels I want. However, all MSx pins does not change their level. 

 

May be ATMEL start points wrong number (46,47,..)? Seems like pin number should be the number from 0-32, and 47 seems suspicious. If you could point me to the official documentation or some examples (where MS pins are used as GPIOs) - it would be also great.

// This code is generated by ATMEL start
#define GPIO_MS1 GPIO(GPIO_PORTA, 47)
#define GPIO_MS2 GPIO(GPIO_PORTA, 46)
#define GPIO_15 GPIO(GPIO_PORTA, 15)

// Then in init finction

void system_init(void)
{
    init_mcu();

    // This code does not work. Pin never goes HIGH.
    gpio_set_pin_direction(GPIO_MS1, GPIO_DIRECTION_OUT);
    gpio_set_pin_level(GPIO_MS1, true);
    gpio_set_pin_function(GPIO_MS1, GPIO_PIN_FUNCTION_OFF);

    gpio_set_pin_direction(GPIO_MS2, GPIO_DIRECTION_OUT);
    gpio_set_pin_level(GPIO_MS2, false);
    gpio_set_pin_function(GPIO_MS2, GPIO_PIN_FUNCTION_OFF);

    // This code WORKS just fine for all normal GPIOs.
    gpio_set_pin_direction(GPIO_15, GPIO_DIRECTION_OUT);
    gpio_set_pin_level(GPIO_15, true);
     //even when I comment this line:
    gpio_set_pin_function(GPIO_15, GPIO_PIN_FUNCTION_OFF);

}

 

Last Edited: Sun. Jan 21, 2018 - 05:59 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

fredgolm wrote:
May be ATMEL start points wrong number (46,47,..)?

No, they are not wrong, see the peripheral I/O defines in the file samb11g18a.h

/* ========== Peripheral I/O pin numbers ========== */
#define PIN_LP_GPIO_0               (  0)  /**< Pin Number for LP_GPIO_0 */
#define PIN_LP_GPIO_1               (  1)  /**< Pin Number for LP_GPIO_1 */
#define PIN_LP_GPIO_2               (  2)  /**< Pin Number for LP_GPIO_2 */
#define PIN_LP_GPIO_3               (  3)  /**< Pin Number for LP_GPIO_3 */
#define PIN_LP_GPIO_4               (  4)  /**< Pin Number for LP_GPIO_4 */
#define PIN_LP_GPIO_5               (  5)  /**< Pin Number for LP_GPIO_5 */
#define PIN_LP_GPIO_6               (  6)  /**< Pin Number for LP_GPIO_6 */
#define PIN_LP_GPIO_7               (  7)  /**< Pin Number for LP_GPIO_7 */
#define PIN_LP_GPIO_8               (  8)  /**< Pin Number for LP_GPIO_8 */
#define PIN_LP_GPIO_9               (  9)  /**< Pin Number for LP_GPIO_9 */
#define PIN_LP_GPIO_10              ( 10)  /**< Pin Number for LP_GPIO_10 */
#define PIN_LP_GPIO_11              ( 11)  /**< Pin Number for LP_GPIO_11 */
#define PIN_LP_GPIO_12              ( 12)  /**< Pin Number for LP_GPIO_12 */
#define PIN_LP_GPIO_13              ( 13)  /**< Pin Number for LP_GPIO_13 */
#define PIN_LP_GPIO_14              ( 14)  /**< Pin Number for LP_GPIO_14 */
#define PIN_LP_GPIO_15              ( 15)  /**< Pin Number for LP_GPIO_15 */
#define PIN_LP_GPIO_16              ( 16)  /**< Pin Number for LP_GPIO_16 */
#define PIN_LP_GPIO_17              ( 17)  /**< Pin Number for LP_GPIO_17 */
#define PIN_LP_GPIO_18              ( 18)  /**< Pin Number for LP_GPIO_18 */
#define PIN_LP_GPIO_19              ( 19)  /**< Pin Number for LP_GPIO_19 */
#define PIN_LP_GPIO_20              ( 20)  /**< Pin Number for LP_GPIO_20 */
#define PIN_LP_GPIO_22              ( 22)  /**< Pin Number for LP_GPIO_22 */
#define PIN_LP_GPIO_23              ( 23)  /**< Pin Number for LP_GPIO_23 */
#define PIN_AO_GPIO_2               ( 29)  /**< Pin Number for AO_GPIO_2 */
#define PIN_AO_GPIO_1               ( 30)  /**< Pin Number for AO_GPIO_1 */
#define PIN_AO_GPIO_0               ( 31)  /**< Pin Number for AO_GPIO_0 */
#define PIN_GPIO_MS4                ( 44)  /**< Pin Number for GPIO_MS4 */
#define PIN_GPIO_MS3                ( 45)  /**< Pin Number for GPIO_MS3 */
#define PIN_GPIO_MS2                ( 46)  /**< Pin Number for GPIO_MS2 */
#define PIN_GPIO_MS1                ( 47)  /**< Pin Number for GPIO_MS1 */

/* ========== Peripheral I/O masks ========== */
#define GPIO_LP_GPIO_0              (_U_(1) << 0) /**< GPIO Mask for LP_GPIO_0 */
#define GPIO_LP_GPIO_1              (_U_(1) << 1) /**< GPIO Mask for LP_GPIO_1 */
#define GPIO_LP_GPIO_2              (_U_(1) << 2) /**< GPIO Mask for LP_GPIO_2 */
#define GPIO_LP_GPIO_3              (_U_(1) << 3) /**< GPIO Mask for LP_GPIO_3 */
#define GPIO_LP_GPIO_4              (_U_(1) << 4) /**< GPIO Mask for LP_GPIO_4 */
#define GPIO_LP_GPIO_5              (_U_(1) << 5) /**< GPIO Mask for LP_GPIO_5 */
#define GPIO_LP_GPIO_6              (_U_(1) << 6) /**< GPIO Mask for LP_GPIO_6 */
#define GPIO_LP_GPIO_7              (_U_(1) << 7) /**< GPIO Mask for LP_GPIO_7 */
#define GPIO_LP_GPIO_8              (_U_(1) << 8) /**< GPIO Mask for LP_GPIO_8 */
#define GPIO_LP_GPIO_9              (_U_(1) << 9) /**< GPIO Mask for LP_GPIO_9 */
#define GPIO_LP_GPIO_10             (_U_(1) << 10) /**< GPIO Mask for LP_GPIO_10 */
#define GPIO_LP_GPIO_11             (_U_(1) << 11) /**< GPIO Mask for LP_GPIO_11 */
#define GPIO_LP_GPIO_12             (_U_(1) << 12) /**< GPIO Mask for LP_GPIO_12 */
#define GPIO_LP_GPIO_13             (_U_(1) << 13) /**< GPIO Mask for LP_GPIO_13 */
#define GPIO_LP_GPIO_14             (_U_(1) << 14) /**< GPIO Mask for LP_GPIO_14 */
#define GPIO_LP_GPIO_15             (_U_(1) << 15) /**< GPIO Mask for LP_GPIO_15 */
#define GPIO_LP_GPIO_16             (_U_(1) << 0) /**< GPIO Mask for LP_GPIO_16 */
#define GPIO_LP_GPIO_17             (_U_(1) << 1) /**< GPIO Mask for LP_GPIO_17 */
#define GPIO_LP_GPIO_18             (_U_(1) << 2) /**< GPIO Mask for LP_GPIO_18 */
#define GPIO_LP_GPIO_19             (_U_(1) << 3) /**< GPIO Mask for LP_GPIO_19 */
#define GPIO_LP_GPIO_20             (_U_(1) << 4) /**< GPIO Mask for LP_GPIO_20 */
#define GPIO_LP_GPIO_22             (_U_(1) << 6) /**< GPIO Mask for LP_GPIO_22 */
#define GPIO_LP_GPIO_23             (_U_(1) << 7) /**< GPIO Mask for LP_GPIO_23 */
#define GPIO_AO_GPIO_2              (_U_(1) << 13) /**< GPIO Mask for AO_GPIO_2 */
#define GPIO_AO_GPIO_1              (_U_(1) << 14) /**< GPIO Mask for AO_GPIO_1 */
#define GPIO_AO_GPIO_0              (_U_(1) << 15) /**< GPIO Mask for AO_GPIO_0 */
#define GPIO_GPIO_MS4               (_U_(1) << 12) /**< GPIO Mask for GPIO_MS4 */
#define GPIO_GPIO_MS3               (_U_(1) << 13) /**< GPIO Mask for GPIO_MS3 */
#define GPIO_GPIO_MS2               (_U_(1) << 14) /**< GPIO Mask for GPIO_MS2 */
#define GPIO_GPIO_MS1               (_U_(1) << 15) /**< GPIO Mask for GPIO_MS1 */

/* ========== Peripheral I/O indexes ========== */
#define GPIO_LP_GPIO_0_IDX          (  0)  /**< GPIO Index Number for LP_GPIO_0 */
#define GPIO_LP_GPIO_1_IDX          (  1)  /**< GPIO Index Number for LP_GPIO_1 */
#define GPIO_LP_GPIO_2_IDX          (  2)  /**< GPIO Index Number for LP_GPIO_2 */
#define GPIO_LP_GPIO_3_IDX          (  3)  /**< GPIO Index Number for LP_GPIO_3 */
#define GPIO_LP_GPIO_4_IDX          (  4)  /**< GPIO Index Number for LP_GPIO_4 */
#define GPIO_LP_GPIO_5_IDX          (  5)  /**< GPIO Index Number for LP_GPIO_5 */
#define GPIO_LP_GPIO_6_IDX          (  6)  /**< GPIO Index Number for LP_GPIO_6 */
#define GPIO_LP_GPIO_7_IDX          (  7)  /**< GPIO Index Number for LP_GPIO_7 */
#define GPIO_LP_GPIO_8_IDX          (  8)  /**< GPIO Index Number for LP_GPIO_8 */
#define GPIO_LP_GPIO_9_IDX          (  9)  /**< GPIO Index Number for LP_GPIO_9 */
#define GPIO_LP_GPIO_10_IDX         ( 10)  /**< GPIO Index Number for LP_GPIO_10 */
#define GPIO_LP_GPIO_11_IDX         ( 11)  /**< GPIO Index Number for LP_GPIO_11 */
#define GPIO_LP_GPIO_12_IDX         ( 12)  /**< GPIO Index Number for LP_GPIO_12 */
#define GPIO_LP_GPIO_13_IDX         ( 13)  /**< GPIO Index Number for LP_GPIO_13 */
#define GPIO_LP_GPIO_14_IDX         ( 14)  /**< GPIO Index Number for LP_GPIO_14 */
#define GPIO_LP_GPIO_15_IDX         ( 15)  /**< GPIO Index Number for LP_GPIO_15 */
#define GPIO_LP_GPIO_16_IDX         ( 16)  /**< GPIO Index Number for LP_GPIO_16 */
#define GPIO_LP_GPIO_17_IDX         ( 17)  /**< GPIO Index Number for LP_GPIO_17 */
#define GPIO_LP_GPIO_18_IDX         ( 18)  /**< GPIO Index Number for LP_GPIO_18 */
#define GPIO_LP_GPIO_19_IDX         ( 19)  /**< GPIO Index Number for LP_GPIO_19 */
#define GPIO_LP_GPIO_20_IDX         ( 20)  /**< GPIO Index Number for LP_GPIO_20 */
#define GPIO_LP_GPIO_22_IDX         ( 22)  /**< GPIO Index Number for LP_GPIO_22 */
#define GPIO_LP_GPIO_23_IDX         ( 23)  /**< GPIO Index Number for LP_GPIO_23 */
#define GPIO_AO_GPIO_2_IDX          ( 29)  /**< GPIO Index Number for AO_GPIO_2 */
#define GPIO_AO_GPIO_1_IDX          ( 30)  /**< GPIO Index Number for AO_GPIO_1 */
#define GPIO_AO_GPIO_0_IDX          ( 31)  /**< GPIO Index Number for AO_GPIO_0 */
#define GPIO_GPIO_MS4_IDX           ( 44)  /**< GPIO Index Number for GPIO_MS4 */
#define GPIO_GPIO_MS3_IDX           ( 45)  /**< GPIO Index Number for GPIO_MS3 */
#define GPIO_GPIO_MS2_IDX           ( 46)  /**< GPIO Index Number for GPIO_MS2 */
#define GPIO_GPIO_MS1_IDX           ( 47)  /**< GPIO Index Number for GPIO_MS1 */

Sorry, since I do not work with this chip, I cannot help you with your code issues.  Good luck.

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

Last Edited: Sun. Jan 21, 2018 - 07:35 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your reply. So when I check under debugger the value of GPIO_14 (defined as GPIO(GPIO_PORTA, 14)) and GPIO_MS2 (defined as GPIO(GPIO_PORTA, 46)) are same values equal to 14. And 46 = 32 + 14.

This makes me think that definition of the MS1 pin is wrong. In the local makers club ppl confirmed that they could not program MSx ports as normal GPIOs as well. Any other ideas? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Any other ideas?

 

Are you using a SAMB11 Xplained Pro board?  If not, which chip do you have, an ATSAMB11-XR2100A or an ATSAMB11-ZR210CA?  I will investigate this further no promises on results..

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I am using ATSAMB11-MR210CA on a custom board. After programming I unplug a programmer and checking the voltage level directly on ATSAMB11-MR210CA pins. Pins MS3 and MS4 are not connected on my board, so no peripherals can affect the readings. Not sure if this helps, but when we define pin as 

#define GPIO_MS2 GPIO(GPIO_PORTB, 46) 

Instead of 

#define GPIO_MS2 GPIO(GPIO_PORTA, 46) // Autogenerated code by Atmel Start

The value changes from 14 to 46.

As for promises - it is certainly understandable, no expectations. There was a hope that someone came across this issue before. And thanks a lot for your cooperation.

Last Edited: Mon. Jan 22, 2018 - 08:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

fredgolm wrote:
Yes, I am using ATSAMB11-MR210CA on a custom board.
That is the module number, the chip on the module is what I was asking for.  The module datasheet only has this to say

 

 Refer to the ATSAMB11-2100A datasheet for more information.

​and that is incomplete in itself as a search on Microchip only returns a link back to the module that references that statement.

 

The module number does not bring up anything in Start, so what chip did you actually select when configuring your Start project?  Also, what version of Start is your project configured for?

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

Last Edited: Mon. Jan 22, 2018 - 11:19 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 so what chip did you actually select when configuring your Start project?

So module ATSAMB11-MR210CA underneath is using SAMB11 QFN SOC. In it's documentation here (http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-42426-SmartConnect-SAMB11-SOC_Datasheet.pdf) it points the module name: ATSAMB11G18A. So in Atmel Studio I started the project for ATSAMB11G18A, which happened to be same micro-controller as used in XPlained Pro board (it uses ATSAMB11-MR510CA AFAIK) . There are some example there as well. Main documentation is here: http://www.microchip.com/wwwproducts/en/ATSAMB11 

Also, what version of Start is your project configured for?

And I am using the latest Atmel Studio 7, ASF 4, downloaded it in January 2018. Was using PINMUX configurator to configure GPIO pins (PINMUX Configurator).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Okay, that is the info I needed, working on some ideas.

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

fredgolm wrote:
May be ATMEL start points wrong number (46,47,..)?
More on this.

 

The defined GPIO_15, GPIO_MS1 and GPIO_MS2 are 8 bit packed representations of the port|pin and are used as parameters in functions in main, hal_gpio.h and possibly elsewhere.

 

The macros GPIO_PORT and GPIO_PIN are used to unpack the port|pin values and are used as parameters in the functions in hpl_gpio.h, hpl_gpio_base.h and possibly elsewhere. 

 

See the snippet below, this is found in hpl_gpio.h

/**
 * \brief Macros for the pin and port group, lower 5
 * bits stands for pin number in the group, higher 3
 * bits stands for port group
 */
#define GPIO_PIN(n) (((n)&0x1Fu) << 0)
#define GPIO_PORT(n) ((n) >> 5)
#define GPIO(port, pin) ((((port)&0x7u) << 5) + ((pin)&0x1Fu))

The decimal value 47 for GPIO_MS1 is 00101111​ in binary.  if you separate that binary number per the brief above you end up with 001 for the port, corresponding to PORTA, and 1111 for the pin, corresponding to pin 15.

 

The decimal value 46 for GPIO_MS1 is 00101110 in binary.  if you separate that binary number per the brief above you end up with 001 for the port, corresponding to PORTA, and 1110 for the pin, corresponding to pin 14.

 

  Why the pin values used in the defines of 47 and 46

#define GPIO_MS1 GPIO(GPIO_PORTA, 47)
#define GPIO_MS2 GPIO(GPIO_PORTA, 46)

are the same as the packed values of GPIO_MS1 and GPIO_MS2 is odd though.

 

I certainly don't have the answer for why your code does not work.

 

EDIT: Substantially changed

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

Last Edited: Tue. Jan 23, 2018 - 10:25 AM