This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] LP-MSPM0G3507:第一个在 MSPM0G3507 Launch Pad 上测试编译环境的代码

Guru**** 2482225 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1248899/lp-mspm0g3507-first-code-to-test-build-environment-on-mspm0g3507-launch-pad

器件型号:LP-MSPM0G3507
主题中讨论的其他器件:MSPM0G3507

好了、只需设置我的构建环境即可。 因此、第一个使 LED 闪烁的程序很简单:

#include "ti_msp_dl_config.h"
#include "ti/devices/msp/m0p/mspm0g350x.h"
#include "ti/devices/msp/peripherals/hw_gpio.h"


int main(void) {
  GPIO_Regs *GPIOA=(GPIO_Regs *)GPIOA_BASE; // set up point to GPIO A

  GPIOA->DOE31_0 |= 1; // enable PA0
  
  while (1) {
    for (int i=0; i<100000; i++); // pause
    GPIOA->DOUT31_0 ^= 1; // toggle PA0
  }
}

使用 objdump–x 快速查看、编译的代码看起来像是它设置了正确的中断等

arm-none-eabi-objdump -x gcc/pwm_led_driver.out 

gcc/pwm_led_driver.out:     file format elf32-littlearm
gcc/pwm_led_driver.out
architecture: armv6s-m, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x000000c0

Program Header:
    LOAD off    0x00001000 vaddr 0x00000000 paddr 0x00000000 align 2**12
         filesz 0x000001b8 memsz 0x000001b8 flags r-x
    LOAD off    0x00002000 vaddr 0x20200000 paddr 0x000001b8 align 2**12
         filesz 0x00000000 memsz 0x00000000 flags rw-
    LOAD off    0x00000000 vaddr 0x20200000 paddr 0x20200000 align 2**12
         filesz 0x00000000 memsz 0x00000000 flags rw-
