2019年9月2日 星期一

STM32H7 HAL_SPI_Transmit_DMA not working (return HAL_ERROR)

Configure the TX DMA only:
    /* Configure the DMA handler for Transmission process */
    hdma_tx.Instance                 = SPIx_TX_DMA_STREAM;
    hdma_tx.Init.FIFOMode            = DMA_FIFOMODE_DISABLE;
    hdma_tx.Init.FIFOThreshold       = DMA_FIFO_THRESHOLD_FULL;
    hdma_tx.Init.MemBurst            = DMA_MBURST_INC4;
    hdma_tx.Init.PeriphBurst         = DMA_PBURST_INC4;
    hdma_tx.Init.Request             = SPIx_TX_DMA_REQUEST;
    hdma_tx.Init.Direction           = DMA_MEMORY_TO_PERIPH;
    hdma_tx.Init.PeriphInc           = DMA_PINC_DISABLE;
    hdma_tx.Init.MemInc              = DMA_MINC_ENABLE;
    hdma_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
    hdma_tx.Init.MemDataAlignment    = DMA_MDATAALIGN_BYTE;
    hdma_tx.Init.Mode                = DMA_NORMAL;
    hdma_tx.Init.Priority            = DMA_PRIORITY_LOW;

    HAL_DMA_Init(&hdma_tx);

    /* Associate the initialized DMA handle to the the SPI handle */
    __HAL_LINKDMA(hspi, hdmatx, hdma_tx);

But, in HAL_SPI_Transmit_DMA.c check with the RX DMA:
  /* Packing mode management is enabled by the DMA settings */
  if (((hspi->Init.DataSize > SPI_DATASIZE_16BIT) && (hspi->hdmarx->Init.MemDataAlignment != DMA_MDATAALIGN_WORD))    || \
      ((hspi->Init.DataSize > SPI_DATASIZE_8BIT) && ((hspi->hdmarx->Init.MemDataAlignment != DMA_MDATAALIGN_HALFWORD) && \
                                                         (hspi->hdmarx->Init.MemDataAlignment != DMA_MDATAALIGN_WORD))))
  {
    /* Restriction the DMA data received is not allowed in this mode */
    errorcode = HAL_ERROR;
    __HAL_UNLOCK(hspi);
    return errorcode;
  }

After STM32H7xx_HAL_Driver V1.4.0 / 30-November-2018:
HAL SPI:
Update HAL_SPI_Transmit_DMA : checking hmdtx instead of hdmrx.

2018年9月15日 星期六

STM32H7 SDRAM hardfault

The STM32H7xx SDRAM Brief :

The two default regions of SDRAM banks are not cacheable. Even if the cache is enabled,
the data or instructions do not go through the cache.

To benefit from cache acceleration, the SDRAM banks can be remapped from 0xC000 0000 and 0xD000 0000 to 0x6000 0000 and 0x7000 0000 respectively, which are, by default, cacheable regions. This is done by setting the field BMAP[1:0] bits in the FMC_BCR1 register.  Figure shows the different external memory mappings and their corresponding BMAP[1:0] values.


If the remapping is not suitable for the application, the Cortex®-M7 MPU can be used to
modify the propriety of the default SDRAM memory region to be cacheable.

The hardfault caused by unaligned memory access. STM32H7xx devices have the external SDRAM mapped to the address range 0xC0000000 - 0xCFFFFFFF (max. 256MB) and 0xD0000000 - 0xDFFFFFFF. According to the ARMv7-M Architecture Reference Manual chapter B3.1 (table B3-1), the area 0xC0000000-0xDFFFFFFF (512MB) is specified as Device Memory Type. According to chapter A3.2.1, all accesses to Device Memory Types must be naturally aligned.

Initializes the MPU so that the SDRAM memory area is considered as Normal Memory type instead of Device Memory type. This disables the access alignment restrictions.

    MPU_Region_InitTypeDef MPU_InitStruct;
    HAL_MPU_Disable();

    /* Configure the MPU attributes as WT for SDRAM */
    MPU_Region_InitTypeDef MPU_InitStruct;
    MPU_InitStruct.Enable = MPU_REGION_ENABLE;
    MPU_InitStruct.BaseAddress = 0xD0000000;
    MPU_InitStruct.Size = MPU_REGION_SIZE_32MB;
    MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
    MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
    MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
    MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
    MPU_InitStruct.Number = MPU_REGION_NUMBER1;
    MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
    MPU_InitStruct.SubRegionDisable = 0x00;
    MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;

    HAL_MPU_ConfigRegion(&MPU_InitStruct);

    /* Enable the MPU */
    HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);

