小编eva*_*ing的帖子

匹配来自STM32F0和zlib的CRC32

我正在研究运行Linux和STM32F0的计算机之间的通信链接.我想对我的数据包使用某种错误检测,因为STM32F0有CRC32 hw,我在Linux上有zlib和CRC32,我认为在我的项目中使用CRC32是个好主意.问题是我不会在不同平台上获得相同数据的CRC值.

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <zlib.h>

int
main(void)
{
  uint8_t byte0 = 0x00;
  uint32_t crc0 = crc32(0L, Z_NULL, 0);
  crc0 = crc32(crc0, &byte0, 1);
  printf("CRC32 value of %" PRIu8 " is: %08" PRIx32 "\n", byte0, crc0);
}
Run Code Online (Sandbox Code Playgroud)

输出CRC32 value of 0 is: d202ef8d与几个在线计算器的结果相匹配.

看来我在STM32上使用的任何设置都无法获得相同的CRC.我已经找到了一个关于CRC hw如何在ST的应用笔记中计算其值的流程图,但我无法弄清楚它是如何在zlib中完成的.

有谁知道它们是否兼容?

[编辑1]它们都使用相同的初始值和多项式.

[编辑2] STM32代码相对来说非常复杂,因为它使用的是hw.

...
/* Default values are used for init value and polynomial, see edit 1 */
CRC->CR |= CRC_CR_RESET;
CRC->DR = (uint8_t)0x00; …
Run Code Online (Sandbox Code Playgroud)

c linux crc32 crc stm32

4
推荐指数
2
解决办法
5788
查看次数

在os x上用python3安装pyside

我试图在osx mountain lion上安装pyside和python3.我一直都在尝试

brew install pyside
Run Code Online (Sandbox Code Playgroud)

但它只适用于python2.

我也尝试过使用pyside github rep的buildscripts.进行必要的更改

./build_and_install
Run Code Online (Sandbox Code Playgroud)

然而,失败了

Linking CXX shared library libpyside.cpython-33m.dylib
[  4%] Built target pyside
[  4%] Running generator for QtCore...
/bin/sh: /Users/einar/devel/pkg/pyside-sandbox-python3/bin/SHIBOKEN_GENERATOR-NOTFOUND: No such file or directory
make[2]: *** [PySide/QtCore/PySide/QtCore/qabstracteventdispatcher_wrapper.cpp] Error 127
make[1]: *** [PySide/QtCore/CMakeFiles/QtCore.dir/all] Error 2
make: *** [all] Error 2
Run Code Online (Sandbox Code Playgroud)

我现在不知道该怎么办.我发现这个页面pyside论坛建议我只需要通过符号链接一些东西来让它在python3中工作,brew install pyside/usr/local/Cellar/pyside/1.1.2/lib只有一些名为2.7的文件.

有没有人设法让pyside在osx上使用python3或者知道如何做到这一点的指导?我的google-fu让我失望了.

python macos homebrew pyside python-3.x

3
推荐指数
1
解决办法
4921
查看次数

VHDL状态机差异(用于合成)

我参加了一个关于嵌入式系统设计的课程和我的一个同学,他们采取了另一种方法,声称另一门课程的讲师不会让他们实现这样的状态机:

architecture behavioral of sm is
    type state_t is (s1, s2, s3);
    signal state : state_t;
begin
    oneproc: process(Rst, Clk)
    begin
        if (Rst = '1') then
            -- Reset
        elsif (rising_edge(Clk)) then
            case state is
                when s1 =>
                    if (input = '1') then
                        state <= s2;
                    else
                        state <= s1;
                    end if;
                    ...
                    ...
                    ...

            end case;
        end if;
    end process;
end architecture;
Run Code Online (Sandbox Code Playgroud)

但相反,他们必须这样做:

architecture behavioral of sm is
    type state_t is (s1, s2, s3);
    signal state, next_state : state_t;
begin …
Run Code Online (Sandbox Code Playgroud)

state-machine vhdl

3
推荐指数
1
解决办法
3418
查看次数

是否在C中定义了结构类型的对齐方式?

我知道C结构中的成员与他们需要的任何边界对齐.

struct S {
  uint8_t ui8;
  /* invisible padding here */
  uint32_t ui32;
};
Run Code Online (Sandbox Code Playgroud)

我的问题是,struct S是否定义了实例的对齐方式?

