Esp wifi/fix wifi logs (#2117)
* Fix `wifi-logs` feature * Some clarifications in the esp-wifi migration guide * CHANGELOG.md * Review comments * Check more features
This commit is contained in:
parent
05941ccc37
commit
6295c5f9da
@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- esp-wifi now allocates memory from the global allocator provided by `esp-alloc` (#2099)
|
||||
|
||||
### Fixed
|
||||
- Feature `wifi-logs` doesn't break the build anymore (#2117)
|
||||
|
||||
### Removed
|
||||
|
||||
|
||||
@ -60,3 +60,31 @@ You now need to have a global allocator provided by `esp-alloc` providing alloca
|
||||
|
||||
// ...
|
||||
```
|
||||
|
||||
The size of the heap depends on what you are going to use esp-wifi for and if you are using the heap for your own allocations or not.
|
||||
|
||||
E.g. when using `coex` you need around 92k. If not using `coex`, going lower than 72k you will observe some failed allocations but it might still work. Going even lower will make things fail.
|
||||
|
||||
### Using your own allocator
|
||||
|
||||
You can also use your own allocator instead of using `esp-alloc`. To do that you need to opt-out of the default feature `esp-alloc` and provide two functions:
|
||||
|
||||
```rust
|
||||
#[no_mangle]
|
||||
pub extern "C" fn esp_wifi_free_internal_heap() -> usize {
|
||||
// return size of free allocatable RAM
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn esp_wifi_allocate_from_internal_ram(size: usize) -> *mut u8 {
|
||||
// allocate memory of size `size` from internal memory
|
||||
unsafe {
|
||||
core::alloc::alloc(
|
||||
esp_alloc::MemoryCapability::Internal.into(),
|
||||
core::alloc::Layout::from_size_align_unchecked(size, 4),
|
||||
)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
It's important to allocate from internal memory (i.e. not PSRAM)
|
||||
|
||||
@ -6,15 +6,19 @@ pub unsafe extern "C" fn syslog(_priority: u32, _format: *const u8, _args: VaLis
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(any(target_arch = "riscv32", all(target_arch = "xtensa", xtensa_has_vaarg)))]
|
||||
{
|
||||
extern "C" {
|
||||
fn vsnprintf(buffer: *mut u8, len: usize, fmt: *const u8, args: VaListImpl);
|
||||
}
|
||||
|
||||
let mut buf = [0u8; 512];
|
||||
vsnprintf(&mut buf as *mut u8, 512, _format, _args);
|
||||
let res_str = str_from_c(&buf as *const u8);
|
||||
info!("{}", res_str);
|
||||
let res_str = core::ffi::CStr::from_ptr(&buf as *const _ as *const i8);
|
||||
info!("{}", res_str.to_str().unwrap());
|
||||
}
|
||||
else
|
||||
{
|
||||
let res_str = str_from_c(_format);
|
||||
info!("{}", res_str);
|
||||
let res_str = core::ffi::CStr::from_ptr(_format as *const i8);
|
||||
info!("{}", res_str.to_str().unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2044,6 +2044,7 @@ impl PromiscuousPkt<'_> {
|
||||
}
|
||||
|
||||
#[cfg(feature = "sniffer")]
|
||||
#[allow(clippy::type_complexity)]
|
||||
static SNIFFER_CB: Mutex<RefCell<Option<fn(PromiscuousPkt)>>> = Mutex::new(RefCell::new(None));
|
||||
|
||||
#[cfg(feature = "sniffer")]
|
||||
|
||||
@ -1449,7 +1449,7 @@ pub unsafe extern "C" fn log_write(
|
||||
format: *const crate::binary::c_types::c_char,
|
||||
args: ...
|
||||
) {
|
||||
let args = core::mem::transmute(args);
|
||||
let args = core::mem::transmute::<core::ffi::VaListImpl<'_>, core::ffi::VaListImpl<'_>>(args);
|
||||
crate::compat::syslog::syslog(level, format as *const u8, args);
|
||||
}
|
||||
|
||||
@ -1477,6 +1477,9 @@ pub unsafe extern "C" fn log_writev(
|
||||
format: *const crate::binary::c_types::c_char,
|
||||
args: esp_wifi_sys::include::va_list,
|
||||
) {
|
||||
// annotations on transmute here would require different types for RISC-V and
|
||||
// Xtensa - so let's allow `missing_transmute_annotations` in this case
|
||||
#[allow(clippy::missing_transmute_annotations)]
|
||||
let args = core::mem::transmute(args);
|
||||
crate::compat::syslog::syslog(level, format as *const u8, args);
|
||||
}
|
||||
|
||||
@ -652,11 +652,12 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
|
||||
}
|
||||
|
||||
Package::EspWifi => {
|
||||
let mut features = format!("--features={chip},async,ps-min-modem,defmt");
|
||||
let mut features = format!(
|
||||
"--features={chip},async,ps-min-modem,defmt,dump-packets,wifi-logs"
|
||||
);
|
||||
|
||||
if device.contains("wifi") {
|
||||
features
|
||||
.push_str(",wifi-default,esp-now,embedded-svc,embassy-net,dump-packets")
|
||||
features.push_str(",wifi-default,esp-now,embedded-svc,embassy-net,sniffer")
|
||||
}
|
||||
if device.contains("bt") {
|
||||
features.push_str(",ble")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user