Other solutions for the STM32H7xx: Remap the SDRAM to address  0x60000000 - 0x7FFFFFFF or Generate code with the natural alignment.

References:
https://www.st.com/resource/en/application_note/dm00306681.pdf
https://developer.arm.com/docs/ddi0403/e/armv7-m-architecture-reference-manual
http://www.keil.com/support/docs/3777.htm
https://www.st.com/resource/en/application_note/dm00272912.pdf

2013年11月15日 星期五

Installing MySQL with phpMyAdmin On NAS4Free

* Platform OS        : FreeBSD 9.1-RELEASE-p5 (kern.osreldate: 901000)
* Version               : 9.1.0.1 - Sandstorm (revision 847)
* Build date           : Sun Aug 18 03:49:41 CEST 2013

Install MySQL server

First.
ADD a new Group on WebGUI and called mysql
ADD a new User on WebGUI and called mysql
Set the Set the account's primary group to mysql.

§  Log into NAS4Free using SSH or Telnet, for instance by using Putty
§  Create the MySQL data directory:
# mkdir /<directory_name>/db/mysql
§  Create the MySQL symbolic link:
# ln -s /<directory_name>/db/mysql /var/db/mysql
§  Change the owner:
# chown -R mysql:mysql /<directory_name>/db/mysql/
§  Allow anyone access the temporary directory:
# chmod 777 /tmp
# chmod 777 /var/tmp
# chmod 777 /ftmp
§  Install MySQL server:
# pkg_add -r mysql50-server
§  Create database:
# /usr/local/bin/mysql_install_db --user=mysql
# chown -R mysql /var/db/mysql
§  Start MySQL:
# /usr/local/bin/mysqld_safe &
§  Change the password:
# /usr/local/bin/mysqladmin -u root password 'root_password'
§  Edit config file:
# vi /etc/rc.conf
§  Start MySQL automatically by adding contents like that in this file:
mysql_enable="YES"
§  Reboot

Install PHP

§  The file cause WebGUI crash, Backup this file:
cp /usr/local/lib/libxml2.so.5 /tmp/libxml2.so.5
§  Install PHP packages:
# pkg_add -r php5-extensions
# pkg_add -r php5-xmlrpc
# pkg_add -r php5-gettext
# pkg_add -r php5-mcrypt
# pkg_add -r php5-mysql
# pkg_add -r php5-mbstring
# pkg_add -r php5-mysqli
§  Fix WebGUI crash problem:
# mv /usr/local/bin/php /usr/local/bin/php-cli
# cp /usr/local/bin/php-cgi /usr/local/bin/php
# rm /usr/local/lib/libxml2.so.5
# cp /tmp/libxml2.so.5 /usr/local/lib/libxml2.so.5

Install phpMyAdmin

  • Create the phpMyAdmin directory:
# mkdir /<directory_name>
§  Extract the contents of the phpMyAdmin to the new directory. Run the following command in Linux terminal.
# cd /<directory_name>
# fetch http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.0.9/phpMyAdmin-4.0.9-all-languages.tar.gz
# tar -zxvf phpMyAdmin-4.0.9-all-languages.tar.gz
§  Create the phpMyAdmin symbolic link:
# ln -s /<directory_name>/phpMyAdmin-4.0.9-all-languages /<directory_name>/phpMyAdmin
# ln -s /<directory_name>/phpMyAdmin /<web_directory>/phpMyAdmin
§  Access phpMyAdmin:
http://< NAS4Free_IP >/phpMyAdmin

2013年6月1日 星期六

Running Dropbox at Startup on QNAP NAS

* Model              : SS-439 Pro
* Version            : 3.8.3 build0426
* Date               : 2013/04/26

Make a new share on QNAP NAS and called Dropbox