struct S my_s; 
Run Code Online (Sandbox Code Playgroud)

是否my_s定义了对齐?是否struct Sui32成为其第一个成员是否重要?

我搜索过但只找到了关于struct member alignment的信息.

c struct memory-alignment

3
推荐指数
1
解决办法
125
查看次数

怎么"sizeof(char [0])"与GCC编译得很好

我的一位同事(void) sizeof (char[0])在一条多线的末端插入了一个宏,do {...} while (0)显然是一个替代品.我环顾四周,但我找不到它的任何参考,它甚至编译它让我感到惊讶.

它是有效的C吗?我很想参考std.

c gcc

3
推荐指数
1
解决办法
104
查看次数

从二进制搜索树递归构建数组时的Java StackOverflowError

我试图通过首先构建一个数组(inorder)来平衡BST,然后从我的数组重建整个树.

我有:

 public void toArray(E[] a) {
  toArray(root, a, 0);
 }

 /*
  * Adds all elements from the tree rooted at n in inorder to the array a
  * starting at a[index].
  * Returns the index of the last inserted element + 1 (the first empty
  * position in a).
  */
 private int toArray(BinaryNode<E> node, E[] a, int index) {
  if (node.left != null) {
   index = toArray(node, a, index);
  }

  a[index] = node.element;
  index++;

  if (node.right != null) { …
Run Code Online (Sandbox Code Playgroud)

java stack-overflow rebuild binary-tree

2
推荐指数
1
解决办法
1304
查看次数

当git rm和git add在不同的文件上完成时重命名文件

我刚刚做了git rm file1.c以后的git status节目

On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    deleted:    file1.c

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    dir/file2.c
    dir/file3.c
Run Code Online (Sandbox Code Playgroud)

到目前为止一切顺利.但是,如果git add dir/file2.c我得到了

On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local …
Run Code Online (Sandbox Code Playgroud)

git

2
推荐指数
1
解决办法
988
查看次数

C zlib crc32 和 Python zlib crc32 不匹配

我在 Python 和 C 中对 crc32 进行了一些试验,但我的结果不匹配。

C:
#include <stdio.h>
#include <stdlib.h>
#include <zlib.h>

#define NUM_BYTES 9

int
main(void)
{

  uint8_t bytes[NUM_BYTES] = {1, 2, 3, 4, 5, 6, 7, 8, 9};

  uint32_t crc = crc32(0L, Z_NULL, 0);

  for (int i = 0; i < NUM_BYTES; ++i) {
    crc = crc32(crc, bytes, 1);
  }

  printf("CRC32 value is: %" PRIu32 "\n", crc);
}
Run Code Online (Sandbox Code Playgroud)

给出输出 CRC32 value is: 3136421207

Python

In [1]: import zlib
In [2]: int(zlib.crc32("123456789") + 2**32)
Out[2]: 3421780262
Run Code Online (Sandbox Code Playgroud)

在 …

c python crc32 zlib

2
推荐指数
1
解决办法
9038
查看次数

使用 JLink 和 GDB 读取 Cortex M0 MCU 的外设寄存器

我正在尝试使用 GDB 读取 MCU ADC 寄存器,但我似乎无法找到它是如何完成的。

使用x\10x 0x40012708ingdb仅返回零,就像我尝试读取的任何内存映射外设寄存器一样。

这有可能吗?如果是这样,它是如何完成的?

谢谢!

peripherals gdb cortex-m

2
推荐指数
1
解决办法
3324
查看次数

Systemd dbus sd_bus_call_method() 与数组

我正在尝试使用 systemd dbus 修改一些代码。

方法调用如下所示:

res = sd_bus_call_method(bus,
    SERVICE_NAME,
    OBJECT_PATH,
    INTERFACE,
    "AddData",
    &error, &m,
    "ss",
    data->key,
    data->valyue);
Run Code Online (Sandbox Code Playgroud)

现在我正在尝试将其更改为:

res = sd_bus_call_method(bus,
    SERVICE_NAME,
    OBJECT_PATH,
    INTERFACE,
    "AddData",
    &error, &m,
    "(a(ss))",
    /* WHAT DO I PASS HERE? */);
Run Code Online (Sandbox Code Playgroud)

我找不到示例或文档,并且代码对我来说不是很清楚。

dbus systemd

2
推荐指数
1
解决办法
3723
查看次数