private flags = 0x5000200: [Version5 EABI] [soft-float ABI]

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .intvecs      000000c0  00000000  00000000  00001000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  1 .text         000000f8  000000c0  000000c0  000010c0  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .ramfunc      00000000  20200000  20200000  00002000  2**0
                  CONTENTS
  3 .rodata       00000000  000001b8  000001b8  00002000  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  4 .ARM.extab    00000000  000001b8  000001b8  00002000  2**0
                  CONTENTS
  5 .data         00000000  20200000  000001b8  00002000  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  6 .bss          00000000  20200000  000001b8  00002000  2**0
                  ALLOC
  7 .debug_info   0001c956  00000000  00000000  00002000  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
  8 .debug_abbrev 00000bb8  00000000  00000000  0001e956  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
  9 .debug_aranges 00000268  00000000  00000000  0001f50e  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 10 .debug_rnglists 000000b8  00000000  00000000  0001f776  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 11 .debug_line   00002b9d  00000000  00000000  0001f82e  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 12 .debug_str    00003b1f  00000000  00000000  000223cb  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 13 .comment      00000097  00000000  00000000  00025eea  2**0
                  CONTENTS, READONLY
 14 .ARM.attributes 0000002c  00000000  00000000  00025f81  2**0
                  CONTENTS, READONLY
 15 .debug_frame  00000670  00000000  00000000  00025fb0  2**2
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 16 .debug_ranges 00000688  00000000  00000000  00026620  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 17 .debug_loc    000023d6  00000000  00000000  00026ca8  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
SYMBOL TABLE:
00000000 l    d  .intvecs	00000000 .intvecs
000000c0 l    d  .text	00000000 .text
20200000 l    d  .ramfunc	00000000 .ramfunc
000001b8 l    d  .rodata	00000000 .rodata
000001b8 l    d  .ARM.extab	00000000 .ARM.extab
20200000 l    d  .data	00000000 .data
20200000 l    d  .bss	00000000 .bss
00000000 l    d  .debug_info	00000000 .debug_info
00000000 l    d  .debug_abbrev	00000000 .debug_abbrev
00000000 l    d  .debug_aranges	00000000 .debug_aranges
00000000 l    d  .debug_rnglists	00000000 .debug_rnglists
00000000 l    d  .debug_line	00000000 .debug_line
00000000 l    d  .debug_str	00000000 .debug_str
00000000 l    d  .comment	00000000 .comment
00000000 l    d  .ARM.attributes	00000000 .ARM.attributes
00000000 l    d  .debug_frame	00000000 .debug_frame
00000000 l    d  .debug_ranges	00000000 .debug_ranges
00000000 l    d  .debug_loc	00000000 .debug_loc
00000000 l    df *ABS*	00000000 startup_mspm0g3507_gcc.c
00000000 l    df *ABS*	00000000 pwm_led_driver.c
00000000 l    df *ABS*	00000000 ti_msp_dl_config.c
00000000 l    df *ABS*	00000000 dl_common.c
00000000 l    df *ABS*	00000000 dl_timer.c
000001ac  w    F .text	00000008 TIMG6_IRQHandler
000001ac  w    F .text	00000008 TIMG8_IRQHandler
20200000 g       .data	00000000 __data_start__
000001ac  w    F .text	00000008 I2C0_IRQHandler
000001ac  w    F .text	00000008 HardFault_Handler
00000080 g       *ABS*	00000000 _Min_Stack_Size
000001ac  w    F .text	00000008 SysTick_Handler
000001ac  w    F .text	00000008 PendSV_Handler
000001ac  w    F .text	00000008 NMI_Handler
000001b8 g       .ARM.extab	00000000 __exidx_end
000001ac  w    F .text	00000008 I2C1_IRQHandler
000001ac  w    F .text	00000008 UART1_IRQHandler
000001b8 g       .text	00000000 __etext
000001ac  w    F .text	00000008 TIMA1_IRQHandler
20200000 g       *ABS*	00000000 _vtable_base_address
000001ac  w    F .text	00000008 UART0_IRQHandler
000001ac  w    F .text	00000008 ADC0_IRQHandler
20200000 g       .debug_info	00000000 __HeapLimit
20200000 g       .debug_info	00000000 __heap_end__
20200000 g       .bss	00000000 __bss_start__
000001ac  w    F .text	00000008 SPI1_IRQHandler
000001b8 g       .ARM.extab	00000000 __exidx_start
000001ac  w    F .text	00000008 TIMG0_IRQHandler
000001ac  w    F .text	00000008 ADC1_IRQHandler
000001ac  w    F .text	00000008 GROUP1_IRQHandler
000001ac  w    F .text	00000008 RTC_IRQHandler
00000114  w    F .text	00000098 Reset_Handler
000001ac  w    F .text	00000008 GROUP0_IRQHandler
20200000 g       .debug_info	00000000 end
000001ac  w    F .text	00000008 UART2_IRQHandler
20200000 g       .data	00000000 __data_end__
20200000 g       .bss	00000000 __bss_end__
00000000 g       *ABS*	00000000 _Min_Heap_Size
000001ac g     F .text	00000008 Default_Handler
20200000 g       .debug_info	00000000 __end
000001b8 g       *ABS*	00000000 __data_load__
000000c0 g     F .text	00000054 main
000001b8 g       *ABS*	00000000 __ramfunct_load__
000001ac  w    F .text	00000008 SVC_Handler
000001b8 g       .text	00000000 __init_array_end
20200000 g       .debug_info	00000000 __heap_start__
000001ac  w    F .text	00000008 TIMG12_IRQHandler
20200000 g       .ramfunc	00000000 __ramfunct_end__
000001ac  w    F .text	00000008 DAC0_IRQHandler
20208000 g       .bss	00000000 __StackTop
000001ac  w    F .text	00000008 TIMG7_IRQHandler
000001ac  w    F .text	00000008 SPI0_IRQHandler
20200000 g       .ramfunc	00000000 __ramfunct_start__
20200000 g       .debug_info	00000000 _end
000001ac  w    F .text	00000008 AES_IRQHandler
00000000 g     O .intvecs	000000c0 interruptVectors
000001ac  w    F .text	00000008 DMA_IRQHandler
000001b8 g       .text	00000000 __init_array_start
000001ac  w    F .text	00000008 TIMA0_IRQHandler
20200000 g       .debug_info	00000000 _stack
000001ac  w    F .text	00000008 UART3_IRQHandler
00000000 g       *ABS*	00000000 _intvecs_base_address
000001ac  w    F .text	00000008 CANFD0_IRQHandler