Declaring a Dropbox QPKG which launches script at startup.
§  Log into QNAP device using SSH or Telnet, for instance by using Putty
§  Edit QPKG config file:
# vi /etc/config/qpkg.conf
§  Declare a new Dropbox package by adding contents like that in this file:
[Dropbox]
Name = Dropbox
Version = 2.0.22
Author = Dropbox
Date = 2013-05-06
Shell = /share/MD0_DATA/.qpkg/Dropbox /Dropbox.sh
Install_Path = /share/MD0_DATA/.qpkg/Dropbox
Enable = TRUE
Note: if NAS doesn't have /share/MD0_DATA (i.e. is a one-drive NAS), put the right directory into the Shell and Install_Path variables.
§  Create the Dropbox package directory:
# mkdir -p /share/MD0_DATA/.qpkg/Dropbox
§  Extract the contents of the Dropbox package to the new directory. Run the following command in Linux terminal.
# cd /share/MD0_DATA/.qpkg/Dropbox
# wget https://www.dropbox.com/download?plat=lnx.x86 --no-check-certificate
# tar -xzf dropbox-lnx.x86-2.0.22.tar.gz
§  Create the Dropbox symbolic link:
# ln -sf /share/MD0_DATA/Dropbox /share/MD0_DATA/.qpkg/Dropbox/Dropbox
§  Create the .dropbox directory:
# mkdir -p /share/MD0_DATA/.qpkg/Dropbox/.dropbox
§  Create the Dropbox script with the contents:
# vi /share/MD0_DATA/.qpkg/Dropbox/Dropbox.sh
§  To be able to enable and disable the Dropbox feature edit the script
#!/bin/sh

CONF=/etc/config/qpkg.conf
QPKG_NAME="Dropbox"

RETVAL=0
QPKG_BASE=
HOME=

DROPBOX_USER="admin"
DAEMON=.dropbox-dist/dropbox

LOCALE=en_US.UTF-8

HOMEDIR=`getent passwd $DROPBOX_USER | cut -d: -f6`

case "$1" in
  start)
 if [ `/sbin/getcfg $QPKG_NAME Enable -u -d FALSE -f $CONF` = UNKNOWN ]; then
       /sbin/setcfg $QPKG_NAME Enable TRUE -f $CONF
 elif [ `/sbin/getcfg $QPKG_NAME Enable -u -d FALSE -f $CONF` != TRUE ]; then
       echo "Dropbox is disabled."
       exit 1
 fi
                 PID=`ps -ef | awk '/[d]ropbox/{print $1}'`
        if [ -z $PID ] ; then
            echo "Starting Dropbox..."
        else
            echo "Dropbox is running. (PID $PID)"
                          exit 1
        fi
         HOME=$(/sbin/getcfg $QPKG_NAME Install_Path -d "" -f $CONF) 
         [ -d $HOMEDIR ] || /bin/mkdir -p $HOMEDIR
#create symbolic links                                    
         [ -d $HOMEDIR/.dropbox ] || ln -sf $HOME/.dropbox $HOMEDIR/.dropbox
         [ -d $HOMEDIR/Dropbox ] || ln -sf $HOME/Dropbox $HOMEDIR/Dropbox
         [ -d /root/.dropbox-dist ] || ln -sf $HOME/.dropbox-dist /root/.dropbox-dist
         [ -d /root/.dropbox ] || ln -sf $HOME/.dropbox /root/.dropbox
         echo 100000 > /proc/sys/fs/inotify/max_user_watches
         OLD_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
         LD_LIBRARY_PATH=$HOME:$LD_LIBRARY_PATH
         export LANG=$LOCALE
         $HOME/$DAEMON > $HOME/Dropbox_status.txt 2>&1 &
         RETVAL=$?
         /bin/sleep 5
         ;;
  stop) 
    PID=`ps -ef | awk '/[d]ropbox/{print $1}'`
         if [ -z $PID ] ; then
        /bin/echo "Dropbox isn't running!"
        exit 1
         fi
         kill -9 $PID
         echo "Dropbox daemon stopped."
         RETVAL=$?
         sleep 3
         ;;
  restart)
         sh $0 stop
         sh $0 start
         RETVAL=$?
         ;;
  status)
    PID=`ps -ef | awk '/[d]ropbox/{print $1}'`
    if [ -z $PID ] ; then
        echo "Dropbox isn't running!"
    else
        echo "Dropbox is running. (PID $PID)"
    fi
         ;;
  *)
         /bin/echo "Usage: $0 {start|stop|restart|status}"
         exit 1
