linux ./configure check your system clock

checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... configure: error: newly created file is older than distributed files!

Check your system clock

系统时间有问题

date -s 2017-07-13

OK!再次编译,通过!

 

转载于:https://www.cnblogs.com/cmyxn/p/7159348.html

fatal: [192.168.5.158]: FAILED! => {"changed": true, "cmd": "cd /usr/src/php-5.3.28/ && ./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php5 --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib && make && make install", "delta": "0:00:07.761196", "end": "2025-06-26 15:07:53.247233", "msg": "non-zero return code", "rc": 1, "start": "2025-06-26 15:07:45.486037", "stderr": "configure: warning: bison versions supported for regeneration of the Zend/PHP parsers: 1.28 1.35 1.75 1.875 2.0 2.1 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5 2.5.1 2.6 2.6.1 2.6.2 2.6.4 (found: none).\nconfigure: warning: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.\nconfigure: error: Cannot find MySQL header files under /usr/local/mysql.\nNote that the MySQL client library is not bundled anymore!", "stderr_lines": ["configure: warning: bison versions supported for regeneration of the Zend/PHP parsers: 1.28 1.35 1.75 1.875 2.0 2.1 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5 2.5.1 2.6 2.6.1 2.6.2 2.6.4 (found: none).", "configure: warning: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.", "configure: error: Cannot find MySQL header files under /usr/local/mysql.", "Note that the MySQL client library is not bundled anymore!"], "stdout": "creating cache ./config.cache\nchecking for Cygwin environment... no\nchecking for mingw32 environment... no\nchecking for egrep... grep -E\nchecking for a sed that does not truncate output... /usr/bin/sed\nchecking host system type... x86_64-unknown-linux-gnu\nchecking target system type... x86_64-unknown-linux-gnu\nchecking for gcc... gcc\nchecking whether the C compiler (gcc ) works... yes\nchecking whether the C compiler (gcc ) is a cross-compiler... no\nchecking whether we are using GNU C... yes\nchecking whether gcc accepts -g... yes\nchecking how to run the C preprocessor... gcc -E\nchecking for icc... no\nchecking for suncc... no\nchecking whether gcc and cc understand -c and -o together... yes\nchecking how to run the C preprocessor... gcc -E\nchecking for AIX... no\nchecking whether ln -s works... yes\nchecking for system library directory... lib\nchecking whether to enable runpaths... yes\nchecking if compiler supports -R... no\nchecking if compiler supports -Wl,-rpath,... yes\nchecking for gawk... gawk\nchecking for bison... no\nchecking for byacc... no\nchecking for bison version... invalid\nchecking for re2c... no\nchecking whether to enable computed goto gcc extension with re2c... no\nchecking whether to force non-PIC code in shared modules... no\nchecking whether /dev/urandom exists... yes\nchecking for pthreads_cflags... -pthread\nchecking for pthreads_lib... \n\n\u001b[1mConfiguring SAPI modules\u001b[m\nchecking for AOLserver support... no\nchecking for Apache 1.x module support via DSO through APXS... no\nchecking for Apache 1.x module support... no\nchecking whether to enable Apache charset compatibility option... no\nchecking for Apache 2.0 filter-module support via DSO through APXS... no\nchecking for Apache 2.0 handler-module support via DSO through APXS... no\nchecking for Apache 1.x (hooks) module support via DSO through APXS... no\nchecking for Apache 1.x (hooks) module support... no\nchecking whether to enable Apache charset compatibility option... no\nchecking for Caudium support... no\nchecking for CLI build... yes\nchecking for Continuity support... no\nchecking for embedded SAPI library support... no\nchecking for FPM build... yes\nchecking for setenv... yes\nchecking for clearenv... yes\nchecking for setproctitle... no\nchecking for library containing socket... none required\nchecking for library containing inet_addr... none required\nchecking for errno.h... yes\nchecking for fcntl.h... yes\nchecking for stdio.h... yes\nchecking for stdlib.h... yes\nchecking for unistd.h... yes\nchecking for sys/uio.h... yes\nchecking for sys/select.h... yes\nchecking for sys/socket.h... yes\nchecking for sys/time.h... yes\nchecking for arpa/inet.h... yes\nchecking for netinet/in.h... yes\nchecking for sysexits.h... yes\nchecking for prctl... yes\nchecking for clock_gettime... yes\nchecking for ptrace... yes\nchecking whether ptrace works... yes\nchecking for proc mem file... mem\nchecking if gcc supports __sync_bool_compare_and_swap... yes\nchecking for TCP_INFO... yes\nchecking for sysconf... yes\nchecking for times... yes\nchecking for kqueue... no\nchecking for port framework... no\nchecking for /dev/poll... no\nchecking for epoll... yes\nchecking for poll... yes\nchecking for select... yes\nchecking for Zeus ISAPI support... no\nchecking for LiteSpeed support... no\nchecking for Milter support... no\nchecking for NSAPI support... no\nchecking for PHTTPD support... no\nchecking for Pi3Web support... no\nchecking whether Roxen module is build using ZTS... no\nchecking for Roxen/Pike support... \nchecking for thttpd... no\nchecking for TUX... no\nchecking for webjames... no\nchecking for chosen SAPI module... fpm\n\n\u001b[1mRunning system checks\u001b[m\nchecking for sendmail... no\nchecking whether system uses EBCDIC... no\nchecking whether byte ordering is bigendian... no\nchecking whether writing to stdout works... This is the test message -- yes\nchecking for socket... yes\nchecking for socketpair... yes\nchecking for htonl... yes\nchecking for gethostname... yes\nchecking for gethostbyaddr... yes\nchecking for yp_get_default_domain... no\nchecking for __yp_get_default_domain... no\nchecking for yp_get_default_domain in -lnsl... no\nchecking for __yp_get_default_domain in -lnsl... no\nchecking for dlopen... no\nchecking for __dlopen... no\nchecking for dlopen in -ldl... yes\nchecking for sin in -lm... yes\nchecking for inet_aton... yes\nchecking for ANSI C header files... yes\nchecking for dirent.h that defines DIR... yes\nchecking for opendir in -ldir... no\nchecking for inttypes.h... yes\nchecking for stdint.h... yes\nchecking for dirent.h... yes\nchecking for ApplicationServices/ApplicationServices.h... no\nchecking for sys/param.h... yes\nchecking for sys/types.h... yes\nchecking for sys/time.h... (cached) yes\nchecking for netinet/in.h... (cached) yes\nchecking for alloca.h... yes\nchecking for arpa/inet.h... (cached) yes\nchecking for arpa/nameser.h... yes\nchecking for assert.h... yes\nchecking for crypt.h... yes\nchecking for dns.h... no\nchecking for fcntl.h... (cached) yes\nchecking for grp.h... yes\nchecking for ieeefp.h... no\nchecking for langinfo.h... yes\nchecking for limits.h... yes\nchecking for locale.h... yes\nchecking for monetary.h... yes\nchecking for netdb.h... yes\nchecking for pwd.h... yes\nchecking for resolv.h... yes\nchecking for signal.h... yes\nchecking for stdarg.h... yes\nchecking for stdlib.h... (cached) yes\nchecking for string.h... yes\nchecking for syslog.h... yes\nchecking for sysexits.h... (cached) yes\nchecking for sys/ioctl.h... yes\nchecking for sys/file.h... yes\nchecking for sys/mman.h... yes\nchecking for sys/mount.h... yes\nchecking for sys/poll.h... yes\nchecking for sys/resource.h... yes\nchecking for sys/select.h... (cached) yes\nchecking for sys/socket.h... (cached) yes\nchecking for sys/stat.h... yes\nchecking for sys/statfs.h... yes\nchecking for sys/statvfs.h... yes\nchecking for sys/vfs.h... yes\nchecking for sys/sysexits.h... no\nchecking for sys/varargs.h... no\nchecking for sys/wait.h... yes\nchecking for sys/loadavg.h... no\nchecking for termios.h... yes\nchecking for unistd.h... (cached) yes\nchecking for unix.h... no\nchecking for utime.h... yes\nchecking for sys/utsname.h... yes\nchecking for sys/ipc.h... yes\nchecking for dlfcn.h... yes\nchecking for assert.h... (cached) yes\nchecking for fopencookie... yes\nchecking for broken getcwd... no\nchecking for broken libc stdio... yes\nchecking whether struct tm is in sys/time.h or time.h... time.h\nchecking for tm_zone in struct tm... yes\nchecking for missing declarations of reentrant functions... done\nchecking for fclose declaration... ok\nchecking for tm_gmtoff in struct tm... yes\nchecking for struct flock... yes\nchecking for socklen_t... yes\nchecking size of size_t... 8\nchecking size of long long... 8\nchecking size of long long int... 8\nchecking size of long... 8\nchecking size of int... 4\nchecking size of intmax_t... 8\nchecking size of ssize_t... 8\nchecking size of ptrdiff_t... 8\nchecking for st_blksize in struct stat... yes\nchecking for st_blocks in struct stat... yes\nchecking for st_rdev in struct stat... yes\nchecking for size_t... yes\nchecking for uid_t in sys/types.h... yes\nchecking for struct sockaddr_storage... yes\nchecking for field sa_len in struct sockaddr... no\nchecking for IPv6 support... yes\nchecking for vprintf... yes\nchecking for alphasort... yes\nchecking for asctime_r... yes\nchecking for chroot... yes\nchecking for ctime_r... yes\nchecking for cuserid... yes\nchecking for crypt... no\nchecking for flock... yes\nchecking for ftok... yes\nchecking for funopen... no\nchecking for gai_strerror... yes\nchecking for gcvt... yes\nchecking for getloadavg... yes\nchecking for getlogin... yes\nchecking for getprotobyname... yes\nchecking for getprotobynumber... yes\nchecking for getservbyname... yes\nchecking for getservbyport... yes\nchecking for gethostname... (cached) yes\nchecking for getrusage... yes\nchecking for gettimeofday... yes\nchecking for gmtime_r... yes\nchecking for getpwnam_r... yes\nchecking for getgrnam_r... yes\nchecking for getpwuid_r... yes\nchecking for grantpt... yes\nchecking for inet_ntoa... yes\nchecking for inet_ntop... yes\nchecking for inet_pton... yes\nchecking for isascii... yes\nchecking for link... yes\nchecking for localtime_r... yes\nchecking for lockf... yes\nchecking for lchown... yes\nchecking for lrand48... yes\nchecking for memcpy... yes\nchecking for memmove... yes\nchecking for mkstemp... yes\nchecking for mmap... yes\nchecking for nl_langinfo... yes\nchecking for perror... yes\nchecking for poll... yes\nchecking for ptsname... yes\nchecking for putenv... yes\nchecking for realpath... yes\nchecking for random... yes\nchecking for rand_r... yes\nchecking for scandir... yes\nchecking for setitimer... yes\nchecking for setlocale... yes\nchecking for localeconv... yes\nchecking for setenv... (cached) yes\nchecking for setpgid... yes\nchecking for setsockopt... yes\nchecking for setvbuf... yes\nchecking for shutdown... yes\nchecking for sin... yes\nchecking for snprintf... yes\nchecking for srand48... yes\nchecking for srandom... yes\nchecking for statfs... yes\nchecking for statvfs... yes\nchecking for std_syslog... no\nchecking for strcasecmp... yes\nchecking for strcoll... yes\nchecking for strdup... yes\nchecking for strerror... yes\nchecking for strftime... yes\nchecking for strnlen... yes\nchecking for strptime... yes\nchecking for strstr... yes\nchecking for strtok_r... yes\nchecking for symlink... yes\nchecking for tempnam... yes\nchecking for tzset... yes\nchecking for unlockpt... yes\nchecking for unsetenv... yes\nchecking for usleep... yes\nchecking for utime... yes\nchecking for vsnprintf... yes\nchecking for vasprintf... yes\nchecking for asprintf... yes\nchecking for nanosleep... yes\nchecking for nanosleep in -lrt... yes\nchecking for getaddrinfo... yes\nchecking for __sync_fetch_and_add... yes\nchecking for strlcat... no\nchecking for strlcpy... no\nchecking for getopt... yes\nchecking whether utime accepts a null argument... yes\nchecking for working alloca.h... (cached) yes\nchecking for alloca... yes\nchecking for declared timezone... yes\nchecking for type of reentrant time-related functions... POSIX\nchecking for readdir_r... yes\nchecking for type of readdir_r... POSIX\nchecking for in_addr_t... yes\nchecking for crypt_r... no\n\n\u001b[1mGeneral settings\u001b[m\nchecking whether to include gcov symbols... no\nchecking whether to include debugging symbols... no\nchecking layout of installed files... PHP\nchecking path to configuration file... /usr/local/php5\nchecking where to scan for configuration files... \nchecking whether to enable safe mode by default... no\nchecking for safe mode exec dir... /usr/local/php/bin\nchecking whether to enable PHP's own SIGCHLD handler... no\nchecking whether to enable magic quotes by default... no\nchecking whether to explicitly link against libgcc... no\nchecking whether to enable short tags by default... yes\nchecking whether to enable dmalloc... no\nchecking whether to enable IPv6 support... yes\nchecking how big to make fd sets... using system default\n\n\u001b[1mConfiguring extensions\u001b[m\nchecking size of long... (cached) 8\nchecking size of int... (cached) 4\nchecking for int32_t... yes\nchecking for uint32_t... yes\nchecking for sys/types.h... (cached) yes\nchecking for inttypes.h... (cached) yes\nchecking for stdint.h... (cached) yes\nchecking for string.h... (cached) yes\nchecking for stdlib.h... (cached) yes\nchecking for strtoll... yes\nchecking for atoll... yes\nchecking for strftime... (cached) yes\nchecking which regex library to use... php\nchecking whether to enable LIBXML support... yes\nchecking libxml2 install dir... no\nchecking for xml2-config path... /usr/bin/xml2-config\nchecking whether libxml build works... yes\nchecking for OpenSSL support... no\nchecking for Kerberos support... no\nchecking for PCRE library to use... bundled\nchecking whether to enable the SQLite3 extension... yes\nchecking bundled sqlite3 library... yes\nchecking for ZLIB support... yes\nchecking if the location of ZLIB install directory is defined... no\nchecking for gzgets in -lz... yes\nchecking whether to enable bc style precision math functions... no\nchecking for BZip2 support... no\nchecking whether to enable calendar conversion support... no\nchecking whether to enable ctype functions... yes\nchecking for cURL support... no\nchecking if we should use cURL for url streams... no\nchecking for QDBM support... no\nchecking for GDBM support... no\nchecking for NDBM support... no\nchecking for Berkeley DB4 support... no\nchecking for Berkeley DB3 support... no\nchecking for Berkeley DB2 support... no\nchecking for DB1 support... no\nchecking for DBM support... no\nchecking for CDB support... no\nchecking for INI File support... no\nchecking for FlatFile support... no\nchecking whether to enable DBA interface... no\nchecking whether to enable DOM support... yes\nchecking for xml2-config path... (cached) /usr/bin/xml2-config\nchecking whether libxml build works... (cached) yes\nchecking for ENCHANT support... no\nchecking whether to enable EXIF (metadata from images) support... no\nchecking for fileinfo support... yes\nchecking for utimes... yes\nchecking for strndup... yes\nchecking whether to enable input filter support... yes\nchecking pcre install prefix... no\nchecking whether to enable FTP support... no\nchecking OpenSSL dir for FTP... no\nchecking for GD support... yes\nchecking for the location of libjpeg... /usr/lib\nchecking for the location of libpng... no\nchecking for the location of libXpm... no\nchecking for FreeType 2... no\nchecking for T1lib support... no\nchecking whether to enable truetype string function in GD... no\nchecking whether to enable JIS-mapped Japanese font support in GD... no\nchecking for fabsf... yes\nchecking for floorf... yes\nchecking for jpeg_read_header in -ljpeg... yes\nchecking for png_write_image in -lpng... yes\nIf configure fails try --with-xpm-dir=<DIR>\nIf configure fails try --with-freetype-dir=<DIR>\nchecking for GNU gettext support... no\nchecking for GNU MP support... no\nchecking for mhash support... no\nchecking whether to enable hash support... yes\nchecking whether byte ordering is bigendian... (cached) no\nchecking size of short... 2\nchecking size of int... (cached) 4\nchecking size of long... (cached) 8\nchecking size of long long... (cached) 8\nchecking for iconv support... yes\nchecking for iconv... yes\nchecking if iconv is glibc's... yes\nchecking if iconv supports errno... yes\nchecking if your cpp allows macro usage in include lines... yes\nchecking for IMAP support... no\nchecking for IMAP Kerberos support... no\nchecking for IMAP SSL support... no\nchecking for InterBase support... no\nchecking whether to enable internationalization support... no\nchecking whether to enable JavaScript Object Serialization support... yes\nchecking for ANSI C header files... (cached) yes\nchecking for LDAP support... no\nchecking for LDAP Cyrus SASL support... no\nchecking whether to enable multibyte string support... yes\nchecking whether to enable multibyte regex support... yes\nchecking whether to check multibyte regex backtrack... yes\nchecking for external libmbfl... no\nchecking for external oniguruma... no\nchecking for variable length prototypes and stdarg.h... yes\nchecking for stdlib.h... (cached) yes\nchecking for string.h... (cached) yes\nchecking for strings.h... yes\nchecking for unistd.h... (cached) yes\nchecking for sys/time.h... (cached) yes\nchecking for sys/times.h... yes\nchecking for stdarg.h... (cached) yes\nchecking size of int... (cached) 4\nchecking size of short... (cached) 2\nchecking size of long... (cached) 8\nchecking for working const... yes\nchecking whether time.h and sys/time.h may both be included... yes\nchecking for working alloca.h... (cached) yes\nchecking for alloca... (cached) yes\nchecking for 8-bit clean memcmp... yes\nchecking for stdarg.h... (cached) yes\nchecking for mcrypt support... no\nchecking for MSSQL support via FreeTDS... no\nchecking for MySQL support... yes\nchecking for specified location of the MySQL UNIX socket... no", "stdout_lines": ["creating cache ./config.cache", "checking for Cygwin environment... no", "checking for mingw32 environment... no", "checking for egrep... grep -E", "checking for a sed that does not truncate output... /usr/bin/sed", "checking host system type... x86_64-unknown-linux-gnu", "checking target system type... x86_64-unknown-linux-gnu", "checking for gcc... gcc", "checking whether the C compiler (gcc ) works... yes", "checking whether the C compiler (gcc ) is a cross-compiler... no", "checking whether we are using GNU C... yes", "checking whether gcc accepts -g... yes", "checking how to run the C preprocessor... gcc -E", "checking for icc... no", "checking for suncc... no", "checking whether gcc and cc understand -c and -o together... yes", "checking how to run the C preprocessor... gcc -E", "checking for AIX... no", "checking whether ln -s works... yes", "checking for system library directory... lib", "checking whether to enable runpaths... yes", "checking if compiler supports -R... no", "checking if compiler supports -Wl,-rpath,... yes", "checking for gawk... gawk", "checking for bison... no", "checking for byacc... no", "checking for bison version... invalid", "checking for re2c... no", "checking whether to enable computed goto gcc extension with re2c... no", "checking whether to force non-PIC code in shared modules... no", "checking whether /dev/urandom exists... yes", "checking for pthreads_cflags... -pthread", "checking for pthreads_lib... ", "", "\u001b[1mConfiguring SAPI modules\u001b[m", "checking for AOLserver support... no", "checking for Apache 1.x module support via DSO through APXS... no", "checking for Apache 1.x module support... no", "checking whether to enable Apache charset compatibility option... no", "checking for Apache 2.0 filter-module support via DSO through APXS... no", "checking for Apache 2.0 handler-module support via DSO through APXS... no", "checking for Apache 1.x (hooks) module support via DSO through APXS... no", "checking for Apache 1.x (hooks) module support... no", "checking whether to enable Apache charset compatibility option... no", "checking for Caudium support... no", "checking for CLI build... yes", "checking for Continuity support... no", "checking for embedded SAPI library support... no", "checking for FPM build... yes", "checking for setenv... yes", "checking for clearenv... yes", "checking for setproctitle... no", "checking for library containing socket... none required", "checking for library containing inet_addr... none required", "checking for errno.h... yes", "checking for fcntl.h... yes", "checking for stdio.h... yes", "checking for stdlib.h... yes", "checking for unistd.h... yes", "checking for sys/uio.h... yes", "checking for sys/select.h... yes", "checking for sys/socket.h... yes", "checking for sys/time.h... yes", "checking for arpa/inet.h... yes", "checking for netinet/in.h... yes", "checking for sysexits.h... yes", "checking for prctl... yes", "checking for clock_gettime... yes", "checking for ptrace... yes", "checking whether ptrace works... yes", "checking for proc mem file... mem", "checking if gcc supports __sync_bool_compare_and_swap... yes", "checking for TCP_INFO... yes", "checking for sysconf... yes", "checking for times... yes", "checking for kqueue... no", "checking for port framework... no", "checking for /dev/poll... no", "checking for epoll... yes", "checking for poll... yes", "checking for select... yes", "checking for Zeus ISAPI support... no", "checking for LiteSpeed support... no", "checking for Milter support... no", "checking for NSAPI support... no", "checking for PHTTPD support... no", "checking for Pi3Web support... no", "checking whether Roxen module is build using ZTS... no", "checking for Roxen/Pike support... ", "checking for thttpd... no", "checking for TUX... no", "checking for webjames... no", "checking for chosen SAPI module... fpm", "", "\u001b[1mRunning system checks\u001b[m", "checking for sendmail... no", "checking whether system uses EBCDIC... no", "checking whether byte ordering is bigendian... no", "checking whether writing to stdout works... This is the test message -- yes", "checking for socket... yes", "checking for socketpair... yes", "checking for htonl... yes", "checking for gethostname... yes", "checking for gethostbyaddr... yes", "checking for yp_get_default_domain... no", "checking for __yp_get_default_domain... no", "checking for yp_get_default_domain in -lnsl... no", "checking for __yp_get_default_domain in -lnsl... no", "checking for dlopen... no", "checking for __dlopen... no", "checking for dlopen in -ldl... yes", "checking for sin in -lm... yes", "checking for inet_aton... yes", "checking for ANSI C header files... yes", "checking for dirent.h that defines DIR... yes", "checking for opendir in -ldir... no", "checking for inttypes.h... yes", "checking for stdint.h... yes", "checking for dirent.h... yes", "checking for ApplicationServices/ApplicationServices.h... no", "checking for sys/param.h... yes", "checking for sys/types.h... yes", "checking for sys/time.h... (cached) yes", "checking for netinet/in.h... (cached) yes", "checking for alloca.h... yes", "checking for arpa/inet.h... (cached) yes", "checking for arpa/nameser.h... yes", "checking for assert.h... yes", "checking for crypt.h... yes", "checking for dns.h... no", "checking for fcntl.h... (cached) yes", "checking for grp.h... yes", "checking for ieeefp.h... no", "checking for langinfo.h... yes", "checking for limits.h... yes", "checking for locale.h... yes", "checking for monetary.h... yes", "checking for netdb.h... yes", "checking for pwd.h... yes", "checking for resolv.h... yes", "checking for signal.h... yes", "checking for stdarg.h... yes", "checking for stdlib.h... (cached) yes", "checking for string.h... yes", "checking for syslog.h... yes", "checking for sysexits.h... (cached) yes", "checking for sys/ioctl.h... yes", "checking for sys/file.h... yes", "checking for sys/mman.h... yes", "checking for sys/mount.h... yes", "checking for sys/poll.h... yes", "checking for sys/resource.h... yes", "checking for sys/select.h... (cached) yes", "checking for sys/socket.h... (cached) yes", "checking for sys/stat.h... yes", "checking for sys/statfs.h... yes", "checking for sys/statvfs.h... yes", "checking for sys/vfs.h... yes", "checking for sys/sysexits.h... no", "checking for sys/varargs.h... no", "checking for sys/wait.h... yes", "checking for sys/loadavg.h... no", "checking for termios.h... yes", "checking for unistd.h... (cached) yes", "checking for unix.h... no", "checking for utime.h... yes", "checking for sys/utsname.h... yes", "checking for sys/ipc.h... yes", "checking for dlfcn.h... yes", "checking for assert.h... (cached) yes", "checking for fopencookie... yes", "checking for broken getcwd... no", "checking for broken libc stdio... yes", "checking whether struct tm is in sys/time.h or time.h... time.h", "checking for tm_zone in struct tm... yes", "checking for missing declarations of reentrant functions... done", "checking for fclose declaration... ok", "checking for tm_gmtoff in struct tm... yes", "checking for struct flock... yes", "checking for socklen_t... yes", "checking size of size_t... 8", "checking size of long long... 8", "checking size of long long int... 8", "checking size of long... 8", "checking size of int... 4", "checking size of intmax_t... 8", "checking size of ssize_t... 8", "checking size of ptrdiff_t... 8", "checking for st_blksize in struct stat... yes", "checking for st_blocks in struct stat... yes", "checking for st_rdev in struct stat... yes", "checking for size_t... yes", "checking for uid_t in sys/types.h... yes", "checking for struct sockaddr_storage... yes", "checking for field sa_len in struct sockaddr... no", "checking for IPv6 support... yes", "checking for vprintf... yes", "checking for alphasort... yes", "checking for asctime_r... yes", "checking for chroot... yes", "checking for ctime_r... yes", "checking for cuserid... yes", "checking for crypt... no", "checking for flock... yes", "checking for ftok... yes", "checking for funopen... no", "checking for gai_strerror... yes", "checking for gcvt... yes", "checking for getloadavg... yes", "checking for getlogin... yes", "checking for getprotobyname... yes", "checking for getprotobynumber... yes", "checking for getservbyname... yes", "checking for getservbyport... yes", "checking for gethostname... (cached) yes", "checking for getrusage... yes", "checking for gettimeofday... yes", "checking for gmtime_r... yes", "checking for getpwnam_r... yes", "checking for getgrnam_r... yes", "checking for getpwuid_r... yes", "checking for grantpt... yes", "checking for inet_ntoa... yes", "checking for inet_ntop... yes", "checking for inet_pton... yes", "checking for isascii... yes", "checking for link... yes", "checking for localtime_r... yes", "checking for lockf... yes", "checking for lchown... yes", "checking for lrand48... yes", "checking for memcpy... yes", "checking for memmove... yes", "checking for mkstemp... yes", "checking for mmap... yes", "checking for nl_langinfo... yes", "checking for perror... yes", "checking for poll... yes", "checking for ptsname... yes", "checking for putenv... yes", "checking for realpath... yes", "checking for random... yes", "checking for rand_r... yes", "checking for scandir... yes", "checking for setitimer... yes", "checking for setlocale... yes", "checking for localeconv... yes", "checking for setenv... (cached) yes", "checking for setpgid... yes", "checking for setsockopt... yes", "checking for setvbuf... yes", "checking for shutdown... yes", "checking for sin... yes", "checking for snprintf... yes", "checking for srand48... yes", "checking for srandom... yes", "checking for statfs... yes", "checking for statvfs... yes", "checking for std_syslog... no", "checking for strcasecmp... yes", "checking for strcoll... yes", "checking for strdup... yes", "checking for strerror... yes", "checking for strftime... yes", "checking for strnlen... yes", "checking for strptime... yes", "checking for strstr... yes", "checking for strtok_r... yes", "checking for symlink... yes", "checking for tempnam... yes", "checking for tzset... yes", "checking for unlockpt... yes", "checking for unsetenv... yes", "checking for usleep... yes", "checking for utime... yes", "checking for vsnprintf... yes", "checking for vasprintf... yes", "checking for asprintf... yes", "checking for nanosleep... yes", "checking for nanosleep in -lrt... yes", "checking for getaddrinfo... yes", "checking for __sync_fetch_and_add... yes", "checking for strlcat... no", "checking for strlcpy... no", "checking for getopt... yes", "checking whether utime accepts a null argument... yes", "checking for working alloca.h... (cached) yes", "checking for alloca... yes", "checking for declared timezone... yes", "checking for type of reentrant time-related functions... POSIX", "checking for readdir_r... yes", "checking for type of readdir_r... POSIX", "checking for in_addr_t... yes", "checking for crypt_r... no", "", "\u001b[1mGeneral settings\u001b[m", "checking whether to include gcov symbols... no", "checking whether to include debugging symbols... no", "checking layout of installed files... PHP", "checking path to configuration file... /usr/local/php5", "checking where to scan for configuration files... ", "checking whether to enable safe mode by default... no", "checking for safe mode exec dir... /usr/local/php/bin", "checking whether to enable PHP's own SIGCHLD handler... no", "checking whether to enable magic quotes by default... no", "checking whether to explicitly link against libgcc... no", "checking whether to enable short tags by default... yes", "checking whether to enable dmalloc... no", "checking whether to enable IPv6 support... yes", "checking how big to make fd sets... using system default", "", "\u001b[1mConfiguring extensions\u001b[m", "checking size of long... (cached) 8", "checking size of int... (cached) 4", "checking for int32_t... yes", "checking for uint32_t... yes", "checking for sys/types.h... (cached) yes", "checking for inttypes.h... (cached) yes", "checking for stdint.h... (cached) yes", "checking for string.h... (cached) yes", "checking for stdlib.h... (cached) yes", "checking for strtoll... yes", "checking for atoll... yes", "checking for strftime... (cached) yes", "checking which regex library to use... php", "checking whether to enable LIBXML support... yes", "checking libxml2 install dir... no", "checking for xml2-config path... /usr/bin/xml2-config", "checking whether libxml build works... yes", "checking for OpenSSL support... no", "checking for Kerberos support... no", "checking for PCRE library to use... bundled", "checking whether to enable the SQLite3 extension... yes", "checking bundled sqlite3 library... yes", "checking for ZLIB support... yes", "checking if the location of ZLIB install directory is defined... no", "checking for gzgets in -lz... yes", "checking whether to enable bc style precision math functions... no", "checking for BZip2 support... no", "checking whether to enable calendar conversion support... no", "checking whether to enable ctype functions... yes", "checking for cURL support... no", "checking if we should use cURL for url streams... no", "checking for QDBM support... no", "checking for GDBM support... no", "checking for NDBM support... no", "checking for Berkeley DB4 support... no", "checking for Berkeley DB3 support... no", "checking for Berkeley DB2 support... no", "checking for DB1 support... no", "checking for DBM support... no", "checking for CDB support... no", "checking for INI File support... no", "checking for FlatFile support... no", "checking whether to enable DBA interface... no", "checking whether to enable DOM support... yes", "checking for xml2-config path... (cached) /usr/bin/xml2-config", "checking whether libxml build works... (cached) yes", "checking for ENCHANT support... no", "checking whether to enable EXIF (metadata from images) support... no", "checking for fileinfo support... yes", "checking for utimes... yes", "checking for strndup... yes", "checking whether to enable input filter support... yes", "checking pcre install prefix... no", "checking whether to enable FTP support... no", "checking OpenSSL dir for FTP... no", "checking for GD support... yes", "checking for the location of libjpeg... /usr/lib", "checking for the location of libpng... no", "checking for the location of libXpm... no", "checking for FreeType 2... no", "checking for T1lib support... no", "checking whether to enable truetype string function in GD... no", "checking whether to enable JIS-mapped Japanese font support in GD... no", "checking for fabsf... yes", "checking for floorf... yes", "checking for jpeg_read_header in -ljpeg... yes", "checking for png_write_image in -lpng... yes", "If configure fails try --with-xpm-dir=<DIR>", "If configure fails try --with-freetype-dir=<DIR>", "checking for GNU gettext support... no", "checking for GNU MP support... no", "checking for mhash support... no", "checking whether to enable hash support... yes", "checking whether byte ordering is bigendian... (cached) no", "checking size of short... 2", "checking size of int... (cached) 4", "checking size of long... (cached) 8", "checking size of long long... (cached) 8", "checking for iconv support... yes", "checking for iconv... yes", "checking if iconv is glibc's... yes", "checking if iconv supports errno... yes", "checking if your cpp allows macro usage in include lines... yes", "checking for IMAP support... no", "checking for IMAP Kerberos support... no", "checking for IMAP SSL support... no", "checking for InterBase support... no", "checking whether to enable internationalization support... no", "checking whether to enable JavaScript Object Serialization support... yes", "checking for ANSI C header files... (cached) yes", "checking for LDAP support... no", "checking for LDAP Cyrus SASL support... no", "checking whether to enable multibyte string support... yes", "checking whether to enable multibyte regex support... yes", "checking whether to check multibyte regex backtrack... yes", "checking for external libmbfl... no", "checking for external oniguruma... no", "checking for variable length prototypes and stdarg.h... yes", "checking for stdlib.h... (cached) yes", "checking for string.h... (cached) yes", "checking for strings.h... yes", "checking for unistd.h... (cached) yes", "checking for sys/time.h... (cached) yes", "checking for sys/times.h... yes", "checking for stdarg.h... (cached) yes", "checking size of int... (cached) 4", "checking size of short... (cached) 2", "checking size of long... (cached) 8", "checking for working const... yes", "checking whether time.h and sys/time.h may both be included... yes", "checking for working alloca.h... (cached) yes", "checking for alloca... (cached) yes", "checking for 8-bit clean memcmp... yes", "checking for stdarg.h... (cached) yes", "checking for mcrypt support... no", "checking for MSSQL support via FreeTDS... no", "checking for MySQL support... yes", "checking for specified location of the MySQL UNIX socket... no"]}
06-27
修改为'' #ifndef FCS_MPC_H_ #define FCS_MPC_H_ #include "stm32f1xx_hal.h" #include "config.h" #include "defines.h" #include "math.h" // PI CONTROLLER STRUCTURE AND FUNCTIONS typedef struct { float Kp; float Ki; float integral; float max_output; float integral_limit; float dt; } PI_Controller_t; void PI_Init(PI_Controller_t *pi, float Kp, float Ki, float max_out, float int_limit, float dt_sec); float PI_Update(PI_Controller_t *pi, float setpoint, float measurement); void PI_Reset(PI_Controller_t *pi); // FCS-MPC (PHASE VARIABLE) STRUCTURE AND FUNCTIONS typedef struct { // Motor parameters float R_ohm; float L_henry; float flux_linkage_Wb; float Ts_seconds; // Prediction coefficients (pre-calculate for efficiency) float A_coeff; // (1 - Ts*R/L) float B_coeff; // Ts/L // Current references (phase values, set internally during MPC step) float ia_ref_A; float ib_ref_A; float ic_ref_A; // Measured/Estimated values from the previous step, used for prediction float ia_measured_A; float ib_measured_A; float ic_measured_A; float v_bus_V; float theta_el_rad; // rotor angle float omega_el_rad_s; // rotor speed // Last optimal state chosen by MPC (index 0-7 corresponding to Sa,Sb,Sc) uint8_t optimal_switch_state_index; } FCS_MPC_Phase_Ctrl_t; void FCS_MPC_Phase_Init(FCS_MPC_Phase_Ctrl_t *mpc); uint8_t FCS_MPC_Phase_Step(FCS_MPC_Phase_Ctrl_t *mpc, float ia_measured_A, float ib_measured_A, /* ic can be derived: -ia-ib */ float current_theta_el_rad, float current_omega_el_rad_s, float I_peak_ref_A, /* Amplitude of phase current from speed PI */ float v_bus_V); // Helper function to apply the chosen inverter state to PWM timers void ApplyInverterState(uint8_t state_index, int pwm_resolution, TIM_TypeDef* TIMx_MOTOR); // HALL SENSOR STRUCTURE AND FUNCTIONS typedef struct { // Configuration uint8_t Poles; int32_t initial_angle_q31; uint16_t K1_filter; uint16_t K2_filter; float speed_loop_interval_s; // Raw Hall states uint8_t HallUVW[3]; uint8_t Hall_State_Raw; uint8_t OldHall_State_Raw; uint8_t current_sector_index; // Angle Estimation int32_t ele_angleIQ; int32_t old_ele_angleIQ_for_speed; // Speed Estimation uint32_t hall_edge_timer_count; int32_t Speed_RPM; float omega_el_rad_s_estimated; // Internal state for interpolation (if using advanced Hall.c logic) uint8_t Move_State; // 0: stopped, 1: forward, 2: backward // Add more fields here if you fully implement the Hall.c interpolation logic: // int32_t angleIQ_interpolated; // int32_t step_angle_error; // int32_t step_angle_per_count; // int32_t step_angle_fitter; // int32_t Speed_countFitter; } HallSensor_t; // Hall state to sector mapping (from your original code, (W<<2)|(V<<1)|U) // Example: hall_to_pos[8] = {0,0,2,1,4,5,3,0}; You might need to adjust this. // This table maps raw Hall state (W V U) to a sector index 0-5. // The angle associated with the start of these sectors must be in hall_sector_start_angles_q31. extern const uint8_t hall_state_to_sector_map[8]; extern const int32_t hall_sector_start_angles_q31[6]; // Electrical angles (0-65535) for sectors 0-5 void HallSensor_Init(HallSensor_t *hall, uint8_t pole_pairs, int32_t initial_angle_offset_q31, float speed_update_interval_s); void HallSensor_UpdateAngle(HallSensor_t *hall, GPIO_TypeDef* U_PORT, uint16_t U_PIN, GPIO_TypeDef* V_PORT, uint16_t V_PIN, GPIO_TypeDef* W_PORT, uint16_t W_PIN); void HallSensor_UpdateSpeed(HallSensor_t *hall); // Called at a slower, fixed rate #endif /* FCS_MPC_H_ */ #include "fcs_mpc.h" //=========================================================================== // PI CONTROLLER IMPLEMENTATION //=========================================================================== void PI_Init(PI_Controller_t *pi, float Kp, float Ki, float max_out, float int_limit, float dt_sec) { pi->Kp = Kp; pi->Ki = Ki; pi->max_output = max_out; pi->integral_limit = int_limit; pi->dt = dt_sec; pi->integral = 0.0f; } float PI_Update(PI_Controller_t *pi, float setpoint, float measurement) { float error = setpoint - measurement; // Integral term with anti-windup pi->integral += error * pi->dt; if (pi->integral > pi->integral_limit) { pi->integral = pi->integral_limit; } else if (pi->integral < -pi->integral_limit) { pi->integral = -pi->integral_limit; } float output = pi->Kp * error + pi->Ki * pi->integral; // Output saturation if (output > pi->max_output) { output = pi->max_output; } else if (output < -pi->max_output) { output = -pi->max_output; } return output; } void PI_Reset(PI_Controller_t *pi) { pi->integral = 0.0f; } // INVERTER SWITCHING LOGIC static const uint8_t fcs_mpc_switch_states[8][3] = { {0,0,0}, {1,0,0}, {1,1,0}, {0,1,0}, {0,1,1}, {0,0,1}, {1,0,1}, {1,1,1} }; void ApplyInverterState(uint8_t state_index, int pwm_resolution, TIM_TypeDef* TIMx_MOTOR) { if (state_index > 7) state_index = 0; // Safety clamp // Assumes TIMx_MOTOR->CCRx controls the duty cycle of the high-side switch. // For complementary PWM, when CCRx = 0, low-side is effectively ON. // When CCRx = pwm_resolution (ARR), high-side is effectively ON. // This mapping needs to match your timer's complementary PWM mode configuration. // Phase U (e.g., TIMx_MOTOR->CCR1 or specific channel for U) if (fcs_mpc_switch_states[state_index][0]) { // Sa = 1 (High U ON) TIMx_MOTOR->LEFT_TIM_U = pwm_resolution; // Using macro from defines.h } else { // Sa = 0 (Low U ON) TIMx_MOTOR->LEFT_TIM_U = 0; } // Phase V (e.g., TIMx_MOTOR->CCR2 or specific channel for V) if (fcs_mpc_switch_states[state_index][1]) { // Sb = 1 (High V ON) TIMx_MOTOR->LEFT_TIM_V = pwm_resolution; } else { // Sb = 0 (Low V ON) TIMx_MOTOR->LEFT_TIM_V = 0; } // Phase W (e.g., TIMx_MOTOR->CCR3 or specific channel for W) if (fcs_mpc_switch_states[state_index][2]) { // Sc = 1 (High W ON) TIMx_MOTOR->LEFT_TIM_W = pwm_resolution; } else { // Sc = 0 (Low W ON) TIMx_MOTOR->LEFT_TIM_W = 0; } // IMPORTANT: Ensure your timer (e.g., TIM1/TIM8) is configured for: // 1. Complementary outputs with dead-time insertion. // 2. Master Output Enable (MOE) bit is set in BDTR register. } //=========================================================================== // FCS-MPC (PHASE VARIABLE) IMPLEMENTATION //=========================================================================== void FCS_MPC_Phase_Init(FCS_MPC_Phase_Ctrl_t *mpc) { mpc->R_ohm = MOTOR_R_OHM; mpc->L_henry = MOTOR_L_HENRY; mpc->flux_linkage_Wb = MOTOR_FLUX_LINKAGE_Wb; mpc->Ts_seconds = SAMPLING_TIME_S; if (mpc->L_henry < 1e-9f) mpc->L_henry = 1e-9f; // Avoid division by zero mpc->A_coeff = (1.0f - mpc->Ts_seconds * mpc->R_ohm / mpc->L_henry); mpc->B_coeff = mpc->Ts_seconds / mpc->L_henry; mpc->ia_ref_A = 0.0f; mpc->ib_ref_A = 0.0f; mpc->ic_ref_A = 0.0f; mpc->optimal_switch_state_index = 0; // Start with zero vector (000) } uint8_t FCS_MPC_Phase_Step(FCS_MPC_Phase_Ctrl_t *mpc, float ia_measured_A, float ib_measured_A, float current_theta_el_rad, float current_omega_el_rad_s, float I_peak_ref_A, float v_bus_V) { mpc->ia_measured_A = ia_measured_A; mpc->ib_measured_A = ib_measured_A; mpc->ic_measured_A = -ia_measured_A - ib_measured_A; // Assuming balanced system ia+ib+ic=0 mpc->theta_el_rad = current_theta_el_rad; mpc->omega_el_rad_s = current_omega_el_rad_s; // Use filtered/best estimate mpc->v_bus_V = v_bus_V; // --- Generate Phase Current References for next state (k+1) --- // Predicted angle for references: theta_e_ref(k+1) = theta_e(k) + omega_e(k)*Ts float theta_el_ref_rad = mpc->theta_el_rad + mpc->omega_el_rad_s * mpc->Ts_seconds; theta_el_ref_rad = fmodf(theta_el_ref_rad, TWO_PI_F); // Normalize to [0, 2*PI) or (-PI, PI] then adjust if (theta_el_ref_rad < 0.0f) { theta_el_ref_rad += TWO_PI_F; } mpc->ia_ref_A = I_peak_ref_A * sinf(theta_el_ref_rad); mpc->ib_ref_A = I_peak_ref_A * sinf(theta_el_ref_rad - (TWO_PI_F / 3.0f)); mpc->ic_ref_A = I_peak_ref_A * sinf(theta_el_ref_rad + (TWO_PI_F / 3.0f)); // More robustly: mpc->ic_ref_A = -mpc->ia_ref_A - mpc->ib_ref_A; float min_cost = 1e18f; // A very large number uint8_t best_s_idx = mpc->optimal_switch_state_index; // Default to previous if all costs are huge // --- Calculate Back-EMFs for current state (k) --- // ea(k) = Ke * omega_e(k) * sin(theta_e(k)) float ea_k = mpc->flux_linkage_Wb * mpc->omega_el_rad_s * sinf(mpc->theta_el_rad); float eb_k = mpc->flux_linkage_Wb * mpc->omega_el_rad_s * sinf(mpc->theta_el_rad - (TWO_PI_F / 3.0f)); float ec_k = mpc->flux_linkage_Wb * mpc->omega_el_rad_s * sinf(mpc->theta_el_rad + (TWO_PI_F / 3.0f)); // Or ec_k = -ea_k - eb_k; (if BEMFs are perfectly balanced and sinusoidal) // --- Iterate through all 8 switching states --- for (uint8_t s_idx = 0; s_idx < 8; ++s_idx) { // Get terminal voltages va_N, vb_N, vc_N (w.r.t. negative DC bus) for this state float va_N_k = (float)fcs_mpc_switch_states[s_idx][0] * mpc->v_bus_V; // U phase float vb_N_k = (float)fcs_mpc_switch_states[s_idx][1] * mpc->v_bus_V; // V phase float vc_N_k = (float)fcs_mpc_switch_states[s_idx][2] * mpc->v_bus_V; // W phase // Calculate phase-to-motor-neutral voltages van, vbn, vcn // van = (2*vaN - vbN - vcN) / 3 float van_k = (2.0f * va_N_k - vb_N_k - vc_N_k) / 3.0f; float vbn_k = (-va_N_k + 2.0f * vb_N_k - vc_N_k) / 3.0f; float vcn_k = (-va_N_k - vb_N_k + 2.0f * vc_N_k) / 3.0f; // --- Predict currents ia(k+1), ib(k+1), ic(k+1) --- // ia(k+1) = A_coeff * ia(k) + B_coeff * (van(k) - ea(k)) float ia_pred_k1 = mpc->A_coeff * mpc->ia_measured_A + mpc->B_coeff * (van_k - ea_k); float ib_pred_k1 = mpc->A_coeff * mpc->ib_measured_A + mpc->B_coeff * (vbn_k - eb_k); //float ic_pred_k1 = mpc->A_coeff * mpc->ic_measured_A + mpc->B_coeff * (vcn_k - ec_k); // For 2-phase current sensing, can use: float ic_pred_k1 = -ia_pred_k1 - ib_pred_k1; // --- Cost Function --- // J = w1*(ia_ref - ia_pred)^2 + w2*(ib_ref - ib_pred)^2 (+ w3*(ic_ref - ic_pred)^2) // Using two phases is usually sufficient if currents are balanced. float err_a = mpc->ia_ref_A - ia_pred_k1; float err_b = mpc->ib_ref_A - ib_pred_k1; // float err_c = mpc->ic_ref_A - ic_pred_k1; // Only if ic_ref and ic_pred are independently calculated float cost = err_a * err_a + err_b * err_b; // + err_c * err_c; // Optional: Add switching frequency penalty // int changes = (fcs_mpc_switch_states[s_idx][0] != fcs_mpc_switch_states[mpc->optimal_switch_state_index][0]) + // (fcs_mpc_switch_states[s_idx][1] != fcs_mpc_switch_states[mpc->optimal_switch_state_index][1]) + // (fcs_mpc_switch_states[s_idx][2] != fcs_mpc_switch_states[mpc->optimal_switch_state_index][2]); // if (changes > 0) cost += SWITCHING_PENALTY_WEIGHT * (float)changes; if (cost < min_cost) { min_cost = cost; best_s_idx = s_idx; } } mpc->optimal_switch_state_index = best_s_idx; return best_s_idx; } //=========================================================================== // HALL SENSOR IMPLEMENTATION //=========================================================================== // Define these based on your motor's Hall sequence and desired sector definition. // This is from your first code sample: hall_to_pos[8] = {0,0,2,1,4,5,3,0}; (for W V U input) // Hall states (binary W V U) corresponding to sectors 0-5. // Modify this if your Hall sensor wiring or motor is different. // WVU | Sector Index | Typical Elec Angle Start (Idealized for this map) // --- | ------------ | --------------------------------------------------- // 000 | 0 (Invalid) | - // 001 | 0 (U only) | (Sector 0) Could be 330-30 or 0-60. Your map has it as 0. // 010 | 2 (V only) | (Sector 2) // 011 | 1 (V+U) | (Sector 1) // 100 | 4 (W only) | (Sector 4) // 101 | 5 (W+U) | (Sector 5) // 110 | 3 (W+V) | (Sector 3) // 111 | 0 (Invalid) | - // Let's use your map directly: hall_state_to_sector_map[raw_hall_state_wvu] const uint8_t hall_state_to_sector_map[8] = {0, 0, 2, 1, 4, 5, 3, 0}; // Index is (W<<2 | V<<1 | U) // Electrical angles (0-65535 for 0-2PI) for the START of each of the 6 sectors. // These must correspond to the sectors defined by hall_state_to_sector_map. // If sector 0 from map is 0-60 deg, sector 1 is 60-120, etc. // This needs careful validation with your specific hall_to_pos logic. // Let's assume the sectors from hall_to_pos are sequential electrical angle blocks. const int32_t hall_sector_start_angles_q31[6] = { 0, // Start of sector 0 (e.g., hall state 001 if map[1]=0) 10923, // Start of sector 1 (60 deg) 21845, // Start of sector 2 (120 deg) 32768, // Start of sector 3 (180 deg) 43691, // Start of sector 4 (240 deg) 54613 // Start of sector 5 (300 deg) }; void HallSensor_Init(HallSensor_t *hall, uint8_t pole_pairs, int32_t initial_angle_offset_q31, float speed_update_interval_s) { hall->Poles = pole_pairs; hall->initial_angle_q31 = initial_angle_offset_q31; hall->K1_filter = HALL_FILTER_K1; // From config.h hall->K2_filter = HALL_FILTER_K2; // From config.h hall->speed_loop_interval_s = speed_update_interval_s; hall->Hall_State_Raw = 0; hall->OldHall_State_Raw = 0; hall->current_sector_index = 0; hall->ele_angleIQ = 0; // Will be updated on first read hall->old_ele_angleIQ_for_speed = 0; hall->hall_edge_timer_count = 0; hall->Speed_RPM = 0; hall->omega_el_rad_s_estimated = 0.0f; hall->Move_State = 0; // Stopped // Initialize other interpolation-specific fields if used } // This function should be called very frequently (e.g., every PWM cycle / MPC step) void HallSensor_UpdateAngle(HallSensor_t *hall, GPIO_TypeDef* U_PORT, uint16_t U_PIN, GPIO_TypeDef* V_PORT, uint16_t V_PIN, GPIO_TypeDef* W_PORT, uint16_t W_PIN) { // Read Hall sensor inputs (active low assumed, hence '!') hall->HallUVW[0] = !(U_PORT->IDR & U_PIN); // U hall->HallUVW[1] = !(V_PORT->IDR & V_PIN); // V hall->HallUVW[2] = !(W_PORT->IDR & W_PIN); // W hall->OldHall_State_Raw = hall->Hall_State_Raw; hall->Hall_State_Raw = (hall->HallUVW[2] << 2) | (hall->HallUVW[1] << 1) | hall->HallUVW[0]; // W V U order hall->current_sector_index = hall_state_to_sector_map[hall->Hall_State_Raw]; // Basic angle estimation: Angle is the start of the current sector // More advanced interpolation (like in your HALL.c sample) can be added here. // For now, this provides a coarse angle update at Hall edges. int32_t base_angle_q31 = hall_sector_start_angles_q31[hall->current_sector_index]; // If stopped for too long, or at startup, set angle to middle of sector if (hall->hall_edge_timer_count > (PWM_FREQ / 10)) { // e.g. > 0.1 sec assuming PWM_FREQ is call rate hall->Move_State = 0; // Add 30 electrical degrees (10923 / 2 for Q31) to be in middle of sector base_angle_q31 += (10923 / 2); } if (hall->Hall_State_Raw != hall->OldHall_State_Raw && hall_state_to_sector_map[hall->Hall_State_Raw] != hall_state_to_sector_map[hall->OldHall_State_Raw] && // Ensure valid sector change hall->Hall_State_Raw !=0 && hall->OldHall_State_Raw !=0 ) { // Ignore invalid states for transition logic // Determine direction (simplified) int8_t sector_diff = hall->current_sector_index - hall_state_to_sector_map[hall->OldHall_State_Raw]; if (sector_diff == 1 || sector_diff == -5) { // Forward (e.g. 0->1, or 5->0) hall->Move_State = 1; } else if (sector_diff == -1 || sector_diff == 5) { // Backward (e.g. 1->0, or 0->5) hall->Move_State = 2; } else { hall->Move_State = 0; // Unlikely/error transition if not 0,0 } hall->hall_edge_timer_count = 0; // Reset timer on valid edge } else { hall->hall_edge_timer_count++; } // --- Simple angle interpolation based on speed (placeholder for advanced logic) --- // If moving, advance angle slightly based on last known speed // This crude interpolation helps smooth the angle between Hall edges. // A proper implementation would use hall_edge_timer_count to estimate current speed more accurately // and interpolate within the 60-degree sector. if (hall->Move_State == 1) { // Forward base_angle_q31 += (int32_t)(hall->omega_el_rad_s_estimated * SAMPLING_TIME_S * (65535.0f / TWO_PI_F) * 0.5f) ; // Small increment } else if (hall->Move_State == 2) { // Backward base_angle_q31 -= (int32_t)(hall->omega_el_rad_s_estimated * SAMPLING_TIME_S * (65535.0f / TWO_PI_F) * 0.5f); // Small decrement } // Apply initial offset for d-q alignment int32_t calibrated_angle_q31 = base_angle_q31 - hall->initial_angle_q31; // Normalize to 0-65535 range if (calibrated_angle_q31 < 0) { calibrated_angle_q31 += 65536; } else if (calibrated_angle_q31 >= 65536) { calibrated_angle_q31 -= 65536; } hall->ele_angleIQ = calibrated_angle_q31; } // This function should be called at a fixed, slower rate (e.g., every 1-10ms by TIM2) void HallSensor_UpdateSpeed(HallSensor_t *hall) { int32_t angle_diff_q31 = hall->ele_angleIQ - hall->old_ele_angleIQ_for_speed; // Handle angle wrap-around for difference calculation if (hall->Move_State == 1) { // Forward if (angle_diff_q31 < -32768) angle_diff_q31 += 65536; // Wrapped from 65535 to 0 } else if (hall->Move_State == 2) { // Backward if (angle_diff_q31 > 32768) angle_diff_q31 -= 65536; // Wrapped from 0 to 65535 } else { // Stopped or invalid angle_diff_q31 = 0; } hall->old_ele_angleIQ_for_speed = hall->ele_angleIQ; if (hall->Move_State == 0) { hall->omega_el_rad_s_estimated = 0.0f; hall->Speed_RPM = 0; return; } // Calculate electrical speed in rad/s // angle_diff_rads = (angle_diff_q31 / 65535.0f) * 2*PI float delta_theta_rad = (float)angle_diff_q31 * (TWO_PI_F / 65535.0f); if (hall->speed_loop_interval_s > 1e-6f) { // Avoid division by zero hall->omega_el_rad_s_estimated = delta_theta_rad / hall->speed_loop_interval_s; } else { hall->omega_el_rad_s_estimated = 0.0f; } // Calculate mechanical speed in RPM // omega_mech_rad_s = omega_elec_rad_s / PolePairs // RPM = omega_mech_rad_s * (60 / 2*PI) float omega_mech_rad_s = hall->omega_el_rad_s_estimated / (float)hall->Poles; hall->Speed_RPM = (int32_t)(omega_mech_rad_s * (60.0f / TWO_PI_F)); // Simple low-pass filter on RPM (optional) // static float filtered_rpm = 0.0f; // filtered_rpm = 0.8f * filtered_rpm + 0.2f * (float)hall->Speed_RPM; // hall->Speed_RPM = (int32_t)filtered_rpm; } #include "stm32f1xx_hal.h" // Change if using a different STM32 series #include "main.h" // Often created by CubeMX, can define HAL handles here #include "fcs_mpc.h" // Our FCS-MPC, PI, Hall logic #include "config.h" // Project configuration #include "defines.h" // Hardware definitions (pins, timers) #include <string.h> // For memset if used (e.g. for adc_buffer) //=========================================================================== // HAL Handles (declare here, define where CubeMX puts them, e.g. in main.c or stm32f1xx_hal_msp.c) //=========================================================================== ADC_HandleTypeDef hadc1; DMA_HandleTypeDef hdma_adc1; TIM_HandleTypeDef htim1; // Assuming TIM1 is for Left Motor PWM TIM_HandleTypeDef htim2; // Assuming TIM2 is for Speed Control Loop //=========================================================================== // Global Variables //=========================================================================== volatile adc_buf_t adc_buffer; // Buffer for ADC conversion results via DMA volatile uint8_t adc_conversion_complete = 0; // FCS-MPC, PI, and Hall Sensor instances for the left motor FCS_MPC_Phase_Ctrl_t mpc_left_phase; PI_Controller_t speed_pi_left; HallSensor_t hall_left; // Control variables volatile float speed_reference_rpm_left = 0.0f; volatile float current_I_peak_ref_A_left = 0.0f; // Output of speed PI, input to MPC volatile uint8_t motor_enable_flag = 0; // Set to 1 to enable motor // ADC Offsets volatile int adc_offset_s R1 = 2048; // Phase A current sensor offset volatile int adc_offset_s R2 = 2048; // Phase B current sensor offset volatile int adc_offset_dcl = 2048; // DC link current sensor offset volatile int adc_offset_calibration_counter = 0; // Battery voltage volatile float battery_voltage_V = 36.0f; // Initial estimate // Timeout and buzzer (from your original code) volatile uint32_t system_timeout_counter = 0; uint32_t buzzerFreq = 0; uint32_t buzzerPattern = 0; uint32_t buzzerTimer_ms = 0; // Changed to ms for clarity // PWM resolution const int pwm_timer_resolution = (64000000 / 2 / PWM_FREQ); // Example calculation //=========================================================================== // Function Prototypes (Private to main.c) //=========================================================================== void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_DMA_Init(void); static void MX_ADC1_Init(void); static void MX_TIM1_Init(void); // For Left Motor PWM static void MX_TIM2_Init(void); // For Speed Control Loop Timer static void Calibrate_ADC_Offsets(void); void Process_Motor_Control(void); // Main motor control logic called from ADC ISR context //=========================================================================== // MAIN FUNCTION //=========================================================================== int main(void) { HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_DMA_Init(); // DMA must be initialized before ADC and Timers using it MX_ADC1_Init(); MX_TIM1_Init(); // Left Motor PWM Timer MX_TIM2_Init(); // Speed Control Loop Timer // Initialize control structures FCS_MPC_Phase_Init(&mpc_left_phase); PI_Init(&speed_pi_left, SPEED_PI_KP, SPEED_PI_KI, SPEED_PI_MAX_OUTPUT_AMPS, SPEED_PI_INTEGRAL_LIMIT, (float)SPEED_CONTROL_INTERVAL_MS / 1000.0f); HallSensor_Init(&hall_left, MOTOR_POLE_PAIRS, HALL_INITIAL_ANGLE_Q31, (float)SPEED_CONTROL_INTERVAL_MS / 1000.0f); // Start ADC offset calibration adc_offset_calibration_counter = 0; // Start ADC with DMA if (HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&adc_buffer, sizeof(adc_buf_t) / sizeof(uint16_t)) != HAL_OK) { // Error_Handler(); // ADC DMA start error } // ADC is typically triggered by a PWM timer (e.g., TIM1 update event) for synchronization. // Ensure MX_ADC1_Init and MX_TIM1_Init configure this trigger. // Wait for ADC offset calibration to complete while (adc_offset_calibration_counter < ADC_OFFSET_CALIBRATION_SAMPLES) { HAL_Delay(1); // Simple delay, ADC ISR will increment counter } // Start PWM channels for Left Motor (U, V, W and their complementary N channels) HAL_TIM_PWM_Start(&htim1, LEFT_TIM_U_CHANNEL); HAL_TIMEx_PWMN_Start(&htim1, LEFT_TIM_U_CHANNEL); HAL_TIM_PWM_Start(&htim1, LEFT_TIM_V_CHANNEL); HAL_TIMEx_PWMN_Start(&htim1, LEFT_TIM_V_CHANNEL); HAL_TIM_PWM_Start(&htim1, LEFT_TIM_W_CHANNEL); HAL_TIMEx_PWMN_Start(&htim1, LEFT_TIM_W_CHANNEL); __HAL_TIM_MOE_ENABLE(&htim1); // Enable Master Output for TIM1 (critical for advanced timers) // Start Timer for Speed Control Loop HAL_TIM_Base_Start_IT(&htim2); // motor_enable_flag = 1; // Enable motor operation // speed_reference_rpm_left = 200.0f; // Set an initial speed reference while (1) { // Main loop for lower priority tasks, communication, safety checks HAL_Delay(10); // Example delay buzzerTimer_ms += 10; // Buzzer logic (example from your code, adapt timing) if (buzzerFreq != 0 && (buzzerTimer_ms / 100) % (buzzerPattern + 1) == 0) { // Check every 100ms part of pattern if ((buzzerTimer_ms % (1000 / (buzzerFreq * 2))) == 0) { // Toggle based on buzzerFreq //HAL_GPIO_TogglePin(BUZZER_PORT, BUZZER_PIN); // Define BUZZER_PORT/PIN } } else { // HAL_GPIO_WritePin(BUZZER_PORT, BUZZER_PIN, GPIO_PIN_RESET); } system_timeout_counter++; if (system_timeout_counter > TIMEOUT) { motor_enable_flag = 0; // Safety stop // Error_Handler(); // Or some other fault state } } } //=========================================================================== // ADC OFFSET CALIBRATION (Called from ADC ISR during startup) //=========================================================================== static void Calibrate_ADC_Offsets(void) { if (adc_offset_calibration_counter == 0) { adc_offset_sR1 = adc_buffer.rl1; // Assuming rl1 is phase A current adc_offset_sR2 = adc_buffer.rl2; // Assuming rl2 is phase B current adc_offset_dcl = adc_buffer.dcl; } else { adc_offset_sR1 = (adc_offset_sR1 + adc_buffer.rl1) / 2; adc_offset_sR2 = (adc_offset_sR2 + adc_buffer.rl2) / 2; adc_offset_dcl = (adc_offset_dcl + adc_buffer.dcl) / 2; } adc_offset_calibration_counter++; } //=========================================================================== // MOTOR CONTROL PROCESSING (Called from ADC ISR context) //=========================================================================== void Process_Motor_Control(void) { // --- Update Battery Voltage (less frequently) --- static uint16_t battery_update_counter = 0; if (++battery_update_counter >= 100) { // Update approx every 100*Ts (e.g. 5ms if Ts=50us) battery_update_counter = 0; battery_voltage_V = battery_voltage_V * 0.99f + ((float)adc_buffer.batt1 * ADC_DC_VOLTAGE_SCALE) * 0.01f; } // --- DC Current Limit & Enable Logic --- float dc_current_A = fabsf((float)(adc_buffer.dcl - adc_offset_dcl) * MOTOR_AMP_CONV_DC_AMP); if (dc_current_A > DC_CUR_LIMIT || system_timeout_counter > TIMEOUT || motor_enable_flag == 0) { __HAL_TIM_MOE_DISABLE_UNCONDITIONALLY(&htim1); // Force disable PWM outputs (check if MOE_DISABLE is better) ApplyInverterState(0, pwm_timer_resolution, LEFT_TIM); // Apply zero vector PI_Reset(&speed_pi_left); // Reset PI integral current_I_peak_ref_A_left = 0.0f; // motor_enable_flag = 0; // Optionally force disable here return; // Skip further motor control } else { __HAL_TIM_MOE_ENABLE(&htim1); // Ensure PWM outputs are enabled } // --- Hall Sensor Angle Update (High Frequency) --- HallSensor_UpdateAngle(&hall_left, LEFT_HALL_U_PORT, LEFT_HALL_U_PIN, LEFT_HALL_V_PORT, LEFT_HALL_V_PIN, LEFT_HALL_W_PORT, LEFT_HALL_W_PIN); // --- Get Current Measurements (Amps) --- float ia_left_A = (float)(adc_buffer.rl1 - adc_offset_sR1) * ADC_PHASE_CURRENT_SCALE; float ib_left_A = (float)(adc_buffer.rl2 - adc_offset_sR2) * ADC_PHASE_CURRENT_SCALE; // --- Get Electrical Angle (Radians) --- // hall_left.ele_angleIQ is already calibrated (0-65535 for 0-2PI) float theta_el_left_rad = (float)hall_left.ele_angleIQ * (TWO_PI_F / 65535.0f); // --- Get Electrical Speed (Radians/s) --- // Use the speed estimated by HallSensor_UpdateSpeed, which is updated slower. // For MPC, a faster, potentially noisier estimate might be derived from d(theta)/dt here, // or a filtered version of it. For simplicity, using the one from HallSensor_UpdateSpeed. float omega_el_left_rad_s = hall_left.omega_el_rad_s_estimated; // From HallSensor_UpdateSpeed // --- Call FCS-MPC Step --- // current_I_peak_ref_A_left is updated by the speed PI controller in TIM2_IRQHandler uint8_t optimal_state_idx = FCS_MPC_Phase_Step(&mpc_left_phase, ia_left_A, ib_left_A, theta_el_left_rad, omega_el_left_rad_s, current_I_peak_ref_A_left, battery_voltage_V); // --- Apply the chosen inverter state --- ApplyInverterState(optimal_state_idx, pwm_timer_resolution, LEFT_TIM); } //=========================================================================== // STM32 HAL CALLBACKS & ISRs //=========================================================================== // ADC Conversion Complete Callback (called after DMA finishes a sequence) void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) { if (hadc->Instance == ADC1) { // Check if it's the ADC we're using for motor control HAL_GPIO_WritePin(LED_PORT, LED_PIN, GPIO_PIN_SET); // Debug: Toggle LED on ADC completion if (adc_offset_calibration_counter < ADC_OFFSET_CALIBRATION_SAMPLES) { Calibrate_ADC_Offsets(); } else { // Normal operation: Process motor control Process_Motor_Control(); } HAL_GPIO_WritePin(LED_PORT, LED_PIN, GPIO_PIN_RESET); // Debug: Toggle LED } } // Timer Interrupt for Speed Controller (e.g., TIM2, every SPEED_CONTROL_INTERVAL_MS) void TIM2_IRQHandler(void) { HAL_TIM_IRQHandler(&htim2); // Clear flags and call HAL_TIM_PeriodElapsedCallback } // HAL Timer Period Elapsed Callback (called by TIM2_IRQHandler for TIM2) void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { if (htim->Instance == SPEED_LOOP_TIMER) { // Check if it's our speed loop timer if (motor_enable_flag && adc_offset_calibration_counter >= ADC_OFFSET_CALIBRATION_SAMPLES) { // 1. Update Hall Sensor Speed Calculation (updates hall_left.Speed_RPM and omega_el_rad_s_estimated) HallSensor_UpdateSpeed(&hall_left); // 2. Run Speed PI Controller float actual_speed_rpm_left = (float)hall_left.Speed_RPM; current_I_peak_ref_A_left = PI_Update(&speed_pi_left, speed_reference_rpm_left, actual_speed_rpm_left); } else { // Reset PI controller if motor disabled or still calibrating PI_Reset(&speed_pi_left); current_I_peak_ref_A_left = 0.0f; HallSensor_UpdateSpeed(&hall_left); // Keep it running to get zero speed if stopped } } } //=========================================================================== // SYSTEM CONFIGURATION FUNCTIONS (Placeholders - Implement with CubeMX or manually) //=========================================================================== void SystemClock_Config(void) { // ... Your system clock configuration (e.g., HSI, HSE, PLL to 64MHz or 72MHz for F1) // Example for 64MHz from HSI PLL (common for F103 if no external crystal) RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2; // HSI is 8MHz, so 8/2 * 16 = 64MHz RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { /* Error_Handler(); */ } RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; // APB1 Max 36MHz RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; // APB2 Max 72MHz (or HCLK if less) if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { /* Error_Handler(); */ } // Latency 2 for >48MHz PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; // ADC clk = PCLK2/6 (e.g. 64/6 = ~10.6MHz, max 14MHz) if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { /* Error_Handler(); */ } } static void MX_GPIO_Init(void) { // Enable GPIO Clocks (e.g. __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); etc.) // Configure Hall Sensor Pins as Inputs (e.g., with pull-ups if needed) // Configure LED Pin as Output // Configure Buzzer Pin as Output // Configure PWM pins (TIM1_CH1, CH1N, CH2, CH2N, CH3, CH3N) - This is often done in MX_TIM1_Init's HAL_TIM_MspInit } static void MX_DMA_Init(void) { // __HAL_RCC_DMA1_CLK_ENABLE(); // Configure DMA for ADC (NVIC interrupts for DMA channel) // HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0); // High priority for ADC DMA // HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn); } static void MX_ADC1_Init(void) { // Configure ADC1: // - Clock prescaler // - Resolution (12-bit for F1) // - Data alignment (Right) // - ScanConvMode (Enable if multiple channels) // - ContinuousConvMode (Disable if triggered by timer) // - ExternalTrigConv (Set to TIM1_TRGO or similar PWM update event) // - DMAContinuousRequests (Enable) // - Configure ADC channels (rl1, rl2, dcl, batt1 - order must match adc_buf_t and DMA) // - Channel, Rank, SamplingTime // Example: // hadc1.Instance = ADC1; // ... set other parameters ... // if (HAL_ADC_Init(&hadc1) != HAL_OK) { /* Error_Handler(); */ } // ADC_ChannelConfTypeDef sConfig = {0}; // sConfig.Channel = ADC_CHANNEL_0; // Example for rl1 on PA0 // sConfig.Rank = ADC_REGULAR_RANK_1; // sConfig.SamplingTime = ADC_SAMPLETIME_7CYCLES_5; // Adjust as needed // if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { /* Error_Handler(); */ } // ... configure other channels ... } static void MX_TIM1_Init(void) { // Configure TIM1 for Center-Aligned PWM for 3-phase motor control: // - Prescaler, CounterMode (CenterAligned1/2/3), Period (pwm_timer_resolution - 1) // - ClockDivision // - RepetitionCounter (0) // - AutoReloadPreload (Enable) // Configure PWM Channels (CH1, CH2, CH3): // - Mode (PWM1/PWM2), Pulse (initially 0 or center), Polarity (High) // - Complementary Channel Config: NIdleState, NPolarity // Configure Break and DeadTime: // - OffStateRunMode/OffStateIDLEMode, LockLevel, DeadTime, BreakState, BreakPolarity, AutomaticOutput (Enable) // Configure Trigger Output (TRGO) for ADC synchronization (e.g., on Update Event) // Example: // htim1.Instance = TIM1; // ... // if (HAL_TIM_PWM_Init(&htim1) != HAL_OK) { /* Error_Handler(); */ } // TIM_MasterConfigTypeDef sMasterConfig = {0}; // sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE; // Trigger ADC on update // sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; // if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK) { /* Error_Handler(); */ } // ... configure PWM channels ... // ... configure BreakDeadTime ... } static void MX_TIM2_Init(void) { // Configure TIM2 as a basic timer for periodic interrupts (Speed Control Loop): // - Prescaler, CounterMode (Up), Period (to achieve SPEED_CONTROL_INTERVAL_MS) // - ClockDivision, AutoReloadPreload // Example calculation for period: // Target Freq = 1000 / SPEED_CONTROL_INTERVAL_MS (e.g., 100Hz for 10ms) // TIM2_CLK is typically PCLK1 (e.g., 32MHz if HCLK=64MHz, APB1_Div=2) // Prescaler = (TIM2_CLK / Target_Freq / Desired_Max_Period_Value_~65535) - 1 // Period = (TIM2_CLK / Prescaler+1 / Target_Freq) - 1 // Example: TIM2_CLK=32MHz, Interval=10ms (100Hz) // Prescaler = 319; Period = (32MHz / 320 / 100Hz) - 1 = 1000 - 1 = 999 // htim2.Instance = TIM2; // htim2.Init.Prescaler = 319; // Adjust for your PCLK1 // htim2.Init.Period = 999; // Adjust for your prescaler and PCLK1 // ... // if (HAL_TIM_Base_Init(&htim2) != HAL_OK) { /* Error_Handler(); */ } // Enable TIM2 interrupt in NVIC // HAL_NVIC_SetPriority(TIM2_IRQn, 1, 0); // Lower priority than ADC/PWM // HAL_NVIC_EnableIRQ(TIM2_IRQn); } void Error_Handler(void) { __disable_irq(); while (1) { // Indicate error, e.g., blink LED rapidly } } #ifdef USE_FULL_ASSERT void assert_failed(uint8_t *file, uint32_t line) { // User can add his own implementation to report the file name and line number // ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) } #endif /* USE_FULL_ASSERT */
05-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值