但是 LED 不闪烁,并且尝试|= 1和&=~1(例如开和关)也不工作。 所以,像往常一样,我必须做一些简单的错误! 有什么想法吗?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    我很确定您还需要使用类似下面的内容来设置 IOMUX 焊盘:

    > IOMUX->SECCFG.PINCM[1] = (IOMUX_PINCM_PC_CONNECTED |(uint32_t) 0x00000001);

    其中、[1]是指数据表(SLASEX6A)中的 PA0、而 PF=1是("众所周知") GPIO 功能。 (我的 Launchpad 已损坏、因此我无法自行尝试。)

    [编辑:次要澄清]

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 David:

    Bruce 是正确的、 也必须配置 IOMUX。

    我认为索引需要递减 1以反映头文件中使用的0索引(请参阅下面来自 mspm0g350x.h 的代码段、IOMUX_PINCM1实际上定义为0而不是1)。  

    因此、Bruce shared 的行应该是:

    IOMUX->SECCFG.PINCM[0] = (IOMUX_PINCM_PC_CONNECTED | ((uint32_t) 0x00000001));

    当然、您也可以仅使用 IOMUX_PINCM1 。  

    您还将需要启用 GPIO 外设的电源。 在修改任何 GPIOA 寄存器之前、您应该首先在代码中执行此操作。  

    GPIOA->GPRCM.PWREN = (GPIO_PWREN_KEY_UNLOCK_W | GPIO_PWREN_ENABLE_ENABLE);
    delay_cycles(16);

    有关更多详细信息、请参阅技术参考手册(SLAU846)的这一节。

    此致、
    布兰登·费舍尔

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    感谢两位-是的、这解决了问题。 昨晚读了 TRM 我意识到我需要设置 IOMUX。 在阅读数据表时、我没有找到表6-1、直到您指明了它!

    喜欢注释"PF=1是"众所周知的"GPIO 函数"-是的,我找不到它写的任何地方 PF=1 ;它也有其他 PF 值。

    Brandon 使用[0]是正确的,但在我的 mspm0g350x.h 中并没有体现-我仍在原始的 mspmp_sdk_1_00_00_04上-我将会查看最新的版本。

    Bruce -您是如何打破 Launchpad 的?

    总之、我当前的代码-它会闪烁 LED、我已将不需要的代码添加了注释!

    #include "ti_msp_dl_config.h"
    #include "ti/devices/msp/m0p/mspm0g350x.h"
    // #include "ti/devices/msp/peripherals/hw_gpio.h"
    // #include "ti/devices/msp/peripherals/hw_iomux.h"
    
    
    int main(void) {
      //  static GPIO_Regs *GPIOA=(GPIO_Regs *)GPIOA_BASE; // set up point to GPIO A
      //  static IOMUX_REG *IOMUX=(IOMUX_Regs *)IOMUX_BASE; // set up point to IOMUX
    
      GPIOA->GPRCM.PWREN = (GPIO_PWREN_KEY_UNLOCK_W | GPIO_PWREN_ENABLE_ENABLE);
      delay_cycles(16);
    
      IOMUX->SECCFG.PINCM[0] = (uint32_t) (IOMUX_PINCM_PC_CONNECTED | 1);
      GPIOA->DOE31_0 |= 1; // enable PA0
      
      while (1) {
        for (uint32_t i=0; i<10000000; i++) {
          asm ("nop");
        } // pause
        GPIOA->DOUT31_0 ^= 1; // toggle PA0
      }
    }