esac

exit $RETVAL
§  Set the execute bit:
# chmod +x /share/MD0_DATA/.qpkg/Dropbox/Dropbox.sh
§  Reboot
References:

2012年8月29日 星期三

How to select suitable crystals and external components

In http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/APPLICATION_NOTE/CD00221665.pdf

External capacitors calculation

CL :   pF (crystal manufacturer)
CS :   pF

CL1 = CL2 =  pF

Gain margin calculation

ESR :   Ω (crystal manufacturer)
F :   Hz (crystal manufacturer)
CO :   pF (crystal manufacturer)
CL :   pF (crystal manufacturer)
gm :   mA/V (microcontroller manufacturer)

gmcrit =  mA/V
gainmargin = 
crystal will 

Calculating drive level

ESR :   Ω (crystal manufacturer)
F :   Hz (crystal manufacturer)
CL1 :   pF (calculation)
CS :   pF
Cprobe :   pF (oscilloscope manufacturer)
Vpp :   V (measurement)

DL =  uW

Calculating external resistor

F :   Hz (crystal manufacturer)
CL2 :   pF (calculation)
DL :   uW (measurement)
DL :   uW (crystal manufacturer)

REXT =  Ω

2012年8月3日 星期五

How to determine using which flash device to store the configuration data for configuring Altera FPGA

In http://www.altera.com/literature/hb/cfg/cyc_c51014.pdf

Table 1 lists the supported Altera EPCS devices.


Example 1. Compression Ratio Calculation

EP4SGX530 = 189,000,000 bits

EPCS128 = 134,217,728 bits

Preliminary data indicates that compression typically reduces the configuration bitstream size by 35% to 55%. Assume worst case that is 35% decompression.

189,000,000 bits x 0.65 = 122,850,000 bits

The EPCS128 device is suitable.



For example: Cyclone V E FPGA Device 5CEA7

In http://www.altera.com/literature/hb/cyclone-v/cv_51002.pdf
Table 43 lists the uncompressed raw binary file (.rbf) sizes for Cyclone V devices.


The EPCS64 device is suitable for the  Cyclone V E FPGA Device 5CEA7 .

2011年10月18日 星期二

Dump the Memory

PMDump v1.2


Open up a command prompt type the "pmdump -list" command


"pmdump -listdisplays a list of running Process with their Process ID (PID)


OR type the "tasklist" command


"tasklistdisplays a list of applications and services with their Process ID (PID) for all tasks running on either a local or a remote computer.


then dump the memory contents of a process


type the "pmdump <PID> <filename>" command
ex: pmdump 777 dump.bin



pmdump 1.2 - (c) 2002, Arne Vidstrom (arne.vidstrom@ntsecurity.nu)
           - http://ntsecurity.nu/toolbox/pmdump/


Usage: pmdump <pid> <filename>


        - dumps the process memory contents to a file


       pmdump -list


        - lists all running processes and their PID's





ManTech Physical Memory Dump Utility


mdd_1.3.zip



a physical memory acquisition tool for imaging Windows based computers

ManTech Memory DD 1.3 acquires a forensic image of physical memory and stores it as a raw binary file.

Memory DD must be run with Administrator privileges

type the "mdd_1.3 -o <outputfile>" command
ex: mdd_1.3 -o dump.bin

 -> mdd
 -> ManTech Physical Memory Dump Utility
    Copyright (C) 2008 ManTech Security & Mission Assurance

 -> This program comes with ABSOLUTELY NO WARRANTY; for details use option `-w'
    This is free software, and you are welcome to redistribute it
    under certain conditions; use option `-c' for details.


mdd ManTech Physical Memory Dump Utility

Usage:

mdd <-o OUTPUTFILE> [-qvcw]

     -o OUTPUTFILE     output file for dump
     -q                quiet; no output except on error
     -v                verbose; output offsets of failed mappings
     -c                redistribution conditions for GPL
     -w                warranty information for GPL