从8位微控制器中的存储器位置(带有24位地址)读取值

时间:2019-07-16 08:24:41

标签: c pointers memory embedded

我认为它应该像这样简单:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <surefire-plugin.version>2.22.0</surefire-plugin.version>
        <quarkus.version>0.18.0</quarkus.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencyManagement>
        <dependencies>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-bom</artifactId>
            <version>${quarkus.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>

        <dependency>
        <groupId>com.google.code.findbugs</groupId>
        <artifactId>jsr305</artifactId>
        <version>3.0.2</version>
    </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>


        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.1.8.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.1.8.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>

        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

         <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
            </dependency>

            <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-resteasy</artifactId>
            </dependency>


            <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-junit5</artifactId>
            <scope>test</scope>
            </dependency>


            <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <scope>test</scope>
        </dependency>

      <dependency>
           <groupId>io.quarkus</groupId>
           <artifactId>quarkus-spring-di</artifactId>
        </dependency>
      </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>


      <plugin>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-maven-plugin</artifactId>
        <version>${quarkus.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>build</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${surefire-plugin.version}</version>
        <configuration>
          <systemProperties>
            <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
          </systemProperties>
        </configuration>
      </plugin>
      </plugins>
    </build>
<profiles>
    <profile>
      <id>native</id>
      <activation>
        <property>
          <name>native</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-maven-plugin</artifactId>
            <version>${quarkus.version}</version>
            <executions>
              <execution>
                <goals>
                  <goal>native-image</goal>
                </goals>
                <configuration>
                  <enableHttpUrlHandler>true</enableHttpUrlHandler>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>${surefire-plugin.version}</version>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
                <configuration>
                <systemProperties>
         <native.image.path>
            ${project.build.directory}/${project.build.finalName}-runner
         </native.image.path>
                  </systemProperties>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

如果存储位置具有以下值:the following value

然后2019-07-16 15:27:17,757 INFO [io.qua.dep.QuarkusAugmentor] (main) Beginning quarkus augmentation 2019-07-16 15:27:19,054 INFO [io.qua.arc.pro.BeanProcessor] (build-13) -13) Found unrecommended usage of private members (use package-private instead) in application beans: - @Inject field com.example.demo.GreeterBean#messageProducer 2019-07-16 15:27:19,325 INFO [io.qua.dep.QuarkusAugmentor] (main) ain) Quarkus augmentation completed in 1568ms 2019-07-16 15:27:19,831 INFO [io.und.servlet] (main) No Spring WebApplicationInitializer types detected on classpath 2019-07-16 15:27:20,177 INFO [io.quarkus] (main) Quarkus rkus 0.18.0 started in 2.698s. Listening on: http://[::]:8080 2019-07-16 15:27:20,178 INFO [io.quarkus] (main) Installetalle d features: [cdi, resteasy, spring-di] 应该等于uint32_t getCrc(void) { uint32_t expectedCrc = *(uint32_t*)0x27FF0; return expectedCrc; }

但是令人惊讶的是,该值为:expectedCrc

我尝试定义一个指向0xECD8743D的指针,并为其分配内存地址,如下所示:

0x82828282

但是指针本身的值为uint32_t,而uint32_t getCrc(void) { uint32_t *ptr = (uint32_t*)0x27FF0; uint32_t expectedCrc = *ptr; return expectedCrc; } 等于0xFFFF

我在不同的内存地址中找到了这两个值:

enter image description here

我也尝试过使用expectedCrc进行相同操作,但是它给出了相同的值。

最后,我尝试使用0x82828282检查此控制器中指向char的指针的大小,答案是char *ptr = (char*)0x27FF0,它等于uint8_t size = sizeof(char*);

我认为这与24位内存地址和CPU架构有关。我正在使用0xb0控制器。

有人可以解释为什么会这样吗?

更新

我尝试用176替换地址stm8,它工作正常。所以问题出在长地址。我想在最后一个地址中写入CRC值,以避免在程序变大时用代码本身覆盖它。我该如何处理?

2 个答案:

答案 0 :(得分:5)

来自Cosmic编译器数据表https://www.cosmic-software.com/pdf/cxstm8_pd.pdf

  

cxstm8根据应用程序的大小提供2种不同的内存模型。

     

对于小于64k的应用程序,“第0节”内存模型通过默认函数调用和2字节指针来提供最佳代码密度。

     

对于大于64k的应用程序,标准内存模型为轻松使用线性寻址空间提供了最佳的灵活性。每个模型都带有自己的一组库。

这可能是导致您出现问题的原因。如果要直接访问16位以上地址的内存位置,则需要使用正确的内存模型。

答案 1 :(得分:2)

@Raje回答说这与内存模型有关,我在 COSMIC用户指南中做了进一步的阅读,发现以下内容:

  

STM8编译器支持两种应用程序内存模型   大于64K,让您选择最有效的行为   取决于您的处理器配置和应用程序。所有   这些模型允许代码大于64K,然后起作用   指针默认为@far指针(3个字节)。数据指针是   除非使用明确声明,否则默认为@near指针(2个字节)   @far修饰符。

因此,解决方案是将scanner添加到指针的类型如下:

@far

问题解决了。